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 gpui_native_theme::{ActiveTheme as _, Size};
|
||||||
|
|
||||||
use crate::resize_handle::ResizeHandle;
|
use crate::resize_handle::ResizeHandle;
|
||||||
use crate::shell::{LayoutState, Side, SidebarToggles, sidebar_toggle_button};
|
|
||||||
use crate::window_controls::{TRAFFIC_LIGHT_PAD, WindowControls, titlebar_strip};
|
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.
|
/// 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,
|
window_controls: bool,
|
||||||
/// The pill bar leads the window: pad for the macOS traffic lights.
|
/// The pill bar leads the window: pad for the macOS traffic lights.
|
||||||
traffic_light_pad: bool,
|
traffic_light_pad: bool,
|
||||||
/// The layout whose sidebar toggles render in the pill bar.
|
/// Builds the pill bar's leading element on each frame.
|
||||||
sidebar_toggles: Option<Entity<LayoutState>>,
|
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 {
|
impl Dock {
|
||||||
@@ -798,7 +799,8 @@ impl Dock {
|
|||||||
state,
|
state,
|
||||||
window_controls: false,
|
window_controls: false,
|
||||||
traffic_light_pad: false,
|
traffic_light_pad: false,
|
||||||
sidebar_toggles: None,
|
tab_prefix: None,
|
||||||
|
tab_suffix: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -814,9 +816,21 @@ impl Dock {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Renders the sidebar toggles in the pill bar.
|
/// Leads the pill bar with `prefix`, rebuilt on each frame.
|
||||||
pub fn sidebar_toggles(mut self, state: Entity<LayoutState>) -> Self {
|
pub fn tab_prefix<F>(mut self, prefix: F) -> Self
|
||||||
self.sidebar_toggles = Some(state);
|
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
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -828,7 +842,8 @@ impl RenderOnce for Dock {
|
|||||||
window_controls: self.window_controls,
|
window_controls: self.window_controls,
|
||||||
traffic_light_pad: self.traffic_light_pad,
|
traffic_light_pad: self.traffic_light_pad,
|
||||||
height: cx.theme().titlebar_height,
|
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);
|
let root = render_node(&self.id, &self.state, &tree, &titlebar, window, cx);
|
||||||
|
|
||||||
@@ -852,8 +867,10 @@ struct Titlebar {
|
|||||||
window_controls: bool,
|
window_controls: bool,
|
||||||
traffic_light_pad: bool,
|
traffic_light_pad: bool,
|
||||||
height: Pixels,
|
height: Pixels,
|
||||||
/// The layout whose sidebar toggles lead and trail the tab bar.
|
/// Builds the tab bar's leading element on each frame.
|
||||||
toggles: Option<Entity<LayoutState>>,
|
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.
|
/// 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));
|
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 tabs_fit_id = SharedString::from(format!("{dock_id}-pane-{}-tabs-fit", pane.key));
|
||||||
|
|
||||||
let toggles = titlebar
|
let prefix = titlebar.prefix.as_ref().map(|prefix| prefix());
|
||||||
.toggles
|
let suffix = titlebar.suffix.as_ref().map(|suffix| suffix());
|
||||||
.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()
|
h_flex()
|
||||||
.id(bar_id.clone())
|
.id(bar_id.clone())
|
||||||
@@ -1142,8 +1139,8 @@ fn render_pane(
|
|||||||
padding_x
|
padding_x
|
||||||
})
|
})
|
||||||
.pr(padding_x)
|
.pr(padding_x)
|
||||||
.when_some(toggle_left, |bar, button| {
|
.when_some(prefix, |bar, element| {
|
||||||
bar.child(div().flex_none().mr_1().child(button))
|
bar.child(div().flex_none().mr_1().child(element))
|
||||||
})
|
})
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
@@ -1166,8 +1163,8 @@ fn render_pane(
|
|||||||
window,
|
window,
|
||||||
cx,
|
cx,
|
||||||
))
|
))
|
||||||
.when_some(toggle_right, |bar, button| {
|
.when_some(suffix, |bar, element| {
|
||||||
bar.child(div().flex_none().ml_1().child(button))
|
bar.child(div().flex_none().ml_1().child(element))
|
||||||
})
|
})
|
||||||
.when(titlebar.window_controls, |bar| {
|
.when(titlebar.window_controls, |bar| {
|
||||||
bar.child(WindowControls::new(SharedString::from(format!(
|
bar.child(WindowControls::new(SharedString::from(format!(
|
||||||
|
|||||||
@@ -23,25 +23,12 @@ use crate::resize_handle::ResizeHandle;
|
|||||||
use crate::window_controls::{TRAFFIC_LIGHT_PAD, WindowControls, titlebar_strip};
|
use crate::window_controls::{TRAFFIC_LIGHT_PAD, WindowControls, titlebar_strip};
|
||||||
use crate::window_frame::frame;
|
use crate::window_frame::frame;
|
||||||
|
|
||||||
/// Where the sidebar show/hide toggles live.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
|
|
||||||
pub enum SidebarToggles {
|
|
||||||
/// No toggles.
|
|
||||||
Hidden,
|
|
||||||
/// In each sidebar's header strip.
|
|
||||||
Strips,
|
|
||||||
#[default]
|
|
||||||
/// In the center dock's tab bar.
|
|
||||||
Tabbar,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The layout the application owns.
|
/// The layout the application owns.
|
||||||
pub struct LayoutState {
|
pub struct LayoutState {
|
||||||
left_visible: bool,
|
left_visible: bool,
|
||||||
right_visible: bool,
|
right_visible: bool,
|
||||||
left_width: Pixels,
|
left_width: Pixels,
|
||||||
right_width: Pixels,
|
right_width: Pixels,
|
||||||
sidebar_toggles: SidebarToggles,
|
|
||||||
#[cfg(feature = "toast")]
|
#[cfg(feature = "toast")]
|
||||||
toasts: Entity<Toasts>,
|
toasts: Entity<Toasts>,
|
||||||
#[cfg(feature = "alert")]
|
#[cfg(feature = "alert")]
|
||||||
@@ -56,7 +43,6 @@ impl LayoutState {
|
|||||||
right_visible: false,
|
right_visible: false,
|
||||||
left_width: SIDEBAR_DEFAULT_WIDTH,
|
left_width: SIDEBAR_DEFAULT_WIDTH,
|
||||||
right_width: SIDEBAR_DEFAULT_WIDTH,
|
right_width: SIDEBAR_DEFAULT_WIDTH,
|
||||||
sidebar_toggles: SidebarToggles::default(),
|
|
||||||
#[cfg(feature = "toast")]
|
#[cfg(feature = "toast")]
|
||||||
toasts: _cx.new(|_| Toasts::default()),
|
toasts: _cx.new(|_| Toasts::default()),
|
||||||
#[cfg(feature = "alert")]
|
#[cfg(feature = "alert")]
|
||||||
@@ -80,19 +66,6 @@ impl LayoutState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets where the sidebar show/hide toggles live.
|
|
||||||
pub fn set_sidebar_toggles(&mut self, toggles: SidebarToggles, cx: &mut Context<Self>) {
|
|
||||||
if self.sidebar_toggles != toggles {
|
|
||||||
self.sidebar_toggles = toggles;
|
|
||||||
cx.notify();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Where the sidebar show/hide toggles live.
|
|
||||||
pub fn sidebar_toggles(&self) -> SidebarToggles {
|
|
||||||
self.sidebar_toggles
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Whether the left sidebar is visible.
|
/// Whether the left sidebar is visible.
|
||||||
pub fn is_left_sidebar_visible(&self) -> bool {
|
pub fn is_left_sidebar_visible(&self) -> bool {
|
||||||
self.left_visible
|
self.left_visible
|
||||||
@@ -251,7 +224,6 @@ impl RenderOnce for Shell {
|
|||||||
|
|
||||||
let left_visible = state.read(cx).is_left_sidebar_visible();
|
let left_visible = state.read(cx).is_left_sidebar_visible();
|
||||||
let right_visible = state.read(cx).is_right_sidebar_visible();
|
let right_visible = state.read(cx).is_right_sidebar_visible();
|
||||||
let strip_toggles = state.read(cx).sidebar_toggles() == SidebarToggles::Strips;
|
|
||||||
|
|
||||||
let left_material = left
|
let left_material = left
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@@ -270,7 +242,6 @@ impl RenderOnce for Shell {
|
|||||||
material: left_material,
|
material: left_material,
|
||||||
height: titlebar_height,
|
height: titlebar_height,
|
||||||
padding_x: metrics.dense_padding_x,
|
padding_x: metrics.dense_padding_x,
|
||||||
toggle: strip_toggles,
|
|
||||||
};
|
};
|
||||||
layout
|
layout
|
||||||
.child(
|
.child(
|
||||||
@@ -330,7 +301,6 @@ impl RenderOnce for Shell {
|
|||||||
material: false,
|
material: false,
|
||||||
height: titlebar_height,
|
height: titlebar_height,
|
||||||
padding_x: metrics.dense_padding_x,
|
padding_x: metrics.dense_padding_x,
|
||||||
toggle: strip_toggles,
|
|
||||||
},
|
},
|
||||||
window,
|
window,
|
||||||
cx,
|
cx,
|
||||||
@@ -357,12 +327,7 @@ impl RenderOnce for Shell {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// One sidebar show/hide toggle.
|
/// One sidebar show/hide toggle.
|
||||||
pub(crate) fn sidebar_toggle_button<I>(
|
fn sidebar_toggle_button<I>(id: I, side: Side, state: &Entity<LayoutState>, cx: &App) -> Button
|
||||||
id: I,
|
|
||||||
side: Side,
|
|
||||||
state: &Entity<LayoutState>,
|
|
||||||
cx: &App,
|
|
||||||
) -> Button
|
|
||||||
where
|
where
|
||||||
I: Into<ElementId>,
|
I: Into<ElementId>,
|
||||||
{
|
{
|
||||||
@@ -406,8 +371,6 @@ struct Titlebar {
|
|||||||
material: bool,
|
material: bool,
|
||||||
height: Pixels,
|
height: Pixels,
|
||||||
padding_x: Pixels,
|
padding_x: Pixels,
|
||||||
/// Whether the strip carries the sidebar's hide toggle.
|
|
||||||
toggle: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sidebar_region<I>(
|
fn sidebar_region<I>(
|
||||||
@@ -468,14 +431,12 @@ where
|
|||||||
cx,
|
cx,
|
||||||
))
|
))
|
||||||
.map(|strip| match titlebar.side {
|
.map(|strip| match titlebar.side {
|
||||||
Side::Left => strip.when(titlebar.toggle, |strip| {
|
Side::Left => strip.child(sidebar_toggle_button(
|
||||||
strip.child(sidebar_toggle_button(
|
(id, "sidebar-toggle"),
|
||||||
(id, "sidebar-toggle"),
|
Side::Left,
|
||||||
Side::Left,
|
state,
|
||||||
state,
|
cx,
|
||||||
cx,
|
)),
|
||||||
))
|
|
||||||
}),
|
|
||||||
Side::Right => strip.child(WindowControls::new((id, "window-controls"))),
|
Side::Right => strip.child(WindowControls::new((id, "window-controls"))),
|
||||||
})
|
})
|
||||||
.into_any_element()
|
.into_any_element()
|
||||||
|
|||||||
@@ -288,8 +288,7 @@ impl Gallery {
|
|||||||
let center = Dock::new("gallery-dock", self.dock_state.clone())
|
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.
|
// 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())
|
.window_controls(!self.layout_state.read(cx).is_right_sidebar_visible())
|
||||||
.traffic_light_pad(!self.layout_state.read(cx).is_left_sidebar_visible())
|
.traffic_light_pad(!self.layout_state.read(cx).is_left_sidebar_visible());
|
||||||
.sidebar_toggles(self.layout_state.clone());
|
|
||||||
|
|
||||||
let right_sidebar = DockSidebar::new("gallery-dock-sidebar", self.dock_state.clone());
|
let right_sidebar = DockSidebar::new("gallery-dock-sidebar", self.dock_state.clone());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user