sudara / melatonin_inspector

A JUCE module that gives you the ability to inspect and visually edit (non-destructively) components in your UI.
MIT License
145 stars 17 forks source link

Make copy of stringified value when displaying properties with Object values #111

Closed ImJimmi closed 5 months ago

ImJimmi commented 6 months ago

Fixes a bug where Component properties with Object values would get turned into strings due to the use of juce::TextPropertyComponent and shared values.

To reproduce:

juce::Component component;
component.getProperties().set("foo", new juce::DynamicObject{});
jassert(component.getProperties()["foo"].isObject()); // TRUE
jassert(component.getProperties()["foo"].isString()); // FALSE

// Inspect component with the inspector...

jassert(component.getProperties()["foo"].isObject()); // FALSE
jassert(component.getProperties()["foo"].isString()); // TRUE

This is due to how juce::TextPropertyComponent uses juce::Value - when it goes to display the value, it sets the text of it's juce::Label to the stringified version of the object. This causes a listener-change callback in the juce::Value that the label refers to which causes the underlying juce::var, originally in the component's properties list, to also be turned into a string.

The proposed solution here is to simply make a copy of the stringified value if the value is an object type.

ImJimmi commented 6 months ago

For context, this breaks a lot of stuff in JIVE because the styling API sets a "style-sheet" property on the component, but when that property is displayed in the inspector, the property is converted to a string and so the actual style-sheet object is destroyed.

In this case, the text on the buttons can no longer retrieve their correct font colour as their style-sheets are destroyed:

inspector-bug

sudara commented 6 months ago

Thanks for both the fix and all the documentation! Back from vacation and this is on my list to look at next!

sudara commented 5 months ago

Thanks for the contribution!!