From e2153c919811cdc73c5e34c73e74e4bbbe800f34 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Wed, 30 Jul 2025 15:38:14 +0800 Subject: [PATCH] dock: Hide panel toolbar when dock is collapsed. (#1105) --- crates/ui/src/dock/tab_panel.rs | 10 ++++++---- crates/ui/src/form.rs | 4 ++-- crates/ui/src/tab/tab.rs | 1 - crates/ui/src/tab/tab_bar.rs | 17 +++++++++++++---- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/crates/ui/src/dock/tab_panel.rs b/crates/ui/src/dock/tab_panel.rs index 488996c7..7104ec85 100644 --- a/crates/ui/src/dock/tab_panel.rs +++ b/crates/ui/src/dock/tab_panel.rs @@ -417,6 +417,10 @@ impl TabPanel { window: &mut Window, cx: &mut Context, ) -> impl IntoElement { + if self.collapsed { + return div(); + } + let zoomed = self.zoomed; let view = cx.entity().clone(); let zoomable_toolbar_visible = state.zoomable.map_or(false, |v| v.toolbar_visible()); @@ -424,7 +428,6 @@ impl TabPanel { h_flex() .gap_1() .occlude() - .items_center() .when_some(self.toolbar_buttons(window, cx), |this, buttons| { this.children(buttons.into_iter().map(|btn| btn.xsmall().ghost())) }) @@ -600,7 +603,6 @@ impl TabPanel { return h_flex() .justify_between() - .items_center() .line_height(rems(1.0)) .h(px(30.)) .py_2() @@ -660,8 +662,8 @@ impl TabPanel { let tabs_count = self.panels.len(); TabBar::new("tab-bar") - .mt(-px(1.)) - .track_scroll(self.tab_bar_scroll_handle.clone()) + .tab_item_top_offset(-px(1.)) + .track_scroll(&self.tab_bar_scroll_handle) .when( left_dock_button.is_some() || bottom_dock_button.is_some(), |this| { diff --git a/crates/ui/src/form.rs b/crates/ui/src/form.rs index a1184fd1..3d733d30 100644 --- a/crates/ui/src/form.rs +++ b/crates/ui/src/form.rs @@ -266,8 +266,8 @@ impl FormField { /// Set the focus handle for the form field. /// /// If not set, the form field will not be focusable. - pub fn track_focus(mut self, focus_handle: FocusHandle) -> Self { - self.focus_handle = Some(focus_handle); + pub fn track_focus(mut self, focus_handle: &FocusHandle) -> Self { + self.focus_handle = Some(focus_handle.clone()); self } diff --git a/crates/ui/src/tab/tab.rs b/crates/ui/src/tab/tab.rs index abe82e3b..5d9eb2c8 100644 --- a/crates/ui/src/tab/tab.rs +++ b/crates/ui/src/tab/tab.rs @@ -153,7 +153,6 @@ impl TabVariant { fg: cx.theme().tab_foreground, bg: cx.theme().transparent, borders: Edges { - top: px(1.), left: px(1.), right: px(1.), ..Default::default() diff --git a/crates/ui/src/tab/tab_bar.rs b/crates/ui/src/tab/tab_bar.rs index 373dcef5..bb2c4755 100644 --- a/crates/ui/src/tab/tab_bar.rs +++ b/crates/ui/src/tab/tab_bar.rs @@ -6,8 +6,8 @@ use crate::{h_flex, ActiveTheme, IconName, Selectable, Sizable, Size, StyledExt} use gpui::prelude::FluentBuilder as _; use gpui::{ div, Action, AnyElement, App, Corner, Div, Edges, ElementId, IntoElement, ParentElement, - RenderOnce, ScrollHandle, Stateful, StatefulInteractiveElement as _, StyleRefinement, Styled, - Window, + Pixels, RenderOnce, ScrollHandle, Stateful, StatefulInteractiveElement as _, StyleRefinement, + Styled, Window, }; use gpui::{px, InteractiveElement}; use smallvec::SmallVec; @@ -31,6 +31,8 @@ pub struct TabBar { size: Size, menu: bool, on_click: Option>, + /// Special for internal TabPanel to remove the top border. + tab_item_top_offset: Pixels, } impl TabBar { @@ -48,6 +50,7 @@ impl TabBar { selected_index: None, on_click: None, menu: false, + tab_item_top_offset: px(0.), } } @@ -88,8 +91,8 @@ impl TabBar { } /// Track the scroll of the TabBar - pub fn track_scroll(mut self, scroll_handle: ScrollHandle) -> Self { - self.scroll_handle = Some(scroll_handle); + pub fn track_scroll(mut self, scroll_handle: &ScrollHandle) -> Self { + self.scroll_handle = Some(scroll_handle.clone()); self } @@ -137,6 +140,11 @@ impl TabBar { self.on_click = Some(Arc::new(on_click)); self } + + pub(crate) fn tab_item_top_offset(mut self, offset: impl Into) -> Self { + self.tab_item_top_offset = offset.into(); + self + } } impl Styled for TabBar { @@ -257,6 +265,7 @@ impl RenderOnce for TabBar { item_labels.push((child.label.clone(), child.disabled)); child .id(ix) + .mt(self.tab_item_top_offset) .with_variant(self.variant) .with_size(self.size) .when_some(self.selected_index, |this, selected_ix| {