Skip to content

Commit

Permalink
Don't make expensive calls to setResizable except in the constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
sudara committed Aug 30, 2023
1 parent ad641c0 commit 1d43c79
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions melatonin/components/overlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ namespace melatonin

void resized() override
{
TRACE_COMPONENT();
if (outlinedComponent)
{
outlineComponent (outlinedComponent);
Expand Down
1 change: 1 addition & 0 deletions melatonin/components/properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace melatonin

void resized() override
{
TRACE_COMPONENT();
// let the property panel know what total height we need to be
panel.setBounds (getLocalBounds().withTrimmedTop (padding));
}
Expand Down
17 changes: 9 additions & 8 deletions melatonin_inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ namespace melatonin
setContentNonOwned (&inspectorComponent, true);
setupCallbacks();

setResizable (true, false); // calls resized
toggle (inspectorEnabledAtStart);
}

Expand Down Expand Up @@ -150,30 +151,30 @@ namespace melatonin
auto minWidth = inspectorEnabled ? 700 : 380;
auto minHeight = inspectorEnabled ? 800 : 400;

TRACE_EVENT_BEGIN ("component", "props getIntValue");
auto x = settings->props->getIntValue ("x", 0);
auto y = settings->props->getIntValue ("y", 0);
TRACE_EVENT_END ("component");

if (inspectorEnabled)
{
TRACE_EVENT_BEGIN ("component", "restore enabled bounds");
auto width = settings->props->getIntValue ("inspectorEnabledWidth", minWidth);
auto height = settings->props->getIntValue ("inspectorEnabledHeight", minHeight);
setResizable (true, false); // calls resized

// Note: Ideally we'd call setResizable but it recreates the desktop window
// which adds >30ms in Debug with little change of behavior
// setResizable (true, false);

setResizeLimits (minWidth, minHeight, 1200, 1200);
setBounds (x, y, width, height);
TRACE_EVENT_END ("component");
}
else
{
TRACE_EVENT_BEGIN ("component", "restore disabled bounds");
// decrease the resize limits first for the setSize call to work!
// the order of these calls matters a lot
setResizeLimits (minWidth, minHeight, minWidth, minHeight);
setBounds (x, y, minWidth, minHeight);
setResizable (false, false);
TRACE_EVENT_END ("component");

// Keep this commented out, as it will recreate the desktop window
// setResizable (false, false);
}

inspectorComponent.setBounds (getLocalBounds());
Expand Down

0 comments on commit 1d43c79

Please sign in to comment.