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

@ -11,4 +11,6 @@ impl Batch {
pub fn is_empty(&self) -> bool {
true
}
pub fn append(&mut self, _batch: &mut Self) {}
}

View file

@ -268,6 +268,10 @@ impl graphics::Layer for Layer {
}
}
fn bounds(&self) -> Rectangle {
self.bounds
}
fn flush(&mut self) {
self.flush_meshes();
self.flush_text();
@ -288,6 +292,34 @@ impl graphics::Layer for Layer {
self.pending_meshes.clear();
self.pending_text.clear();
}
fn level(&self) -> usize {
if !self.text.is_empty() {
return 4;
}
if !self.images.is_empty() {
return 3;
}
if !self.primitives.is_empty() {
return 2;
}
if !self.triangles.is_empty() {
return 1;
}
0
}
fn merge(&mut self, layer: &mut Self) {
self.quads.append(&mut layer.quads);
self.triangles.append(&mut layer.triangles);
self.primitives.append(&mut layer.primitives);
self.images.append(&mut layer.images);
self.text.append(&mut layer.text);
}
}
impl Default for Layer {

View file

@ -304,6 +304,12 @@ impl Batch {
self.gradients.clear();
self.order.clear();
}
pub fn append(&mut self, batch: &mut Batch) {
self.solids.append(&mut batch.solids);
self.gradients.append(&mut batch.gradients);
self.order.append(&mut batch.order);
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]