Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toggle button filled style implementation #105

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading