Description
Is your feature request related to a problem? Please describe.
I have this widget:
This is the editor where the result can be previewed. And this widget has two states: View
or Edit
, this can be represented as bool
. I believe this is more convenient to store this data in egui::Memory
because this whole thing looks like some complicated widget that receives &mut String
, and using this we can have the same benefits as other widgets have (able to serialize UI memory between runs). Also, creating custom memory and drag it into every function is quite inconvenient.
I looking for the code of CollapsingHeader
, because it has some bool state too (opened or not). And found that Memory
hard-coded all data for collapsing headers and collapsing header uses this private access. And, as I see there is no public interface to store data for a custom widget.
Describe the solution you'd like
First, we can provide an interface to store just a single bool
, i32
, String
using enums for our id.
But a more scalable approach is using HashMap
with Box<dyn Any + ...>
. Using it, we can store arbitrary types for our id
. And default widgets can be painlessly rewritten using it.
We also can require Serialize
+ Deserialize
traits for all objects that should be stored in this type-map (under feature, of course).
But this type-map can possibly add visible runtime overhead comparing to current hard-coded maps.
Describe alternatives you've considered
Not allowing a user to store data in egui::Memory
.
Additional context
I want to try to implement this feature by myself and open a Pull Request. What do you think?