Hi everyone,
I have a question regarding getToggleState().
I added a few radio buttons to be used for triggering some changes in the sound.
I used getToggleState() but It seems like I am forgetting something; when I select a radio button it doesn’t deselect if i click it again. I got some help from Juce tutorials but I think I didn’t quite understand getToggleState()
That’s my code:
enum RadioButtonIds
{
firstButtons = 1001,
secondButtons = 1002,
thirdButtons = 1003,
fourthButtons = 1004,
fifthButtons = 1005
};
void paint (Graphics&) override;
void resized() override;
void updateToggleState (Button* button, String name)
{
auto state = button->getToggleState();
String stateString = state ? "ON" : "OFF";
Logger::outputDebugString (name + " Button changed to " + stateString);
}
void normalToggleState (Button* button, String name)
{
auto state = button->getToggleState();
String stateString = state ? "ON" : "OFF";
String selectedString = state ? " [active]" : "";
Logger::outputDebugString (name + " Button changed to " + stateString);
button->setButtonText (name + selectedString);
}
and in the MainComponentConstructor:
addAndMakeVisible (firstButton);
addAndMakeVisible (secondButton);
addAndMakeVisible(thirdButton);
addAndMakeVisible(fourthButton);
addAndMakeVisible(fifthButton);
addAndMakeVisible(fifthButton);
dimButton .onClick = [this] { normalToggleState (&dimButton, "DIM"); };
airButton .onClick = [this] { normalToggleState (&airButton, "AIR"); };
phaseButton .onClick = [this] { normalToggleState (&phaseButton, "Phase"); };
hpfButton .onClick = [this] { normalToggleState (&hpfButton, "HPF"); };
micInButton .onClick = [this] { updateToggleState (&micInButton, "Mic Input"); };
lineInButton .onClick = [this] { updateToggleState (&lineInButton, "Line Input"); };
dimButton .setRadioGroupId (DimButtons);
airButton .setRadioGroupId (AirButtons);
phaseButton .setRadioGroupId (PhaseButtons);
hpfButton .setRadioGroupId(HPFButtons);
micInButton .setRadioGroupId (InputButtons);
lineInButton .setRadioGroupId (InputButtons);
airButton .setBounds (500, 40, getWidth() - 30, 20);
dimButton .setBounds (500, 70, getWidth() - 30, 20);
phaseButton .setBounds (500, 100, getWidth() - 30, 20);
hpfButton .setBounds (500, 130, getWidth() - 30, 20);
micInButton .setBounds (500, 160, getWidth() - 30, 20);
lineInButton .setBounds (500, 190, getWidth() - 30, 20);
Thank you all!