layout: add transparent and grain options to shell
This commit is contained in:
@@ -26,10 +26,11 @@ full = [
|
|||||||
"toast",
|
"toast",
|
||||||
"window_controls",
|
"window_controls",
|
||||||
]
|
]
|
||||||
|
grain = ["dep:gpui-native-core", "gpui-native-core/grain"]
|
||||||
panel = ["resizable"]
|
panel = ["resizable"]
|
||||||
resize_handle = []
|
resize_handle = []
|
||||||
resizable = ["resize_handle"]
|
resizable = ["resize_handle"]
|
||||||
shell = ["titlebar", "window_controls"]
|
shell = ["titlebar", "window_controls", "grain"]
|
||||||
titlebar = ["window_controls"]
|
titlebar = ["window_controls"]
|
||||||
toast = ["shell", "gpui-native-core/toast", "gpui-native-core/button"]
|
toast = ["shell", "gpui-native-core/toast", "gpui-native-core/button"]
|
||||||
alert = ["shell", "gpui-native-core/alert", "gpui-native-core/button"]
|
alert = ["shell", "gpui-native-core/alert", "gpui-native-core/button"]
|
||||||
|
|||||||
@@ -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
|
//! background. It can split once into two half-width panels with a drag
|
||||||
//! divider between them; dragging the seam resizes the panels and a
|
//! divider between them; dragging the seam resizes the panels and a
|
||||||
//! double-click restores the half split.
|
//! double-click restores the half split.
|
||||||
@@ -67,8 +67,6 @@ impl Panel {
|
|||||||
|
|
||||||
impl RenderOnce for Panel {
|
impl RenderOnce for Panel {
|
||||||
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
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 id = self.id.clone();
|
||||||
let gutter = rems(0.5).to_pixels(window.rem_size());
|
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.
|
// bottom edge, so the top gutter is narrower to even out.
|
||||||
.p_2()
|
.p_2()
|
||||||
.pt_1()
|
.pt_1()
|
||||||
.bg(app_background)
|
|
||||||
.child(row)
|
.child(row)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,10 @@ use gpui::{
|
|||||||
};
|
};
|
||||||
#[cfg(feature = "alert")]
|
#[cfg(feature = "alert")]
|
||||||
use gpui_native_core::alert::{Alerts, AlertsView};
|
use gpui_native_core::alert::{Alerts, AlertsView};
|
||||||
|
use gpui_native_core::grain::grain as grain_overlay;
|
||||||
#[cfg(feature = "toast")]
|
#[cfg(feature = "toast")]
|
||||||
use gpui_native_core::toast::{Toasts, ToastsView};
|
use gpui_native_core::toast::{Toasts, ToastsView};
|
||||||
|
use gpui_native_theme::ActiveTheme as _;
|
||||||
use gpui_native_utils::v_flex;
|
use gpui_native_utils::v_flex;
|
||||||
|
|
||||||
use crate::titlebar::Titlebar;
|
use crate::titlebar::Titlebar;
|
||||||
@@ -23,6 +25,8 @@ pub struct Shell {
|
|||||||
id: ElementId,
|
id: ElementId,
|
||||||
titlebar: Option<Titlebar>,
|
titlebar: Option<Titlebar>,
|
||||||
panel: Option<AnyElement>,
|
panel: Option<AnyElement>,
|
||||||
|
transparent: bool,
|
||||||
|
grain: bool,
|
||||||
#[cfg(feature = "toast")]
|
#[cfg(feature = "toast")]
|
||||||
toasts: Option<Entity<Toasts>>,
|
toasts: Option<Entity<Toasts>>,
|
||||||
#[cfg(feature = "alert")]
|
#[cfg(feature = "alert")]
|
||||||
@@ -39,6 +43,8 @@ impl Shell {
|
|||||||
id: id.into(),
|
id: id.into(),
|
||||||
titlebar: None,
|
titlebar: None,
|
||||||
panel: None,
|
panel: None,
|
||||||
|
transparent: false,
|
||||||
|
grain: false,
|
||||||
#[cfg(feature = "toast")]
|
#[cfg(feature = "toast")]
|
||||||
toasts: None,
|
toasts: None,
|
||||||
#[cfg(feature = "alert")]
|
#[cfg(feature = "alert")]
|
||||||
@@ -61,6 +67,18 @@ impl Shell {
|
|||||||
self
|
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`.
|
/// Hosts the toast overlay raised on `toasts`.
|
||||||
#[cfg(feature = "toast")]
|
#[cfg(feature = "toast")]
|
||||||
pub fn toasts(mut self, toasts: Entity<Toasts>) -> Self {
|
pub fn toasts(mut self, toasts: Entity<Toasts>) -> Self {
|
||||||
@@ -79,12 +97,27 @@ impl Shell {
|
|||||||
impl RenderOnce for Shell {
|
impl RenderOnce for Shell {
|
||||||
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||||
let id = self.id.clone();
|
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()
|
let layout = v_flex()
|
||||||
.w_full()
|
.w_full()
|
||||||
.h_full()
|
.h_full()
|
||||||
.overflow_hidden()
|
.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()));
|
.child(self.panel.unwrap_or_else(|| div().into_any_element()));
|
||||||
|
|
||||||
let frame = frame(layout, window, cx);
|
let frame = frame(layout, window, cx);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ pub struct Titlebar {
|
|||||||
prefix: Vec<AnyElement>,
|
prefix: Vec<AnyElement>,
|
||||||
tab_bar: Option<AnyElement>,
|
tab_bar: Option<AnyElement>,
|
||||||
suffix: Vec<AnyElement>,
|
suffix: Vec<AnyElement>,
|
||||||
|
transparent: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Titlebar {
|
impl Titlebar {
|
||||||
@@ -35,6 +36,7 @@ impl Titlebar {
|
|||||||
prefix: Vec::new(),
|
prefix: Vec::new(),
|
||||||
tab_bar: None,
|
tab_bar: None,
|
||||||
suffix: Vec::new(),
|
suffix: Vec::new(),
|
||||||
|
transparent: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,6 +57,13 @@ impl Titlebar {
|
|||||||
self.suffix = vec![suffix.into_any_element()];
|
self.suffix = vec![suffix.into_any_element()];
|
||||||
self
|
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 {
|
impl ParentElement for Titlebar {
|
||||||
@@ -66,7 +75,6 @@ impl ParentElement for Titlebar {
|
|||||||
impl RenderOnce for Titlebar {
|
impl RenderOnce for Titlebar {
|
||||||
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||||
let theme = cx.theme();
|
let theme = cx.theme();
|
||||||
let app_background = theme.colors.muted;
|
|
||||||
let height = theme.titlebar_height;
|
let height = theme.titlebar_height;
|
||||||
let padding_x = theme.sizes.resolve(Size::default()).dense_padding_x;
|
let padding_x = theme.sizes.resolve(Size::default()).dense_padding_x;
|
||||||
|
|
||||||
@@ -81,7 +89,7 @@ impl RenderOnce for Titlebar {
|
|||||||
.w_full()
|
.w_full()
|
||||||
.h(height)
|
.h(height)
|
||||||
.gap_2()
|
.gap_2()
|
||||||
.bg(app_background)
|
.when(!self.transparent, |bar| bar.bg(theme.colors.muted))
|
||||||
.px(padding_x)
|
.px(padding_x)
|
||||||
.when(cfg!(target_os = "macos"), |bar| bar.pl(TRAFFIC_LIGHT_PAD))
|
.when(cfg!(target_os = "macos"), |bar| bar.pl(TRAFFIC_LIGHT_PAD))
|
||||||
.when(!self.prefix.is_empty(), |bar| {
|
.when(!self.prefix.is_empty(), |bar| {
|
||||||
|
|||||||
@@ -252,6 +252,8 @@ impl Gallery {
|
|||||||
Shell::new("gallery-shell")
|
Shell::new("gallery-shell")
|
||||||
.titlebar(self.gallery_titlebar(gallery, cx))
|
.titlebar(self.gallery_titlebar(gallery, cx))
|
||||||
.panel(self.render_panel())
|
.panel(self.render_panel())
|
||||||
|
.transparent(true)
|
||||||
|
.grain(true)
|
||||||
.toasts(self.toasts.clone())
|
.toasts(self.toasts.clone())
|
||||||
.alerts(self.alerts.clone())
|
.alerts(self.alerts.clone())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user