mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 21:30:03 -04:00
Store/restore emigui memory state (window positions, sizes etc)
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
use crate::{layout::Direction, *};
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||
#[serde(default)]
|
||||
pub(crate) struct State {
|
||||
pub open: bool,
|
||||
pub toggle_time: f64,
|
||||
open: bool,
|
||||
#[serde(skip)] // Times are relative, and we don't want to continue animations anyway
|
||||
toggle_time: f64,
|
||||
}
|
||||
|
||||
impl Default for State {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
open: false,
|
||||
toggle_time: -std::f64::INFINITY,
|
||||
toggle_time: -f64::INFINITY,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,7 +61,7 @@ impl CollapsingHeader {
|
||||
);
|
||||
|
||||
let state = {
|
||||
let mut memory = region.ctx.memory.lock();
|
||||
let mut memory = region.ctx.memory();
|
||||
let mut state = memory.collapsing_headers.entry(id).or_insert(State {
|
||||
open: default_open,
|
||||
..Default::default()
|
||||
|
||||
@@ -7,8 +7,8 @@ use std::{fmt::Debug, hash::Hash, sync::Arc};
|
||||
|
||||
use crate::*;
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct State {
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||
pub(crate) struct State {
|
||||
/// Last known pos
|
||||
pub pos: Pos2,
|
||||
|
||||
@@ -50,7 +50,7 @@ impl Floating {
|
||||
let id = ctx.register_unique_id(self.id, "Floating", default_pos);
|
||||
let layer = Layer::Window(id);
|
||||
|
||||
let (mut state, _is_new) = match ctx.memory.lock().get_floating(id) {
|
||||
let (mut state, _is_new) = match ctx.memory().get_floating(id) {
|
||||
Some(state) => (state, false),
|
||||
None => {
|
||||
let state = State {
|
||||
@@ -90,15 +90,15 @@ impl Floating {
|
||||
state.pos = state.pos.round();
|
||||
|
||||
if move_interact.active || mouse_pressed_on_floating(ctx, id) {
|
||||
ctx.memory.lock().move_floating_to_top(id);
|
||||
ctx.memory().move_floating_to_top(id);
|
||||
}
|
||||
ctx.memory.lock().set_floating_state(id, state);
|
||||
ctx.memory().set_floating_state(id, state);
|
||||
}
|
||||
}
|
||||
|
||||
fn mouse_pressed_on_floating(ctx: &Context, id: Id) -> bool {
|
||||
if let Some(mouse_pos) = ctx.input.mouse_pos {
|
||||
ctx.input.mouse_pressed && ctx.memory.lock().layer_at(mouse_pos) == Layer::Window(id)
|
||||
ctx.input.mouse_pressed && ctx.memory().layer_at(mouse_pos) == Layer::Window(id)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#![allow(unused_variables)] // TODO
|
||||
use crate::*;
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct State {
|
||||
pub size: Vec2,
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||
pub(crate) struct State {
|
||||
size: Vec2,
|
||||
}
|
||||
|
||||
// TODO: auto-shink/grow should be part of another container!
|
||||
@@ -229,7 +229,7 @@ impl Resize {
|
||||
paint_resize_corner(region, &corner_rect, &corner_interact);
|
||||
|
||||
if corner_interact.hovered || corner_interact.active {
|
||||
region.ctx().output.lock().cursor_icon = CursorIcon::ResizeNwSe;
|
||||
region.ctx().output().cursor_icon = CursorIcon::ResizeNwSe;
|
||||
}
|
||||
|
||||
region.memory().resize.insert(id, state);
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
use crate::*;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct State {
|
||||
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize)]
|
||||
#[serde(default)]
|
||||
pub(crate) struct State {
|
||||
/// Positive offset means scrolling down/right
|
||||
pub offset: Vec2,
|
||||
offset: Vec2,
|
||||
|
||||
pub show_scroll: bool, // TODO: default value?
|
||||
show_scroll: bool, // TODO: default value?
|
||||
}
|
||||
|
||||
// TODO: rename VScroll
|
||||
@@ -49,8 +50,7 @@ impl ScrollArea {
|
||||
|
||||
let scroll_area_id = outer_region.id.with("scroll_area");
|
||||
let mut state = ctx
|
||||
.memory
|
||||
.lock()
|
||||
.memory()
|
||||
.scroll_areas
|
||||
.get(&scroll_area_id)
|
||||
.cloned()
|
||||
@@ -105,7 +105,7 @@ impl ScrollArea {
|
||||
}
|
||||
|
||||
// TODO: check that nothing else is being inteacted with
|
||||
if outer_region.contains_mouse(&outer_rect) && ctx.memory.lock().active_id.is_none() {
|
||||
if outer_region.contains_mouse(&outer_rect) && ctx.memory().active_id.is_none() {
|
||||
state.offset.y -= ctx.input.scroll_delta.y;
|
||||
}
|
||||
|
||||
@@ -194,9 +194,7 @@ impl ScrollArea {
|
||||
state.show_scroll = show_scroll_this_frame;
|
||||
|
||||
outer_region
|
||||
.ctx()
|
||||
.memory
|
||||
.lock()
|
||||
.memory()
|
||||
.scroll_areas
|
||||
.insert(scroll_area_id, state);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user