dock: Improve Panel trait changed title to return impl IntoElement. (#1719)
This commit is contained in:
parent
d92e3a3222
commit
43e1029b9f
6 changed files with 21 additions and 13 deletions
|
|
@ -94,11 +94,11 @@ impl Panel for 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)
|
||||
}
|
||||
|
||||
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(
|
||||
div()
|
||||
.w_24()
|
||||
|
|
|
|||
|
|
@ -692,7 +692,7 @@ impl Panel for 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()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,8 +66,8 @@ pub trait Panel: EventEmitter<PanelEvent> + Render + Focusable {
|
|||
}
|
||||
|
||||
/// The title of the panel
|
||||
fn title(&mut self, window: &mut Window, cx: &mut Context<Self>) -> AnyElement {
|
||||
SharedString::from(t!("Dock.Unnamed")).into_any_element()
|
||||
fn title(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
SharedString::from(t!("Dock.Unnamed"))
|
||||
}
|
||||
|
||||
/// 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`.
|
||||
///
|
||||
/// 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> {
|
||||
None
|
||||
fn title_suffix(
|
||||
&mut self,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Option<impl IntoElement> {
|
||||
None::<gpui::Div>
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
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> {
|
||||
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> {
|
||||
|
|
|
|||
|
|
@ -32,9 +32,10 @@ impl Panel for StackPanel {
|
|||
"StackPanel"
|
||||
}
|
||||
|
||||
fn title(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> gpui::AnyElement {
|
||||
"StackPanel".into_any_element()
|
||||
fn title(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
"StackPanel"
|
||||
}
|
||||
|
||||
fn set_active(&mut self, active: bool, window: &mut Window, cx: &mut Context<Self>) {
|
||||
for panel in &self.panels {
|
||||
panel.set_active(active, window, cx);
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ impl Panel for 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)
|
||||
.map(|panel| panel.title(window, cx))
|
||||
.unwrap_or("Empty Tab".into_any_element())
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ impl Panel for 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()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue