dropdown: Support change options for the dropdown (#824)

This commit is contained in:
Floyd Wang 2025-04-30 10:33:21 +08:00 committed by GitHub
parent dd3b8b1f3d
commit a5e5fc52b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 7 deletions

View file

@ -138,21 +138,24 @@ impl DropdownStory {
.title_prefix("UI: ") .title_prefix("UI: ")
}), }),
simple_dropdown2: cx.new(|cx| { simple_dropdown2: cx.new(|cx| {
Dropdown::new( let mut dropdown =
"string-list2", Dropdown::new("string-list2", SearchableVec::new(vec![]), None, window, cx)
.small()
.placeholder("Language")
.title_prefix("Language: ");
dropdown.set_items(
SearchableVec::new(vec![ SearchableVec::new(vec![
"Rust".into(), "Rust".into(),
"Go".into(), "Go".into(),
"C++".into(), "C++".into(),
"JavaScript".into(), "JavaScript".into(),
]), ]),
None,
window, window,
cx, cx,
) );
.small()
.placeholder("Language") dropdown
.title_prefix("Language: ")
}), }),
simple_dropdown3: cx.new(|cx| { simple_dropdown3: cx.new(|cx| {
Dropdown::new("string-list3", Vec::<SharedString>::new(), None, window, cx) Dropdown::new("string-list3", Vec::<SharedString>::new(), None, window, cx)

View file

@ -600,6 +600,16 @@ where
}) })
.child(title) .child(title)
} }
/// Set the items for the dropdown.
pub fn set_items(&mut self, items: D, _: &mut Window, cx: &mut Context<Self>)
where
D: DropdownDelegate + 'static,
{
self.list.update(cx, |list, _| {
list.delegate_mut().delegate = items;
});
}
} }
impl<D> Sizable for Dropdown<D> impl<D> Sizable for Dropdown<D>