Implement basic layer merging for graphics::layer::Stack

This commit is contained in:
Héctor Ramón Jiménez 2025-08-16 23:15:20 +02:00
parent 95769fcd59
commit d3e9547079
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
6 changed files with 122 additions and 17 deletions

View file

@ -17,8 +17,8 @@ pub struct Layer {
pub bounds: Rectangle,
pub quads: Vec<(Quad, Background)>,
pub primitives: Vec<Item<Primitive>>,
pub text: Vec<Item<Text>>,
pub images: Vec<Image>,
pub text: Vec<Item<Text>>,
}
impl Layer {
@ -284,6 +284,10 @@ impl graphics::Layer for Layer {
}
}
fn bounds(&self) -> Rectangle {
self.bounds
}
fn flush(&mut self) {}
fn resize(&mut self, bounds: Rectangle) {
@ -298,6 +302,29 @@ impl graphics::Layer for Layer {
self.text.clear();
self.images.clear();
}
fn level(&self) -> usize {
if !self.text.is_empty() {
return 3;
}
if !self.images.is_empty() {
return 2;
}
if !self.primitives.is_empty() {
return 1;
}
0
}
fn merge(&mut self, layer: &mut Self) {
self.quads.append(&mut layer.quads);
self.primitives.append(&mut layer.primitives);
self.text.append(&mut layer.text);
self.images.append(&mut layer.images);
}
}
#[derive(Debug, Clone)]