Skip to content

Commit

Permalink
WIP toggle button
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseDiazRohena committed Dec 5, 2023
1 parent 1deac9f commit cce84fc
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,14 @@ set(SourceFiles
libs/tote_bag/juce_gui/components/widgets/LabelSlider.h
libs/tote_bag/juce_gui/components/widgets/ParameterSlider.h
libs/tote_bag/juce_gui/components/widgets/ParameterTextButton.h
libs/tote_bag/juce_gui/components/widgets/tbl_ToggleButton.h
libs/tote_bag/juce_gui/components/widgets/DrawableParameterButton.cpp
libs/tote_bag/juce_gui/components/widgets/FlatTextButton.cpp
libs/tote_bag/juce_gui/components/widgets/FlatTextChooser.cpp
libs/tote_bag/juce_gui/components/widgets/LabelSlider.cpp
libs/tote_bag/juce_gui/components/widgets/ParameterSlider.cpp
libs/tote_bag/juce_gui/components/widgets/ParameterTextButton.cpp
libs/tote_bag/juce_gui/components/widgets/tbl_ToggleButton.cpp

libs/tote_bag/juce_gui/lookandfeel/LookAndFeel.h
libs/tote_bag/juce_gui/lookandfeel/LookAndFeelConstants.h
Expand Down
14 changes: 14 additions & 0 deletions libs/tote_bag/juce_gui/components/widgets/tbl_ToggleButton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 2023 Tote Bag Labs

#include "tbl_ToggleButton.h"

namespace tote_bag
{
ToggleButton::ToggleButton (const juce::String& parameterId,
juce::AudioProcessorValueTreeState& stateToControl)
: juce::ToggleButton (parameterId)
, buttonValue (stateToControl, parameterId, *this)
{
setClickingTogglesState (true);
}
} // namespace tote_bag
22 changes: 22 additions & 0 deletions libs/tote_bag/juce_gui/components/widgets/tbl_ToggleButton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

// 2023 Tote Bag Labs

#pragma once

#include <juce_audio_processors/juce_audio_processors.h>
#include <juce_gui_basics/juce_gui_basics.h>

namespace tote_bag
{
class ToggleButton : public juce::ToggleButton
{
public:
ToggleButton (const juce::String& parameterId,
juce::AudioProcessorValueTreeState& stateToControl);

private:
juce::AudioProcessorValueTreeState::ButtonAttachment buttonValue;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ToggleButton)
};
} // namespace tote_bag
25 changes: 14 additions & 11 deletions src/gui/panels/ValentineCenterPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace detail
// Get ratio of svg dimensions so we can correctly resize it.
inline constexpr auto kButtonWidth = 108.1f;
inline constexpr auto kButtonHeight = 201.84f;
inline constexpr auto kButtonRatio = kButtonWidth / kButtonHeight;
inline constexpr auto kButtonWHRatio = kButtonWidth / kButtonHeight;

inline const juce::String kCrushSliderText = "CRUSH";
} // namespace detail
Expand All @@ -28,19 +28,12 @@ CenterPanel::CenterPanel (ValentineAudioProcessor& processor)
, crushSlider (detail::kCrushSliderText,
parameterID (VParameter::bitCrush),
processor.treeState)
, crushEnableButton (
juce::Drawable::createFromImageData (BinaryData::on_button_svg,
BinaryData::on_button_svgSize)
.get(),
juce::Drawable::createFromImageData (BinaryData::off_button_svg,
BinaryData::off_button_svgSize)
.get(),
parameterID (VParameter::crushEnable),
processor.treeState)
, crushEnableButton (parameterID (VParameter::crushEnable), processor.treeState)
, valentineLogo (
juce::Drawable::createFromImageData (BinaryData::logo_218x40_svg,
BinaryData::logo_218x40_svgSize))
{
addAndMakeVisible (crushEnableButton);
addAndMakeVisible (valentineLogo.get());
}

Expand Down Expand Up @@ -75,9 +68,19 @@ void CenterPanel::resized()
topRowBorder = topRowBounds.reduced (margin);

auto topRowComponents = topRowBorder.reduced (margin);
const auto topRowSliders = topRowComponents.removeFromLeft (
auto topRowSliders = topRowComponents.removeFromLeft (
juce::roundToInt (topRowComponents.getWidth() * .65f));

// Get basic width for top row sliders
auto topRowSliderWidth = juce::roundToInt (topRowSliders.getHeight() * .33f);
// Use that width as reference for button width
const auto topRowButtonWidth = juce::roundToInt (topRowSliderWidth * .25f);
// Adjust button width to make room
topRowSliderWidth -= topRowButtonWidth;

const auto crushButtonBounds = topRowSliders.removeFromLeft (topRowButtonWidth);
crushEnableButton.setBounds (crushButtonBounds);

const auto logoHeight = juce::roundToInt (topRowComponents.getHeight() * .25f);
topRowComponents.removeFromTop (logoHeight * 1.45f);
topRowComponents.removeFromRight (logoHeight * .5f);
Expand Down
4 changes: 2 additions & 2 deletions src/gui/panels/ValentineCenterPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#pragma once

#include "tote_bag/juce_gui/components/widgets/DrawableParameterButton.h"
#include "tote_bag/juce_gui/components/widgets/LabelSlider.h"
#include "tote_bag/juce_gui/components/widgets/tbl_ToggleButton.h"

#include <juce_gui_basics/juce_gui_basics.h>

Expand All @@ -30,7 +30,7 @@ class CenterPanel : public juce::Component
float borderCornerSize;

LabelSlider crushSlider;
DrawableParameterButton crushEnableButton;
ToggleButton crushEnableButton;

std::unique_ptr<juce::Drawable> valentineLogo;

Expand Down

0 comments on commit cce84fc

Please sign in to comment.