layout: add sidebar toggles and shell toggle control
This commit is contained in:
@@ -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.
|
/// 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
|
||||||
@@ -166,6 +176,8 @@ pub struct Shell {
|
|||||||
left_sidebar: Option<Sidebar>,
|
left_sidebar: Option<Sidebar>,
|
||||||
right_sidebar: Option<AnyElement>,
|
right_sidebar: Option<AnyElement>,
|
||||||
center: Option<AnyElement>,
|
center: Option<AnyElement>,
|
||||||
|
/// Whether the left strip renders the default sidebar toggle.
|
||||||
|
toggle_button: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Shell {
|
impl Shell {
|
||||||
@@ -180,9 +192,16 @@ impl Shell {
|
|||||||
left_sidebar: None,
|
left_sidebar: None,
|
||||||
right_sidebar: None,
|
right_sidebar: None,
|
||||||
center: 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.
|
/// Sets the left sidebar's navigation list.
|
||||||
pub fn left_sidebar(mut self, sidebar: Sidebar) -> Self {
|
pub fn left_sidebar(mut self, sidebar: Sidebar) -> Self {
|
||||||
self.left_sidebar = Some(sidebar);
|
self.left_sidebar = Some(sidebar);
|
||||||
@@ -242,6 +261,7 @@ 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: self.toggle_button,
|
||||||
};
|
};
|
||||||
layout
|
layout
|
||||||
.child(
|
.child(
|
||||||
@@ -301,6 +321,7 @@ 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: false,
|
||||||
},
|
},
|
||||||
window,
|
window,
|
||||||
cx,
|
cx,
|
||||||
@@ -354,12 +375,8 @@ where
|
|||||||
.on_click({
|
.on_click({
|
||||||
let state = state.clone();
|
let state = state.clone();
|
||||||
move |_, _, cx| match side {
|
move |_, _, cx| match side {
|
||||||
Side::Left => state.update(cx, |state, cx| {
|
Side::Left => state.update(cx, LayoutState::toggle_left_sidebar),
|
||||||
state.set_left_sidebar_visible(!state.is_left_sidebar_visible(), cx)
|
Side::Right => state.update(cx, LayoutState::toggle_right_sidebar),
|
||||||
}),
|
|
||||||
Side::Right => state.update(cx, |state, cx| {
|
|
||||||
state.set_right_sidebar_visible(!state.is_right_sidebar_visible(), cx)
|
|
||||||
}),
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -371,6 +388,8 @@ 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>(
|
||||||
@@ -431,12 +450,14 @@ where
|
|||||||
cx,
|
cx,
|
||||||
))
|
))
|
||||||
.map(|strip| match titlebar.side {
|
.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"),
|
(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()
|
||||||
|
|||||||
@@ -639,10 +639,8 @@ impl Render for WelcomePanel {
|
|||||||
.variant(ButtonVariant::Secondary)
|
.variant(ButtonVariant::Secondary)
|
||||||
.small()
|
.small()
|
||||||
.on_click(move |_, _, cx| {
|
.on_click(move |_, _, cx| {
|
||||||
layout_left.update(cx, |state, cx| {
|
layout_left
|
||||||
let visible = !state.is_left_sidebar_visible();
|
.update(cx, LayoutState::toggle_left_sidebar);
|
||||||
state.set_left_sidebar_visible(visible, cx);
|
|
||||||
});
|
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
@@ -651,10 +649,8 @@ impl Render for WelcomePanel {
|
|||||||
.variant(ButtonVariant::Secondary)
|
.variant(ButtonVariant::Secondary)
|
||||||
.small()
|
.small()
|
||||||
.on_click(move |_, _, cx| {
|
.on_click(move |_, _, cx| {
|
||||||
layout_right.update(cx, |state, cx| {
|
layout_right
|
||||||
let visible = !state.is_right_sidebar_visible();
|
.update(cx, LayoutState::toggle_right_sidebar);
|
||||||
state.set_right_sidebar_visible(visible, cx);
|
|
||||||
});
|
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
|
|||||||
Reference in New Issue
Block a user