Skip to content

Commit 20cbb3a

Browse files
authored
Merge pull request #108 from sudara/refx/more_properties
Add button properties
2 parents 2b335c7 + 2ddbaa0 commit 20cbb3a

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

melatonin/component_model.h

+40
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ namespace melatonin
2424
juce::Value pickedColor;
2525
juce::Value timing1, timing2, timing3, timingMax, hasChildren;
2626

27+
juce::Value isToggleable, toggleState, clickTogglesState, radioGroupId;
28+
2729
struct AccessiblityDetail
2830
{
2931
juce::Value title, value, role, handlerType;
@@ -140,6 +142,14 @@ namespace melatonin
140142
typeValue = type (*selectedComponent);
141143
accessibilityHandledValue = selectedComponent->isAccessible();
142144

145+
if (auto button = dynamic_cast<juce::Button*> (selectedComponent.getComponent()))
146+
{
147+
isToggleable = button->isToggleable();
148+
toggleState = button->getToggleState();
149+
clickTogglesState = button->getClickingTogglesState();
150+
radioGroupId = button->getRadioGroupId();
151+
}
152+
143153
nameValue.addListener(this);
144154
widthValue.addListener (this);
145155
heightValue.addListener (this);
@@ -154,6 +164,11 @@ namespace melatonin
154164
interceptsMouseValue.addListener (this);
155165
childrenInterceptsMouseValue.addListener (this);
156166

167+
isToggleable.addListener (this);
168+
toggleState.addListener (this);
169+
clickTogglesState.addListener (this);
170+
radioGroupId.addListener (this);
171+
157172
if (selectedComponent->isAccessible() && selectedComponent->getAccessibilityHandler())
158173
{
159174
auto* accH = selectedComponent->getAccessibilityHandler();
@@ -260,6 +275,11 @@ namespace melatonin
260275
interceptsMouseValue.removeListener (this);
261276
childrenInterceptsMouseValue.removeListener (this);
262277

278+
isToggleable.removeListener (this);
279+
toggleState.removeListener (this);
280+
clickTogglesState.removeListener (this);
281+
radioGroupId.removeListener (this);
282+
263283
for (auto& np : namedProperties)
264284
np.value.removeListener (this);
265285

@@ -321,6 +341,26 @@ namespace melatonin
321341
{
322342
selectedComponent->setInterceptsMouseClicks (interceptsMouseValue.getValue(), childrenInterceptsMouseValue.getValue());
323343
}
344+
else if (value.refersToSameSourceAs (isToggleable))
345+
{
346+
if (auto button = dynamic_cast<juce::Button*> (selectedComponent.getComponent()))
347+
button->setToggleable (isToggleable.getValue());
348+
}
349+
else if (value.refersToSameSourceAs (toggleState))
350+
{
351+
if (auto button = dynamic_cast<juce::Button*> (selectedComponent.getComponent()))
352+
button->setToggleState (toggleState.getValue(), juce::dontSendNotification);
353+
}
354+
else if (value.refersToSameSourceAs (clickTogglesState))
355+
{
356+
if (auto button = dynamic_cast<juce::Button*> (selectedComponent.getComponent()))
357+
button->setClickingTogglesState (clickTogglesState.getValue());
358+
}
359+
else if (value.refersToSameSourceAs (radioGroupId))
360+
{
361+
if (auto button = dynamic_cast<juce::Button*> (selectedComponent.getComponent()))
362+
button->setRadioGroupId (radioGroupId.getValue());
363+
}
324364
else
325365
{
326366
for (auto& nv : namedProperties)

melatonin/components/properties.h

+10
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ namespace melatonin
105105
}
106106
}
107107

108+
// add class specific properies
109+
if (dynamic_cast<juce::Button*> (model.getSelectedComponent()))
110+
{
111+
props.addArray (juce::Array<juce::PropertyComponent*> {
112+
new juce::BooleanPropertyComponent (model.isToggleable, "Is Toggleable", ""),
113+
new juce::BooleanPropertyComponent (model.toggleState, "Toggle State", ""),
114+
new juce::BooleanPropertyComponent (model.clickTogglesState, "Clicking Toggles State", ""),
115+
new juce::TextPropertyComponent (model.radioGroupId, "Radio Group ID", 5, false) });
116+
}
117+
108118
// then the rest of the component flags
109119
props.addArray (juce::Array<juce::PropertyComponent*> {
110120
new juce::TextPropertyComponent (model.lookAndFeelValue, "LookAndFeel", 200, false, false),

0 commit comments

Comments
 (0)