Skip to content

Commit

Permalink
toggle button filled style implementation (#105)
Browse files Browse the repository at this point in the history
* toggle button filled style implementation

* clang format ToggleButton

* run fix_code script

* format using clang-format 17
  • Loading branch information
luismrguimaraes authored Aug 12, 2024
1 parent e4e29e7 commit 294e13c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
8 changes: 7 additions & 1 deletion include/sst/jucegui/components/BaseStyles.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ struct Base
{
SCLASS(base);
PROP(background);
static void initialize() { style::StyleSheet::addClass(styleClass).withProperty(background); }
PROP(background_hover);
static void initialize()
{
style::StyleSheet::addClass(styleClass)
.withProperty(background)
.withProperty(background_hover);
}
};

struct SelectableRegion
Expand Down
4 changes: 2 additions & 2 deletions include/sst/jucegui/components/ButtonPainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace sst::jucegui::components
{
template <typename T> void paintButtonBG(T *that, juce::Graphics &g)
{
float rectCorner = 1.5;
float rectCorner = 1;

auto b = that->getLocalBounds().reduced(1).toFloat();

Expand Down Expand Up @@ -61,7 +61,7 @@ template <typename T> void paintButtonBG(T *that, juce::Graphics &g)
// Only call this in the 'on' state
template <typename T> void paintButtonOnValueBG(T *that, juce::Graphics &g)
{
float rectCorner = 1.5;
float rectCorner = 1;

auto b = that->getLocalBounds().reduced(1).toFloat();
auto bg = that->getColour(T::Styles::fill);
Expand Down
6 changes: 5 additions & 1 deletion include/sst/jucegui/components/ToggleButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@ struct ToggleButton : DiscreteParamEditor,
ToggleButton();
~ToggleButton();

struct Styles : base_styles::PushButton, base_styles::BaseLabel, base_styles::ValueBearing
struct Styles : base_styles::Base,
base_styles::PushButton,
base_styles::BaseLabel,
base_styles::ValueBearing
{
SCLASS(togglebutton);
static void initialize()
{
style::StyleSheet::addClass(styleClass)
.withBaseClass(base_styles::Base::styleClass)
.withBaseClass(base_styles::PushButton::styleClass)
.withBaseClass(base_styles::BaseLabel::styleClass)
.withBaseClass(base_styles::ValueBearing::styleClass);
Expand Down
28 changes: 27 additions & 1 deletion src/sst/jucegui/components/ToggleButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ void ToggleButton::paint(juce::Graphics &g)
{
bool v = data ? data->getValue() : false;

if (drawMode != DrawMode::GLYPH && drawMode != DrawMode::DUAL_GLYPH)
if (drawMode != DrawMode::GLYPH && drawMode != DrawMode::DUAL_GLYPH &&
drawMode != DrawMode::FILLED)
{
v = v && (drawMode != DrawMode::LABELED_BY_DATA);

Expand All @@ -48,6 +49,31 @@ void ToggleButton::paint(juce::Graphics &g)
}
}

if (drawMode == DrawMode::FILLED)
{
if (isHovered)
{
if (v)
g.setColour(getColour(Styles::labelcolor_hover));
else
g.setColour(getColour(Styles::background_hover));
}
else
{
if (v)
g.setColour(getColour(Styles::labelcolor));
else
g.setColour(getColour(Styles::background));
}

auto b = getLocalBounds().reduced(2).toFloat();
g.fillRoundedRectangle(b, 1.f); // corner size should match those in ButtonPainter.h

// Draw outline
g.setColour(getColour(Styles::brightoutline));
g.drawRoundedRectangle(b, 1.f, 1.f);
}

if (isHovered)
{
if (v)
Expand Down

0 comments on commit 294e13c

Please sign in to comment.