Struct rerun::external::eframe::egui::Memory

pub struct Memory {
    pub options: Options,
    pub data: IdTypeMap,
    pub caches: CacheStorage,
    pub(crate) new_font_definitions: Option<FontDefinitions>,
    pub(crate) viewport_id: ViewportId,
    popup: Option<Id>,
    everything_is_visible: bool,
    pub layer_transforms: HashMap<LayerId, TSTransform, RandomState>,
    areas: HashMap<ViewportId, Areas, BuildHasherDefault<NoHashHasher<ViewportId>>>,
    pub(crate) interactions: HashMap<ViewportId, InteractionState, BuildHasherDefault<NoHashHasher<ViewportId>>>,
    pub(crate) focus: HashMap<ViewportId, Focus, BuildHasherDefault<NoHashHasher<ViewportId>>>,
}
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. For this you need to enable the persistence.

If you want to store data for your widgets, you should look at Memory::data

Fields§

§options: Options

Global egui options.

§data: IdTypeMap

This map stores some superficial state for all widgets with custom Ids.

This includes storing whether a crate::CollapsingHeader is open, how far scrolled a crate::ScrollArea is, where the cursor in a crate::TextEdit is, etc.

This is NOT meant to store any important data. Store that in your own structures!

Each read clones the data, so keep your values cheap to clone. If you want to store a lot of data, you should wrap it in Arc<Mutex<…>> so it is cheap to clone.

This will be saved between different program runs if you use the persistence feature.

To store a state common for all your widgets (a singleton), use Id::NULL as the key.

§caches: CacheStorage

Can be used to cache computations from one frame to another.

