Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessibility Multi/Radio/Switch #4819

Merged
merged 1 commit into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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