Merge layers from top to bottom in layer::Stack
This commit is contained in:
parent
fb5ac7dcb0
commit
806500048d
3 changed files with 57 additions and 32 deletions
|
|
@ -143,23 +143,40 @@ impl<T: Layer> Stack<T> {
|
||||||
pub fn merge(&mut self) {
|
pub fn merge(&mut self) {
|
||||||
self.flush();
|
self.flush();
|
||||||
|
|
||||||
let mut current = 0;
|
let mut left = self.active_count;
|
||||||
|
|
||||||
while current < self.active_count {
|
while left > 1 {
|
||||||
let (head, tail) = self.layers.split_at_mut(current + 1);
|
let mut current = left - 1;
|
||||||
|
let mut last = &self.layers[current];
|
||||||
|
let mut last_start = last.start();
|
||||||
|
|
||||||
let layer = &mut head[current];
|
while current > 0 {
|
||||||
let mut candidate = 0;
|
let candidate = &self.layers[current - 1];
|
||||||
|
let start = candidate.start();
|
||||||
|
let end = candidate.end();
|
||||||
|
|
||||||
while let Some(next_layer) = tail.get_mut(candidate)
|
if end == 0 {
|
||||||
&& layer.end() <= next_layer.start()
|
current -= 1;
|
||||||
&& layer.bounds() == next_layer.bounds()
|
continue;
|
||||||
{
|
}
|
||||||
layer.merge(next_layer);
|
|
||||||
candidate += 1;
|
if end > last_start || candidate.bounds() != last.bounds() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
last = candidate;
|
||||||
|
last_start = start;
|
||||||
|
current -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
current += candidate + 1;
|
let (head, tail) = self.layers.split_at_mut(current + 1);
|
||||||
|
let layer = &mut head[current];
|
||||||
|
|
||||||
|
for middle in &mut tail[0..left - current - 1] {
|
||||||
|
layer.merge(middle);
|
||||||
|
}
|
||||||
|
|
||||||
|
left = current;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -305,34 +305,38 @@ impl graphics::Layer for Layer {
|
||||||
|
|
||||||
fn start(&self) -> usize {
|
fn start(&self) -> usize {
|
||||||
if !self.quads.is_empty() {
|
if !self.quads.is_empty() {
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if !self.primitives.is_empty() {
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.images.is_empty() {
|
if !self.primitives.is_empty() {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.text.is_empty() {
|
if !self.images.is_empty() {
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
0
|
if !self.text.is_empty() {
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
usize::MAX
|
||||||
}
|
}
|
||||||
|
|
||||||
fn end(&self) -> usize {
|
fn end(&self) -> usize {
|
||||||
if !self.text.is_empty() {
|
if !self.text.is_empty() {
|
||||||
return 3;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.images.is_empty() {
|
if !self.images.is_empty() {
|
||||||
return 2;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.primitives.is_empty() {
|
if !self.primitives.is_empty() {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !self.quads.is_empty() {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -298,42 +298,46 @@ impl graphics::Layer for Layer {
|
||||||
|
|
||||||
fn start(&self) -> usize {
|
fn start(&self) -> usize {
|
||||||
if !self.quads.is_empty() {
|
if !self.quads.is_empty() {
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if !self.triangles.is_empty() {
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.primitives.is_empty() {
|
if !self.triangles.is_empty() {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.images.is_empty() {
|
if !self.primitives.is_empty() {
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.text.is_empty() {
|
if !self.images.is_empty() {
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
0
|
if !self.text.is_empty() {
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
usize::MAX
|
||||||
}
|
}
|
||||||
|
|
||||||
fn end(&self) -> usize {
|
fn end(&self) -> usize {
|
||||||
if !self.text.is_empty() {
|
if !self.text.is_empty() {
|
||||||
return 4;
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.images.is_empty() {
|
if !self.images.is_empty() {
|
||||||
return 3;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.primitives.is_empty() {
|
if !self.primitives.is_empty() {
|
||||||
return 2;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.triangles.is_empty() {
|
if !self.triangles.is_empty() {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !self.quads.is_empty() {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue