Improve dropdown render_empty builder result from AnyElement to impl IntoElement for better usage

This commit is contained in:
Floyd Wang 2024-07-26 17:26:58 +08:00
parent 55822144c4
commit 11034ec2ac
2 changed files with 6 additions and 6 deletions

View file

@ -116,7 +116,6 @@ impl DropdownStory {
.justify_center() .justify_center()
.text_color(cx.theme().muted_foreground) .text_color(cx.theme().muted_foreground)
.child("No Data") .child("No Data")
.into_any_element()
}) })
}), }),
} }

View file

@ -1,4 +1,4 @@
use std::{borrow::Cow, rc::Rc}; use std::borrow::Cow;
use gpui::{ use gpui::{
actions, deferred, div, prelude::FluentBuilder, px, rems, AnyElement, AppContext, ClickEvent, actions, deferred, div, prelude::FluentBuilder, px, rems, AnyElement, AppContext, ClickEvent,
@ -184,7 +184,7 @@ pub struct Dropdown<D: DropdownDelegate + 'static> {
placeholder: SharedString, placeholder: SharedString,
title_prefix: Option<SharedString>, title_prefix: Option<SharedString>,
selected_value: Option<<D::Item as DropdownItem>::Value>, selected_value: Option<<D::Item as DropdownItem>::Value>,
render_empty: Option<Rc<dyn Fn(&WindowContext) -> AnyElement + 'static>>, render_empty: Option<Box<dyn Fn(&WindowContext) -> AnyElement + 'static>>,
} }
impl<D> Dropdown<D> impl<D> Dropdown<D>
@ -247,11 +247,12 @@ where
self self
} }
pub fn render_empty<F>(mut self, f: F) -> Self pub fn render_empty<E, F>(mut self, f: F) -> Self
where where
F: Fn(&WindowContext) -> AnyElement + 'static, E: IntoElement,
F: Fn(&WindowContext) -> E + 'static,
{ {
self.render_empty = Some(Rc::new(f)); self.render_empty = Some(Box::new(move |cx| f(cx).into_any_element()));
self self
} }