layout: add sidebar toggle placement options

This commit is contained in:
2026-11-11 15:16:28 +07:00
parent d862559643
commit a0ede5e15a
5 changed files with 461 additions and 32 deletions
+62 -3
View File
@@ -19,6 +19,7 @@ use gpui_native_icons::{Icon, IconRole};
use gpui_native_theme::{ActiveTheme as _, Size};
use crate::resize_handle::ResizeHandle;
use crate::shell::{LayoutState, Side, SidebarToggles, sidebar_toggle_button};
use crate::window_controls::{TRAFFIC_LIGHT_PAD, WindowControls, titlebar_strip};
/// The narrowest either side of a split can get, as a fraction of the split.
@@ -779,6 +780,8 @@ pub struct Dock {
window_controls: bool,
/// The pill bar leads the window: pad for the macOS traffic lights.
traffic_light_pad: bool,
/// The layout whose sidebar toggles render in the pill bar.
sidebar_toggles: Option<Entity<LayoutState>>,
}
impl Dock {
@@ -792,6 +795,7 @@ impl Dock {
state,
window_controls: false,
traffic_light_pad: false,
sidebar_toggles: None,
}
}
@@ -806,6 +810,12 @@ impl Dock {
self.traffic_light_pad = traffic_light_pad;
self
}
/// Renders the sidebar toggles in the pill bar.
pub fn sidebar_toggles(mut self, state: Entity<LayoutState>) -> Self {
self.sidebar_toggles = Some(state);
self
}
}
impl RenderOnce for Dock {
@@ -815,6 +825,7 @@ impl RenderOnce for Dock {
window_controls: self.window_controls,
traffic_light_pad: self.traffic_light_pad,
height: cx.theme().titlebar_height,
toggles: self.sidebar_toggles,
};
let root = render_node(&self.id, &self.state, &tree, &titlebar, window, cx);
@@ -833,11 +844,13 @@ impl RenderOnce for Dock {
}
/// Which titlebar duties the pane's pill bar carries.
#[derive(Clone, Copy, Default)]
#[derive(Clone, Default)]
struct Titlebar {
window_controls: bool,
traffic_light_pad: bool,
height: Pixels,
/// The layout whose sidebar toggles lead and trail the tab bar.
toggles: Option<Entity<LayoutState>>,
}
/// The right sidebar content of the dock's active panel.
@@ -1017,7 +1030,7 @@ fn render_pane(
let dock_id = dock_id.clone();
let state = state.clone();
let pane = pane.clone();
let titlebar = *titlebar;
let titlebar = titlebar.clone();
let padding_x = metrics.dense_padding_x;
move |window, cx| {
@@ -1092,6 +1105,32 @@ fn render_pane(
let bar_id = SharedString::from(format!("{dock_id}-pane-{}-bar", pane.key));
let strip_id = SharedString::from(format!("{dock_id}-pane-{}-strip", pane.key));
let tabs_scroll_id =
SharedString::from(format!("{dock_id}-pane-{}-tabs-scroll", pane.key));
let tabs_fit_id = SharedString::from(format!("{dock_id}-pane-{}-tabs-fit", pane.key));
let toggles = titlebar
.toggles
.clone()
.filter(|state| state.read(cx).sidebar_toggles() == SidebarToggles::Tabbar);
let toggle_left = toggles.as_ref().map(|state| {
sidebar_toggle_button(
SharedString::from(format!("{bar_id}-toggle-left")),
Side::Left,
state,
cx,
)
});
let toggle_right = toggles.as_ref().map(|state| {
sidebar_toggle_button(
SharedString::from(format!("{bar_id}-toggle-right")),
Side::Right,
state,
cx,
)
});
h_flex()
.id(bar_id.clone())
@@ -1106,13 +1145,33 @@ fn render_pane(
padding_x
})
.pr(padding_x)
.child(tabs)
.when_some(toggle_left, |bar, button| {
bar.child(div().flex_none().mr_1().child(button))
})
.child(
div()
.id(tabs_scroll_id.clone())
.debug_selector(move || tabs_scroll_id.to_string())
.flex()
.min_w_0()
.overflow_x_scroll()
.child(
div()
.id(tabs_fit_id.clone())
.debug_selector(move || tabs_fit_id.to_string())
.flex_none()
.child(tabs),
),
)
.child(titlebar_strip(
div().id(strip_id.clone()).flex_1().self_stretch(),
strip_id,
window,
cx,
))
.when_some(toggle_right, |bar, button| {
bar.child(div().flex_none().ml_1().child(button))
})
.when(titlebar.window_controls, |bar| {
bar.child(WindowControls::new(SharedString::from(format!(
"{dock_id}-pane-{}-controls",