Handle window paint order (click to bring to front etc)

This commit is contained in:
Emil Ernerfeldt 2020-04-17 23:22:28 +02:00
parent f709423809
commit 481af55ce5
6 changed files with 31 additions and 10 deletions

View file

@ -55,6 +55,15 @@ impl Context {
}
}
pub fn drain_paint_lists(&self) -> Vec<PaintCmd> {
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()

View file

@ -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<Item = PaintCmd> {
pub fn drain(&mut self, window_oreder: &[Id]) -> impl ExactSizeIterator<Item = PaintCmd> {
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(..));

View file

@ -105,7 +105,7 @@ where
let mut contents_region = Region {
ctx: ctx.clone(),
layer: Layer::Popup,
layer,
style,
id: Default::default(),
dir: Direction::Vertical,

View file

@ -13,7 +13,7 @@ pub struct Memory {
windows: HashMap<Id, WindowState>,
/// Top is last
window_order: Vec<Id>,
pub window_order: Vec<Id>,
}
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);
}
}

View file

@ -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,

View file

@ -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());