Skip to content

Commit

Permalink
Named Panel gets cursor and accent mode (#114)
Browse files Browse the repository at this point in the history
Cursor over the text area if you set it. Accent is a color
you can toggle on or off.
  • Loading branch information
baconpaul authored Aug 25, 2024
1 parent d04372a commit f8f7ec6
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 3 deletions.
21 changes: 19 additions & 2 deletions include/sst/jucegui/components/NamedPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

#include <vector>
#include <string>
#include <optional>
#include <juce_gui_basics/juce_gui_basics.h>
#include <string>
#include <sst/jucegui/style/StyleAndSettingsConsumer.h>
#include <sst/jucegui/style/StyleSheet.h>
#include "BaseStyles.h"
Expand All @@ -46,6 +46,7 @@ struct NamedPanel : public juce::Component,

PROP(labelrule);
PROP(selectedtab);
PROP(accentedPanel);

static void initialize()
{
Expand All @@ -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);
}
};

Expand Down Expand Up @@ -93,6 +95,18 @@ struct NamedPanel : public juce::Component,

virtual void enablementChanged() override { repaint(); }

std::optional<juce::MouseCursor> optionalCursor{std::nullopt};
void setOptionalCursorForNameArea(std::optional<juce::MouseCursor> 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.
Expand Down Expand Up @@ -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<int> getHamburgerRegion();

std::function<void()> onHamburger{nullptr};
Expand Down Expand Up @@ -156,6 +172,7 @@ struct NamedPanel : public juce::Component,
std::string name;
std::vector<std::unique_ptr<juce::Component>> additionalHamburgerComponents;
std::unique_ptr<juce::Component> contentAreaComp;
juce::Rectangle<int> lastPaintedHeaderTextRegion;
};
} // namespace sst::jucegui::components

Expand Down
51 changes: 50 additions & 1 deletion src/sst/jucegui/components/NamedPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/sst/jucegui/style/StyleSheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

{
Expand Down Expand Up @@ -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));
}

{
Expand Down

0 comments on commit f8f7ec6

Please sign in to comment.