dock: Hide panel toolbar when dock is collapsed. (#1105)

This commit is contained in:
Jason Lee 2025-07-30 15:38:14 +08:00 committed by GitHub
parent b8db00dd3c
commit e2153c9198
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 21 additions and 11 deletions

View file

@ -417,6 +417,10 @@ impl TabPanel {
window: &mut Window,
cx: &mut Context<Self>,
) -> 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| {

View file

@ -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
}

View file

@ -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()

View file

@ -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<Arc<dyn Fn(&usize, &mut Window, &mut App) + 'static>>,
/// 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<Pixels>) -> 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| {