Skip to content

Commit 2a6997c

Browse files
committed
feat: implement window state management
1 parent b7356ba commit 2a6997c

3 files changed

Lines changed: 61 additions & 3 deletions

File tree

src/app/PluginEditor.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ PluginEditor::PluginEditor(PluginProcessor& p)
1313
0.5f,
1414
2.0f,
1515
16.0f / 9.0f,
16-
64.0f / 9.0f },
16+
64.0f / 9.0f,
17+
700,
18+
360 },
1719
[&p](dmt::gui::window::Layout& layout) {
1820
layout.addPanel<dmt::gui::panel::OscilloscopePanel<float>>(
1921
0, 0, 1, 1, p.oscilloscopeBuffer, p.apvts);

src/dmt/app/AbstractPluginEditor.h

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class AbstractPluginEditor
4040
float maxSizeMultiplier = 2.0f;
4141
float minAspectRatio = 0.5f;
4242
float maxAspectRatio = 2.0f;
43+
int dynamicStartWidth = -1;
44+
int dynamicStartHeight = -1;
4345
};
4446

4547
// Custom constrainer that enforces aspect ratio bounds (min/max aspect
@@ -178,8 +180,29 @@ class AbstractPluginEditor
178180
}
179181
setResizable(false, true);
180182

181-
const auto startWidth = baseWidth * sizeFactor;
182-
const auto startHeight = (baseHeight + headerHeight) * sizeFactor;
183+
// Resolve initial window size using priority order
184+
int initialWidth = baseWidth;
185+
int initialHeight = baseHeight + headerHeight;
186+
187+
// Priority 1: Check for saved window state
188+
int savedWidth = p.getSavedWindowWidth();
189+
int savedHeight = p.getSavedWindowHeight();
190+
if (savedWidth > 0 && savedHeight > 0) {
191+
initialWidth = savedWidth;
192+
initialHeight = savedHeight;
193+
isHeaderHidden = p.getSavedHeaderHiddenState();
194+
}
195+
// Priority 2: Use dynamic start dimensions if in dynamic mode
196+
else if (windowMode == WindowMode::Dynamic &&
197+
_windowConfig.dynamicStartWidth > 0 &&
198+
_windowConfig.dynamicStartHeight > 0) {
199+
initialWidth = _windowConfig.dynamicStartWidth;
200+
initialHeight = _windowConfig.dynamicStartHeight;
201+
}
202+
// Priority 3: Use base dimensions (default, already set above)
203+
204+
const auto startWidth = initialWidth * sizeFactor;
205+
const auto startHeight = initialHeight * sizeFactor;
183206
setSize(startWidth, startHeight);
184207

185208
// Set the callback for header visibility changes
@@ -297,6 +320,7 @@ class AbstractPluginEditor
297320

298321
void handleHeaderVisibilityChange(bool isHeaderVisible)
299322
{
323+
isHeaderHidden = !isHeaderVisible;
300324
const int adjustedHeight =
301325
isHeaderVisible ? baseHeight + headerHeight : baseHeight;
302326

@@ -320,6 +344,9 @@ class AbstractPluginEditor
320344
setConstraints(baseWidth, adjustedHeight);
321345
setSize(baseWidth * sizeFactor, adjustedHeight * sizeFactor);
322346
}
347+
348+
// Save the header visibility state
349+
p.saveWindowState(getWidth(), getHeight(), isHeaderHidden);
323350
}
324351

325352
dmt::gui::window::Layout& getMainLayout() { return mainLayout; }
@@ -383,6 +410,9 @@ class AbstractPluginEditor
383410
compositor.setBounds(getLocalBounds());
384411
compositorAttached = true;
385412
repaint();
413+
414+
// Save the current window state after size correction
415+
p.saveWindowState(getWidth(), getHeight(), isHeaderHidden);
386416
}
387417
}
388418

@@ -479,6 +509,7 @@ class AbstractPluginEditor
479509
float maxSizeMultiplier = 2.0f;
480510
float minAspectRatio = 0.5f;
481511
float maxAspectRatio = 2.0f;
512+
bool isHeaderHidden = false;
482513
int lastWidth = baseWidth;
483514
int lastHeight = baseHeight;
484515
double ratio = baseWidth / baseHeight;

src/dmt/app/AbstractPluginProcessor.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,31 @@ class AbstractPluginProcessor : public juce::AudioProcessor
158158
float getSizeFactor() const { return sizeFactor; }
159159
void setSizeFactor(float newSize) { sizeFactor = newSize; }
160160

161+
//==============================================================================
162+
// Window State Management
163+
164+
void saveWindowState(int width, int height, bool isHeaderHidden)
165+
{
166+
apvts.state.setProperty("windowWidth", width, nullptr);
167+
apvts.state.setProperty("windowHeight", height, nullptr);
168+
apvts.state.setProperty("isHeaderHidden", isHeaderHidden, nullptr);
169+
}
170+
171+
int getSavedWindowWidth() const
172+
{
173+
return static_cast<int>(apvts.state.getProperty("windowWidth", -1));
174+
}
175+
176+
int getSavedWindowHeight() const
177+
{
178+
return static_cast<int>(apvts.state.getProperty("windowHeight", -1));
179+
}
180+
181+
bool getSavedHeaderHiddenState() const
182+
{
183+
return static_cast<bool>(apvts.state.getProperty("isHeaderHidden", false));
184+
}
185+
161186
//==============================================================================
162187
private:
163188
#if PERFETTO

0 commit comments

Comments
 (0)