From 382f841d43682bdd0632e7f60bcd72105de3ccac Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Fri, 2 Aug 2024 11:45:36 -0400 Subject: [PATCH] GlyphButton can have a pair of glyphs Fun! --- include/sst/jucegui/components/GlyphButton.h | 5 +++ src/sst/jucegui/components/GlyphButton.cpp | 36 +++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/include/sst/jucegui/components/GlyphButton.h b/include/sst/jucegui/components/GlyphButton.h index 03dcdea..5349795 100644 --- a/include/sst/jucegui/components/GlyphButton.h +++ b/include/sst/jucegui/components/GlyphButton.h @@ -18,6 +18,7 @@ #ifndef INCLUDE_SST_JUCEGUI_COMPONENTS_GLYPHBUTTON_H #define INCLUDE_SST_JUCEGUI_COMPONENTS_GLYPHBUTTON_H +#include #include #include @@ -39,6 +40,8 @@ struct GlyphButton : public CallbackButtonComponent, public EditableComponentBase { GlyphButton(GlyphPainter::GlyphType type); + GlyphButton(GlyphPainter::GlyphType type, GlyphPainter::GlyphType secondGlyph, + int glyphZeroWidth); // side by side ~GlyphButton(); struct Styles : base_styles::PushButton, base_styles::BaseLabel @@ -56,6 +59,8 @@ struct GlyphButton : public CallbackButtonComponent, int glyphButtonPad{0}; void paint(juce::Graphics &g) override; GlyphPainter::GlyphType glyph; + std::optional secondGlyph{std::nullopt}; + int glyphZeroWidth{0}; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(GlyphButton) }; diff --git a/src/sst/jucegui/components/GlyphButton.cpp b/src/sst/jucegui/components/GlyphButton.cpp index 7d33b7b..966d5f3 100644 --- a/src/sst/jucegui/components/GlyphButton.cpp +++ b/src/sst/jucegui/components/GlyphButton.cpp @@ -27,8 +27,27 @@ GlyphButton::GlyphButton(GlyphPainter::GlyphType t) { } +GlyphButton::GlyphButton(GlyphPainter::GlyphType t, GlyphPainter::GlyphType snd, int g) + : style::StyleConsumer(Styles::styleClass), glyph(t), secondGlyph(snd), glyphZeroWidth(g) +{ +} + GlyphButton::~GlyphButton() {} +juce::Rectangle squareCenter(const juce::Rectangle &b) +{ + if (b.getWidth() > b.getHeight()) + { + auto d = b.getWidth() - b.getHeight(); + return b.withTrimmedLeft(d / 2).withTrimmedRight(d / 2); + } + else + { + auto d = b.getHeight() - b.getWidth(); + return b.withTrimmedTop(d / 2).withTrimmedBottom(d / 2); + } +} + void GlyphButton::paint(juce::Graphics &g) { paintButtonBG(this, g); @@ -37,6 +56,21 @@ void GlyphButton::paint(juce::Graphics &g) col = getColour(Styles::labelcolor_hover); else col = getColour(Styles::labelcolor); - GlyphPainter::paintGlyph(g, getLocalBounds().reduced(glyphButtonPad), glyph, col); + if (secondGlyph.has_value()) + { + if (glyphZeroWidth <= 0) + glyphZeroWidth = getWidth() / 2; + + auto b1 = getLocalBounds().withWidth(glyphZeroWidth); + auto b2 = getLocalBounds().withTrimmedLeft(glyphZeroWidth); + GlyphPainter::paintGlyph(g, squareCenter(b1), glyph, col); + GlyphPainter::paintGlyph(g, squareCenter(b2), *secondGlyph, col); + } + else + { + auto b = squareCenter(getLocalBounds().reduced(glyphButtonPad)); + + GlyphPainter::paintGlyph(g, b, glyph, col); + } } } // namespace sst::jucegui::components \ No newline at end of file