diff --git a/crates/story/src/main.rs b/crates/story/src/main.rs index 17b954b4..75e043a8 100644 --- a/crates/story/src/main.rs +++ b/crates/story/src/main.rs @@ -22,6 +22,7 @@ pub struct AddPanel(DockPlacement); pub struct TogglePanelVisible(SharedString); impl_internal_actions!(story, [AddPanel, TogglePanelVisible]); +actions!(story, [ToggleDockToggleButton]); const MAIN_DOCK_AREA: DockAreaTab = DockAreaTab { id: "main-dock", @@ -41,6 +42,7 @@ pub struct StoryWorkspace { title_bar: Entity, dock_area: Entity, last_layout_state: Option, + toggle_button_visible: bool, _save_layout_task: Option>, } @@ -122,6 +124,11 @@ impl StoryWorkspace { Box::new(AddPanel(DockPlacement::Bottom)), ) .separator() + .menu( + "Show / Hide Dock Toggle Button", + Box::new(ToggleDockToggleButton), + ) + .separator() .menu_with_check( "Sidebar", !invisible_panels @@ -133,7 +140,7 @@ impl StoryWorkspace { "Modal", !invisible_panels .read(cx) - .contains(&SharedString::from("SidebModalar")), + .contains(&SharedString::from("Modal")), Box::new(TogglePanelVisible(SharedString::from("Modal"))), ) .menu_with_check( @@ -161,6 +168,7 @@ impl StoryWorkspace { dock_area, title_bar, last_layout_state: None, + toggle_button_visible: true, _save_layout_task: None, } } @@ -468,6 +476,19 @@ impl StoryWorkspace { }); cx.notify(); } + + fn on_action_toggle_dock_toggle_button( + &mut self, + _: &ToggleDockToggleButton, + _: &mut Window, + cx: &mut Context, + ) { + self.toggle_button_visible = !self.toggle_button_visible; + + self.dock_area.update(cx, |dock_area, _| { + dock_area.show_toggle_button(self.toggle_button_visible); + }); + } } pub fn open_new( @@ -494,6 +515,7 @@ impl Render for StoryWorkspace { .id("story-workspace") .on_action(cx.listener(Self::on_action_add_panel)) .on_action(cx.listener(Self::on_action_toggle_panel_visible)) + .on_action(cx.listener(Self::on_action_toggle_dock_toggle_button)) .relative() .size_full() .flex() diff --git a/crates/ui/src/dock/mod.rs b/crates/ui/src/dock/mod.rs index fe66eb6c..abf95e0a 100644 --- a/crates/ui/src/dock/mod.rs +++ b/crates/ui/src/dock/mod.rs @@ -51,6 +51,8 @@ pub struct DockArea { /// The entity_id of the [`TabPanel`](TabPanel) where each toggle button should be displayed, toggle_button_panels: Edges>, + /// Whether to show the toggle button. + toggle_button_visible: bool, /// The left dock of the dock_area. left_dock: Option>, /// The bottom dock of the dock_area. @@ -456,6 +458,7 @@ impl DockArea { items: dock_item, zoom_view: None, toggle_button_panels: Edges::default(), + toggle_button_visible: true, left_dock: None, right_dock: None, bottom_dock: None, @@ -680,6 +683,7 @@ impl DockArea { } } + /// Toggle the dock at the given placement. pub fn toggle_dock( &self, placement: DockPlacement, @@ -700,6 +704,11 @@ impl DockArea { } } + /// Show or hide the toggle button. + pub fn show_toggle_button(&mut self, visible: bool) { + self.toggle_button_visible = visible; + } + /// Add a panel item to the dock area at the given placement. pub fn add_panel( &mut self, diff --git a/crates/ui/src/dock/tab_panel.rs b/crates/ui/src/dock/tab_panel.rs index 7727cdf5..8b17c014 100644 --- a/crates/ui/src/dock/tab_panel.rs +++ b/crates/ui/src/dock/tab_panel.rs @@ -492,6 +492,9 @@ impl TabPanel { } let dock_area = self.dock_area.upgrade()?.read(cx); + if !dock_area.toggle_button_visible { + return None; + } if !dock_area.is_dock_collapsible(placement, cx) { return None; }