Struct egui::Memory [−][src]
pub struct Memory {
pub options: Options,
pub data: TypeMap,
pub data_temp: TypeMap,
pub id_data: IdAnyMap,
pub id_data_temp: AnyMap<Id, BuilIdHasher>,
pub caches: CacheStorage,
// some fields omitted
}
Expand description
The data that egui persists between frames.
This includes window positions and sizes,
how far the user has scrolled in a ScrollArea
etc.
If you want this to persist when closing your app you should serialize Memory
and store it.
If you want to store data for your widgets, you should look at data
/data_temp
and
id_data
/id_data_temp
fields, and read the documentation of any
module.
Fields
options: Options
data: TypeMap
This map stores current states for widgets that don’t require Id
.
This will be saved between different program runs if you use the persistence
feature.
data_temp: TypeMap
Same as data
, but this data will not be saved between runs.
id_data: IdAnyMap
This map stores current states for all widgets with custom Id
s.
This will be saved between different program runs if you use the persistence
feature.
id_data_temp: AnyMap<Id, BuilIdHasher>
Same as id_data
, but this data will not be saved between runs.
caches: CacheStorage
Can be used to cache computations from one frame to another.
This is for saving CPU when you have something that may take 1-100ms to compute. Things that are very slow (>100ms) should instead be done async (i.e. in another thread) so as not to lock the UI thread.
use egui::util::cache::{ComputerMut, FrameCache};
#[derive(Default)]
struct CharCounter {}
impl ComputerMut<&str, usize> for CharCounter {
fn compute(&mut self, s: &str) -> usize {
s.chars().count() // you probably want to cache something more expensive than this
}
}
type CharCountCache<'a> = FrameCache<usize, CharCounter>;
let mut memory = ctx.memory();
let cache = memory.caches.cache::<CharCountCache<'_>>();
assert_eq!(cache.get("hello"), 5);
Implementations
Top-most layer at the given position.
Give keyboard focus to a specific widget.
See also crate::Response::request_focus
.
Surrender keyboard focus for a specific widget.
See also crate::Response::surrender_focus
.
Stop editing of active TextEdit
(if any).
Forget window positions, sizes etc. Can be used to auto-layout windows.
Popups
Popups are things like combo-boxes, color pickers, menus etc. Only one can be be open at a time.
If true, all windows, menus, tooltips etc are to be visible at once.
This is useful for testing, benchmarking, pre-caching, etc.
Experimental feature!
If true, all windows, menus, tooltips etc are to be visible at once.
This is useful for testing, benchmarking, pre-caching, etc.
Experimental feature!
Trait Implementations
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations
impl !RefUnwindSafe for Memory
impl !UnwindSafe for Memory
Blanket Implementations
Mutably borrows from an owned value. Read more