core: layer deferred surfaces with draw priorities

This commit is contained in:
2026-11-13 03:38:44 +07:00
parent 306644e581
commit dad833f998
8 changed files with 58 additions and 36 deletions
+2
View File
@@ -13,6 +13,7 @@ use gpui_native_utils::ResultLogErr as _;
use crate::button::{Button, ButtonVariant}; use crate::button::{Button, ButtonVariant};
use crate::common::DismissHandler; use crate::common::DismissHandler;
use crate::common::Sizable as _; use crate::common::Sizable as _;
use crate::common::TOAST_LAYER;
use crate::common::v_flex; use crate::common::v_flex;
/// How alarming an [`Alert`] is; picks the icon and the accent color. /// How alarming an [`Alert`] is; picks the icon and the accent color.
@@ -345,5 +346,6 @@ impl RenderOnce for AlertsView {
) )
})), })),
) )
.with_priority(TOAST_LAYER)
} }
} }
+5 -4
View File
@@ -20,7 +20,7 @@ use gpui_native_theme::ActiveTheme as _;
use gpui_native_theme::{BORDER_WIDTH, POPUP_MAX_HEIGHT, Size}; use gpui_native_theme::{BORDER_WIDTH, POPUP_MAX_HEIGHT, Size};
use gpui_native_utils::ResultLogErr as _; use gpui_native_utils::ResultLogErr as _;
use crate::common::{Sizable, StyledExt as _, h_flex, v_flex}; use crate::common::{OVERLAY_LAYER, Sizable, StyledExt as _, h_flex, v_flex};
use crate::input::{Input, InputState, InputStateEvent}; use crate::input::{Input, InputState, InputStateEvent};
use crate::scroll_area::ScrollArea; use crate::scroll_area::ScrollArea;
@@ -744,9 +744,10 @@ where
.inset_0(), .inset_0(),
); );
wrapper.child(deferred( wrapper.child(
anchored().offset(point(px(0.), spacing_unit)).child(panel), deferred(anchored().offset(point(px(0.), spacing_unit)).child(panel))
)) .with_priority(OVERLAY_LAYER),
)
}) })
} }
} }
+2 -1
View File
@@ -12,7 +12,7 @@ use gpui::{
use gpui_native_icons::Icon; use gpui_native_icons::Icon;
use gpui_native_theme::{ActiveTheme as _, POPUP_MAX_HEIGHT, Size}; use gpui_native_theme::{ActiveTheme as _, POPUP_MAX_HEIGHT, Size};
use crate::common::{h_flex, v_flex}; use crate::common::{DIALOG_LAYER, h_flex, v_flex};
use crate::input::{Input, InputState, InputStateEvent}; use crate::input::{Input, InputState, InputStateEvent};
use crate::scroll_area::{ScrollArea, ScrollAxes}; use crate::scroll_area::{ScrollArea, ScrollAxes};
@@ -512,6 +512,7 @@ impl Render for CommandPaletteState {
.child(scrim) .child(scrim)
.child(panel), .child(panel),
) )
.with_priority(DIALOG_LAYER)
.into_any_element() .into_any_element()
} }
} }
+7
View File
@@ -6,6 +6,13 @@ pub use gpui_native_utils::{StyledExt, h_flex, v_flex};
/// A handler told to clean up after a dismissed surface. /// A handler told to clean up after a dismissed surface.
pub type DismissHandler = std::rc::Rc<dyn Fn(&mut gpui::App)>; pub type DismissHandler = std::rc::Rc<dyn Fn(&mut gpui::App)>;
/// Deferred draw priority of window-modal surfaces; default layer 0 stays for in-flow chrome like resize handles.
pub const DIALOG_LAYER: usize = 1;
/// Deferred draw priority of floating panels, so controls inside a dialog open above it.
pub const OVERLAY_LAYER: usize = 2;
/// Deferred draw priority of passive notifications, so they stay visible over dialogs.
pub const TOAST_LAYER: usize = 3;
/// A component that can be told which size to render at. /// A component that can be told which size to render at.
pub trait Sizable: Sized { pub trait Sizable: Sized {
/// Sets the size. /// Sets the size.
+21 -17
View File
@@ -5,13 +5,13 @@ use gpui::{
Animation, AnimationExt as _, AnyElement, App, DefiniteLength, ElementId, Animation, AnimationExt as _, AnyElement, App, DefiniteLength, ElementId,
InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, ParentElement as _, InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, ParentElement as _,
RenderOnce, Role, ScrollHandle, SharedString, StatefulInteractiveElement as _, Styled as _, RenderOnce, Role, ScrollHandle, SharedString, StatefulInteractiveElement as _, Styled as _,
Window, canvas, div, ease_out_quint, relative, Window, canvas, deferred, div, ease_out_quint, relative,
}; };
use gpui_native_icons::IconRole; use gpui_native_icons::IconRole;
use gpui_native_theme::{ActiveTheme as _, TextRole, Typeset as _}; use gpui_native_theme::{ActiveTheme as _, TextRole, Typeset as _};
use crate::button::{Button, ButtonVariant}; use crate::button::{Button, ButtonVariant};
use crate::common::{Sizable, v_flex}; use crate::common::{DIALOG_LAYER, Sizable, v_flex};
use crate::scroll_area::ScrollArea; use crate::scroll_area::ScrollArea;
/// Requests the dialog's close: `false` closes. /// Requests the dialog's close: `false` closes.
@@ -136,7 +136,7 @@ impl RenderOnce for Dialog {
let root = div().absolute().inset_0(); let root = div().absolute().inset_0();
if !self.open { if !self.open {
return root; return root.into_any_element();
} }
let (scrim_color, border, foreground, surface, radius, shadows, enter_duration) = { let (scrim_color, border, foreground, surface, radius, shadows, enter_duration) = {
@@ -292,19 +292,23 @@ impl RenderOnce for Dialog {
}) })
}); });
root.flex() deferred(
.items_center() root.flex()
.justify_center() .items_center()
.p_4() .justify_center()
.child(scrim.with_animation( .p_4()
"dialog-scrim-enter", .child(scrim.with_animation(
Animation::new(enter_duration).with_easing(ease_out_quint()), "dialog-scrim-enter",
|scrim, delta| scrim.opacity(delta), Animation::new(enter_duration).with_easing(ease_out_quint()),
)) |scrim, delta| scrim.opacity(delta),
.child(panel.with_animation( ))
"dialog-enter", .child(panel.with_animation(
Animation::new(enter_duration).with_easing(ease_out_quint()), "dialog-enter",
|panel, delta| panel.opacity(delta), Animation::new(enter_duration).with_easing(ease_out_quint()),
)) |panel, delta| panel.opacity(delta),
)),
)
.with_priority(DIALOG_LAYER)
.into_any_element()
} }
} }
+11 -6
View File
@@ -15,7 +15,7 @@ use gpui_native_icons::{Icon, IconRole, icon as icon_glyph};
use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, POPUP_MAX_HEIGHT}; use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, POPUP_MAX_HEIGHT};
use gpui_native_utils::focus_handle; use gpui_native_utils::focus_handle;
use crate::common::v_flex; use crate::common::{OVERLAY_LAYER, v_flex};
use crate::scroll_area::{ScrollArea, ScrollAxes}; use crate::scroll_area::{ScrollArea, ScrollAxes};
/// Runs the item's action. The menu closes itself before the handler runs. /// Runs the item's action. The menu closes itself before the handler runs.
@@ -557,7 +557,11 @@ pub(crate) fn anchored_menu_panel(
} }
.offset(point(px(0.), chrome.spacing_unit)); .offset(point(px(0.), chrome.spacing_unit));
Some(deferred(anchored.child(panel)).into_any_element()) Some(
deferred(anchored.child(panel))
.with_priority(OVERLAY_LAYER)
.into_any_element(),
)
} }
/// Builds one menu panel: chrome, rows, focus, navigation, and dismissals. /// Builds one menu panel: chrome, rows, focus, navigation, and dismissals.
@@ -894,8 +898,8 @@ fn render_item(
.absolute() .absolute()
.inset_0(), .inset_0(),
) )
.child(deferred( .child(
div().absolute().left_full().top_0().child(menu_panel( deferred(div().absolute().left_full().top_0().child(menu_panel(
window, window,
cx, cx,
flyout.state, flyout.state,
@@ -916,8 +920,9 @@ fn render_item(
enter_duration: flyout.enter_duration, enter_duration: flyout.enter_duration,
debug_prefix: "submenu", debug_prefix: "submenu",
}, },
)), )))
)) .with_priority(OVERLAY_LAYER),
)
}) })
.into_any_element() .into_any_element()
} }
+8 -7
View File
@@ -10,7 +10,7 @@ use gpui::{
}; };
use gpui_native_theme::ActiveTheme as _; use gpui_native_theme::ActiveTheme as _;
use crate::common::v_flex; use crate::common::{OVERLAY_LAYER, v_flex};
/// Reports the next open state of a [`Popover`]: `true` to open, `false` to close. /// Reports the next open state of a [`Popover`]: `true` to open, `false` to close.
type ChangeHandler = Rc<dyn Fn(bool, &mut Window, &mut App)>; type ChangeHandler = Rc<dyn Fn(bool, &mut Window, &mut App)>;
@@ -224,15 +224,16 @@ impl RenderOnce for Popover {
.inset_0(), .inset_0(),
); );
wrapper.child(deferred( wrapper.child(
anchored() deferred(anchored().offset(point(Pixels::ZERO, anchor_gap)).child(
.offset(point(Pixels::ZERO, anchor_gap)) panel.with_animation(
.child(panel.with_animation(
"popover-enter", "popover-enter",
Animation::new(enter_duration).with_easing(ease_out_quint()), Animation::new(enter_duration).with_easing(ease_out_quint()),
|panel, delta| panel.opacity(delta), |panel, delta| panel.opacity(delta),
)), ),
)) ))
.with_priority(OVERLAY_LAYER),
)
}) })
} }
} }
+2 -1
View File
@@ -14,7 +14,7 @@ use gpui_native_theme::{ActiveTheme as _, TOAST_MAX_WIDTH};
use gpui_native_utils::ResultLogErr as _; use gpui_native_utils::ResultLogErr as _;
use crate::button::{Button, ButtonVariant}; use crate::button::{Button, ButtonVariant};
use crate::common::{DismissHandler, Sizable as _}; use crate::common::{DismissHandler, Sizable as _, TOAST_LAYER};
/// The action handler of a [`Toast`]. /// The action handler of a [`Toast`].
pub type ActionHandler = Rc<dyn Fn(&mut App)>; pub type ActionHandler = Rc<dyn Fn(&mut App)>;
@@ -259,6 +259,7 @@ impl RenderOnce for ToastsView {
)) ))
}), }),
) )
.with_priority(TOAST_LAYER)
} }
} }