This is for saving CPU time when you have something that may take 1-100ms to compute. Very slow operations (>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>;

ctx.memory_mut(|mem| {
    let cache = mem.caches.cache::<CharCountCache<'_>>();
    assert_eq!(cache.get("hello"), 5);
});
§new_font_definitions: Option<FontDefinitions>§viewport_id: ViewportId§popup: Option<Id>§everything_is_visible: bool§layer_transforms: HashMap<LayerId, TSTransform, RandomState>

Transforms per layer

§areas: HashMap<ViewportId, Areas, BuildHasherDefault<NoHashHasher<ViewportId>>>§interactions: HashMap<ViewportId, InteractionState, BuildHasherDefault<NoHashHasher<ViewportId>>>§focus: HashMap<ViewportId, Focus, BuildHasherDefault<NoHashHasher<ViewportId>>>

Implementations§

§

impl Memory

pub fn areas(&self) -> &Areas

Access memory of the Areas, such as Windows.

pub fn areas_mut(&mut self) -> &mut Areas

Access memory of the Areas, such as Windows.

pub fn layer_id_at(&self, pos: Pos2) -> Option<LayerId>

Top-most layer at the given position.

pub fn layer_ids(&self) -> impl ExactSizeIterator

An iterator over all layers. Back-to-front, top is last.

pub fn had_focus_last_frame(&self, id: Id) -> bool

Check if the layer had focus last frame. returns true if the layer had focus last frame, but not this one.

pub fn has_focus(&self, id: Id) -> bool

Does this widget have keyboard focus?

This function does not consider whether the UI as a whole (e.g. window) has the keyboard focus. That makes this function suitable for deciding widget state that should not be disrupted if the user moves away from the window and back.

pub fn focused(&self) -> Option<Id>

Which widget has keyboard focus?

pub fn set_focus_lock_filter(&mut self, id: Id, event_filter: EventFilter)

Set an event filter for a widget.

This allows you to control whether the widget will loose focus when the user presses tab, arrow keys, or escape.

You must first give focus to the widget before calling this.

pub fn request_focus(&mut self, id: Id)

Give keyboard focus to a specific widget. See also crate::Response::request_focus.

pub fn surrender_focus(&mut self, id: Id)

Surrender keyboard focus for a specific widget. See also crate::Response::surrender_focus.

pub fn interested_in_focus(&mut self, id: Id)

Register this widget as being interested in getting keyboard focus. This will allow the user to select it with tab and shift-tab. This is normally done automatically when handling interactions, but it is sometimes useful to pre-register interest in focus, e.g. before deciding which type of underlying widget to use, as in the crate::DragValue widget, so a widget can be focused and rendered correctly in a single frame.

pub fn stop_text_input(&mut self)

Stop editing the active TextEdit (if any).

pub fn is_anything_being_dragged(&self) -> bool

👎Deprecated: Use Context::dragged_id instead

Is any widget being dragged?

pub fn is_being_dragged(&self, id: Id) -> bool

👎Deprecated: Use Context::is_being_dragged instead

Is this specific widget being dragged?

A widget that sense both clicks and drags is only marked as “dragged” when the mouse has moved a bit, but is_being_dragged will return true immediately.

pub fn dragged_id(&self) -> Option<Id>

👎Deprecated: Use Context::dragged_id instead

Get the id of the widget being dragged, if any.

Note that this is set as soon as the mouse is pressed, so the widget may not yet be marked as “dragged”, as that can only happen after the mouse has moved a bit (at least if the widget is interesated in both clicks and drags).

pub fn set_dragged_id(&mut self, id: Id)

👎Deprecated: Use Context::set_dragged_id instead

Set which widget is being dragged.

pub fn stop_dragging(&mut self)

👎Deprecated: Use Context::stop_dragging instead

Stop dragging any widget.

pub fn dragging_something_else(&self, not_this: Id) -> bool

👎Deprecated: Use Context::dragging_something_else instead

Is something else being dragged?

Returns true if we are dragging something, but not the given widget.

pub fn reset_areas(&mut self)

Forget window positions, sizes etc. Can be used to auto-layout windows.

pub fn area_rect(&self, id: impl Into<Id>) -> Option<Rect>

Obtain the previous rectangle of an area.

§

impl Memory

§Popups

Popups are things like combo-boxes, color pickers, menus etc. Only one can be open at a time.

pub fn is_popup_open(&self, popup_id: Id) -> bool

Is the given popup open?

pub fn any_popup_open(&self) -> bool

Is any popup open?

pub fn open_popup(&mut self, popup_id: Id)

Open the given popup and close all others.

pub fn close_popup(&mut self)

Close the open popup, if any.

pub fn toggle_popup(&mut self, popup_id: Id)

Toggle the given popup between closed and open.

Note: At most, only one popup can be open at a time.

pub fn everything_is_visible(&self) -> bool

If true, all windows, menus, tooltips, etc., will be visible at once.

This is useful for testing, benchmarking, pre-caching, etc.

Experimental feature!

pub fn set_everything_is_visible(&mut self, value: bool)

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§

§

impl Clone for Memory

§

fn clone(&self) -> Memory

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for Memory

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for Memory

§

fn default() -> Memory

Returns the “default value” for a type. Read more
§

impl<'de> Deserialize<'de> for Memory
where Memory: Default,

§

fn deserialize<__D>( __deserializer: __D ) -> Result<Memory, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl Serialize for Memory

§

fn serialize<__S>( &self, __serializer: __S ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Memory

§

impl !RefUnwindSafe for Memory

§

impl Send for Memory

§

impl Sync for Memory

§

impl Unpin for Memory

§

impl !UnwindSafe for Memory

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Az for T

source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

source§

fn cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> CheckedAs for T

source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> DynClone for T
where T: Clone,

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

source§

fn lossy_into(self) -> Dst

Performs the conversion.
§

impl<T> NoneValue for T
where T: Default,

§

type NoneType = T

§

fn null_value() -> T

The none-equivalent value.
source§

impl<T> OverflowingAs for T

source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> SaturatingAs for T

source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
§

impl<T> To for T
where T: ?Sized,

§

fn to<T>(self) -> T
where Self: Into<T>,

Converts to T by calling Into<T>::into.
§

fn try_to<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Tries to convert to T by calling TryInto<T>::try_into.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> UnwrappedAs for T

source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> WrappingAs for T

source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + Serialize + for<'a> Deserialize<'a> + Send + Sync,

§

impl<T> Ungil for T
where T: Send,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T

§

impl<T> WasmNotSync for T
where T: Sync,