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

Accesibility Change One: Show Acessible Info #99

Merged
merged 2 commits into from
Mar 12, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
68 changes: 68 additions & 0 deletions melatonin/component_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@ namespace melatonin
virtual void componentModelChanged (ComponentModel& model) = 0;
};

juce::Value nameValue;
juce::Value widthValue, heightValue, xValue, yValue;
juce::Value enabledValue, opaqueValue, hasCachedImageValue, accessibilityHandledValue;
juce::Value visibleValue, wantsFocusValue, interceptsMouseValue, childrenInterceptsMouseValue;
juce::Value lookAndFeelValue, typeValue, fontValue, alphaValue;
juce::Value pickedColor;
juce::Value timing1, timing2, timing3, timingMax, hasChildren;

struct AccessiblityDetail
{
juce::Value title, value, role, handlerType;
} accessiblityDetail;

double timingWithChildren1, timingWithChildren2, timingWithChildren3, timingWithChildrenMax;

ComponentModel() = default;
Expand Down Expand Up @@ -121,6 +128,7 @@ namespace melatonin
return;
}

nameValue = selectedComponent->getName();
lookAndFeelValue = lnfString (selectedComponent);
visibleValue = selectedComponent->isVisible();
enabledValue = selectedComponent->isEnabled();
Expand All @@ -132,6 +140,7 @@ namespace melatonin
typeValue = type (*selectedComponent);
accessibilityHandledValue = selectedComponent->isAccessible();

nameValue.addListener(this);
widthValue.addListener (this);
heightValue.addListener (this);
xValue.addListener (this);
Expand All @@ -145,6 +154,65 @@ namespace melatonin
interceptsMouseValue.addListener (this);
childrenInterceptsMouseValue.addListener (this);

if (selectedComponent->isAccessible() && selectedComponent->getAccessibilityHandler())
{
auto* accH = selectedComponent->getAccessibilityHandler();
accessiblityDetail.handlerType = type (*accH);
if (accH->getValueInterface())
{
accessiblityDetail.value = accH->getValueInterface()->getCurrentValueAsString();
}
else
{
accessiblityDetail.value = "no value interface";
}
accessiblityDetail.title = accH->getTitle();
auto role = accH->getRole();
switch (role)
{
// Amazingly juce doesn' thave a display name fn for these
#define DN(x) \
case juce::AccessibilityRole::x: \
accessiblityDetail.role = #x; \
break;
DN (button)
DN (toggleButton)
DN (radioButton)
DN (comboBox)
DN (image)
DN (slider)
DN (label)
DN (staticText)
DN (editableText)
DN (menuItem)
DN (menuBar)
DN (popupMenu)
DN (table)
DN (tableHeader)
DN (column)
DN (row)
DN (cell)
DN (hyperlink)
DN (list)
DN (listItem)
DN (tree)
DN (treeItem)
DN (progressBar)
DN (group)
DN (dialogWindow)
DN (window)
DN (scrollBar)
DN (tooltip)
DN (splashScreen)
DN (ignored)
DN (unspecified)
#undef DN
default:
accessiblityDetail.role = juce::String ("Unknown ") + juce::String ((int) role);
break;
}
}

{
bool interceptsMouse = false;
bool childrenInterceptsMouse = false;
Expand Down
55 changes: 55 additions & 0 deletions melatonin/components/accesibility.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

#pragma once
#include "melatonin_inspector/melatonin/component_model.h"

namespace melatonin
{
class Accessibility : public juce::Component, private ComponentModel::Listener
{
public:
Accessibility(ComponentModel & m) : model(m) {
addAndMakeVisible (&panel);
model.addListener (*this);
}

void updateProperties()
{
panel.clear();

if (!model.getSelectedComponent())
return;

auto& ad = model.accessiblityDetail;
auto aprops = juce::Array<juce::PropertyComponent*> {
new juce::TextPropertyComponent (ad.title, "Title", 200, false, false),
new juce::TextPropertyComponent (ad.value, "Value", 200, false, false),
new juce::TextPropertyComponent (ad.role, "Role", 200, false, false),
new juce::TextPropertyComponent (ad.handlerType, "Handler", 200, false, false),
};
for (auto* p : aprops)
{
p->setLookAndFeel (&getLookAndFeel());
}
panel.addProperties(aprops, 0);
resized();
}

protected:
ComponentModel& model;
void componentModelChanged (ComponentModel& model) override {
updateProperties();
}


void resized() override
{
TRACE_COMPONENT();
// let the property panel know what total height we need to be
panel.setBounds (getLocalBounds().withTrimmedTop (padding));
}

int padding {3};

juce::PropertyPanel panel { "Accessibility" };
};
}
1 change: 1 addition & 0 deletions melatonin/components/properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ namespace melatonin
// Always have class up top
juce::Array<juce::PropertyComponent*> props = {
new juce::TextPropertyComponent (model.typeValue, "Class", 200, false, false),
new juce::TextPropertyComponent (model.nameValue, "Name", 200, false, false),
};

// Then prioritize model properties
Expand Down
5 changes: 5 additions & 0 deletions melatonin/helpers/component_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ namespace melatonin
return juce::String ("Editor: ") + editor->getAudioProcessor()->getName();
}
#endif
else if (c && c->isAccessible() && c->getAccessibilityHandler() && !c->getAccessibilityHandler()->getTitle().isEmpty())
{
auto acctitle = c->getAccessibilityHandler()->getTitle();
return acctitle;
}
else if (c && !c->getName().isEmpty())
{
return c->getName();
Expand Down
9 changes: 9 additions & 0 deletions melatonin/inspector_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "melatonin_inspector/melatonin/components/component_tree_view_item.h"
#include "melatonin_inspector/melatonin/components/preview.h"
#include "melatonin_inspector/melatonin/components/properties.h"
#include "melatonin_inspector/melatonin/components/accesibility.h"
#include "melatonin_inspector/melatonin/lookandfeel.h"

/*
Expand Down Expand Up @@ -37,12 +38,14 @@ namespace melatonin
addChildComponent (colorPicker);
addChildComponent (preview);
addChildComponent (properties);
addChildComponent (accessibility);

// z-order on panels is higher so they are clickable
addAndMakeVisible (boxModelPanel);
addAndMakeVisible (colorPickerPanel);
addAndMakeVisible (previewPanel);
addAndMakeVisible (propertiesPanel);
addAndMakeVisible (accessibilityPanel);

addAndMakeVisible (searchBox);
addAndMakeVisible (searchIcon);
Expand Down Expand Up @@ -251,6 +254,9 @@ namespace melatonin
colorPicker.setBounds (colorPickerBounds.withTrimmedLeft (32));
colorPickerPanel.setBounds (colorPickerBounds.removeFromTop (32).removeFromLeft (200));

accessibilityPanel.setBounds (mainCol.removeFromTop (32));
accessibility.setBounds (mainCol.removeFromTop (accessibility.isVisible() ? 110 : 0).withTrimmedLeft(32));

propertiesPanel.setBounds (mainCol.removeFromTop (33)); // extra pixel for divider
properties.setBounds (mainCol.withTrimmedLeft (32));

Expand Down Expand Up @@ -391,6 +397,9 @@ namespace melatonin
Properties properties { model };
CollapsablePanel propertiesPanel { "PROPERTIES", &properties, true };

Accessibility accessibility { model };
CollapsablePanel accessibilityPanel { "ACCESSIBILITY", &accessibility, false };

// TODO: move to its own component
juce::TreeView tree;
juce::Label emptySelectionPrompt { "SelectionPrompt", "Select any component to see components tree" };
Expand Down