mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-06 02:37:21 +00:00
Sort mouse regions by their stacking context's depth
This commit is contained in:
parent
44c8ee5709
commit
fb26f8195b
1 changed files with 9 additions and 5 deletions
|
@ -20,6 +20,7 @@ pub struct Scene {
|
||||||
struct StackingContext {
|
struct StackingContext {
|
||||||
layers: Vec<Layer>,
|
layers: Vec<Layer>,
|
||||||
active_layer_stack: Vec<usize>,
|
active_layer_stack: Vec<usize>,
|
||||||
|
depth: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -187,7 +188,7 @@ pub struct Image {
|
||||||
|
|
||||||
impl Scene {
|
impl Scene {
|
||||||
pub fn new(scale_factor: f32) -> Self {
|
pub fn new(scale_factor: f32) -> Self {
|
||||||
let stacking_context = StackingContext::new(None);
|
let stacking_context = StackingContext::new(0, None);
|
||||||
Scene {
|
Scene {
|
||||||
scale_factor,
|
scale_factor,
|
||||||
stacking_contexts: vec![stacking_context],
|
stacking_contexts: vec![stacking_context],
|
||||||
|
@ -212,21 +213,23 @@ impl Scene {
|
||||||
|
|
||||||
pub fn mouse_regions(&self) -> Vec<(MouseRegion, usize)> {
|
pub fn mouse_regions(&self) -> Vec<(MouseRegion, usize)> {
|
||||||
let mut regions = Vec::new();
|
let mut regions = Vec::new();
|
||||||
for (stacking_depth, stacking_context) in self.stacking_contexts.iter().enumerate() {
|
for stacking_context in self.stacking_contexts.iter() {
|
||||||
for layer in &stacking_context.layers {
|
for layer in &stacking_context.layers {
|
||||||
for mouse_region in &layer.mouse_regions {
|
for mouse_region in &layer.mouse_regions {
|
||||||
regions.push((mouse_region.clone(), stacking_depth));
|
regions.push((mouse_region.clone(), stacking_context.depth));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
regions.sort_by_key(|(_, depth)| *depth);
|
||||||
regions
|
regions
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn push_stacking_context(&mut self, clip_bounds: Option<RectF>) {
|
pub fn push_stacking_context(&mut self, clip_bounds: Option<RectF>) {
|
||||||
|
let depth = self.active_stacking_context().depth + 1;
|
||||||
self.active_stacking_context_stack
|
self.active_stacking_context_stack
|
||||||
.push(self.stacking_contexts.len());
|
.push(self.stacking_contexts.len());
|
||||||
self.stacking_contexts
|
self.stacking_contexts
|
||||||
.push(StackingContext::new(clip_bounds))
|
.push(StackingContext::new(depth, clip_bounds))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pop_stacking_context(&mut self) {
|
pub fn pop_stacking_context(&mut self) {
|
||||||
|
@ -293,10 +296,11 @@ impl Scene {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StackingContext {
|
impl StackingContext {
|
||||||
fn new(clip_bounds: Option<RectF>) -> Self {
|
fn new(depth: usize, clip_bounds: Option<RectF>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
layers: vec![Layer::new(clip_bounds)],
|
layers: vec![Layer::new(clip_bounds)],
|
||||||
active_layer_stack: vec![0],
|
active_layer_stack: vec![0],
|
||||||
|
depth,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue