diff --git a/emigui/src/context.rs b/emigui/src/context.rs index 447346a1..561abf46 100644 --- a/emigui/src/context.rs +++ b/emigui/src/context.rs @@ -55,6 +55,15 @@ impl Context { } } + pub fn drain_paint_lists(&self) -> Vec { + let memory = self.memory.lock().unwrap(); + self.graphics + .lock() + .unwrap() + .drain(&memory.window_order) + .collect() + } + /// Is the user interacting with anything? pub fn any_active(&self) -> bool { self.memory.lock().unwrap().active_id.is_some() diff --git a/emigui/src/layers.rs b/emigui/src/layers.rs index b84c871e..2b481d12 100644 --- a/emigui/src/layers.rs +++ b/emigui/src/layers.rs @@ -7,6 +7,7 @@ use crate::{Id, PaintCmd}; pub enum Layer { Background, Window(Id), + /// Tooltips etc Popup, } @@ -29,12 +30,13 @@ impl GraphicLayers { } } - pub fn drain(&mut self) -> impl ExactSizeIterator { + pub fn drain(&mut self, window_oreder: &[Id]) -> impl ExactSizeIterator { let mut all_commands: Vec<_> = self.bg.drain(..).collect(); - // TODO: order - for window in self.windows.values_mut() { - all_commands.extend(window.drain(..)); + for id in window_oreder { + if let Some(window) = self.windows.get_mut(id) { + all_commands.extend(window.drain(..)); + } } all_commands.extend(self.popup.drain(..)); diff --git a/emigui/src/layout.rs b/emigui/src/layout.rs index 5343421c..696fc4f9 100644 --- a/emigui/src/layout.rs +++ b/emigui/src/layout.rs @@ -105,7 +105,7 @@ where let mut contents_region = Region { ctx: ctx.clone(), - layer: Layer::Popup, + layer, style, id: Default::default(), dir: Direction::Vertical, diff --git a/emigui/src/memory.rs b/emigui/src/memory.rs index 3110aec2..27cf4f33 100644 --- a/emigui/src/memory.rs +++ b/emigui/src/memory.rs @@ -13,7 +13,7 @@ pub struct Memory { windows: HashMap, /// Top is last - window_order: Vec, + pub window_order: Vec, } impl Memory { @@ -44,7 +44,13 @@ impl Memory { Layer::Background } - pub fn move_window_to_top(&mut self, _id: Id) { - // TODO + pub fn move_window_to_top(&mut self, id: Id) { + if self.window_order.last() == Some(&id) { + return; // common case early-out + } + if let Some(index) = self.window_order.iter().position(|x| *x == id) { + self.window_order.remove(index); + } + self.window_order.push(id); } } diff --git a/emigui/src/window.rs b/emigui/src/window.rs index 56f8a785..4fc46add 100644 --- a/emigui/src/window.rs +++ b/emigui/src/window.rs @@ -46,7 +46,7 @@ impl Window { let mut contents_region = Region { ctx: ctx.clone(), - layer: Layer::Popup, + layer, style, id: Default::default(), dir: Direction::Vertical, diff --git a/example_glium/src/main.rs b/example_glium/src/main.rs index 18a8e510..47127611 100644 --- a/example_glium/src/main.rs +++ b/example_glium/src/main.rs @@ -91,10 +91,14 @@ fn main() { example_app.ui(&mut region); emigui.ui(&mut region); - // TODO: Make it simpler to show a window + // TODO: Make it even simpler to show a window Window::new("Test window").show(region.ctx(), |region| { region.add(label!("Grab the window and move it around!")); }); + Window::new("Another test window").show(region.ctx(), |region| { + region.add(label!("This might be on top of the other window?")); + region.add(label!("Second line of text")); + }); let mesh = emigui.paint(); painter.paint(&display, mesh, emigui.texture());