From 99ee10bd0558fd49bc383a666b060f8b40ae388e Mon Sep 17 00:00:00 2001 From: Timothy Schoen Date: Tue, 3 Oct 2023 21:51:16 +0200 Subject: [PATCH] Fixed object browser bugs, made object reference panel slightly better --- Source/Dialogs/Deken.h | 2 +- Source/Dialogs/Dialogs.cpp | 4 +- Source/Dialogs/ObjectBrowserDialog.h | 24 ++++++++-- Source/Dialogs/ObjectReferenceDialog.h | 62 +++++++++++++++++++------- 4 files changed, 69 insertions(+), 23 deletions(-) diff --git a/Source/Dialogs/Deken.h b/Source/Dialogs/Deken.h index b28560337..4ce1bd971 100644 --- a/Source/Dialogs/Deken.h +++ b/Source/Dialogs/Deken.h @@ -681,7 +681,7 @@ class Deken : public Component listBox.setBounds(getLocalBounds().withHeight(listBox.getHeight())); listBox.getViewport()->setBounds(bounds); - refreshButton.setBounds(getLocalBounds().removeFromTop(40).removeFromLeft(40)); + refreshButton.setBounds(getLocalBounds().removeFromTop(40).removeFromLeft(40).translated(2, 0)); } // Show error message in statusbar diff --git a/Source/Dialogs/Dialogs.cpp b/Source/Dialogs/Dialogs.cpp index 797af3cd0..5d67ecf16 100644 --- a/Source/Dialogs/Dialogs.cpp +++ b/Source/Dialogs/Dialogs.cpp @@ -218,7 +218,7 @@ void Dialogs::showHeavyExportDialog(std::unique_ptr* target, Component* void Dialogs::showObjectBrowserDialog(std::unique_ptr* target, Component* parent) { - auto* dialog = new Dialog(target, parent, 750, 450, true); + auto* dialog = new Dialog(target, parent, 750, 480, true); auto* dialogContent = new ObjectBrowserDialog(parent, dialog); dialog->setViewedComponent(dialogContent); @@ -227,7 +227,7 @@ void Dialogs::showObjectBrowserDialog(std::unique_ptr* target, Component void Dialogs::showObjectReferenceDialog(std::unique_ptr* target, Component* parent, String const& objectName) { - auto* dialog = new Dialog(target, parent, 750, 450, true); + auto* dialog = new Dialog(target, parent, 750, 480, true); auto* dialogContent = new ObjectReferenceDialog(dynamic_cast(parent), false); dialogContent->showObject(objectName); diff --git a/Source/Dialogs/ObjectBrowserDialog.h b/Source/Dialogs/ObjectBrowserDialog.h index 094de4917..1944c65f2 100644 --- a/Source/Dialogs/ObjectBrowserDialog.h +++ b/Source/Dialogs/ObjectBrowserDialog.h @@ -253,9 +253,10 @@ class ObjectViewer : public Component { buttonBounds.removeFromTop(5); openHelp.setBounds(buttonBounds.removeFromTop(25)); - objectDragArea.setBounds(getLocalBounds().withTrimmedTop(48).withTrimmedBottom(130).withTrimmedLeft(12).withTrimmedRight(6)); + objectDragArea.setBounds(getLocalBounds().withTrimmedTop(48).withTrimmedBottom(120).withTrimmedLeft(12).withTrimmedRight(6)); } + void paintOverChildren(Graphics& g) override { g.setColour(findColour(PlugDataColour::outlineColourId)); @@ -268,7 +269,7 @@ class ObjectViewer : public Component { auto objectDisplayBounds = infoBounds.removeFromTop(100).reduced(60); auto colour = findColour(PlugDataColour::panelTextColourId); - Fonts::drawStyledText(g, objectName, getLocalBounds().removeFromTop(35).translated(0, 4), colour, Bold, 16.0f, Justification::centred); + Fonts::drawStyledText(g, objectName, getLocalBounds().removeFromTop(24).translated(0, 4), colour, Bold, 16.0f, Justification::centred); auto numInlets = unknownInletLayout ? "Unknown" : String(inlets.size()); auto numOutlets = unknownOutletLayout ? "Unknown" : String(outlets.size()); @@ -688,7 +689,7 @@ class ObjectSearchComponent : public Component input.setBounds(inputBounds); - clearButton.setBounds(inputBounds.removeFromRight(32)); + clearButton.setBounds(inputBounds.removeFromRight(30).translated(4, 0)); listBox.setBounds(tableBounds); } @@ -812,7 +813,7 @@ class ObjectBrowserDialog : public Component { void resized() override { - auto b = getLocalBounds().reduced(1); + auto b = getLocalBounds().withTrimmedTop(40).reduced(1); objectViewer.setBounds(b.removeFromRight(260)); objectSearch.setBounds(b); b.removeFromTop(35); @@ -827,6 +828,21 @@ class ObjectBrowserDialog : public Component { { g.setColour(findColour(PlugDataColour::panelBackgroundColourId)); g.fillRoundedRectangle(getLocalBounds().reduced(1).toFloat(), Corners::windowCornerRadius); + + g.setColour(findColour(PlugDataColour::panelBackgroundColourId)); + g.fillRoundedRectangle(getLocalBounds().reduced(1).toFloat(), Corners::windowCornerRadius); + + g.setColour(findColour(PlugDataColour::toolbarBackgroundColourId)); + + auto toolbarBounds = Rectangle(1, 1, getWidth() - 2, 40); + g.fillRoundedRectangle(toolbarBounds, Corners::windowCornerRadius); + g.fillRect(toolbarBounds.withTrimmedTop(15.0f)); + + g.setColour(findColour(PlugDataColour::toolbarOutlineColourId)); + g.drawHorizontalLine(40, 0.0f, getWidth()); + g.drawHorizontalLine(70, 0.0f, getWidth()); + + Fonts::drawStyledText(g, "Object Browser", Rectangle(0.0f, 4.0f, getWidth(), 32.0f), findColour(PlugDataColour::panelTextColourId), Semibold, 15, Justification::centred); } private: diff --git a/Source/Dialogs/ObjectReferenceDialog.h b/Source/Dialogs/ObjectReferenceDialog.h index 63aeb547f..56a44161f 100644 --- a/Source/Dialogs/ObjectReferenceDialog.h +++ b/Source/Dialogs/ObjectReferenceDialog.h @@ -23,19 +23,21 @@ class ObjectInfoPanel : public Component { g.setColour(findColour(PlugDataColour::outlineColourId)); g.drawLine(0, 1, getWidth(), 0); - Fonts::drawStyledText(g, categoryName, getLocalBounds().toFloat().removeFromTop(24), findColour(PlugDataColour::panelTextColourId), FontStyle::Bold, 14.0f); + Fonts::drawStyledText(g, categoryName, getLocalBounds().toFloat().removeFromTop(24).translated(2, 0), findColour(PlugDataColour::panelTextColourId), FontStyle::Bold, 14.0f); float totalHeight = 24; for (int i = 0; i < panelContent.size(); i++) { auto textHeight = layouts[i].getHeight(); - auto bounds = Rectangle(24.0f, totalHeight + 6.0f, getWidth() - 48.0f, textHeight); - - Fonts::drawStyledText(g, panelContent[i].first, bounds.removeFromLeft(128), findColour(PlugDataColour::panelTextColourId), FontStyle::Semibold, 13.5f); + + auto bounds = Rectangle(36.0f, totalHeight + 6.0f, getWidth() - 48.0f, textHeight); + auto nameWidth = std::max(Fonts::getSemiBoldFont().getStringWidth(panelContent[i].first), 64); + + Fonts::drawStyledText(g, panelContent[i].first, bounds.removeFromLeft(nameWidth), findColour(PlugDataColour::panelTextColourId), FontStyle::Semibold, 13.5f); layouts[i].draw(g, bounds); g.setColour(findColour(PlugDataColour::outlineColourId)); - g.drawLine(24.0f, totalHeight, getWidth() - 24.0f, totalHeight); + g.drawLine(36.0f, totalHeight, getWidth() - 24.0f, totalHeight); totalHeight += textHeight + 12; } @@ -47,10 +49,27 @@ class ObjectInfoPanel : public Component { int totalHeight = 24; for (auto const& [name, description] : panelContent) { + auto nameWidth = std::max(Fonts::getSemiBoldFont().getStringWidth(name), 64); + AttributedString str; - str.append(description, Font(13.5f), findColour(PlugDataColour::panelTextColourId)); + + auto lines = StringArray::fromLines(description); + + // Draw anything between () as bold + for (auto const& line : lines) { + if (line.contains("(") && line.contains(")")) { + auto type = line.fromFirstOccurrenceOf("(", false, false).upToFirstOccurrenceOf(")", false, false); + auto description = line.fromFirstOccurrenceOf(")", false, false); + str.append(type + ":", Fonts::getSemiBoldFont().withHeight(13.5f), findColour(PlugDataColour::panelTextColourId)); + + str.append(description + "\n", Font(13.5f), findColour(PlugDataColour::panelTextColourId)); + } else { + str.append(line, Font(13.5f), findColour(PlugDataColour::panelTextColourId)); + } + } + TextLayout layout; - layout.createLayout(str, width - 192.0f); + layout.createLayout(str, width - (nameWidth + 64.0f)); layouts.add(layout); totalHeight += layout.getHeight() + 12; } @@ -162,7 +181,7 @@ class ObjectInfoPanel : public Component { { categoriesViewport.setBounds(getLocalBounds()); - int totalHeight = 0; + int totalHeight = 24; for (auto* category : categories) { category->recalculateLayout(getWidth()); category->setTopLeftPosition(0, totalHeight); @@ -203,12 +222,9 @@ class ObjectReferenceDialog : public Component { void resized() override { - backButton.setBounds(8, 6, 40, 40); - - auto buttonBounds = getLocalBounds().removeFromBottom(80).reduced(30, 0).translated(0, -30); - buttonBounds.removeFromTop(10); + backButton.setBounds(2, 0, 40, 40); - auto rightPanelBounds = getLocalBounds().removeFromRight(getLocalBounds().proportionOfWidth(0.7f)).reduced(20, 40); + auto rightPanelBounds = getLocalBounds().withTrimmedTop(40).removeFromRight(getLocalBounds().proportionOfWidth(0.65f)).reduced(20, 0); objectInfoPanel.setBounds(rightPanelBounds); } @@ -217,16 +233,30 @@ class ObjectReferenceDialog : public Component { { g.setColour(findColour(PlugDataColour::panelBackgroundColourId)); g.fillRoundedRectangle(getLocalBounds().reduced(1).toFloat(), Corners::windowCornerRadius); + + g.setColour(findColour(PlugDataColour::panelBackgroundColourId)); + g.fillRoundedRectangle(getLocalBounds().reduced(1).toFloat(), Corners::windowCornerRadius); + + g.setColour(findColour(PlugDataColour::toolbarBackgroundColourId)); + + auto toolbarBounds = Rectangle(1, 1, getWidth() - 2, 40); + g.fillRoundedRectangle(toolbarBounds, Corners::windowCornerRadius); + g.fillRect(toolbarBounds.withTrimmedTop(15.0f)); + g.setColour(findColour(PlugDataColour::toolbarOutlineColourId)); + g.drawHorizontalLine(40, 0.0f, getWidth()); + if (objectName.isEmpty()) return; - auto leftPanelBounds = getLocalBounds().withTrimmedRight(getLocalBounds().proportionOfWidth(0.7f)); + auto leftPanelBounds = getLocalBounds().withTrimmedRight(getLocalBounds().proportionOfWidth(0.65f)); - auto infoBounds = leftPanelBounds.withTrimmedBottom(100).withTrimmedTop(100).withTrimmedLeft(5).reduced(10); + g.drawVerticalLine(leftPanelBounds.getRight(), 40.0f, getHeight() - 40.0f); + + auto infoBounds = leftPanelBounds.withTrimmedBottom(100).withTrimmedTop(140).withTrimmedLeft(5).reduced(10); auto objectDisplayBounds = leftPanelBounds.removeFromTop(140); - Fonts::drawStyledText(g, "Reference: " + objectName, getLocalBounds().removeFromTop(35).translated(0, 4), findColour(PlugDataColour::panelTextColourId), Bold, 16, Justification::centred); + Fonts::drawStyledText(g, "Object Reference: " + objectName, getLocalBounds().removeFromTop(35).translated(0, 4), findColour(PlugDataColour::panelTextColourId), Bold, 16, Justification::centred); auto colour = findColour(PlugDataColour::panelTextColourId);