From d2ac4c446db1aca59fc9952e3ef024d20bcf4bd9 Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Sun, 15 Nov 2026 11:52:51 +0700 Subject: [PATCH] layout: add transparent and grain options to shell --- crates/layout/Cargo.toml | 3 ++- crates/layout/src/panel.rs | 5 +---- crates/layout/src/shell.rs | 35 ++++++++++++++++++++++++++++++++++- crates/layout/src/titlebar.rs | 12 ++++++++++-- examples/gallery/src/main.rs | 2 ++ 5 files changed, 49 insertions(+), 8 deletions(-) diff --git a/crates/layout/Cargo.toml b/crates/layout/Cargo.toml index 58c29a3..5613a2b 100644 --- a/crates/layout/Cargo.toml +++ b/crates/layout/Cargo.toml @@ -26,10 +26,11 @@ full = [ "toast", "window_controls", ] +grain = ["dep:gpui-native-core", "gpui-native-core/grain"] panel = ["resizable"] resize_handle = [] resizable = ["resize_handle"] -shell = ["titlebar", "window_controls"] +shell = ["titlebar", "window_controls", "grain"] titlebar = ["window_controls"] toast = ["shell", "gpui-native-core/toast", "gpui-native-core/button"] alert = ["shell", "gpui-native-core/alert", "gpui-native-core/button"] diff --git a/crates/layout/src/panel.rs b/crates/layout/src/panel.rs index c4898a7..4e187d1 100644 --- a/crates/layout/src/panel.rs +++ b/crates/layout/src/panel.rs @@ -1,4 +1,4 @@ -//! The panel row: the window's main content, island-style on the muted +//! The panel row: the window's main content, island-style over the app //! background. It can split once into two half-width panels with a drag //! divider between them; dragging the seam resizes the panels and a //! double-click restores the half split. @@ -67,8 +67,6 @@ impl Panel { impl RenderOnce for Panel { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { - let theme = cx.theme(); - let app_background = theme.colors.muted; let id = self.id.clone(); let gutter = rems(0.5).to_pixels(window.rem_size()); @@ -113,7 +111,6 @@ impl RenderOnce for Panel { // bottom edge, so the top gutter is narrower to even out. .p_2() .pt_1() - .bg(app_background) .child(row) } } diff --git a/crates/layout/src/shell.rs b/crates/layout/src/shell.rs index 1857451..a9435a4 100644 --- a/crates/layout/src/shell.rs +++ b/crates/layout/src/shell.rs @@ -9,8 +9,10 @@ use gpui::{ }; #[cfg(feature = "alert")] use gpui_native_core::alert::{Alerts, AlertsView}; +use gpui_native_core::grain::grain as grain_overlay; #[cfg(feature = "toast")] use gpui_native_core::toast::{Toasts, ToastsView}; +use gpui_native_theme::ActiveTheme as _; use gpui_native_utils::v_flex; use crate::titlebar::Titlebar; @@ -23,6 +25,8 @@ pub struct Shell { id: ElementId, titlebar: Option, panel: Option, + transparent: bool, + grain: bool, #[cfg(feature = "toast")] toasts: Option>, #[cfg(feature = "alert")] @@ -39,6 +43,8 @@ impl Shell { id: id.into(), titlebar: None, panel: None, + transparent: false, + grain: false, #[cfg(feature = "toast")] toasts: None, #[cfg(feature = "alert")] @@ -61,6 +67,18 @@ impl Shell { self } + /// Paints the app background with the translucent material fill. + pub fn transparent(mut self, transparent: bool) -> Self { + self.transparent = transparent; + self + } + + /// Textures the app background with a film-grain overlay. + pub fn grain(mut self, grain: bool) -> Self { + self.grain = grain; + self + } + /// Hosts the toast overlay raised on `toasts`. #[cfg(feature = "toast")] pub fn toasts(mut self, toasts: Entity) -> Self { @@ -79,12 +97,27 @@ impl Shell { impl RenderOnce for Shell { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { let id = self.id.clone(); + let theme = cx.theme(); + + let background = if self.transparent { + theme.material.background + } else { + theme.colors.muted + }; let layout = v_flex() .w_full() .h_full() .overflow_hidden() - .when_some(self.titlebar, |layout, titlebar| layout.child(titlebar)) + .bg(background) + .when(self.transparent && self.grain, |layout| { + layout.child(grain_overlay()) + }); + + let layout = layout + .when_some(self.titlebar, |layout, titlebar| { + layout.child(titlebar.transparent(self.transparent)) + }) .child(self.panel.unwrap_or_else(|| div().into_any_element())); let frame = frame(layout, window, cx); diff --git a/crates/layout/src/titlebar.rs b/crates/layout/src/titlebar.rs index 458bcac..2d9d35d 100644 --- a/crates/layout/src/titlebar.rs +++ b/crates/layout/src/titlebar.rs @@ -22,6 +22,7 @@ pub struct Titlebar { prefix: Vec, tab_bar: Option, suffix: Vec, + transparent: bool, } impl Titlebar { @@ -35,6 +36,7 @@ impl Titlebar { prefix: Vec::new(), tab_bar: None, suffix: Vec::new(), + transparent: false, } } @@ -55,6 +57,13 @@ impl Titlebar { self.suffix = vec![suffix.into_any_element()]; self } + + /// Leaves the strip unpainted so the shell's material backdrop shows through. + #[cfg(feature = "shell")] + pub(crate) fn transparent(mut self, transparent: bool) -> Self { + self.transparent = transparent; + self + } } impl ParentElement for Titlebar { @@ -66,7 +75,6 @@ impl ParentElement for Titlebar { impl RenderOnce for Titlebar { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { let theme = cx.theme(); - let app_background = theme.colors.muted; let height = theme.titlebar_height; let padding_x = theme.sizes.resolve(Size::default()).dense_padding_x; @@ -81,7 +89,7 @@ impl RenderOnce for Titlebar { .w_full() .h(height) .gap_2() - .bg(app_background) + .when(!self.transparent, |bar| bar.bg(theme.colors.muted)) .px(padding_x) .when(cfg!(target_os = "macos"), |bar| bar.pl(TRAFFIC_LIGHT_PAD)) .when(!self.prefix.is_empty(), |bar| { diff --git a/examples/gallery/src/main.rs b/examples/gallery/src/main.rs index 37b6ee3..e2c0ef3 100644 --- a/examples/gallery/src/main.rs +++ b/examples/gallery/src/main.rs @@ -252,6 +252,8 @@ impl Gallery { Shell::new("gallery-shell") .titlebar(self.gallery_titlebar(gallery, cx)) .panel(self.render_panel()) + .transparent(true) + .grain(true) .toasts(self.toasts.clone()) .alerts(self.alerts.clone()) }