Support automatic reset of expanded arrays/objects when DefaultExpand setting changes
#47
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR enables automatic reset of expanded arrays/objects when the
DefaultExpandsetting changes between two frames. This is enabled by default, but can be controlled via configuration methodJsonTree::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 theDefaultExpandsetting, e.g. to only expand and highlight search term matches within the tree.This works by storing (temporarily, not persisted) the hash of the
DefaultExpandvalue inegui'sIdTypeMap(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 changedDefaultExpandsetting 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 abutton.clicked()call could be registered to trigger a reset of the expanded arrays/objects.