Files
serumalt/Source/GUI/ToggleButton.h
T
biggy 8364737d1c perf(gui): skip unchanged repaints and gate updates by tab
Add change detection to Display, WaveformDisplay, FilterDisplay,
EnvelopeDisplay, and LFODisplay so repaint() is only called when
values actually change. Gate updateVisuals() by currentTab so only
the visible tab's displays are updated each timer tick. Similarly
gate updateModList/updateMacroList to their respective tabs.

Manage dynamically created controls via ownedControls
unique_ptr vector instead of raw new leaks. Null-check parameter
lookups before creating attachments. Hold engine control lock
when reading matrix/macros/LFO shape data.

Fix envelope display curve directions (attack rising from bottom,
decay falling toward sustain, release falling toward bottom).
Add tooltip to FilterDisplay noting the approximation. Replace
ToggleButton raw param pointer with ParameterAttachment for proper
gesture handling. Sync preset and scale combos to processor state.
2026-09-09 14:33:41 +02:00

44 lines
1.4 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).
//
// Inherits SettableTooltipClient so setTooltip() works exactly like it does on
// juce::Button / juce::Slider / juce::ComboBox (juce::Component itself has no
// tooltip support).
// ===========================================================================
class ToggleButton : public juce::Component,
public juce::SettableTooltipClient
{
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;
std::unique_ptr<juce::ParameterAttachment> attachment;
std::function<void (bool)> onClick;
juce::Colour onColour = theme::accent;
};
} // namespace serum