mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-09 21:26:14 +03:00
Rename height to z-index
This commit is contained in:
parent
dfe2fd0386
commit
2b4fd53202
@ -16,7 +16,7 @@ pub struct Overlay {
|
||||
fit_mode: OverlayFitMode,
|
||||
position_mode: OverlayPositionMode,
|
||||
hoverable: bool,
|
||||
height: Option<usize>,
|
||||
z_index: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
@ -83,7 +83,7 @@ impl Overlay {
|
||||
fit_mode: OverlayFitMode::None,
|
||||
position_mode: OverlayPositionMode::Window,
|
||||
hoverable: false,
|
||||
height: None,
|
||||
z_index: None,
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,8 +112,8 @@ impl Overlay {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_height(mut self, height: usize) -> Self {
|
||||
self.height = Some(height);
|
||||
pub fn with_z_index(mut self, z_index: usize) -> Self {
|
||||
self.z_index = Some(z_index);
|
||||
self
|
||||
}
|
||||
}
|
||||
@ -211,7 +211,7 @@ impl Element for Overlay {
|
||||
OverlayFitMode::None => {}
|
||||
}
|
||||
|
||||
cx.paint_stacking_context(None, self.height, |cx| {
|
||||
cx.paint_stacking_context(None, self.z_index, |cx| {
|
||||
if self.hoverable {
|
||||
enum OverlayHoverCapture {}
|
||||
// Block hovers in lower stacking contexts
|
||||
|
@ -360,14 +360,14 @@ impl Presenter {
|
||||
for mut mouse_event in mouse_events {
|
||||
let mut valid_regions = Vec::new();
|
||||
|
||||
// GPUI elements are arranged by height but sibling elements can register overlapping
|
||||
// GPUI elements are arranged by z_index but sibling elements can register overlapping
|
||||
// mouse regions. As such, hover events are only fired on overlapping elements which
|
||||
// are at the same height as the topmost element which overlaps with the mouse.
|
||||
// are at the same z-index as the topmost element which overlaps with the mouse.
|
||||
match &mouse_event {
|
||||
MouseEvent::Hover(_) => {
|
||||
let mut top_most_height = None;
|
||||
let mut highest_z_index = None;
|
||||
let mouse_position = self.mouse_position.clone();
|
||||
for (region, height) in self.mouse_regions.iter().rev() {
|
||||
for (region, z_index) in self.mouse_regions.iter().rev() {
|
||||
// Allow mouse regions to appear transparent to hovers
|
||||
if !region.hoverable {
|
||||
continue;
|
||||
@ -375,15 +375,15 @@ impl Presenter {
|
||||
|
||||
let contains_mouse = region.bounds.contains_point(mouse_position);
|
||||
|
||||
if contains_mouse && top_most_height.is_none() {
|
||||
top_most_height = Some(height);
|
||||
if contains_mouse && highest_z_index.is_none() {
|
||||
highest_z_index = Some(z_index);
|
||||
}
|
||||
|
||||
// This unwrap relies on short circuiting boolean expressions
|
||||
// The right side of the && is only executed when contains_mouse
|
||||
// is true, and we know above that when contains_mouse is true
|
||||
// top_most_height is set
|
||||
if contains_mouse && height == top_most_height.unwrap() {
|
||||
// highest_z_index is set.
|
||||
if contains_mouse && z_index == highest_z_index.unwrap() {
|
||||
//Ensure that hover entrance events aren't sent twice
|
||||
if self.hovered_region_ids.insert(region.id()) {
|
||||
valid_regions.push(region.clone());
|
||||
@ -712,12 +712,12 @@ impl<'a> PaintContext<'a> {
|
||||
pub fn paint_stacking_context<F>(
|
||||
&mut self,
|
||||
clip_bounds: Option<RectF>,
|
||||
height: Option<usize>,
|
||||
z_index: Option<usize>,
|
||||
f: F,
|
||||
) where
|
||||
F: FnOnce(&mut Self),
|
||||
{
|
||||
self.scene.push_stacking_context(clip_bounds, height);
|
||||
self.scene.push_stacking_context(clip_bounds, z_index);
|
||||
f(self);
|
||||
self.scene.pop_stacking_context();
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ pub struct Scene {
|
||||
struct StackingContext {
|
||||
layers: Vec<Layer>,
|
||||
active_layer_stack: Vec<usize>,
|
||||
height: usize,
|
||||
z_index: usize,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
@ -205,7 +205,7 @@ impl Scene {
|
||||
.layers
|
||||
.iter()
|
||||
.flat_map(|layer| &layer.mouse_regions)
|
||||
.map(|region| (region.clone(), context.height))
|
||||
.map(|region| (region.clone(), context.z_index))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
@ -213,7 +213,7 @@ impl Scene {
|
||||
|
||||
impl SceneBuilder {
|
||||
pub fn new(scale_factor: f32) -> Self {
|
||||
let stacking_context = StackingContext::new(0, None);
|
||||
let stacking_context = StackingContext::new(None, 0);
|
||||
SceneBuilder {
|
||||
scale_factor,
|
||||
stacking_contexts: vec![stacking_context],
|
||||
@ -224,7 +224,8 @@ impl SceneBuilder {
|
||||
}
|
||||
|
||||
pub fn build(mut self) -> Scene {
|
||||
self.stacking_contexts.sort_by_key(|context| context.height);
|
||||
self.stacking_contexts
|
||||
.sort_by_key(|context| context.z_index);
|
||||
Scene {
|
||||
scale_factor: self.scale_factor,
|
||||
stacking_contexts: self.stacking_contexts,
|
||||
@ -235,12 +236,12 @@ impl SceneBuilder {
|
||||
self.scale_factor
|
||||
}
|
||||
|
||||
pub fn push_stacking_context(&mut self, clip_bounds: Option<RectF>, height: Option<usize>) {
|
||||
let height = height.unwrap_or_else(|| self.active_stacking_context().height + 1);
|
||||
pub fn push_stacking_context(&mut self, clip_bounds: Option<RectF>, z_index: Option<usize>) {
|
||||
let z_index = z_index.unwrap_or_else(|| self.active_stacking_context().z_index + 1);
|
||||
self.active_stacking_context_stack
|
||||
.push(self.stacking_contexts.len());
|
||||
self.stacking_contexts
|
||||
.push(StackingContext::new(height, clip_bounds))
|
||||
.push(StackingContext::new(clip_bounds, z_index))
|
||||
}
|
||||
|
||||
pub fn pop_stacking_context(&mut self) {
|
||||
@ -332,11 +333,11 @@ impl SceneBuilder {
|
||||
}
|
||||
|
||||
impl StackingContext {
|
||||
fn new(height: usize, clip_bounds: Option<RectF>) -> Self {
|
||||
fn new(clip_bounds: Option<RectF>, z_index: usize) -> Self {
|
||||
Self {
|
||||
layers: vec![Layer::new(clip_bounds)],
|
||||
active_layer_stack: vec![0],
|
||||
height,
|
||||
z_index,
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user