dock: Hide panel toolbar when dock is collapsed. (#1105)
This commit is contained in:
parent
b8db00dd3c
commit
e2153c9198
4 changed files with 21 additions and 11 deletions
|
|
@ -417,6 +417,10 @@ impl TabPanel {
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) -> impl IntoElement {
|
) -> impl IntoElement {
|
||||||
|
if self.collapsed {
|
||||||
|
return div();
|
||||||
|
}
|
||||||
|
|
||||||
let zoomed = self.zoomed;
|
let zoomed = self.zoomed;
|
||||||
let view = cx.entity().clone();
|
let view = cx.entity().clone();
|
||||||
let zoomable_toolbar_visible = state.zoomable.map_or(false, |v| v.toolbar_visible());
|
let zoomable_toolbar_visible = state.zoomable.map_or(false, |v| v.toolbar_visible());
|
||||||
|
|
@ -424,7 +428,6 @@ impl TabPanel {
|
||||||
h_flex()
|
h_flex()
|
||||||
.gap_1()
|
.gap_1()
|
||||||
.occlude()
|
.occlude()
|
||||||
.items_center()
|
|
||||||
.when_some(self.toolbar_buttons(window, cx), |this, buttons| {
|
.when_some(self.toolbar_buttons(window, cx), |this, buttons| {
|
||||||
this.children(buttons.into_iter().map(|btn| btn.xsmall().ghost()))
|
this.children(buttons.into_iter().map(|btn| btn.xsmall().ghost()))
|
||||||
})
|
})
|
||||||
|
|
@ -600,7 +603,6 @@ impl TabPanel {
|
||||||
|
|
||||||
return h_flex()
|
return h_flex()
|
||||||
.justify_between()
|
.justify_between()
|
||||||
.items_center()
|
|
||||||
.line_height(rems(1.0))
|
.line_height(rems(1.0))
|
||||||
.h(px(30.))
|
.h(px(30.))
|
||||||
.py_2()
|
.py_2()
|
||||||
|
|
@ -660,8 +662,8 @@ impl TabPanel {
|
||||||
let tabs_count = self.panels.len();
|
let tabs_count = self.panels.len();
|
||||||
|
|
||||||
TabBar::new("tab-bar")
|
TabBar::new("tab-bar")
|
||||||
.mt(-px(1.))
|
.tab_item_top_offset(-px(1.))
|
||||||
.track_scroll(self.tab_bar_scroll_handle.clone())
|
.track_scroll(&self.tab_bar_scroll_handle)
|
||||||
.when(
|
.when(
|
||||||
left_dock_button.is_some() || bottom_dock_button.is_some(),
|
left_dock_button.is_some() || bottom_dock_button.is_some(),
|
||||||
|this| {
|
|this| {
|
||||||
|
|
|
||||||
|
|
@ -266,8 +266,8 @@ impl FormField {
|
||||||
/// Set the focus handle for the form field.
|
/// Set the focus handle for the form field.
|
||||||
///
|
///
|
||||||
/// If not set, the form field will not be focusable.
|
/// If not set, the form field will not be focusable.
|
||||||
pub fn track_focus(mut self, focus_handle: FocusHandle) -> Self {
|
pub fn track_focus(mut self, focus_handle: &FocusHandle) -> Self {
|
||||||
self.focus_handle = Some(focus_handle);
|
self.focus_handle = Some(focus_handle.clone());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,6 @@ impl TabVariant {
|
||||||
fg: cx.theme().tab_foreground,
|
fg: cx.theme().tab_foreground,
|
||||||
bg: cx.theme().transparent,
|
bg: cx.theme().transparent,
|
||||||
borders: Edges {
|
borders: Edges {
|
||||||
top: px(1.),
|
|
||||||
left: px(1.),
|
left: px(1.),
|
||||||
right: px(1.),
|
right: px(1.),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ use crate::{h_flex, ActiveTheme, IconName, Selectable, Sizable, Size, StyledExt}
|
||||||
use gpui::prelude::FluentBuilder as _;
|
use gpui::prelude::FluentBuilder as _;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, Action, AnyElement, App, Corner, Div, Edges, ElementId, IntoElement, ParentElement,
|
div, Action, AnyElement, App, Corner, Div, Edges, ElementId, IntoElement, ParentElement,
|
||||||
RenderOnce, ScrollHandle, Stateful, StatefulInteractiveElement as _, StyleRefinement, Styled,
|
Pixels, RenderOnce, ScrollHandle, Stateful, StatefulInteractiveElement as _, StyleRefinement,
|
||||||
Window,
|
Styled, Window,
|
||||||
};
|
};
|
||||||
use gpui::{px, InteractiveElement};
|
use gpui::{px, InteractiveElement};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
|
@ -31,6 +31,8 @@ pub struct TabBar {
|
||||||
size: Size,
|
size: Size,
|
||||||
menu: bool,
|
menu: bool,
|
||||||
on_click: Option<Arc<dyn Fn(&usize, &mut Window, &mut App) + 'static>>,
|
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 {
|
impl TabBar {
|
||||||
|
|
@ -48,6 +50,7 @@ impl TabBar {
|
||||||
selected_index: None,
|
selected_index: None,
|
||||||
on_click: None,
|
on_click: None,
|
||||||
menu: false,
|
menu: false,
|
||||||
|
tab_item_top_offset: px(0.),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,8 +91,8 @@ impl TabBar {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Track the scroll of the TabBar
|
/// Track the scroll of the TabBar
|
||||||
pub fn track_scroll(mut self, scroll_handle: ScrollHandle) -> Self {
|
pub fn track_scroll(mut self, scroll_handle: &ScrollHandle) -> Self {
|
||||||
self.scroll_handle = Some(scroll_handle);
|
self.scroll_handle = Some(scroll_handle.clone());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -137,6 +140,11 @@ impl TabBar {
|
||||||
self.on_click = Some(Arc::new(on_click));
|
self.on_click = Some(Arc::new(on_click));
|
||||||
self
|
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 {
|
impl Styled for TabBar {
|
||||||
|
|
@ -257,6 +265,7 @@ impl RenderOnce for TabBar {
|
||||||
item_labels.push((child.label.clone(), child.disabled));
|
item_labels.push((child.label.clone(), child.disabled));
|
||||||
child
|
child
|
||||||
.id(ix)
|
.id(ix)
|
||||||
|
.mt(self.tab_item_top_offset)
|
||||||
.with_variant(self.variant)
|
.with_variant(self.variant)
|
||||||
.with_size(self.size)
|
.with_size(self.size)
|
||||||
.when_some(self.selected_index, |this, selected_ix| {
|
.when_some(self.selected_index, |this, selected_ix| {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue