layout: add unified shell titlebar
This commit is contained in:
@@ -53,6 +53,7 @@ use gpui_native_layout::dock::{Dock, DockSidebar, DockState, Panel, SplitDirecti
|
||||
use gpui_native_layout::resizable::{Resizable, ResizableState};
|
||||
use gpui_native_layout::resize_handle::ResizeHandle;
|
||||
use gpui_native_layout::shell::{LayoutState, Shell};
|
||||
use gpui_native_layout::titlebar::Titlebar;
|
||||
use gpui_native_theme::{
|
||||
ActiveTheme as _, CODE_OVERSCROLL_MAX, Theme, ThemeVariant, active_preset, mode_override,
|
||||
set_mode_override, set_preset,
|
||||
@@ -228,6 +229,8 @@ struct Gallery {
|
||||
sidebar_transparent: bool,
|
||||
/// Whether a film-grain overlay textures the window.
|
||||
grain: bool,
|
||||
/// Whether the shell draws the unified titlebar.
|
||||
titlebar: bool,
|
||||
}
|
||||
|
||||
impl Gallery {
|
||||
@@ -286,9 +289,14 @@ impl Gallery {
|
||||
});
|
||||
|
||||
let center = Dock::new("gallery-dock", self.dock_state.clone())
|
||||
// The pill bar is the titlebar strip whenever no right sidebar sits to its right.
|
||||
.window_controls(!self.layout_state.read(cx).is_right_sidebar_visible())
|
||||
.traffic_light_pad(!self.layout_state.read(cx).is_left_sidebar_visible());
|
||||
// The pill bar is the titlebar strip whenever no right sidebar sits
|
||||
// to its right and the shell titlebar has not taken the chrome over.
|
||||
.window_controls(
|
||||
!self.titlebar && !self.layout_state.read(cx).is_right_sidebar_visible(),
|
||||
)
|
||||
.traffic_light_pad(
|
||||
!self.titlebar && !self.layout_state.read(cx).is_left_sidebar_visible(),
|
||||
);
|
||||
|
||||
let right_sidebar = DockSidebar::new("gallery-dock-sidebar", self.dock_state.clone());
|
||||
|
||||
@@ -296,6 +304,33 @@ impl Gallery {
|
||||
.left_sidebar(left_sidebar)
|
||||
.center(center)
|
||||
.right_sidebar(right_sidebar)
|
||||
.when(self.titlebar, |shell| {
|
||||
shell.titlebar(self.gallery_titlebar(cx))
|
||||
})
|
||||
}
|
||||
|
||||
/// The demo titlebar: a sidebar toggle and the app title.
|
||||
fn gallery_titlebar(&self, cx: &App) -> Titlebar {
|
||||
let layout = self.layout_state.clone();
|
||||
let title_color = cx.theme().colors.muted_foreground;
|
||||
|
||||
Titlebar::new("gallery-titlebar")
|
||||
.child(
|
||||
Button::new("titlebar-toggle-left")
|
||||
.icon(IconRole::PanelLeft)
|
||||
.variant(ButtonVariant::Ghost)
|
||||
.small()
|
||||
.accessibility_label("Toggle left sidebar")
|
||||
.on_click(move |_, _, cx| {
|
||||
layout.update(cx, LayoutState::toggle_left_sidebar);
|
||||
}),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.text_sm()
|
||||
.text_color(title_color)
|
||||
.child("gpui-native-kit"),
|
||||
)
|
||||
}
|
||||
|
||||
fn render_dialog(open: bool, gallery: WeakEntity<Self>) -> Dialog {
|
||||
@@ -600,6 +635,7 @@ impl Render for WelcomePanel {
|
||||
let dock_state = self.dock_state.clone();
|
||||
let gallery = self.gallery.clone();
|
||||
let grain_gallery = self.gallery.clone();
|
||||
let titlebar_gallery = self.gallery.clone();
|
||||
|
||||
ScrollArea::new("welcome-demo")
|
||||
.size_full()
|
||||
@@ -682,6 +718,20 @@ impl Render for WelcomePanel {
|
||||
.log_err();
|
||||
}),
|
||||
)
|
||||
.child(
|
||||
Button::new("welcome-toggle-titlebar")
|
||||
.label("Toggle titlebar")
|
||||
.variant(ButtonVariant::Secondary)
|
||||
.small()
|
||||
.on_click(move |_, _, cx| {
|
||||
titlebar_gallery
|
||||
.update(cx, |gallery, cx| {
|
||||
gallery.titlebar = !gallery.titlebar;
|
||||
cx.notify();
|
||||
})
|
||||
.log_err();
|
||||
}),
|
||||
)
|
||||
.child(
|
||||
Button::new("welcome-split")
|
||||
.label("Split active right")
|
||||
@@ -4486,6 +4536,7 @@ fn main() {
|
||||
alert_open: false,
|
||||
sidebar_transparent: true,
|
||||
grain: true,
|
||||
titlebar: false,
|
||||
});
|
||||
|
||||
let palette = cx.new(|cx| {
|
||||
|
||||
Reference in New Issue
Block a user