Skip to content

Commit

Permalink
Merge pull request #2027 from alcomposer/fix-split-inspector
Browse files Browse the repository at this point in the history
Split inspector fixes:
  • Loading branch information
timothyschoen authored Dec 25, 2024
2 parents aa8ec6f + 060f393 commit d27793b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 23 deletions.
8 changes: 8 additions & 0 deletions Source/Components/Buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ class ToolbarRadioButton final : public TextButton {
class SmallIconButton : public TextButton {
using TextButton::TextButton;

bool hitTest(int x, int y) override
{
if (getLocalBounds().reduced(2).contains(x, y))
return true;

return false;
}

void mouseEnter(MouseEvent const& e) override
{
repaint();
Expand Down
5 changes: 5 additions & 0 deletions Source/Sidebar/Inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ class Inspector final : public Component {
loadParameters(properties);
}

bool isEmpty()
{
return properties.empty();
}

bool loadParameters(SmallArray<ObjectParameters, 6>& objectParameters)
{
properties = objectParameters;
Expand Down
46 changes: 23 additions & 23 deletions Source/Sidebar/Sidebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,6 @@ void Sidebar::paint(Graphics& g)
if (!sidebarHidden) {
g.setColour(findColour(PlugDataColour::sidebarBackgroundColourId));
g.fillRect(0, 30, getWidth(), getHeight());
}
}

void Sidebar::paintOverChildren(Graphics& g)
{
g.setColour(findColour(PlugDataColour::toolbarOutlineColourId));
g.drawLine(0.5f, 30, 0.5f, getHeight() + 0.5f);

g.drawLine(dividerBounds.getX() + 4, dividerBounds.getCentreY(), dividerBounds.getRight() - 4, dividerBounds.getCentreY());

if (!sidebarHidden) {
g.drawLine(0, 30, getWidth(), 30);

g.setColour(findColour(PlugDataColour::toolbarOutlineColourId).withAlpha(0.5f));
g.drawLine(getWidth() - 30, 30, getWidth() - 30, getHeight() + 0.5f);

auto panelName = panelNames[currentPanel];
if (inspectorButton.isInspectorAuto() && inspector->isVisible())
Expand All @@ -131,7 +116,7 @@ void Sidebar::paintOverChildren(Graphics& g)

if (inspectorButton.isInspectorPinned()) {
auto inpectorPos = Point<int>(0, dividerFactor * getHeight());
if(!inspector->isVisible()) inpectorPos.setY(getHeight() - 30);
if (inspector->isEmpty()) inpectorPos.setY(getHeight() - 30);
g.setColour(findColour(PlugDataColour::sidebarActiveBackgroundColourId));
g.fillRect(inpectorPos.x, inpectorPos.y, getWidth() - 30, 30);
auto inspectorTitle = inspector->getTitle();
Expand All @@ -142,6 +127,21 @@ void Sidebar::paintOverChildren(Graphics& g)
}
}

void Sidebar::paintOverChildren(Graphics& g)
{
g.setColour(findColour(PlugDataColour::toolbarOutlineColourId));
g.drawLine(0.5f, 30, 0.5f, getHeight() + 0.5f);

g.drawLine(dividerBounds.getX() + 4, dividerBounds.getCentreY(), dividerBounds.getRight() - 4, dividerBounds.getCentreY());

if (!sidebarHidden) {
g.drawLine(0, 30, getWidth(), 30);

g.setColour(findColour(PlugDataColour::toolbarOutlineColourId).withAlpha(0.5f));
g.drawLine(getWidth() - 30, 30, getWidth() - 30, getHeight() + 0.5f);
}
}

void Sidebar::settingsChanged(String const& name, var const& value)
{
if (name == "centre_sidepanel_buttons") {
Expand Down Expand Up @@ -192,15 +192,15 @@ void Sidebar::resized()
}
inspector->setBounds(bounds);
} else {
auto bottomB = bounds.removeFromBottom(dividerPos);
auto bottomB = bounds.removeFromBottom(inspector->isEmpty() ? 30 : dividerPos);
auto resetB = bottomB.removeFromTop(30);
inspector->setBounds(bottomB);
auto const resetBounds = resetB.removeFromLeft(30);
if (extraSettingsButton)
extraSettingsButton->setVisible(true);
if (resetInspectorButton) {
resetInspectorButton->setBounds(resetBounds);
resetInspectorButton->setVisible(true);
resetInspectorButton->setVisible(!inspector->isEmpty());
}
}
} else {
Expand Down Expand Up @@ -241,7 +241,7 @@ void Sidebar::mouseDrag(MouseEvent const& e)

setBounds(getParentWidth() - newWidth, getY(), newWidth, getHeight());
getParentComponent()->resized();
} else if (isDraggingDivider) {
} else if (isDraggingDivider && !inspector->isEmpty()) {
auto const newDividerY = static_cast<float>(jlimit(30, getHeight() - 30, e.getEventRelativeTo(this).getPosition().y - dragOffset));
dividerFactor = newDividerY / getHeight();
resized();
Expand All @@ -266,7 +266,7 @@ void Sidebar::mouseMove(MouseEvent const& e)

if (resizeCursor)
e.originalComponent->setMouseCursor(MouseCursor::LeftRightResizeCursor);
else if (inspectorButton.isInspectorPinned() && resizeVertical) {
else if (inspectorButton.isInspectorPinned() && resizeVertical && !inspector->isEmpty() && e.getPosition().getX() < (getWidth() - 30)) {
isDraggingDivider = true;
e.originalComponent->setMouseCursor(MouseCursor::UpDownResizeCursor);
} else
Expand Down Expand Up @@ -331,7 +331,7 @@ void Sidebar::showPanel(SidePanel const panelToShow)
break;
case SidePanel::InspectorPan:
if (!sidebarHidden) {
auto const isVisible = (inspectorButton.isInspectorPinned() || inspectorButton.isInspectorAuto()) && lastParameters.not_empty();
auto const isVisible = (inspectorButton.isInspectorPinned() || (inspectorButton.isInspectorAuto() && !inspector->isEmpty()));
if (!areParamObjectsAllValid()) {
clearInspector();
}
Expand Down Expand Up @@ -455,7 +455,7 @@ void Sidebar::showParameters(SmallArray<Component*>& objects, SmallArray<ObjectP

auto const haveParams = showOnSelect && params.not_empty() && activeParams;

auto const isVis = (inspectorButton.isInspectorAuto() || inspectorButton.isInspectorPinned()) && params.not_empty() && showOnSelect && activeParams;
auto const isVis = (inspectorButton.isInspectorAuto() && params.not_empty() && showOnSelect && activeParams) || inspectorButton.isInspectorPinned();

// Reset console notifications if the inspector is not visible and console is
if (!isVis && currentPanel == SidePanel::ConsolePan) {
Expand Down Expand Up @@ -526,7 +526,7 @@ void Sidebar::updateExtraSettingsButton()

void Sidebar::hideParameters()
{
if (inspectorButton.isInspectorAuto() || inspectorButton.isInspectorPinned()) {
if (inspectorButton.isInspectorAuto()) {
inspector->setVisible(false);
}

Expand Down

0 comments on commit d27793b

Please sign in to comment.