Handle window paint order (click to bring to front etc)
This commit is contained in:
parent
f709423809
commit
481af55ce5
6 changed files with 31 additions and 10 deletions
|
@ -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?
|
/// Is the user interacting with anything?
|
||||||
pub fn any_active(&self) -> bool {
|
pub fn any_active(&self) -> bool {
|
||||||
self.memory.lock().unwrap().active_id.is_some()
|
self.memory.lock().unwrap().active_id.is_some()
|
||||||
|
|
|
@ -7,6 +7,7 @@ use crate::{Id, PaintCmd};
|
||||||
pub enum Layer {
|
pub enum Layer {
|
||||||
Background,
|
Background,
|
||||||
Window(Id),
|
Window(Id),
|
||||||
|
/// Tooltips etc
|
||||||
Popup,
|
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();
|
let mut all_commands: Vec<_> = self.bg.drain(..).collect();
|
||||||
|
|
||||||
// TODO: order
|
for id in window_oreder {
|
||||||
for window in self.windows.values_mut() {
|
if let Some(window) = self.windows.get_mut(id) {
|
||||||
all_commands.extend(window.drain(..));
|
all_commands.extend(window.drain(..));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
all_commands.extend(self.popup.drain(..));
|
all_commands.extend(self.popup.drain(..));
|
||||||
|
|
|
@ -105,7 +105,7 @@ where
|
||||||
|
|
||||||
let mut contents_region = Region {
|
let mut contents_region = Region {
|
||||||
ctx: ctx.clone(),
|
ctx: ctx.clone(),
|
||||||
layer: Layer::Popup,
|
layer,
|
||||||
style,
|
style,
|
||||||
id: Default::default(),
|
id: Default::default(),
|
||||||
dir: Direction::Vertical,
|
dir: Direction::Vertical,
|
||||||
|
|
|
@ -13,7 +13,7 @@ pub struct Memory {
|
||||||
windows: HashMap<Id, WindowState>,
|
windows: HashMap<Id, WindowState>,
|
||||||
|
|
||||||
/// Top is last
|
/// Top is last
|
||||||
window_order: Vec<Id>,
|
pub window_order: Vec<Id>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Memory {
|
impl Memory {
|
||||||
|
@ -44,7 +44,13 @@ impl Memory {
|
||||||
Layer::Background
|
Layer::Background
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn move_window_to_top(&mut self, _id: Id) {
|
pub fn move_window_to_top(&mut self, id: Id) {
|
||||||
// TODO
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ impl Window {
|
||||||
|
|
||||||
let mut contents_region = Region {
|
let mut contents_region = Region {
|
||||||
ctx: ctx.clone(),
|
ctx: ctx.clone(),
|
||||||
layer: Layer::Popup,
|
layer,
|
||||||
style,
|
style,
|
||||||
id: Default::default(),
|
id: Default::default(),
|
||||||
dir: Direction::Vertical,
|
dir: Direction::Vertical,
|
||||||
|
|
|
@ -91,10 +91,14 @@ fn main() {
|
||||||
example_app.ui(&mut region);
|
example_app.ui(&mut region);
|
||||||
emigui.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| {
|
Window::new("Test window").show(region.ctx(), |region| {
|
||||||
region.add(label!("Grab the window and move it around!"));
|
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();
|
let mesh = emigui.paint();
|
||||||
painter.paint(&display, mesh, emigui.texture());
|
painter.paint(&display, mesh, emigui.texture());
|
||||||
|
|
Loading…
Reference in a new issue