diff --git a/crates/app/src/story_workspace.rs b/crates/app/src/story_workspace.rs index da25213a..c8630f38 100644 --- a/crates/app/src/story_workspace.rs +++ b/crates/app/src/story_workspace.rs @@ -204,6 +204,15 @@ impl StoryWorkspace { dock_area.update(cx, |dock_area, cx| { dock_area.load(state, cx).context("load layout")?; + dock_area.set_dock_collapsible( + Edges { + left: true, + bottom: true, + right: true, + ..Default::default() + }, + cx, + ); Ok::<(), anyhow::Error>(()) }) diff --git a/crates/ui/src/dock/dock.rs b/crates/ui/src/dock/dock.rs index b7d2cb76..41bf3941 100644 --- a/crates/ui/src/dock/dock.rs +++ b/crates/ui/src/dock/dock.rs @@ -65,6 +65,11 @@ pub struct Dock { /// The size is means the width or height of the Dock, if the placement is left or right, the size is width, otherwise the size is height. pub(super) size: Pixels, pub(super) open: bool, + /// Whether the Dock is collapsible, default: true + pub(super) collapsible: bool, + + // Runtime state + /// Whether the Dock is resizing is_resizing: bool, } @@ -93,6 +98,7 @@ impl Dock { dock_area, panel, open: true, + collapsible: true, size: px(200.0), is_resizing: false, } @@ -110,6 +116,17 @@ impl Dock { Self::new(dock_area, DockPlacement::Right, cx) } + /// Update the Dock to be collapsible or not. + /// + /// And if the Dock is not collapsible, it will be open. + pub fn set_collapsible(&mut self, collapsible: bool, cx: &mut ViewContext) { + self.collapsible = collapsible; + if !collapsible { + self.open = true + } + cx.notify(); + } + pub(super) fn from_state( dock_area: WeakView, placement: DockPlacement, @@ -137,6 +154,7 @@ impl Dock { panel, open, size, + collapsible: true, is_resizing: false, } } diff --git a/crates/ui/src/dock/mod.rs b/crates/ui/src/dock/mod.rs index 7860c2de..ede75bbc 100644 --- a/crates/ui/src/dock/mod.rs +++ b/crates/ui/src/dock/mod.rs @@ -435,6 +435,55 @@ impl DockArea { } } + /// Set the dock at the given placement to be open or closed. + /// + /// Only the left, bottom, right dock can be toggled. + pub fn set_dock_collapsible( + &mut self, + collapsible_edges: Edges, + cx: &mut ViewContext, + ) { + if let Some(left_dock) = self.left_dock.as_ref() { + left_dock.update(cx, |dock, cx| { + dock.set_collapsible(collapsible_edges.left, cx); + }); + } + + if let Some(bottom_dock) = self.bottom_dock.as_ref() { + bottom_dock.update(cx, |dock, cx| { + dock.set_collapsible(collapsible_edges.bottom, cx); + }); + } + + if let Some(right_dock) = self.right_dock.as_ref() { + right_dock.update(cx, |dock, cx| { + dock.set_collapsible(collapsible_edges.right, cx); + }); + } + } + + /// Determine if the dock at the given placement is collapsible. + pub fn is_dock_collapsible(&self, placement: DockPlacement, cx: &AppContext) -> bool { + match placement { + DockPlacement::Left => self + .left_dock + .as_ref() + .map(|dock| dock.read(cx).collapsible) + .unwrap_or(false), + DockPlacement::Bottom => self + .bottom_dock + .as_ref() + .map(|dock| dock.read(cx).collapsible) + .unwrap_or(false), + DockPlacement::Right => self + .right_dock + .as_ref() + .map(|dock| dock.read(cx).collapsible) + .unwrap_or(false), + DockPlacement::Center => false, + } + } + pub fn toggle_dock(&self, placement: DockPlacement, cx: &mut ViewContext) { let dock = match placement { DockPlacement::Left => &self.left_dock, diff --git a/crates/ui/src/dock/panel.rs b/crates/ui/src/dock/panel.rs index 100c97b0..4fe93b92 100644 --- a/crates/ui/src/dock/panel.rs +++ b/crates/ui/src/dock/panel.rs @@ -57,11 +57,6 @@ pub trait Panel: EventEmitter + FocusableView { true } - /// Return true if the panel is collapsible, default is `false`. - fn collapsible(&self, _cx: &WindowContext) -> bool { - false - } - /// The addition popup menu of the panel, default is `None`. fn popup_menu(&self, this: PopupMenu, _cx: &WindowContext) -> PopupMenu { this @@ -84,7 +79,6 @@ pub trait PanelView: 'static + Send + Sync { fn title_style(&self, _cx: &WindowContext) -> Option; fn closeable(&self, cx: &WindowContext) -> bool; fn zoomable(&self, cx: &WindowContext) -> bool; - fn collapsible(&self, cx: &WindowContext) -> bool; fn popup_menu(&self, menu: PopupMenu, cx: &WindowContext) -> PopupMenu; fn toolbar_buttons(&self, cx: &WindowContext) -> Vec