diff --git a/crates/ui/src/dock/panel.rs b/crates/ui/src/dock/panel.rs index 27195544..5cad66e9 100644 --- a/crates/ui/src/dock/panel.rs +++ b/crates/ui/src/dock/panel.rs @@ -59,6 +59,13 @@ pub trait Panel: EventEmitter + Render + Focusable { /// Once you have defined a panel name, this must not be changed. fn panel_name(&self) -> &'static str; + /// The name of the tab of the panel, default is `None`. + /// + /// Used to display in the already collapsed tab panel. + fn tab_name(&self, cx: &App) -> Option { + None + } + /// The title of the panel fn title(&self, window: &Window, cx: &App) -> AnyElement { SharedString::from(t!("Dock.Unnamed")).into_any_element() @@ -137,6 +144,7 @@ pub trait Panel: EventEmitter + Render + Focusable { pub trait PanelView: 'static + Send + Sync { fn panel_name(&self, cx: &App) -> &'static str; fn panel_id(&self, cx: &App) -> EntityId; + fn tab_name(&self, cx: &App) -> Option; fn title(&self, window: &Window, cx: &App) -> AnyElement; fn title_suffix(&self, window: &mut Window, cx: &mut App) -> Option; fn title_style(&self, cx: &App) -> Option; @@ -162,6 +170,10 @@ impl PanelView for Entity { self.entity_id() } + fn tab_name(&self, cx: &App) -> Option { + self.read(cx).tab_name(cx) + } + fn title(&self, window: &Window, cx: &App) -> AnyElement { self.read(cx).title(window, cx) } diff --git a/crates/ui/src/dock/tab_panel.rs b/crates/ui/src/dock/tab_panel.rs index 8b17c014..231dfd88 100644 --- a/crates/ui/src/dock/tab_panel.rs +++ b/crates/ui/src/dock/tab_panel.rs @@ -691,7 +691,13 @@ impl TabPanel { Some( Tab::new("") - .child(panel.title(window, cx)) + .map(|this| { + if let Some(tab_name) = panel.tab_name(cx) { + this.child(tab_name) + } else { + this.child(panel.title(window, cx)) + } + }) .py_2() .selected(active) .disabled(disabled)