Skip to content

Commit e987b07

Browse files
committed
Fixes the X button in the editor UI's behavior for properties with default values.
For properties without default values, the X button moves through 3 states, and alwas moves from state 1 towards state 3: 1) Property is set to a value, eg height="7" 2) Property is set to empty string, eg height="" 3) Property is not set at all This is nice behavior! But it doesn't work that way for properties with default value, like min-width and friends. Those properties just oscillate between states 1 and 2 and can't ever get to 3. This PR fixes that -- I believe the issue has to do w/ callbacks triggering when we don't want them to. This PR also makes a UI style change in that for properties in state 3, we grey out the text showing the user what default value is going to be applied. I think this makes it more clear that there is a default, here's what it is, no it's not set in your xml file explicitly. This also applies to values that were inherited -- you can see what's inherited but we make it clear that it's not set on this node.
1 parent 7a7bb73 commit e987b07

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

modules/foleys_gui_magic/Editor/foleys_StylePropertyComponent.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,32 @@ StylePropertyComponent::StylePropertyComponent (MagicGUIBuilder& builderToUse, j
7575
remove.setConnectedEdges (juce::TextButton::ConnectedOnLeft | juce::TextButton::ConnectedOnRight);
7676
remove.onClick = [&]
7777
{
78-
node.removeProperty (property, &builder.getUndoManager());
78+
// Three states:
79+
// 1) Property has a non-empty value -> set to empty string
80+
// 2) Property is explicitly empty string -> remove property entirely
81+
// 3) Property not set (only default) -> do nothing
82+
83+
if (node.hasProperty (property))
84+
{
85+
if (node.getProperty (property).toString().isEmpty())
86+
{
87+
// State 2 -> State 3: remove property entirely
88+
// Break the label's Value binding BEFORE removing to prevent sync-back
89+
if (auto* label = dynamic_cast<juce::Label*>(editor.get()))
90+
{
91+
juce::Value disconnected;
92+
label->getTextValue().referTo (disconnected);
93+
}
94+
node.removeProperty (property, &builder.getUndoManager());
95+
}
96+
else
97+
{
98+
// State 1 -> State 2: set to empty string
99+
node.setProperty (property, "", &builder.getUndoManager());
100+
}
101+
}
102+
// State 3: property not set, do nothing (button should be disabled)
103+
79104
refresh();
80105
};
81106

modules/foleys_gui_magic/Editor/foleys_StyleTextPropertyComponent.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,13 @@ void StyleTextPropertyComponent::refresh()
6969
if (node == inheritedFrom)
7070
{
7171
label->getTextValue().referTo (node.getPropertyAsValue (property, &builder.getUndoManager()));
72+
label->setColour (juce::Label::textColourId, EditorColours::text);
7273
}
7374
else
7475
{
7576
label->getTextValue().referTo (label->getTextValue());
7677
label->setText (value.toString(), juce::dontSendNotification);
78+
label->setColour (juce::Label::textColourId, EditorColours::disabledText);
7779
}
7880
}
7981

0 commit comments

Comments
 (0)