From e987b0727f5fa8ea02e57389a234596e4d874cc3 Mon Sep 17 00:00:00 2001 From: Alex Levenson Date: Tue, 9 Dec 2025 16:07:02 -0800 Subject: [PATCH] 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. --- .../Editor/foleys_StylePropertyComponent.cpp | 27 ++++++++++++++++++- .../foleys_StyleTextPropertyComponent.cpp | 2 ++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/modules/foleys_gui_magic/Editor/foleys_StylePropertyComponent.cpp b/modules/foleys_gui_magic/Editor/foleys_StylePropertyComponent.cpp index 4dfc8afe..096d870b 100644 --- a/modules/foleys_gui_magic/Editor/foleys_StylePropertyComponent.cpp +++ b/modules/foleys_gui_magic/Editor/foleys_StylePropertyComponent.cpp @@ -75,7 +75,32 @@ StylePropertyComponent::StylePropertyComponent (MagicGUIBuilder& builderToUse, j remove.setConnectedEdges (juce::TextButton::ConnectedOnLeft | juce::TextButton::ConnectedOnRight); remove.onClick = [&] { - node.removeProperty (property, &builder.getUndoManager()); + // Three states: + // 1) Property has a non-empty value -> set to empty string + // 2) Property is explicitly empty string -> remove property entirely + // 3) Property not set (only default) -> do nothing + + if (node.hasProperty (property)) + { + if (node.getProperty (property).toString().isEmpty()) + { + // State 2 -> State 3: remove property entirely + // Break the label's Value binding BEFORE removing to prevent sync-back + if (auto* label = dynamic_cast(editor.get())) + { + juce::Value disconnected; + label->getTextValue().referTo (disconnected); + } + node.removeProperty (property, &builder.getUndoManager()); + } + else + { + // State 1 -> State 2: set to empty string + node.setProperty (property, "", &builder.getUndoManager()); + } + } + // State 3: property not set, do nothing (button should be disabled) + refresh(); }; diff --git a/modules/foleys_gui_magic/Editor/foleys_StyleTextPropertyComponent.cpp b/modules/foleys_gui_magic/Editor/foleys_StyleTextPropertyComponent.cpp index 41a7ec28..3dfc9724 100644 --- a/modules/foleys_gui_magic/Editor/foleys_StyleTextPropertyComponent.cpp +++ b/modules/foleys_gui_magic/Editor/foleys_StyleTextPropertyComponent.cpp @@ -69,11 +69,13 @@ void StyleTextPropertyComponent::refresh() if (node == inheritedFrom) { label->getTextValue().referTo (node.getPropertyAsValue (property, &builder.getUndoManager())); + label->setColour (juce::Label::textColourId, EditorColours::text); } else { label->getTextValue().referTo (label->getTextValue()); label->setText (value.toString(), juce::dontSendNotification); + label->setColour (juce::Label::textColourId, EditorColours::disabledText); } }