layout: add sidebar toggles and shell toggle control

This commit is contained in:
2026-11-14 16:50:15 +07:00
parent 93860e3c1d
commit ce77809132
2 changed files with 37 additions and 20 deletions
+29 -8
View File
@@ -66,6 +66,16 @@ impl LayoutState {
}
}
/// Opens the left sidebar when closed, closes it when open.
pub fn toggle_left_sidebar(&mut self, cx: &mut Context<Self>) {
self.set_left_sidebar_visible(!self.left_visible, cx);
}
/// Opens the right sidebar when closed, closes it when open.
pub fn toggle_right_sidebar(&mut self, cx: &mut Context<Self>) {
self.set_right_sidebar_visible(!self.right_visible, cx);
}
/// Whether the left sidebar is visible.
pub fn is_left_sidebar_visible(&self) -> bool {
self.left_visible
@@ -166,6 +176,8 @@ pub struct Shell {
left_sidebar: Option<Sidebar>,
right_sidebar: Option<AnyElement>,
center: Option<AnyElement>,
/// Whether the left strip renders the default sidebar toggle.
toggle_button: bool,
}
impl Shell {
@@ -180,9 +192,16 @@ impl Shell {
left_sidebar: None,
right_sidebar: None,
center: None,
toggle_button: true,
}
}
/// Renders the default sidebar toggle in the left strip's trailing end.
pub fn toggle_button(mut self, toggle_button: bool) -> Self {
self.toggle_button = toggle_button;
self
}
/// Sets the left sidebar's navigation list.
pub fn left_sidebar(mut self, sidebar: Sidebar) -> Self {
self.left_sidebar = Some(sidebar);
@@ -242,6 +261,7 @@ impl RenderOnce for Shell {
material: left_material,
height: titlebar_height,
padding_x: metrics.dense_padding_x,
toggle: self.toggle_button,
};
layout
.child(
@@ -301,6 +321,7 @@ impl RenderOnce for Shell {
material: false,
height: titlebar_height,
padding_x: metrics.dense_padding_x,
toggle: false,
},
window,
cx,
@@ -354,12 +375,8 @@ where
.on_click({
let state = state.clone();
move |_, _, cx| match side {
Side::Left => state.update(cx, |state, cx| {
state.set_left_sidebar_visible(!state.is_left_sidebar_visible(), cx)
}),
Side::Right => state.update(cx, |state, cx| {
state.set_right_sidebar_visible(!state.is_right_sidebar_visible(), cx)
}),
Side::Left => state.update(cx, LayoutState::toggle_left_sidebar),
Side::Right => state.update(cx, LayoutState::toggle_right_sidebar),
}
})
}
@@ -371,6 +388,8 @@ struct Titlebar {
material: bool,
height: Pixels,
padding_x: Pixels,
/// Whether the strip carries the sidebar's hide toggle.
toggle: bool,
}
fn sidebar_region<I>(
@@ -431,12 +450,14 @@ where
cx,
))
.map(|strip| match titlebar.side {
Side::Left => strip.child(sidebar_toggle_button(
Side::Left => strip.when(titlebar.toggle, |strip| {
strip.child(sidebar_toggle_button(
(id, "sidebar-toggle"),
Side::Left,
state,
cx,
)),
))
}),
Side::Right => strip.child(WindowControls::new((id, "window-controls"))),
})
.into_any_element()
+4 -8
View File
@@ -639,10 +639,8 @@ impl Render for WelcomePanel {
.variant(ButtonVariant::Secondary)
.small()
.on_click(move |_, _, cx| {
layout_left.update(cx, |state, cx| {
let visible = !state.is_left_sidebar_visible();
state.set_left_sidebar_visible(visible, cx);
});
layout_left
.update(cx, LayoutState::toggle_left_sidebar);
}),
)
.child(
@@ -651,10 +649,8 @@ impl Render for WelcomePanel {
.variant(ButtonVariant::Secondary)
.small()
.on_click(move |_, _, cx| {
layout_right.update(cx, |state, cx| {
let visible = !state.is_right_sidebar_visible();
state.set_right_sidebar_visible(visible, cx);
});
layout_right
.update(cx, LayoutState::toggle_right_sidebar);
}),
)
.child(