diff --git a/crates/ui/src/dock/mod.rs b/crates/ui/src/dock/mod.rs index c5a96d52..7860c2de 100644 --- a/crates/ui/src/dock/mod.rs +++ b/crates/ui/src/dock/mod.rs @@ -37,28 +37,31 @@ pub enum DockEvent { /// The main area of the dock. pub struct DockArea { id: SharedString, - /// The version is used to special the default layout, this is like the `panel_version` in `trait Panel`. + /// The version is used to special the default layout, this is like the `panel_version` in [`Panel`](Panel). version: Option, pub(crate) bounds: Bounds, /// The center view of the dockarea. items: DockItem, - /// The entity_id of the TabPanel where each toggle button should be displayed, + /// The entity_id of the [`TabPanel`](TabPanel) where each toggle button should be displayed, toggle_button_panels: Edges>, - /// The left dock of the dockarea. + /// The left dock of the dock_area. left_dock: Option>, - /// The bottom dock of the dockarea. + /// The bottom dock of the dock_area. bottom_dock: Option>, - /// The right dock of the dockarea. + /// The right dock of the dock_area. right_dock: Option>, - /// The top zoom view of the dockarea, if any. + /// The top zoom view of the dock_area, if any. zoom_view: Option, /// Lock panels layout, but allow to resize. is_locked: bool, + /// The panel style, default is [`PanelStyle::Default`](PanelStyle::Default). + pub(crate) panel_style: PanelStyle, + _subscriptions: Vec, } @@ -296,6 +299,7 @@ impl DockArea { right_dock: None, bottom_dock: None, is_locked: false, + panel_style: PanelStyle::Default, _subscriptions: vec![], }; @@ -304,6 +308,12 @@ impl DockArea { this } + /// Set the panel style of the dock area. + pub fn panel_style(mut self, style: PanelStyle) -> Self { + self.panel_style = style; + self + } + /// Set version of the dock area. pub fn set_version(&mut self, version: usize, cx: &mut ViewContext) { self.version = Some(version); diff --git a/crates/ui/src/dock/panel.rs b/crates/ui/src/dock/panel.rs index 17ece554..100c97b0 100644 --- a/crates/ui/src/dock/panel.rs +++ b/crates/ui/src/dock/panel.rs @@ -16,6 +16,15 @@ pub enum PanelEvent { LayoutChanged, } +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum PanelStyle { + /// Display the TabBar when there are multiple tabs, otherwise display the simple title. + Default, + /// Always display the tab bar. + TabBar, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct TitleStyle { pub background: Hsla, pub foreground: Hsla, diff --git a/crates/ui/src/dock/tab_panel.rs b/crates/ui/src/dock/tab_panel.rs index ecbbf545..8dddce53 100644 --- a/crates/ui/src/dock/tab_panel.rs +++ b/crates/ui/src/dock/tab_panel.rs @@ -20,8 +20,8 @@ use crate::{ }; use super::{ - ClosePanel, DockArea, DockItemState, DockPlacement, Panel, PanelEvent, PanelView, StackPanel, - ToggleZoom, + ClosePanel, DockArea, DockItemState, DockPlacement, Panel, PanelEvent, PanelStyle, PanelView, + StackPanel, ToggleZoom, }; #[derive(Clone, Copy)] @@ -455,11 +455,16 @@ impl TabPanel { fn render_title_bar(&self, state: TabState, cx: &mut ViewContext) -> impl IntoElement { let view = cx.view().clone(); + let Some(dock_area) = self.dock_area.upgrade() else { + return div().into_any_element(); + }; + let panel_style = dock_area.read(cx).panel_style; + let left_dock_button = self.render_dock_toggle_button(DockPlacement::Left, cx); let bottom_dock_button = self.render_dock_toggle_button(DockPlacement::Bottom, cx); let right_dock_button = self.render_dock_toggle_button(DockPlacement::Right, cx); - if self.panels.len() == 1 { + if self.panels.len() == 1 && panel_style == PanelStyle::Default { let panel = self.panels.get(0).unwrap(); let title_style = panel.title_style(cx);