Skip to content

Commit

Permalink
Unify bool component style
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyschoen committed Dec 9, 2024
1 parent 8187d89 commit cc5285d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 68 deletions.
55 changes: 9 additions & 46 deletions Source/Components/PropertiesPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class PropertiesPanel : public Component {

auto titleX = x;
if (parent.titleAlignment == AlignWithPropertyName) {
titleX += 12;
titleX += 11;
}

auto title = getName();
Expand Down Expand Up @@ -542,18 +542,16 @@ class PropertiesPanel : public Component {
void paint(Graphics& g) override
{
bool isDown = getValue<bool>(toggleStateValue);
bool isHovered = isMouseOver();

auto bounds = getLocalBounds().toFloat().removeFromRight(getWidth() / (2.0f - hideLabel));

if (isDown || isHovered) {
Path p;
p.addRoundedRectangle(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(), Corners::largeCornerRadius, Corners::largeCornerRadius, false, roundTopCorner, false, roundBottomCorner);

// Add some alpha to make it look good on any background...
g.setColour(findColour(TextButton::buttonColourId).withAlpha(isDown ? 0.9f : 0.7f));
g.fillPath(p);
}
auto buttonBounds = bounds.reduced(4);

auto contrast = isDown ? 0.3f : 0.0f;
if(isMouseOver()) contrast += 0.05;

// Add some alpha to make it look good on any background...
g.setColour(findColour(PlugDataColour::sidebarActiveBackgroundColourId).contrasting(contrast).withAlpha(0.3f));
g.fillRoundedRectangle(buttonBounds, Corners::defaultCornerRadius);

auto textColour = findColour(PlugDataColour::panelTextColourId);

Expand Down Expand Up @@ -592,42 +590,7 @@ class PropertiesPanel : public Component {
StringArray textOptions;
Value toggleStateValue;
};

struct InspectorBoolComponent : public BoolComponent
{
using BoolComponent::BoolComponent;

void paint(Graphics& g) override
{
bool isDown = getValue<bool>(toggleStateValue);

auto bounds = getLocalBounds().toFloat().removeFromRight(getWidth() / (2.0f - hideLabel));
auto buttonBounds = bounds.reduced(4);

auto contrast = isDown ? 0.2f : 0.05f;
if(isMouseOver()) contrast += 0.025;
// Add some alpha to make it look good on any background...
g.setColour(findColour(PlugDataColour::sidebarActiveBackgroundColourId).contrasting(contrast).withAlpha(0.3f));
g.fillRoundedRectangle(buttonBounds, Corners::defaultCornerRadius);

auto textColour = findColour(PlugDataColour::panelTextColourId);

if (!isEnabled()) {
textColour = findColour(PlugDataColour::panelTextColourId).withAlpha(0.5f);
}
Fonts::drawText(g, textOptions[isDown], bounds, textColour, 14.0f, Justification::centred);

// Paint label
PropertiesPanelProperty::paint(g);
}

PropertiesPanelProperty* createCopy() override
{
return new InspectorBoolComponent(getName(), toggleStateValue, textOptions);
}

};

struct InspectorColourComponent : public PropertiesPanelProperty
, public Value::Listener {

Expand Down
31 changes: 14 additions & 17 deletions Source/Dialogs/AudioSettingsPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class ChannelToggleProperty : public PropertiesPanel::BoolComponent {
: PropertiesPanel::BoolComponent(channelName, isEnabled, { "Disabled", "Enabled" })
, callback(std::move(onClick))
{
setPreferredHeight(28);
setPreferredHeight(30);
repaint();
}

Expand All @@ -132,26 +132,23 @@ class ChannelToggleProperty : public PropertiesPanel::BoolComponent {
void paint(Graphics& g) override
{
bool isDown = getValue<bool>(toggleStateValue);
bool isHovered = isMouseOver();

Path backgroundShape;
backgroundShape.addRoundedRectangle(0, 0, getWidth(), getHeight(), Corners::largeCornerRadius, Corners::largeCornerRadius, roundTopCorner, roundTopCorner, roundBottomCorner, roundBottomCorner);

g.setColour(findColour(PlugDataColour::panelForegroundColourId).darker(0.015f));
g.fillPath(backgroundShape);

auto buttonBounds = getLocalBounds().toFloat().removeFromRight(getWidth() / (2.0f - hideLabel));
auto bounds = getLocalBounds().toFloat().removeFromRight(getWidth() / (2.0f - hideLabel));
auto buttonBounds = bounds.reduced(4);

auto contrast = isDown ? 0.3f : 0.0f;
if(isMouseOver()) contrast += 0.05;

// Add some alpha to make it look good on any background...
g.setColour(findColour(PlugDataColour::sidebarActiveBackgroundColourId).contrasting(contrast).withAlpha(0.3f));
g.fillRoundedRectangle(buttonBounds, Corners::defaultCornerRadius);

Path buttonShape;
buttonShape.addRoundedRectangle(buttonBounds.getX(), buttonBounds.getY(), buttonBounds.getWidth(), buttonBounds.getHeight(), Corners::largeCornerRadius, Corners::largeCornerRadius, false, roundTopCorner, false, roundBottomCorner);
auto textColour = findColour(PlugDataColour::panelTextColourId);

if (isDown || isHovered) {
// Add some alpha to make it look good on any background...
g.setColour(findColour(TextButton::buttonColourId).withAlpha(isDown ? 0.9f : 0.7f));
g.fillPath(buttonShape);
if (!isEnabled()) {
textColour = findColour(PlugDataColour::panelTextColourId).withAlpha(0.5f);
}

Fonts::drawText(g, textOptions[isDown], buttonBounds, findColour(PlugDataColour::panelTextColourId), 14.0f, Justification::centred);
Fonts::drawText(g, textOptions[isDown], bounds, textColour, 14.0f, Justification::centred);

// Paint label
PropertiesPanelProperty::paint(g);
Expand Down
2 changes: 1 addition & 1 deletion Source/LookAndFeel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ void PlugDataLook::drawPropertyComponentLabel(Graphics& g, int width, int height
auto textW = jmin(300, component.getWidth() / 2);
auto r = Rectangle<float>(textW, 0, component.getWidth() - textW, component.getHeight() - 1);

Fonts::drawFittedText(g, component.getName(), indent + 2, r.getY(), r.getX(), r.getHeight(), colour, 1, 1.0f, (float)jmin(height, 24) * 0.65f, Justification::centredLeft);
Fonts::drawFittedText(g, component.getName(), indent + 1, r.getY(), r.getX(), r.getHeight(), colour, 1, 1.0f, (float)jmin(height, 24) * 0.65f, Justification::centredLeft);
}

void PlugDataLook::drawPropertyPanelSectionHeader(Graphics& g, String const& name, bool isOpen, int width, int height)
Expand Down
6 changes: 3 additions & 3 deletions Source/Objects/ArrayObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ struct ArrayPropertiesPanel : public PropertiesPanelProperty
addAndMakeVisible(properties.add(new PropertiesPanel::EditableComponent<String>("Name", graph->name)));
addAndMakeVisible(properties.add(new PropertiesPanel::EditableComponent<int>("Size", graph->size)));
addAndMakeVisible(properties.add(new PropertiesPanel::RangeComponent("Range", graph->range, false)));
addAndMakeVisible(properties.add(new PropertiesPanel::InspectorBoolComponent("Save contents", graph->saveContents, { "No", "Yes" })));
addAndMakeVisible(properties.add(new PropertiesPanel::BoolComponent("Save contents", graph->saveContents, { "No", "Yes" })));
addAndMakeVisible(properties.add(new PropertiesPanel::ComboComponent("Draw Style", graph->drawMode, { "Points", "Polygon", "Bezier curve" })));

// To detect name changes, so we can redraw the array title
Expand All @@ -750,7 +750,7 @@ struct ArrayPropertiesPanel : public PropertiesPanelProperty
addAndMakeVisible(deleteButton);
}

auto newHeight = (192 * graphs.size()) + 24;
auto newHeight = (176 * graphs.size()) + 24;
setPreferredHeight(newHeight);
if (auto* propertiesPanel = findParentComponentOfClass<PropertiesPanel>()) {
propertiesPanel->updatePropHolderLayout();
Expand All @@ -776,7 +776,7 @@ struct ArrayPropertiesPanel : public PropertiesPanelProperty
if (!graphs[i])
continue;

auto start = (i * 192) - 6;
auto start = (i * 176) - 6;
g.setColour(findColour(PlugDataColour::sidebarActiveBackgroundColourId).withAlpha(0.75f));
g.fillRoundedRectangle(0.0f, start + 26, getWidth(), 158, Corners::largeCornerRadius);

Expand Down
2 changes: 1 addition & 1 deletion Source/Sidebar/Inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class Inspector : public Component {
case tColour:
return new PropertiesPanel::InspectorColourComponent(name, *value);
case tBool:
return new PropertiesPanel::InspectorBoolComponent(name, *value, options);
return new PropertiesPanel::BoolComponent(name, *value, options);
case tCombo:
return new PropertiesPanel::ComboComponent(name, *value, options);
case tRangeFloat:
Expand Down

0 comments on commit cc5285d

Please sign in to comment.