Skip to content

Commit 7b046dc

Browse files
committed
Fix bugs for new sidebar system
1 parent 8086f95 commit 7b046dc

4 files changed

Lines changed: 39 additions & 30 deletions

File tree

Source/Sidebar/CommandInput.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ class CommandInput final
570570
}
571571
case hash("clear"): {
572572
commandHistory.clear();
573-
// editor->console->clear(); // TODO: sidepanel update
573+
editor->consolePanel->clear();
574574
if (auto* cnv = getCurrentCanvas()) {
575575
cnv->deselectAll();
576576
cnv->updateSidebarSelection();

Source/Sidebar/Inspector.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ class Inspector final : public Component {
8383
};
8484

8585
PropertiesPanel panel;
86-
Label emptyLabel;
8786
TextButton resetButton;
8887
SmallArray<ObjectParameters, 6> properties;
8988
PropertyRedirector redirector;
@@ -97,19 +96,13 @@ class Inspector final : public Component {
9796
panel.setDrawShadowAndOutline(false);
9897
addAndMakeVisible(panel);
9998

100-
emptyLabel.setText("(no object selected)", dontSendNotification);
101-
emptyLabel.setJustificationType(Justification::centred);
102-
emptyLabel.setInterceptsMouseClicks(false, false);
103-
addAndMakeVisible(emptyLabel);
104-
10599
lookAndFeelChanged();
106100
}
107101

108102
void lookAndFeelChanged() override
109103
{
110104
panel.setSeparatorColour(PlugDataColour::sidebarBackgroundColourId);
111105
panel.setPanelColour(PlugDataColour::sidebarActiveBackgroundColourId);
112-
emptyLabel.setColour(Label::textColourId, PlugDataColours::sidebarTextColour.withAlpha(0.55f));
113106
}
114107

115108
void visibilityChanged() override
@@ -125,7 +118,6 @@ class Inspector final : public Component {
125118
void resized() override
126119
{
127120
panel.setBounds(getLocalBounds().withTrimmedTop(2));
128-
emptyLabel.setBounds(getLocalBounds().reduced(12));
129121
resetButton.setTopLeftPosition(getLocalBounds().withTrimmedRight(23).getRight(), 0);
130122

131123
panel.setContentWidth(getWidth() - 16);
@@ -176,7 +168,6 @@ class Inspector final : public Component {
176168
{
177169
bool const empty = panel.isEmpty();
178170
panel.setVisible(!empty);
179-
emptyLabel.setVisible(empty);
180171
repaint();
181172
}
182173

Source/Sidebar/Sidebar.cpp

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,17 @@ void Sidebar::addPanel(SidePanel panel)
173173
rebuildPanelTable();
174174
updateSelectorButtonStates();
175175

176-
// If this is the first panel on this sidebar, make it active.
177176
if (!hasCurrentPanel && panel != InspectorPanel) {
178177
currentPanel = panel;
179178
hasCurrentPanel = true;
180179
if (auto* btn = getSelectorButton(panel))
181180
btn->setToggleState(true, dontSendNotification);
182-
if (auto* p = getPanelComponent(panel))
183-
p->setVisible(!sidebarHidden);
184181
}
185182

183+
for(auto& entry : panelTable)
184+
entry.panel->setVisible(entry.id == currentPanel && !sidebarHidden);
185+
186+
updateCommandInputVisibility();
186187
updateExtraSettingsButton();
187188
resized();
188189
repaint();
@@ -233,6 +234,7 @@ void Sidebar::removePanel(SidePanel panel)
233234
rebuildPanelTable();
234235
updateSelectorButtonStates();
235236
updateExtraSettingsButton();
237+
updateCommandInputVisibility();
236238
resized();
237239
repaint();
238240
}
@@ -328,6 +330,12 @@ void Sidebar::paintOverChildren(Graphics& g)
328330
g.drawLine(getWidth() - 0.5f, 30, getWidth() - 0.5f, getHeight() + 0.5f);
329331
}
330332
g.drawLine(0, 30, getWidth(), 30);
333+
334+
if(currentPanel == InspectorPanel && !inspectorPtr->isVisible())
335+
{
336+
g.setColour(PlugDataColours::sidebarTextColour.withAlpha(0.55f));
337+
g.drawText("(no object selected)", getLocalBounds().withTrimmedTop(40), Justification::centredTop);
338+
}
331339
}
332340

333341
int Sidebar::getCommandInputHeight()
@@ -371,11 +379,13 @@ void Sidebar::resized()
371379

372380
if (commandInputPtr && commandInputPtr->isVisible()
373381
&& commandInputPtr->getParentComponent() == this) {
382+
auto commandInputHeight = getCommandInputHeight();
374383
commandInputPtr->setBounds(getLocalBounds()
375-
.removeFromBottom(getCommandInputHeight())
384+
.removeFromBottom(commandInputHeight)
376385
.reduced(8)
377386
.withTrimmedLeft(side == Side::Left ? 30 : 0)
378387
.withTrimmedRight(side == Side::Right ? 30 : 0));
388+
bounds.removeFromBottom(commandInputHeight);
379389
}
380390

381391
bounds.removeFromTop(30);
@@ -515,6 +525,24 @@ bool Sidebar::refreshInspectorVisibility(bool const allowManualShow)
515525
return shouldShow;
516526
}
517527

528+
void Sidebar::updateCommandInputVisibility()
529+
{
530+
auto const wantsCmd = (currentPanel == ConsolePanel) || (hasPanel(ConsolePanel) && inspectorAutoShow && currentPanel == InspectorPanel);
531+
if (commandInputPtr) {
532+
if (wantsCmd && hasPanel(currentPanel)) {
533+
if (commandInputPtr->getParentComponent() != this) {
534+
if (commandInputPtr->getParentComponent())
535+
commandInputPtr->getParentComponent()->removeChildComponent(commandInputPtr);
536+
addAndMakeVisible(commandInputPtr);
537+
} else {
538+
commandInputPtr->setVisible(true);
539+
}
540+
} else if (commandInputPtr->getParentComponent() == this) {
541+
commandInputPtr->setVisible(false);
542+
}
543+
}
544+
}
545+
518546
void Sidebar::showPanel(SidePanel const panelToShow)
519547
{
520548
// Toggle off if clicking the already-active panel
@@ -542,6 +570,7 @@ void Sidebar::showPanel(SidePanel const panelToShow)
542570
refreshInspectorVisibility(true);
543571
}
544572

573+
updateCommandInputVisibility();
545574
updateExtraSettingsButton();
546575
resized();
547576
repaint();
@@ -571,22 +600,6 @@ void Sidebar::showPanel(SidePanel const panelToShow)
571600
updateSelectorButtonStates();
572601
};
573602

574-
// CommandInput belongs to the Console panel.
575-
auto const wantsCmd = (panelToShow == ConsolePanel);
576-
if (commandInputPtr) {
577-
if (wantsCmd && hasPanel(panelToShow)) {
578-
if (commandInputPtr->getParentComponent() != this) {
579-
if (commandInputPtr->getParentComponent())
580-
commandInputPtr->getParentComponent()->removeChildComponent(commandInputPtr);
581-
addAndMakeVisible(commandInputPtr);
582-
} else {
583-
commandInputPtr->setVisible(true);
584-
}
585-
} else if (commandInputPtr->getParentComponent() == this) {
586-
commandInputPtr->setVisible(false);
587-
}
588-
}
589-
590603
switch (panelToShow) {
591604
case ConsolePanel:
592605
if (hasPanel(ConsolePanel))
@@ -624,6 +637,7 @@ void Sidebar::showPanel(SidePanel const panelToShow)
624637
break;
625638
}
626639

640+
updateCommandInputVisibility();
627641
updateExtraSettingsButton();
628642
resized();
629643
repaint();
@@ -773,6 +787,7 @@ void Sidebar::showParameters(SmallArray<Component*>& objects, SmallArray<ObjectP
773787
if (!shouldShowInspector && !inspectorAutoShow)
774788
inspectorManuallyShown = false;
775789

790+
updateCommandInputVisibility();
776791
updateSelectorButtonStates();
777792
updateExtraSettingsButton();
778793
resized();
@@ -789,6 +804,7 @@ void Sidebar::hideParameters()
789804
if (consolePanelPtr && hasPanel(ConsolePanel))
790805
consolePanelPtr->deselect();
791806

807+
updateCommandInputVisibility();
792808
updateSelectorButtonStates();
793809
updateExtraSettingsButton();
794810
resized();

Source/Sidebar/Sidebar.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ class Sidebar final : public Component {
171171

172172
void renderButtonsOnCanvas(NVGcontext* ctx);
173173

174+
void updateCommandInputVisibility();
175+
174176
static constexpr int dragbarWidth = 6;
175177

176178
static String panelIdToString(SidePanel id);

0 commit comments

Comments
 (0)