Skip to content

Commit b744b49

Browse files
authored
Merge pull request #82 from SLM-Audio/syl/gui-cleanup
GUI Cleanup
2 parents fc2232c + 98f1f35 commit b744b49

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

source/gui/mostlyharmless_WebviewBase.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ namespace mostly_harmless::gui {
187187
void create() {
188188
m_clientView = helpers::macos::createView(m_initialWidth, m_initialHeight);
189189
m_webview = std::make_unique<choc::ui::WebView>(m_options);
190-
helpers::macos::setViewSize(m_clientView, m_initialWidth, m_initialHeight);
191190
}
192191

193192
void destroy() {
@@ -198,9 +197,8 @@ namespace mostly_harmless::gui {
198197
helpers::macos::getViewSize(m_clientView, width, height);
199198
}
200199

201-
void setSize(std::uint32_t width, std::uint32_t height) {
202-
helpers::macos::setViewSize(m_clientView, width, height);
203-
helpers::macos::setViewSize(m_webview->getViewHandle(), width, height);
200+
void setSize(std::uint32_t /*width*/, std::uint32_t /*height*/) {
201+
// Because we're using autolayout and autoresizemask on macOS, this is handled already via the config in setParent
204202
}
205203

206204
void setParent(void* parentHandle) {

source/gui/platform/mostlyharmless_GuiHelpersMacOS.mm

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ void getViewSize(void* viewHandle, std::uint32_t* width, std::uint32_t* height)
3333
}
3434

3535
void reparentView(void* hostViewHandle, void* clientViewHandle, void* childViewHandle, Colour backgroundColour) {
36-
createView(0, 0);
3736
auto* host = static_cast<NSView*>(hostViewHandle);
3837
auto* client = static_cast<NSView*>(clientViewHandle);
3938
auto* child = static_cast<NSView*>(childViewHandle);
@@ -45,6 +44,15 @@ void reparentView(void* hostViewHandle, void* clientViewHandle, void* childViewH
4544
CGFloat f32B = static_cast<CGFloat>(b) / 255.0f;
4645
auto* color = [NSColor colorWithCalibratedRed:f32R green:f32G blue:f32B alpha:1];
4746
[[client layer] setBackgroundColor:color.CGColor];
47+
host.autoresizesSubviews = YES;
48+
host.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
49+
host.translatesAutoresizingMaskIntoConstraints = true;
50+
client.autoresizesSubviews = YES;
51+
client.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
52+
client.translatesAutoresizingMaskIntoConstraints = true;
53+
child.autoresizesSubviews = YES;
54+
child.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
55+
child.translatesAutoresizingMaskIntoConstraints = true;
4856
client.frame = host.bounds;
4957
child.frame = host.bounds;
5058
[client addSubview:child];

source/mostlyharmless_PluginBase.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ namespace mostly_harmless::internal {
2525
_host.paramsRescan(CLAP_PARAM_RESCAN_VALUES);
2626
},
2727
.requestGuiResize = [this](std::uint32_t width, std::uint32_t height) -> bool {
28-
return _host.guiRequestResize(width, height);
28+
if (!_host.guiRequestResize(width, height)) {
29+
return false;
30+
}
31+
if (!guiAdjustSize(&width, &height)) {
32+
return false;
33+
}
34+
return guiSetSize(width, height);
2935
}
3036
};
3137
m_state = m_pluginEntry->createState(std::move(context));
@@ -433,7 +439,6 @@ namespace mostly_harmless::internal {
433439
bool PluginBase::guiAdjustSize(std::uint32_t* width, std::uint32_t* height) noexcept {
434440
MH_LOG("GUI: guiAdjustSize()");
435441
if (!m_editor) return false;
436-
if (!m_editor->allowResize()) return false;
437442
m_editor->onResizeRequested(width, height);
438443
return true;
439444
}

0 commit comments

Comments
 (0)