dock: Add tab_name for collapsed tab panels (#751)
This commit is contained in:
parent
9f103bac6f
commit
417e097b1a
2 changed files with 19 additions and 1 deletions
|
|
@ -59,6 +59,13 @@ pub trait Panel: EventEmitter<PanelEvent> + Render + Focusable {
|
||||||
/// Once you have defined a panel name, this must not be changed.
|
/// Once you have defined a panel name, this must not be changed.
|
||||||
fn panel_name(&self) -> &'static str;
|
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
|
/// The title of the panel
|
||||||
fn title(&self, window: &Window, cx: &App) -> AnyElement {
|
fn title(&self, window: &Window, cx: &App) -> AnyElement {
|
||||||
SharedString::from(t!("Dock.Unnamed")).into_any_element()
|
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 {
|
pub trait PanelView: 'static + Send + Sync {
|
||||||
fn panel_name(&self, cx: &App) -> &'static str;
|
fn panel_name(&self, cx: &App) -> &'static str;
|
||||||
fn panel_id(&self, cx: &App) -> EntityId;
|
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(&self, window: &Window, cx: &App) -> AnyElement;
|
||||||
fn title_suffix(&self, window: &mut Window, cx: &mut App) -> Option<AnyElement>;
|
fn title_suffix(&self, window: &mut Window, cx: &mut App) -> Option<AnyElement>;
|
||||||
fn title_style(&self, cx: &App) -> Option<TitleStyle>;
|
fn title_style(&self, cx: &App) -> Option<TitleStyle>;
|
||||||
|
|
@ -162,6 +170,10 @@ impl<T: Panel> PanelView for Entity<T> {
|
||||||
self.entity_id()
|
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 {
|
fn title(&self, window: &Window, cx: &App) -> AnyElement {
|
||||||
self.read(cx).title(window, cx)
|
self.read(cx).title(window, cx)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -691,7 +691,13 @@ impl TabPanel {
|
||||||
|
|
||||||
Some(
|
Some(
|
||||||
Tab::new("")
|
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()
|
.py_2()
|
||||||
.selected(active)
|
.selected(active)
|
||||||
.disabled(disabled)
|
.disabled(disabled)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue