Rename depth to height when referring to stacking contexts

This commit is contained in:
Antonio Scandurra 2022-10-25 12:18:23 +02:00
parent 6a4f3aaa56
commit 33ebfc3f10
2 changed files with 15 additions and 15 deletions

View file

@ -360,14 +360,14 @@ impl Presenter {
for mut mouse_event in mouse_events { for mut mouse_event in mouse_events {
let mut valid_regions = Vec::new(); let mut valid_regions = Vec::new();
// GPUI elements are arranged by depth but sibling elements can register overlapping // GPUI elements are arranged by height but sibling elements can register overlapping
// mouse regions. As such, hover events are only fired on overlapping elements which // mouse regions. As such, hover events are only fired on overlapping elements which
// are at the same depth as the topmost element which overlaps with the mouse. // are at the same height as the topmost element which overlaps with the mouse.
match &mouse_event { match &mouse_event {
MouseEvent::Hover(_) => { MouseEvent::Hover(_) => {
let mut top_most_depth = None; let mut top_most_height = None;
let mouse_position = self.mouse_position.clone(); let mouse_position = self.mouse_position.clone();
for (region, depth) in self.mouse_regions.iter().rev() { for (region, height) in self.mouse_regions.iter().rev() {
// Allow mouse regions to appear transparent to hovers // Allow mouse regions to appear transparent to hovers
if !region.hoverable { if !region.hoverable {
continue; continue;
@ -375,15 +375,15 @@ impl Presenter {
let contains_mouse = region.bounds.contains_point(mouse_position); let contains_mouse = region.bounds.contains_point(mouse_position);
if contains_mouse && top_most_depth.is_none() { if contains_mouse && top_most_height.is_none() {
top_most_depth = Some(depth); top_most_height = Some(height);
} }
// This unwrap relies on short circuiting boolean expressions // This unwrap relies on short circuiting boolean expressions
// The right side of the && is only executed when contains_mouse // The right side of the && is only executed when contains_mouse
// is true, and we know above that when contains_mouse is true // is true, and we know above that when contains_mouse is true
// top_most_depth is set // top_most_height is set
if contains_mouse && depth == top_most_depth.unwrap() { if contains_mouse && height == top_most_height.unwrap() {
//Ensure that hover entrance events aren't sent twice //Ensure that hover entrance events aren't sent twice
if self.hovered_region_ids.insert(region.id()) { if self.hovered_region_ids.insert(region.id()) {
valid_regions.push(region.clone()); valid_regions.push(region.clone());

View file

@ -29,7 +29,7 @@ pub struct SceneBuilder {
struct StackingContext { struct StackingContext {
layers: Vec<Layer>, layers: Vec<Layer>,
active_layer_stack: Vec<usize>, active_layer_stack: Vec<usize>,
depth: usize, height: usize,
} }
#[derive(Default)] #[derive(Default)]
@ -205,7 +205,7 @@ impl Scene {
.layers .layers
.iter() .iter()
.flat_map(|layer| &layer.mouse_regions) .flat_map(|layer| &layer.mouse_regions)
.map(|region| (region.clone(), context.depth)) .map(|region| (region.clone(), context.height))
}) })
.collect() .collect()
} }
@ -224,7 +224,7 @@ impl SceneBuilder {
} }
pub fn build(mut self) -> Scene { pub fn build(mut self) -> Scene {
self.stacking_contexts.sort_by_key(|context| context.depth); self.stacking_contexts.sort_by_key(|context| context.height);
Scene { Scene {
scale_factor: self.scale_factor, scale_factor: self.scale_factor,
stacking_contexts: self.stacking_contexts, stacking_contexts: self.stacking_contexts,
@ -236,11 +236,11 @@ impl SceneBuilder {
} }
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; let height = self.active_stacking_context().height + 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(depth, clip_bounds)) .push(StackingContext::new(height, clip_bounds))
} }
pub fn pop_stacking_context(&mut self) { pub fn pop_stacking_context(&mut self) {
@ -332,11 +332,11 @@ impl SceneBuilder {
} }
impl StackingContext { impl StackingContext {
fn new(depth: usize, clip_bounds: Option<RectF>) -> Self { fn new(height: 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, height,
} }
} }