layout: replace sidebar toggle slots with tab prefix and suffix
This commit is contained in:
+33
-36
@@ -20,7 +20,6 @@ use gpui_native_icons::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.
|
||||
@@ -783,8 +782,10 @@ 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>>,
|
||||
/// Builds the pill bar's leading element on each frame.
|
||||
tab_prefix: Option<Rc<dyn Fn() -> AnyElement>>,
|
||||
/// Builds the pill bar's trailing element on each frame.
|
||||
tab_suffix: Option<Rc<dyn Fn() -> AnyElement>>,
|
||||
}
|
||||
|
||||
impl Dock {
|
||||
@@ -798,7 +799,8 @@ impl Dock {
|
||||
state,
|
||||
window_controls: false,
|
||||
traffic_light_pad: false,
|
||||
sidebar_toggles: None,
|
||||
tab_prefix: None,
|
||||
tab_suffix: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -814,9 +816,21 @@ impl Dock {
|
||||
self
|
||||
}
|
||||
|
||||
/// Renders the sidebar toggles in the pill bar.
|
||||
pub fn sidebar_toggles(mut self, state: Entity<LayoutState>) -> Self {
|
||||
self.sidebar_toggles = Some(state);
|
||||
/// Leads the pill bar with `prefix`, rebuilt on each frame.
|
||||
pub fn tab_prefix<F>(mut self, prefix: F) -> Self
|
||||
where
|
||||
F: Fn() -> AnyElement + 'static,
|
||||
{
|
||||
self.tab_prefix = Some(Rc::new(prefix));
|
||||
self
|
||||
}
|
||||
|
||||
/// Trails the pill bar with `suffix`, rebuilt on each frame.
|
||||
pub fn tab_suffix<F>(mut self, suffix: F) -> Self
|
||||
where
|
||||
F: Fn() -> AnyElement + 'static,
|
||||
{
|
||||
self.tab_suffix = Some(Rc::new(suffix));
|
||||
self
|
||||
}
|
||||
}
|
||||
@@ -828,7 +842,8 @@ 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,
|
||||
prefix: self.tab_prefix,
|
||||
suffix: self.tab_suffix,
|
||||
};
|
||||
let root = render_node(&self.id, &self.state, &tree, &titlebar, window, cx);
|
||||
|
||||
@@ -852,8 +867,10 @@ 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>>,
|
||||
/// Builds the tab bar's leading element on each frame.
|
||||
prefix: Option<Rc<dyn Fn() -> AnyElement>>,
|
||||
/// Builds the tab bar's trailing element on each frame.
|
||||
suffix: Option<Rc<dyn Fn() -> AnyElement>>,
|
||||
}
|
||||
|
||||
/// The right sidebar content of the dock's active panel.
|
||||
@@ -1106,28 +1123,8 @@ fn render_pane(
|
||||
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,
|
||||
)
|
||||
});
|
||||
let prefix = titlebar.prefix.as_ref().map(|prefix| prefix());
|
||||
let suffix = titlebar.suffix.as_ref().map(|suffix| suffix());
|
||||
|
||||
h_flex()
|
||||
.id(bar_id.clone())
|
||||
@@ -1142,8 +1139,8 @@ fn render_pane(
|
||||
padding_x
|
||||
})
|
||||
.pr(padding_x)
|
||||
.when_some(toggle_left, |bar, button| {
|
||||
bar.child(div().flex_none().mr_1().child(button))
|
||||
.when_some(prefix, |bar, element| {
|
||||
bar.child(div().flex_none().mr_1().child(element))
|
||||
})
|
||||
.child(
|
||||
div()
|
||||
@@ -1166,8 +1163,8 @@ fn render_pane(
|
||||
window,
|
||||
cx,
|
||||
))
|
||||
.when_some(toggle_right, |bar, button| {
|
||||
bar.child(div().flex_none().ml_1().child(button))
|
||||
.when_some(suffix, |bar, element| {
|
||||
bar.child(div().flex_none().ml_1().child(element))
|
||||
})
|
||||
.when(titlebar.window_controls, |bar| {
|
||||
bar.child(WindowControls::new(SharedString::from(format!(
|
||||
|
||||
Reference in New Issue
Block a user