dock: Add tab_name for collapsed tab panels (#751)

This commit is contained in:
Floyd Wang 2025-03-28 11:44:34 +08:00 committed by GitHub
parent 9f103bac6f
commit 417e097b1a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View file

@ -59,6 +59,13 @@ pub trait Panel: EventEmitter<PanelEvent> + 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<SharedString> {
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<PanelEvent> + 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<SharedString>;
fn title(&self, window: &Window, cx: &App) -> AnyElement;
fn title_suffix(&self, window: &mut Window, cx: &mut App) -> Option<AnyElement>;
fn title_style(&self, cx: &App) -> Option<TitleStyle>;
@ -162,6 +170,10 @@ impl<T: Panel> PanelView for Entity<T> {
self.entity_id()
}
fn tab_name(&self, cx: &App) -> Option<SharedString> {
self.read(cx).tab_name(cx)
}
fn title(&self, window: &Window, cx: &App) -> AnyElement {
self.read(cx).title(window, cx)
}

View file

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