layout: add transparent and grain options to shell

This commit is contained in:
2026-11-15 11:52:51 +07:00
parent 032158fc01
commit d2ac4c446d
5 changed files with 49 additions and 8 deletions
+1 -4
View File
@@ -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)
}
}
+34 -1
View File
@@ -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<Titlebar>,
panel: Option<AnyElement>,
transparent: bool,
grain: bool,
#[cfg(feature = "toast")]
toasts: Option<Entity<Toasts>>,
#[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<Toasts>) -> 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);
+10 -2
View File
@@ -22,6 +22,7 @@ pub struct Titlebar {
prefix: Vec<AnyElement>,
tab_bar: Option<AnyElement>,
suffix: Vec<AnyElement>,
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| {