diff --git a/emigui/README.md b/emigui/README.md index 37fcc354..748c5c90 100644 --- a/emigui/README.md +++ b/emigui/README.md @@ -13,7 +13,6 @@ This is the core library crate Emigui. It is fully platform independent without * [x] Tooltip * [x] Movable/resizable windows * [x] Kinetic windows - * [ ] BUG FIX: Don't catch clicks on closed windows * [ ] Windows should open from Regions and be boxed by parent region. * Then we could open the example app inside a window in the example app, recursively. * [ ] Scroll areas diff --git a/emigui/src/context.rs b/emigui/src/context.rs index 01dc2f87..8189a4af 100644 --- a/emigui/src/context.rs +++ b/emigui/src/context.rs @@ -156,6 +156,7 @@ impl Context { if !self.last_raw_input.mouse_down || self.last_raw_input.mouse_pos.is_none() { self.memory().active_id = None; } + self.memory().begin_frame(); self.used_ids.lock().clear(); @@ -181,7 +182,7 @@ impl Context { fn drain_paint_lists(&self) -> Vec<(Rect, PaintCmd)> { let memory = self.memory(); - self.graphics().drain(&memory.floating_order).collect() + self.graphics().drain(memory.floating_order()).collect() } fn paint(&self) -> PaintBatches { diff --git a/emigui/src/layers.rs b/emigui/src/layers.rs index 5cee0e36..edf22055 100644 --- a/emigui/src/layers.rs +++ b/emigui/src/layers.rs @@ -37,11 +37,11 @@ impl GraphicLayers { pub fn drain( &mut self, - window_oreder: &[Id], + window_order: &[Id], ) -> impl ExactSizeIterator { let mut all_commands: Vec<_> = self.bg.drain(..).collect(); - for id in window_oreder { + for id in window_order { if let Some(window) = self.windows.get_mut(id) { all_commands.extend(window.drain(..)); } diff --git a/emigui/src/memory.rs b/emigui/src/memory.rs index 55bd98a3..b74033f0 100644 --- a/emigui/src/memory.rs +++ b/emigui/src/memory.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use crate::{ containers::{collapsing_header, floating, resize, scroll_area}, @@ -20,10 +20,12 @@ pub struct Memory { pub(crate) collapsing_headers: HashMap, pub(crate) scroll_areas: HashMap, pub(crate) resize: HashMap, - floating: HashMap, + floating: HashMap, /// Top is last - pub floating_order: Vec, + floating_order: Vec, + floating_visible_last_frame: HashSet, + floating_visible_current_frame: HashSet, } impl Memory { @@ -31,7 +33,12 @@ impl Memory { self.floating.get(&id).cloned() } + pub(crate) fn floating_order(&self) -> &[Id] { + &self.floating_order + } + pub(crate) fn set_floating_state(&mut self, id: Id, state: floating::State) { + self.floating_visible_current_frame.insert(id); let did_insert = self.floating.insert(id, state).is_none(); if did_insert { self.floating_order.push(id); @@ -41,10 +48,14 @@ impl Memory { /// TODO: call once at the start of the frame for the current mouse pos pub fn layer_at(&self, pos: Pos2) -> Layer { for floating_id in self.floating_order.iter().rev() { - if let Some(state) = self.floating.get(floating_id) { - let rect = Rect::from_min_size(state.pos, state.size); - if rect.contains(pos) { - return Layer::Window(*floating_id); + if self.floating_visible_last_frame.contains(floating_id) + || self.floating_visible_current_frame.contains(floating_id) + { + if let Some(state) = self.floating.get(floating_id) { + let rect = Rect::from_min_size(state.pos, state.size); + if rect.contains(pos) { + return Layer::Window(*floating_id); + } } } } @@ -59,5 +70,10 @@ impl Memory { self.floating_order.remove(index); } self.floating_order.push(id); + self.floating_visible_current_frame.insert(id); + } + + pub(crate) fn begin_frame(&mut self) { + self.floating_visible_last_frame = std::mem::take(&mut self.floating_visible_current_frame); } }