From dad833f998fecc0d828e716f3cbf0342d499db81 Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Fri, 13 Nov 2026 03:38:44 +0700 Subject: [PATCH] core: layer deferred surfaces with draw priorities --- crates/core/src/alert.rs | 2 ++ crates/core/src/combobox.rs | 9 +++---- crates/core/src/command_palette.rs | 3 ++- crates/core/src/common.rs | 7 ++++++ crates/core/src/dialog.rs | 38 +++++++++++++++++------------- crates/core/src/menu.rs | 17 ++++++++----- crates/core/src/popover.rs | 15 ++++++------ crates/core/src/toast.rs | 3 ++- 8 files changed, 58 insertions(+), 36 deletions(-) diff --git a/crates/core/src/alert.rs b/crates/core/src/alert.rs index 2eda291..a0b941c 100644 --- a/crates/core/src/alert.rs +++ b/crates/core/src/alert.rs @@ -13,6 +13,7 @@ use gpui_native_utils::ResultLogErr as _; use crate::button::{Button, ButtonVariant}; use crate::common::DismissHandler; use crate::common::Sizable as _; +use crate::common::TOAST_LAYER; use crate::common::v_flex; /// How alarming an [`Alert`] is; picks the icon and the accent color. @@ -345,5 +346,6 @@ impl RenderOnce for AlertsView { ) })), ) + .with_priority(TOAST_LAYER) } } diff --git a/crates/core/src/combobox.rs b/crates/core/src/combobox.rs index 0ac9f07..dbdf2de 100644 --- a/crates/core/src/combobox.rs +++ b/crates/core/src/combobox.rs @@ -20,7 +20,7 @@ use gpui_native_theme::ActiveTheme as _; use gpui_native_theme::{BORDER_WIDTH, POPUP_MAX_HEIGHT, Size}; 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::scroll_area::ScrollArea; @@ -744,9 +744,10 @@ where .inset_0(), ); - wrapper.child(deferred( - anchored().offset(point(px(0.), spacing_unit)).child(panel), - )) + wrapper.child( + deferred(anchored().offset(point(px(0.), spacing_unit)).child(panel)) + .with_priority(OVERLAY_LAYER), + ) }) } } diff --git a/crates/core/src/command_palette.rs b/crates/core/src/command_palette.rs index a7e5c88..737ebdd 100644 --- a/crates/core/src/command_palette.rs +++ b/crates/core/src/command_palette.rs @@ -12,7 +12,7 @@ use gpui::{ use gpui_native_icons::Icon; 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::scroll_area::{ScrollArea, ScrollAxes}; @@ -512,6 +512,7 @@ impl Render for CommandPaletteState { .child(scrim) .child(panel), ) + .with_priority(DIALOG_LAYER) .into_any_element() } } diff --git a/crates/core/src/common.rs b/crates/core/src/common.rs index 53a9d00..7a078f3 100644 --- a/crates/core/src/common.rs +++ b/crates/core/src/common.rs @@ -6,6 +6,13 @@ pub use gpui_native_utils::{StyledExt, h_flex, v_flex}; /// A handler told to clean up after a dismissed surface. pub type DismissHandler = std::rc::Rc; +/// 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. pub trait Sizable: Sized { /// Sets the size. diff --git a/crates/core/src/dialog.rs b/crates/core/src/dialog.rs index 4b5da66..1ad6cd3 100644 --- a/crates/core/src/dialog.rs +++ b/crates/core/src/dialog.rs @@ -5,13 +5,13 @@ use gpui::{ Animation, AnimationExt as _, AnyElement, App, DefiniteLength, ElementId, InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, ParentElement 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_theme::{ActiveTheme as _, TextRole, Typeset as _}; use crate::button::{Button, ButtonVariant}; -use crate::common::{Sizable, v_flex}; +use crate::common::{DIALOG_LAYER, Sizable, v_flex}; use crate::scroll_area::ScrollArea; /// Requests the dialog's close: `false` closes. @@ -136,7 +136,7 @@ impl RenderOnce for Dialog { let root = div().absolute().inset_0(); if !self.open { - return root; + return root.into_any_element(); } let (scrim_color, border, foreground, surface, radius, shadows, enter_duration) = { @@ -292,19 +292,23 @@ impl RenderOnce for Dialog { }) }); - root.flex() - .items_center() - .justify_center() - .p_4() - .child(scrim.with_animation( - "dialog-scrim-enter", - Animation::new(enter_duration).with_easing(ease_out_quint()), - |scrim, delta| scrim.opacity(delta), - )) - .child(panel.with_animation( - "dialog-enter", - Animation::new(enter_duration).with_easing(ease_out_quint()), - |panel, delta| panel.opacity(delta), - )) + deferred( + root.flex() + .items_center() + .justify_center() + .p_4() + .child(scrim.with_animation( + "dialog-scrim-enter", + Animation::new(enter_duration).with_easing(ease_out_quint()), + |scrim, delta| scrim.opacity(delta), + )) + .child(panel.with_animation( + "dialog-enter", + Animation::new(enter_duration).with_easing(ease_out_quint()), + |panel, delta| panel.opacity(delta), + )), + ) + .with_priority(DIALOG_LAYER) + .into_any_element() } } diff --git a/crates/core/src/menu.rs b/crates/core/src/menu.rs index 5b14efa..c59dda5 100644 --- a/crates/core/src/menu.rs +++ b/crates/core/src/menu.rs @@ -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_utils::focus_handle; -use crate::common::v_flex; +use crate::common::{OVERLAY_LAYER, v_flex}; use crate::scroll_area::{ScrollArea, ScrollAxes}; /// 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)); - 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. @@ -894,8 +898,8 @@ fn render_item( .absolute() .inset_0(), ) - .child(deferred( - div().absolute().left_full().top_0().child(menu_panel( + .child( + deferred(div().absolute().left_full().top_0().child(menu_panel( window, cx, flyout.state, @@ -916,8 +920,9 @@ fn render_item( enter_duration: flyout.enter_duration, debug_prefix: "submenu", }, - )), - )) + ))) + .with_priority(OVERLAY_LAYER), + ) }) .into_any_element() } diff --git a/crates/core/src/popover.rs b/crates/core/src/popover.rs index d15c7d2..0dc2ebf 100644 --- a/crates/core/src/popover.rs +++ b/crates/core/src/popover.rs @@ -10,7 +10,7 @@ use gpui::{ }; 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. type ChangeHandler = Rc; @@ -224,15 +224,16 @@ impl RenderOnce for Popover { .inset_0(), ); - wrapper.child(deferred( - anchored() - .offset(point(Pixels::ZERO, anchor_gap)) - .child(panel.with_animation( + wrapper.child( + deferred(anchored().offset(point(Pixels::ZERO, anchor_gap)).child( + panel.with_animation( "popover-enter", Animation::new(enter_duration).with_easing(ease_out_quint()), |panel, delta| panel.opacity(delta), - )), - )) + ), + )) + .with_priority(OVERLAY_LAYER), + ) }) } } diff --git a/crates/core/src/toast.rs b/crates/core/src/toast.rs index 352fdaa..e4b4c0a 100644 --- a/crates/core/src/toast.rs +++ b/crates/core/src/toast.rs @@ -14,7 +14,7 @@ use gpui_native_theme::{ActiveTheme as _, TOAST_MAX_WIDTH}; use gpui_native_utils::ResultLogErr as _; 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`]. pub type ActionHandler = Rc; @@ -259,6 +259,7 @@ impl RenderOnce for ToastsView { )) }), ) + .with_priority(TOAST_LAYER) } }