mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 21:30:03 -04:00
Move Memory and Region to own files
This commit is contained in:
50
emigui/src/memory.rs
Normal file
50
emigui/src/memory.rs
Normal file
@@ -0,0 +1,50 @@
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use crate::{window::WindowState, *};
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct Memory {
|
||||
/// The widget being interacted with (e.g. dragged, in case of a slider).
|
||||
pub(crate) active_id: Option<Id>,
|
||||
|
||||
/// Which foldable regions are open.
|
||||
pub(crate) open_foldables: HashSet<Id>,
|
||||
|
||||
windows: HashMap<Id, WindowState>,
|
||||
|
||||
/// Top is last
|
||||
window_order: Vec<Id>,
|
||||
}
|
||||
|
||||
impl Memory {
|
||||
/// default_rect: where to put it if it does NOT exist
|
||||
pub fn get_or_create_window(&mut self, id: Id, default_rect: Rect) -> WindowState {
|
||||
if let Some(state) = self.windows.get(&id) {
|
||||
*state
|
||||
} else {
|
||||
let state = WindowState { rect: default_rect };
|
||||
self.windows.insert(id, state);
|
||||
self.window_order.push(id);
|
||||
state
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_window_state(&mut self, id: Id, state: WindowState) {
|
||||
self.windows.insert(id, state);
|
||||
}
|
||||
|
||||
pub fn layer_at(&self, pos: Vec2) -> Layer {
|
||||
for window_id in self.window_order.iter().rev() {
|
||||
if let Some(state) = self.windows.get(window_id) {
|
||||
if state.rect.contains(pos) {
|
||||
return Layer::Window(*window_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
Layer::Background
|
||||
}
|
||||
|
||||
pub fn move_window_to_top(&mut self, _id: Id) {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user