40 lines
1.2 KiB
C++
40 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <JuceHeader.h>
|
|
#include "../Resources.h"
|
|
|
|
namespace serum
|
|
{
|
|
|
|
// ===========================================================================
|
|
// LED-style toggle (power) button that drives a float parameter (0/1) or an
|
|
// optional callback (used by RAVE).
|
|
// ===========================================================================
|
|
class ToggleButton : public juce::Component
|
|
{
|
|
public:
|
|
explicit ToggleButton (const juce::String& label = {});
|
|
|
|
void attach (juce::AudioProcessorValueTreeState& apvts, const juce::String& paramId);
|
|
void setOnClick (std::function<void (bool)> cb) { onClick = std::move (cb); }
|
|
|
|
void setOnColour (juce::Colour c) { onColour = c; repaint(); }
|
|
void setLabel (const juce::String& lbl) { label = lbl; repaint(); }
|
|
|
|
void setToggleState (bool s);
|
|
bool getToggleState() const noexcept { return state; }
|
|
|
|
void paint (juce::Graphics& g) override;
|
|
void mouseDown (const juce::MouseEvent&) override;
|
|
|
|
private:
|
|
bool state = false;
|
|
juce::String label;
|
|
juce::RangedAudioParameter* param = nullptr;
|
|
std::unique_ptr<juce::ParameterAttachment> attachment;
|
|
std::function<void (bool)> onClick;
|
|
juce::Colour onColour = theme::accent;
|
|
};
|
|
|
|
} // namespace serum
|