From f8f7ec647907f543aa1a9988f94c1746dd47907b Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 25 Aug 2024 19:58:52 -0400 Subject: [PATCH] Named Panel gets cursor and accent mode (#114) Cursor over the text area if you set it. Accent is a color you can toggle on or off. --- include/sst/jucegui/components/NamedPanel.h | 21 ++++++++- src/sst/jucegui/components/NamedPanel.cpp | 51 ++++++++++++++++++++- src/sst/jucegui/style/StyleSheet.cpp | 2 + 3 files changed, 71 insertions(+), 3 deletions(-) diff --git a/include/sst/jucegui/components/NamedPanel.h b/include/sst/jucegui/components/NamedPanel.h index 55f81a4..d74be4d 100644 --- a/include/sst/jucegui/components/NamedPanel.h +++ b/include/sst/jucegui/components/NamedPanel.h @@ -20,8 +20,8 @@ #include #include +#include #include -#include #include #include #include "BaseStyles.h" @@ -46,6 +46,7 @@ struct NamedPanel : public juce::Component, PROP(labelrule); PROP(selectedtab); + PROP(accentedPanel); static void initialize() { @@ -55,7 +56,8 @@ struct NamedPanel : public juce::Component, .withBaseClass(base_styles::Outlined::styleClass) .withBaseClass(base_styles::BaseLabel::styleClass) .withProperty(labelrule) - .withProperty(selectedtab); + .withProperty(selectedtab) + .withProperty(accentedPanel); } }; @@ -93,6 +95,18 @@ struct NamedPanel : public juce::Component, virtual void enablementChanged() override { repaint(); } + std::optional optionalCursor{std::nullopt}; + void setOptionalCursorForNameArea(std::optional c) { optionalCursor = c; } + void activateOptionalCursorForNamedArea(bool b); + bool isOptionalCursorOn{false}; + + bool isAccented{false}; + void setIsAccented(bool b) + { + isAccented = b; + repaint(); + } + /* * Named Panels can have toggle buttons which attach to a * discrete data source. @@ -126,6 +140,8 @@ struct NamedPanel : public juce::Component, bool hasHamburger{false}; static constexpr int hamburgerSize = 22; void mouseDown(const juce::MouseEvent &event) override; + void mouseMove(const juce::MouseEvent &event) override; + void mouseExit(const juce::MouseEvent &event) override; juce::Rectangle getHamburgerRegion(); std::function onHamburger{nullptr}; @@ -156,6 +172,7 @@ struct NamedPanel : public juce::Component, std::string name; std::vector> additionalHamburgerComponents; std::unique_ptr contentAreaComp; + juce::Rectangle lastPaintedHeaderTextRegion; }; } // namespace sst::jucegui::components diff --git a/src/sst/jucegui/components/NamedPanel.cpp b/src/sst/jucegui/components/NamedPanel.cpp index 40a651b..4c08056 100644 --- a/src/sst/jucegui/components/NamedPanel.cpp +++ b/src/sst/jucegui/components/NamedPanel.cpp @@ -51,7 +51,14 @@ void NamedPanel::paint(juce::Graphics &g) g.setColour(getColour(Styles::background)); } g.fillRoundedRectangle(b.toFloat(), cornerRadius); - g.setColour(getColour(Styles::brightoutline)); + if (isAccented) + { + g.setColour(getColour(Styles::accentedPanel)); + } + else + { + g.setColour(getColour(Styles::brightoutline)); + } g.drawRoundedRectangle(b.toFloat(), cornerRadius, 1); paintHeader(g); @@ -129,6 +136,10 @@ void NamedPanel::paintHeader(juce::Graphics &g) } else { + lastPaintedHeaderTextRegion = + ht.withTrimmedLeft((isTogglable ? headerHeight - togglePad : 0)) + .withTrimmedRight(showHamburger * hamburgerSize); + auto q = ht.toFloat() .withTrimmedLeft(labelWidth + 4 + (isTogglable ? headerHeight - togglePad : 0)) .translated(0, ht.getHeight() / 2 - 0.5) @@ -235,6 +246,44 @@ void NamedPanel::mouseDown(const juce::MouseEvent &event) } } +void NamedPanel::mouseMove(const juce::MouseEvent &event) +{ + auto p = localAreaToGlobal(lastPaintedHeaderTextRegion); + if (lastPaintedHeaderTextRegion.toFloat().contains(event.position)) + { + activateOptionalCursorForNamedArea(true); + } + else + { + activateOptionalCursorForNamedArea(false); + } +} + +void NamedPanel::mouseExit(const juce::MouseEvent &event) +{ + activateOptionalCursorForNamedArea(false); +} + +void NamedPanel::activateOptionalCursorForNamedArea(bool b) +{ + if (isOptionalCursorOn != b) + { + isOptionalCursorOn = b; + + if (optionalCursor.has_value()) + { + if (isOptionalCursorOn) + { + setMouseCursor(*optionalCursor); + } + else + { + setMouseCursor(juce::MouseCursor::StandardCursorType::NormalCursor); + } + } + } +} + void NamedPanel::resetTabState() { auto f = getFont(Styles::labelfont); diff --git a/src/sst/jucegui/style/StyleSheet.cpp b/src/sst/jucegui/style/StyleSheet.cpp index 7304466..da02798 100644 --- a/src/sst/jucegui/style/StyleSheet.cpp +++ b/src/sst/jucegui/style/StyleSheet.cpp @@ -254,6 +254,7 @@ struct DarkSheet : public StyleSheetBuiltInImpl using n = components::NamedPanel::Styles; setColour(n::styleClass, n::labelrule, juce::Colour(0x70, 0x70, 0x70)); setColour(n::styleClass, n::selectedtab, juce::Colour(0xFF, 0x90, 00)); + setColour(n::styleClass, n::accentedPanel, juce::Colour(0xFF, 0x90, 00)); } { @@ -384,6 +385,7 @@ struct LightSheet : public StyleSheetBuiltInImpl using n = components::NamedPanel::Styles; setColour(n::styleClass, n::labelrule, juce::Colour(50, 50, 50)); setColour(n::styleClass, n::selectedtab, juce::Colour(0x00, 0x00, 50)); + setColour(n::styleClass, n::accentedPanel, juce::Colour(0x00, 0x00, 50)); } {