Skip to content

Commit

Permalink
Improve dropdown render_empty builder result from AnyElement to `…
Browse files Browse the repository at this point in the history
…impl IntoElement` for better usage
  • Loading branch information
madcodelife committed Jul 26, 2024
1 parent 5582214 commit 11034ec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
1 change: 0 additions & 1 deletion crates/story/src/dropdown_story.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ impl DropdownStory {
.justify_center()
.text_color(cx.theme().muted_foreground)
.child("No Data")
.into_any_element()
})
}),
}
Expand Down
11 changes: 6 additions & 5 deletions crates/ui/src/dropdown.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{borrow::Cow, rc::Rc};
use std::borrow::Cow;

use gpui::{
actions, deferred, div, prelude::FluentBuilder, px, rems, AnyElement, AppContext, ClickEvent,
Expand Down Expand Up @@ -184,7 +184,7 @@ pub struct Dropdown<D: DropdownDelegate + 'static> {
placeholder: SharedString,
title_prefix: Option<SharedString>,
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>
Expand Down Expand Up @@ -247,11 +247,12 @@ where
self
}

pub fn render_empty<F>(mut self, f: F) -> Self
pub fn render_empty<E, F>(mut self, f: F) -> Self
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
}

Expand Down

0 comments on commit 11034ec

Please sign in to comment.