dock: Improve Panel trait changed title to return impl IntoElement. (#1719)

This commit is contained in:
Jason Lee 2025-12-01 18:13:23 +08:00 committed by GitHub
parent d92e3a3222
commit 43e1029b9f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 21 additions and 13 deletions

View file

@ -94,11 +94,11 @@ impl Panel for ContainerPanel {
"ContainerPanel" "ContainerPanel"
} }
fn title(&mut self, window: &mut Window, cx: &mut Context<Self>) -> AnyElement { fn title(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
self.panel.title(window, cx) self.panel.title(window, cx)
} }
fn title_suffix(&mut self, _: &mut Window, cx: &mut Context<Self>) -> Option<AnyElement> { fn title_suffix(&mut self, _: &mut Window, cx: &mut Context<Self>) -> Option<impl IntoElement> {
Some( Some(
div() div()
.w_24() .w_24()

View file

@ -692,7 +692,7 @@ impl Panel for StoryContainer {
"StoryContainer" "StoryContainer"
} }
fn title(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> AnyElement { fn title(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
self.name.clone().into_any_element() self.name.clone().into_any_element()
} }

View file

@ -66,8 +66,8 @@ pub trait Panel: EventEmitter<PanelEvent> + Render + Focusable {
} }
/// The title of the panel /// The title of the panel
fn title(&mut self, window: &mut Window, cx: &mut Context<Self>) -> AnyElement { fn title(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
SharedString::from(t!("Dock.Unnamed")).into_any_element() SharedString::from(t!("Dock.Unnamed"))
} }
/// The theme of the panel title, default is `None`. /// The theme of the panel title, default is `None`.
@ -78,8 +78,12 @@ pub trait Panel: EventEmitter<PanelEvent> + Render + Focusable {
/// The suffix of the panel title, default is `None`. /// The suffix of the panel title, default is `None`.
/// ///
/// This is used to add a suffix element to the panel title. /// This is used to add a suffix element to the panel title.
fn title_suffix(&mut self, window: &mut Window, cx: &mut Context<Self>) -> Option<AnyElement> { fn title_suffix(
None &mut self,
window: &mut Window,
cx: &mut Context<Self>,
) -> Option<impl IntoElement> {
None::<gpui::Div>
} }
/// Whether the panel can be closed, default is `true`. /// Whether the panel can be closed, default is `true`.
@ -197,11 +201,14 @@ impl<T: Panel> PanelView for Entity<T> {
} }
fn title(&self, window: &mut Window, cx: &mut App) -> AnyElement { fn title(&self, window: &mut Window, cx: &mut App) -> AnyElement {
self.update(cx, |this, cx| this.title(window, cx)) self.update(cx, |this, cx| this.title(window, cx).into_any_element())
} }
fn title_suffix(&self, window: &mut Window, cx: &mut App) -> Option<AnyElement> { fn title_suffix(&self, window: &mut Window, cx: &mut App) -> Option<AnyElement> {
self.update(cx, |this, cx| this.title_suffix(window, cx)) self.update(cx, |this, cx| {
this.title_suffix(window, cx)
.map(|el| el.into_any_element())
})
} }
fn title_style(&self, cx: &App) -> Option<TitleStyle> { fn title_style(&self, cx: &App) -> Option<TitleStyle> {

View file

@ -32,9 +32,10 @@ impl Panel for StackPanel {
"StackPanel" "StackPanel"
} }
fn title(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> gpui::AnyElement { fn title(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
"StackPanel".into_any_element() "StackPanel"
} }
fn set_active(&mut self, active: bool, window: &mut Window, cx: &mut Context<Self>) { fn set_active(&mut self, active: bool, window: &mut Window, cx: &mut Context<Self>) {
for panel in &self.panels { for panel in &self.panels {
panel.set_active(active, window, cx); panel.set_active(active, window, cx);

View file

@ -91,7 +91,7 @@ impl Panel for TabPanel {
"TabPanel" "TabPanel"
} }
fn title(&mut self, window: &mut Window, cx: &mut Context<Self>) -> gpui::AnyElement { fn title(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
self.active_panel(cx) self.active_panel(cx)
.map(|panel| panel.title(window, cx)) .map(|panel| panel.title(window, cx))
.unwrap_or("Empty Tab".into_any_element()) .unwrap_or("Empty Tab".into_any_element())

View file

@ -148,7 +148,7 @@ impl Panel for Tiles {
"Tiles" "Tiles"
} }
fn title(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> AnyElement { fn title(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
"Tiles".into_any_element() "Tiles".into_any_element()
} }