Add div.z_index

This commit is contained in:
Marshall Bowers 2023-10-09 13:19:32 -04:00
parent 2654942b3c
commit d3c79c7078
4 changed files with 21 additions and 17 deletions

View file

@ -46,11 +46,12 @@ impl<S: 'static + Send + Sync> Element for Div<S> {
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> Result<()> { ) -> Result<()> {
let style = self.computed_style(); let style = self.computed_style();
cx.stack(0, |cx| style.paint(bounds, cx)); let z_index = style.z_index.unwrap_or(0);
cx.stack(z_index, |cx| style.paint(bounds, cx));
let overflow = &style.overflow; let overflow = &style.overflow;
style.apply_text_style(cx, |cx| { style.apply_text_style(cx, |cx| {
cx.stack(1, |cx| { cx.stack(z_index + 1, |cx| {
style.apply_overflow(bounds, cx, |cx| self.paint_children(overflow, state, cx)) style.apply_overflow(bounds, cx, |cx| self.paint_children(overflow, state, cx))
}) })
})?; })?;
@ -67,6 +68,11 @@ impl<S: 'static + Send + Sync> Element for Div<S> {
} }
impl<S: 'static> Div<S> { impl<S: 'static> Div<S> {
pub fn z_index(mut self, z_index: u32) -> Self {
self.declared_style().z_index = Some(z_index);
self
}
pub fn overflow_hidden(mut self) -> Self { pub fn overflow_hidden(mut self) -> Self {
self.declared_style().overflow.x = Some(Overflow::Hidden); self.declared_style().overflow.x = Some(Overflow::Hidden);
self.declared_style().overflow.y = Some(Overflow::Hidden); self.declared_style().overflow.y = Some(Overflow::Hidden);

View file

@ -95,6 +95,8 @@ pub struct Style {
/// TEXT /// TEXT
pub text: TextStyleRefinement, pub text: TextStyleRefinement,
pub z_index: Option<u32>,
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -335,6 +337,7 @@ impl Default for Style {
corner_radii: Corners::default(), corner_radii: Corners::default(),
box_shadow: Default::default(), box_shadow: Default::default(),
text: TextStyleRefinement::default(), text: TextStyleRefinement::default(),
z_index: None,
} }
} }
} }

View file

@ -52,7 +52,8 @@ impl<S: 'static + Send + Sync> Toast<S> {
div = div.right_4(); div = div.right_4();
} }
div.absolute() div.z_index(5)
.absolute()
.bottom_4() .bottom_4()
.flex() .flex()
.py_2() .py_2()

View file

@ -7,8 +7,9 @@ use gpui3::{relative, rems, Size};
use crate::prelude::*; use crate::prelude::*;
use crate::{ use crate::{
hello_world_rust_editor_with_status_example, random_players_with_call_status, theme, v_stack, hello_world_rust_editor_with_status_example, random_players_with_call_status, theme, v_stack,
ChatMessage, ChatPanel, EditorPane, Livestream, Pane, PaneGroup, Panel, PanelAllowedSides, ChatMessage, ChatPanel, EditorPane, Label, Livestream, Pane, PaneGroup, Panel,
PanelSide, ProjectPanel, SplitDirection, StatusBar, Terminal, TitleBar, PanelAllowedSides, PanelSide, ProjectPanel, SplitDirection, StatusBar, Terminal, TitleBar,
Toast, ToastOrigin,
}; };
#[derive(Element)] #[derive(Element)]
@ -180,17 +181,10 @@ impl<S: 'static + Send + Sync + Clone> WorkspaceElement<S> {
), ),
) )
.child(StatusBar::new()) .child(StatusBar::new())
// An example of a toast is below .child(Toast::new(
// Currently because of stacking order this gets obscured by other elements ToastOrigin::Bottom,
|_, _| vec![Label::new("label").into_any()],
// .child(Toast::new( Box::new(()),
// ToastOrigin::Bottom, ))
// |_, payload| {
// let theme = payload.downcast_ref::<Arc<Theme>>().unwrap();
// vec![Label::new("label").into_any()]
// },
// Box::new(theme.clone()),
// ))
} }
} }