Skip to content

Conversation

@dmackdev
Copy link
Owner

@dmackdev dmackdev commented Jul 19, 2025

This PR enables automatic reset of expanded arrays/objects when the DefaultExpand setting changes between two frames. This is enabled by default, but can be controlled via configuration method JsonTree::auto_reset_expanded(bool).

Automatic reset of expanded arrays/objects eliminates some boilerplate and the current burden on the programmer to currently do this manually via JsonTreeResponse::reset_expanded(egui::Ui). This must be done in order to have the JsonTree automatically expand/collapse those arrays/objects to respect the DefaultExpand setting, e.g. to only expand and highlight search term matches within the tree.

This works by storing (temporarily, not persisted) the hash of the DefaultExpand value in egui's IdTypeMap (superficial widget state) against the JsonTree's Id. When this value changes between two frames, we know to reset the expanded arrays/objects to respect the changed DefaultExpand setting in the next frame. Additionally, a unit struct is also stored temporarily, whose presence indicates that a reset is required. Resetting expanded state is now done lazily, as each node in the tree renders, instead of all at once via the response.

Future work could extend this concept to allow the programmer to register "reset expanded keys" on the JsonTree, which could trigger a reset of the arrays/objects when the key changes between two frames (similar to the dependencies array in React's useEffect). This way, the result of a button.clicked() call could be registered to trigger a reset of the expanded arrays/objects.

@dmackdev dmackdev changed the title Auto reset expanded setting Support automatic reset of expanded arrays/objects when DefaultExpand setting changes Jul 19, 2025
dmackdev added 2 commits July 20, 2025 16:34
set this in JsonTreeRespose::reset_expanded or when default expand changes
reset expanded lazily, without need for HashSet<Id>
@dmackdev dmackdev marked this pull request as ready for review July 21, 2025 19:21
@dmackdev dmackdev force-pushed the auto-reset-expanded branch from 3b44d75 to cc93ffc Compare July 21, 2025 19:24
@dmackdev dmackdev merged commit 4215043 into master Jul 21, 2025
2 checks passed
@dmackdev dmackdev deleted the auto-reset-expanded branch July 21, 2025 20:07
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