Skip to content

Commit

Permalink
Accessibility Multi/Radio/Switch (surge-synthesizer#4819)
Browse files Browse the repository at this point in the history
1. Restore the multiswitch sub components. Ooops!
2. Use the checkable/checed state on MultiSwitch and Switch

Addresses surge-synthesizer#4616
  • Loading branch information
baconpaul authored Aug 10, 2021
1 parent b0bb41c commit bd44a5c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/gui/widgets/MultiSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,17 @@ void MultiSwitch::mouseWheelMove(const juce::MouseEvent &event,

struct MultiSwitchRadioButton : public juce::Component
{
MultiSwitchRadioButton(MultiSwitch *s, float value, const std::string &label)
: mswitch(s), val(value)
MultiSwitchRadioButton(MultiSwitch *s, float value, int ival, const std::string &label)
: mswitch(s), val(value), ival(ival)
{
setDescription(label);
setTitle(label);
setInterceptsMouseClicks(false, false);
setAccessible(true);
}
MultiSwitch *mswitch;
float val;
int ival;

struct RBAH : public juce::AccessibilityHandler
{
Expand Down Expand Up @@ -180,6 +182,16 @@ struct MultiSwitchRadioButton : public juce::Component
mswitch->notifyControlModifierClicked(m);
}

juce::AccessibleState getCurrentState() const override
{
auto state = AccessibilityHandler::getCurrentState();
state = state.withCheckable();
if (mswitch->getIntegerValue() == button->ival)
state = state.withChecked();

return state;
}

MultiSwitch *mswitch;
MultiSwitchRadioButton *button;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(RBAH);
Expand All @@ -196,15 +208,15 @@ void MultiSwitch::setupAccessibility()
if (rows * columns <= 1) // i use an alternate handler below
return;

setAccessible(true);
setFocusContainerType(juce::Component::FocusContainerType::focusContainer);

if (selectionComponents.size() == rows * columns)
{
// Already done it!
return;
removeAllChildren();
selectionComponents.clear();
}

setAccessible(true);
setFocusContainerType(juce::Component::FocusContainerType::focusContainer);

auto sge = firstListenerOfType<SurgeGUIEditor>();
jassert(sge);
if (!sge)
Expand All @@ -219,9 +231,10 @@ void MultiSwitch::setupAccessibility()
{
float val = ((float)sel) / (rows * columns - 1);
auto title = sge->getDisplayForTag(getTag(), true, val);
sel++;

auto ac = std::make_unique<MultiSwitchRadioButton>(this, val, title);
auto ac = std::make_unique<MultiSwitchRadioButton>(this, val, sel, title);

sel++;
ac->getProperties().set("ControlGroup", (int)(c * columns + rows));
ac->setBounds(juce::Rectangle<int>(c * dc, r * dr, dc, dr));
addAndMakeVisible(*ac);
Expand Down
11 changes: 11 additions & 0 deletions src/gui/widgets/Switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ struct SwitchAH : public juce::AccessibilityHandler
[this]() { this->press(); }))
{
}

juce::AccessibleState getCurrentState() const override
{
auto state = AccessibilityHandler::getCurrentState();
state = state.withCheckable();
if (mswitch->getValue() > 0.5)
state = state.withChecked();

return state;
}

void press()
{
if (mswitch->isMultiIntegerValued())
Expand Down

0 comments on commit bd44a5c

Please sign in to comment.