diff --git a/crates/gpui3/src/elements/div.rs b/crates/gpui3/src/elements/div.rs index f577d9b5c63a44b7290c8e4fae3865fdf0ad11c6..804d01f8258faac63976949db4e72a0c223ae945 100644 --- a/crates/gpui3/src/elements/div.rs +++ b/crates/gpui3/src/elements/div.rs @@ -46,11 +46,12 @@ impl Element for Div { cx: &mut ViewContext, ) -> Result<()> { 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; 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)) }) })?; @@ -67,6 +68,11 @@ impl Element for Div { } impl Div { + 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 { self.declared_style().overflow.x = Some(Overflow::Hidden); self.declared_style().overflow.y = Some(Overflow::Hidden); diff --git a/crates/gpui3/src/style.rs b/crates/gpui3/src/style.rs index af2b87d0bbe00340eb571455b37a7d4d1fa38840..56188513119d56ae4daa2a3c82e0eac817bb0238 100644 --- a/crates/gpui3/src/style.rs +++ b/crates/gpui3/src/style.rs @@ -95,6 +95,8 @@ pub struct Style { /// TEXT pub text: TextStyleRefinement, + + pub z_index: Option, } #[derive(Clone, Debug)] @@ -335,6 +337,7 @@ impl Default for Style { corner_radii: Corners::default(), box_shadow: Default::default(), text: TextStyleRefinement::default(), + z_index: None, } } } diff --git a/crates/ui2/src/components/toast.rs b/crates/ui2/src/components/toast.rs index 7a227f8463a651b4c62ddae699f4ed8a5d76bd2c..684e453bfb405b3b58dbf1fade51ab0efc5ee691 100644 --- a/crates/ui2/src/components/toast.rs +++ b/crates/ui2/src/components/toast.rs @@ -52,7 +52,8 @@ impl Toast { div = div.right_4(); } - div.absolute() + div.z_index(5) + .absolute() .bottom_4() .flex() .py_2() diff --git a/crates/ui2/src/components/workspace.rs b/crates/ui2/src/components/workspace.rs index b74654ca8be84b349cf5273bf514152ae5766fa4..8b4329363af83e6bb40424359c9f782278c8c281 100644 --- a/crates/ui2/src/components/workspace.rs +++ b/crates/ui2/src/components/workspace.rs @@ -7,8 +7,9 @@ use gpui3::{relative, rems, Size}; use crate::prelude::*; use crate::{ hello_world_rust_editor_with_status_example, random_players_with_call_status, theme, v_stack, - ChatMessage, ChatPanel, EditorPane, Livestream, Pane, PaneGroup, Panel, PanelAllowedSides, - PanelSide, ProjectPanel, SplitDirection, StatusBar, Terminal, TitleBar, + ChatMessage, ChatPanel, EditorPane, Label, Livestream, Pane, PaneGroup, Panel, + PanelAllowedSides, PanelSide, ProjectPanel, SplitDirection, StatusBar, Terminal, TitleBar, + Toast, ToastOrigin, }; #[derive(Element)] @@ -180,17 +181,10 @@ impl WorkspaceElement { ), ) .child(StatusBar::new()) - // An example of a toast is below - // Currently because of stacking order this gets obscured by other elements - - // .child(Toast::new( - // ToastOrigin::Bottom, - // |_, payload| { - // let theme = payload.downcast_ref::>().unwrap(); - - // vec![Label::new("label").into_any()] - // }, - // Box::new(theme.clone()), - // )) + .child(Toast::new( + ToastOrigin::Bottom, + |_, _| vec![Label::new("label").into_any()], + Box::new(()), + )) } }