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

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

Merged
merged 1 commit into from
May 11, 2024

Conversation

ImJimmi
Copy link
Collaborator

@ImJimmi ImJimmi commented Apr 23, 2024

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:

  • Create a juce::Component.
  • Set an Object property on the component, (you can use any type that inherits from juce::ReferenceCountedObject, e.g. a juce::DynamicObject).
  • Inspect the component with the Inspector such that its properties are shown in the list
  • The Object has been destroyed and replaced with a string in the form "Object 0xabc"
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 ImJimmi changed the title Make copy of property value string when displaying properties with object values Make copy of stringified-value when displaying properties with Object values Apr 23, 2024
@ImJimmi ImJimmi changed the title Make copy of stringified-value when displaying properties with Object values Make copy of stringified value when displaying properties with Object values Apr 23, 2024
@ImJimmi
Copy link
Collaborator Author

ImJimmi commented Apr 23, 2024

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
Copy link
Owner

sudara commented Apr 25, 2024

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

@sudara sudara merged commit fdaffde into sudara:main May 11, 2024
12 checks passed
@sudara
Copy link
Owner

sudara commented May 11, 2024

Thanks for the contribution!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants