diff --git a/crates/ui/src/dock/dock.rs b/crates/ui/src/dock/dock.rs index 6ff4eef6..2232ee78 100644 --- a/crates/ui/src/dock/dock.rs +++ b/crates/ui/src/dock/dock.rs @@ -111,6 +111,12 @@ impl Dock { ) -> Self { Self::subscribe_panel_events(dock_area.clone(), panel.clone(), cx); + if !open { + panel.update(cx, |panel, cx| { + panel.set_collapsed(true, cx); + }); + } + Self { placement, dock_area, @@ -149,8 +155,7 @@ impl Dock { } pub fn toggle_open(&mut self, cx: &mut ViewContext) { - self.open = !self.open; - cx.notify(); + self.set_open(!self.open, cx); } /// Returns the size of the Dock, the size is means the width or height of @@ -169,6 +174,11 @@ impl Dock { /// Set the open state of the Dock. pub fn set_open(&mut self, open: bool, cx: &mut ViewContext) { self.open = open; + cx.defer(move |this, cx| { + this.panel.update(cx, |panel, cx| { + panel.set_collapsed(!open, cx); + }); + }); cx.notify(); } diff --git a/crates/ui/src/dock/tab_panel.rs b/crates/ui/src/dock/tab_panel.rs index 349109da..60ae749b 100644 --- a/crates/ui/src/dock/tab_panel.rs +++ b/crates/ui/src/dock/tab_panel.rs @@ -63,12 +63,14 @@ pub struct TabPanel { stack_panel: Option>, pub(crate) panels: Vec>, pub(crate) active_ix: usize, - tab_bar_scroll_handle: ScrollHandle, - is_zoomed: bool, /// If this is true, the Panel closeable will follow the active panel's closeable, /// otherwise this TabPanel will not able to close pub(crate) closeable: bool, + tab_bar_scroll_handle: ScrollHandle, + is_zoomed: bool, + is_collapsed: bool, + /// When drag move, will get the placement of the panel to be split will_split_placement: Option, } @@ -139,6 +141,7 @@ impl TabPanel { tab_bar_scroll_handle: ScrollHandle::new(), will_split_placement: None, is_zoomed: false, + is_collapsed: false, closeable: true, } } @@ -261,6 +264,11 @@ impl TabPanel { self.stack_panel.is_some() } + pub(super) fn set_collapsed(&mut self, collapsed: bool, cx: &mut ViewContext) { + self.is_collapsed = collapsed; + cx.notify(); + } + fn render_menu_button(&self, cx: &mut ViewContext) -> impl IntoElement { let closeable = self.closeable(cx); let zoomable = self.zoomable(cx); @@ -542,7 +550,13 @@ impl TabPanel { }, ) .children(self.panels.iter().enumerate().map(|(ix, panel)| { - let active = ix == self.active_ix; + let mut active = ix == self.active_ix; + + // Always not show active tab style, if the panel is collapsed + if self.is_collapsed { + active = false; + } + Tab::new(("tab", ix), panel.title(cx)) .py_2() .selected(active)