Store a z-index id per-layer
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
5b906e731d
commit
2c3d9805a4
9 changed files with 50 additions and 49 deletions
|
@ -28,7 +28,7 @@ impl RenderOnce for FacePile {
|
||||||
let isnt_last = ix < player_count - 1;
|
let isnt_last = ix < player_count - 1;
|
||||||
|
|
||||||
div()
|
div()
|
||||||
.z_index((player_count - ix) as u8)
|
.z_index((player_count - ix) as u16)
|
||||||
.when(isnt_last, |div| div.neg_mr_1())
|
.when(isnt_last, |div| div.neg_mr_1())
|
||||||
.child(player)
|
.child(player)
|
||||||
});
|
});
|
||||||
|
|
|
@ -3169,7 +3169,7 @@ pub struct CursorName {
|
||||||
string: SharedString,
|
string: SharedString,
|
||||||
color: Hsla,
|
color: Hsla,
|
||||||
is_top_row: bool,
|
is_top_row: bool,
|
||||||
z_index: u8,
|
z_index: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Cursor {
|
impl Cursor {
|
||||||
|
|
|
@ -110,7 +110,7 @@ pub struct Style {
|
||||||
/// The mouse cursor style shown when the mouse pointer is over an element.
|
/// The mouse cursor style shown when the mouse pointer is over an element.
|
||||||
pub mouse_cursor: Option<CursorStyle>,
|
pub mouse_cursor: Option<CursorStyle>,
|
||||||
|
|
||||||
pub z_index: Option<u8>,
|
pub z_index: Option<u16>,
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
pub debug: bool,
|
pub debug: bool,
|
||||||
|
@ -337,7 +337,7 @@ impl Style {
|
||||||
|
|
||||||
let background_color = self.background.as_ref().and_then(Fill::color);
|
let background_color = self.background.as_ref().and_then(Fill::color);
|
||||||
if background_color.map_or(false, |color| !color.is_transparent()) {
|
if background_color.map_or(false, |color| !color.is_transparent()) {
|
||||||
cx.with_z_index(0, |cx| {
|
cx.with_z_index(1, |cx| {
|
||||||
let mut border_color = background_color.unwrap_or_default();
|
let mut border_color = background_color.unwrap_or_default();
|
||||||
border_color.a = 0.;
|
border_color.a = 0.;
|
||||||
cx.paint_quad(quad(
|
cx.paint_quad(quad(
|
||||||
|
@ -350,12 +350,12 @@ impl Style {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
cx.with_z_index(0, |cx| {
|
cx.with_z_index(2, |cx| {
|
||||||
continuation(cx);
|
continuation(cx);
|
||||||
});
|
});
|
||||||
|
|
||||||
if self.is_border_visible() {
|
if self.is_border_visible() {
|
||||||
cx.with_z_index(0, |cx| {
|
cx.with_z_index(3, |cx| {
|
||||||
let corner_radii = self.corner_radii.to_pixels(bounds.size, rem_size);
|
let corner_radii = self.corner_radii.to_pixels(bounds.size, rem_size);
|
||||||
let border_widths = self.border_widths.to_pixels(rem_size);
|
let border_widths = self.border_widths.to_pixels(rem_size);
|
||||||
let max_border_width = border_widths.max();
|
let max_border_width = border_widths.max();
|
||||||
|
|
|
@ -12,7 +12,7 @@ pub trait Styled: Sized {
|
||||||
|
|
||||||
gpui_macros::style_helpers!();
|
gpui_macros::style_helpers!();
|
||||||
|
|
||||||
fn z_index(mut self, z_index: u8) -> Self {
|
fn z_index(mut self, z_index: u16) -> Self {
|
||||||
self.style().z_index = Some(z_index);
|
self.style().z_index = Some(z_index);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,30 +39,23 @@ use util::{measure, ResultExt};
|
||||||
mod element_cx;
|
mod element_cx;
|
||||||
pub use element_cx::*;
|
pub use element_cx::*;
|
||||||
|
|
||||||
const ACTIVE_DRAG_Z_INDEX: u8 = 1;
|
const ACTIVE_DRAG_Z_INDEX: u16 = 1;
|
||||||
|
|
||||||
/// A global stacking order, which is created by stacking successive z-index values.
|
/// A global stacking order, which is created by stacking successive z-index values.
|
||||||
/// Each z-index will always be interpreted in the context of its parent z-index.
|
/// Each z-index will always be interpreted in the context of its parent z-index.
|
||||||
#[derive(Deref, DerefMut, Clone, Ord, PartialOrd, PartialEq, Eq, Default)]
|
#[derive(Debug, Deref, DerefMut, Clone, Ord, PartialOrd, PartialEq, Eq, Default)]
|
||||||
pub struct StackingOrder {
|
pub struct StackingOrder(SmallVec<[StackingContext; 64]>);
|
||||||
#[deref]
|
|
||||||
#[deref_mut]
|
/// A single entry in a primitive's z-index stacking order
|
||||||
context_stack: SmallVec<[u8; 64]>,
|
#[derive(Clone, Ord, PartialOrd, PartialEq, Eq, Default)]
|
||||||
pub(crate) id: u32,
|
pub struct StackingContext {
|
||||||
|
pub(crate) z_index: u16,
|
||||||
|
pub(crate) id: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for StackingOrder {
|
impl std::fmt::Debug for StackingContext {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
let mut stacks = self.context_stack.iter().peekable();
|
write!(f, "{{{}.{}}} ", self.z_index, self.id)
|
||||||
write!(f, "[({}): ", self.id)?;
|
|
||||||
while let Some(z_index) = stacks.next() {
|
|
||||||
write!(f, "{z_index}")?;
|
|
||||||
if stacks.peek().is_some() {
|
|
||||||
write!(f, "->")?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
write!(f, "]")?;
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -831,7 +824,11 @@ impl<'a> WindowContext<'a> {
|
||||||
if level >= opaque_level {
|
if level >= opaque_level {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if opaque_level.starts_with(&[ACTIVE_DRAG_Z_INDEX]) {
|
if opaque_level
|
||||||
|
.first()
|
||||||
|
.map(|c| c.z_index == ACTIVE_DRAG_Z_INDEX)
|
||||||
|
.unwrap_or(false)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,9 @@ use crate::{
|
||||||
EntityId, FocusHandle, FocusId, FontId, GlobalElementId, GlyphId, Hsla, ImageData,
|
EntityId, FocusHandle, FocusId, FontId, GlobalElementId, GlyphId, Hsla, ImageData,
|
||||||
InputHandler, IsZero, KeyContext, KeyEvent, LayoutId, MonochromeSprite, MouseEvent, PaintQuad,
|
InputHandler, IsZero, KeyContext, KeyEvent, LayoutId, MonochromeSprite, MouseEvent, PaintQuad,
|
||||||
Path, Pixels, PlatformInputHandler, Point, PolychromeSprite, Quad, RenderGlyphParams,
|
Path, Pixels, PlatformInputHandler, Point, PolychromeSprite, Quad, RenderGlyphParams,
|
||||||
RenderImageParams, RenderSvgParams, Scene, Shadow, SharedString, Size, StackingOrder, Style,
|
RenderImageParams, RenderSvgParams, Scene, Shadow, SharedString, Size, StackingContext,
|
||||||
Surface, TextStyleRefinement, Underline, UnderlineStyle, Window, WindowContext,
|
StackingOrder, Style, Surface, TextStyleRefinement, Underline, UnderlineStyle, Window,
|
||||||
SUBPIXEL_VARIANTS,
|
WindowContext, SUBPIXEL_VARIANTS,
|
||||||
};
|
};
|
||||||
|
|
||||||
type AnyMouseListener = Box<dyn FnMut(&dyn Any, DispatchPhase, &mut ElementContext) + 'static>;
|
type AnyMouseListener = Box<dyn FnMut(&dyn Any, DispatchPhase, &mut ElementContext) + 'static>;
|
||||||
|
@ -45,8 +45,8 @@ pub(crate) struct Frame {
|
||||||
pub(crate) scene: Scene,
|
pub(crate) scene: Scene,
|
||||||
pub(crate) depth_map: Vec<(StackingOrder, EntityId, Bounds<Pixels>)>,
|
pub(crate) depth_map: Vec<(StackingOrder, EntityId, Bounds<Pixels>)>,
|
||||||
pub(crate) z_index_stack: StackingOrder,
|
pub(crate) z_index_stack: StackingOrder,
|
||||||
pub(crate) next_stacking_order_id: u32,
|
pub(crate) next_stacking_order_id: u16,
|
||||||
pub(crate) next_root_z_index: u8,
|
pub(crate) next_root_z_index: u16,
|
||||||
pub(crate) content_mask_stack: Vec<ContentMask<Pixels>>,
|
pub(crate) content_mask_stack: Vec<ContentMask<Pixels>>,
|
||||||
pub(crate) element_offset_stack: Vec<Point<Pixels>>,
|
pub(crate) element_offset_stack: Vec<Point<Pixels>>,
|
||||||
pub(crate) requested_input_handler: Option<RequestedInputHandler>,
|
pub(crate) requested_input_handler: Option<RequestedInputHandler>,
|
||||||
|
@ -410,36 +410,40 @@ impl<'a> ElementContext<'a> {
|
||||||
size: self.window().viewport_size,
|
size: self.window().viewport_size,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let new_root_z_index = post_inc(&mut self.window_mut().next_frame.next_root_z_index);
|
||||||
let new_stacking_order_id =
|
let new_stacking_order_id =
|
||||||
post_inc(&mut self.window_mut().next_frame.next_stacking_order_id);
|
post_inc(&mut self.window_mut().next_frame.next_stacking_order_id);
|
||||||
let new_root_z_index = post_inc(&mut self.window_mut().next_frame.next_root_z_index);
|
let new_context = StackingContext {
|
||||||
|
z_index: new_root_z_index,
|
||||||
|
id: new_stacking_order_id,
|
||||||
|
};
|
||||||
|
|
||||||
let old_stacking_order = mem::take(&mut self.window_mut().next_frame.z_index_stack);
|
let old_stacking_order = mem::take(&mut self.window_mut().next_frame.z_index_stack);
|
||||||
self.window_mut().next_frame.z_index_stack.id = new_stacking_order_id;
|
|
||||||
self.window_mut()
|
self.window_mut().next_frame.z_index_stack.push(new_context);
|
||||||
.next_frame
|
|
||||||
.z_index_stack
|
|
||||||
.push(new_root_z_index);
|
|
||||||
self.window_mut().next_frame.content_mask_stack.push(mask);
|
self.window_mut().next_frame.content_mask_stack.push(mask);
|
||||||
let result = f(self);
|
let result = f(self);
|
||||||
self.window_mut().next_frame.content_mask_stack.pop();
|
self.window_mut().next_frame.content_mask_stack.pop();
|
||||||
self.window_mut().next_frame.z_index_stack = old_stacking_order;
|
self.window_mut().next_frame.z_index_stack = old_stacking_order;
|
||||||
|
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Called during painting to invoke the given closure in a new stacking context. The given
|
/// Called during painting to invoke the given closure in a new stacking context. The given
|
||||||
/// z-index is interpreted relative to the previous call to `stack`.
|
/// z-index is interpreted relative to the previous call to `stack`.
|
||||||
pub fn with_z_index<R>(&mut self, z_index: u8, f: impl FnOnce(&mut Self) -> R) -> R {
|
pub fn with_z_index<R>(&mut self, z_index: u16, f: impl FnOnce(&mut Self) -> R) -> R {
|
||||||
let new_stacking_order_id =
|
let new_stacking_order_id =
|
||||||
post_inc(&mut self.window_mut().next_frame.next_stacking_order_id);
|
post_inc(&mut self.window_mut().next_frame.next_stacking_order_id);
|
||||||
let old_stacking_order_id = mem::replace(
|
let new_context = StackingContext {
|
||||||
&mut self.window_mut().next_frame.z_index_stack.id,
|
z_index,
|
||||||
new_stacking_order_id,
|
id: new_stacking_order_id,
|
||||||
);
|
};
|
||||||
self.window_mut().next_frame.z_index_stack.id = new_stacking_order_id;
|
|
||||||
self.window_mut().next_frame.z_index_stack.push(z_index);
|
self.window_mut().next_frame.z_index_stack.push(new_context);
|
||||||
let result = f(self);
|
let result = f(self);
|
||||||
self.window_mut().next_frame.z_index_stack.id = old_stacking_order_id;
|
|
||||||
self.window_mut().next_frame.z_index_stack.pop();
|
self.window_mut().next_frame.z_index_stack.pop();
|
||||||
|
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ impl Styles for Div {}
|
||||||
|
|
||||||
#[derive(IntoElement)]
|
#[derive(IntoElement)]
|
||||||
struct ZIndexExample {
|
struct ZIndexExample {
|
||||||
z_index: u8,
|
z_index: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RenderOnce for ZIndexExample {
|
impl RenderOnce for ZIndexExample {
|
||||||
|
@ -166,7 +166,7 @@ impl RenderOnce for ZIndexExample {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ZIndexExample {
|
impl ZIndexExample {
|
||||||
pub fn new(z_index: u8) -> Self {
|
pub fn new(z_index: u16) -> Self {
|
||||||
Self { z_index }
|
Self { z_index }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub enum ElevationIndex {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ElevationIndex {
|
impl ElevationIndex {
|
||||||
pub fn z_index(self) -> u8 {
|
pub fn z_index(self) -> u16 {
|
||||||
match self {
|
match self {
|
||||||
ElevationIndex::Background => 0,
|
ElevationIndex::Background => 0,
|
||||||
ElevationIndex::Surface => 42,
|
ElevationIndex::Surface => 42,
|
||||||
|
|
|
@ -4326,7 +4326,7 @@ impl Element for DisconnectedOverlay {
|
||||||
overlay: &mut Self::State,
|
overlay: &mut Self::State,
|
||||||
cx: &mut ElementContext,
|
cx: &mut ElementContext,
|
||||||
) {
|
) {
|
||||||
cx.with_z_index(u8::MAX, |cx| {
|
cx.with_z_index(u16::MAX, |cx| {
|
||||||
cx.add_opaque_layer(bounds);
|
cx.add_opaque_layer(bounds);
|
||||||
overlay.paint(cx);
|
overlay.paint(cx);
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue