summaryrefslogtreecommitdiffstats
path: root/widget/src/helpers.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-09-19 03:18:08 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-09-19 03:18:08 +0200
commit3e6e669c4c111b2ac65c7aff1d03c1a1f5ba645f (patch)
treecab4172171919a2383237d1775774377febcedd8 /widget/src/helpers.rs
parent51f7ce73248bea2bb7cc2b662433e46fa0c44dcb (diff)
downloadiced-3e6e669c4c111b2ac65c7aff1d03c1a1f5ba645f.tar.gz
iced-3e6e669c4c111b2ac65c7aff1d03c1a1f5ba645f.tar.bz2
iced-3e6e669c4c111b2ac65c7aff1d03c1a1f5ba645f.zip
Show `combo_box` doc example in multiple places
Diffstat (limited to 'widget/src/helpers.rs')
-rw-r--r--widget/src/helpers.rs57
1 files changed, 56 insertions, 1 deletions
diff --git a/widget/src/helpers.rs b/widget/src/helpers.rs
index 1ed0bde2..d839bc3a 100644
--- a/widget/src/helpers.rs
+++ b/widget/src/helpers.rs
@@ -902,7 +902,62 @@ where
/// Creates a new [`ComboBox`].
///
-/// [`ComboBox`]: crate::ComboBox
+/// Combo boxes display a dropdown list of searchable and selectable options.
+///
+/// # Example
+/// ```no_run
+/// # mod iced { pub mod widget { pub use iced_widget::*; } pub use iced_widget::Renderer; pub use iced_widget::core::*; }
+/// # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>;
+/// #
+/// use iced::widget::combo_box;
+///
+/// struct State {
+/// fruits: combo_box::State<Fruit>,
+/// favorite: Option<Fruit>,
+/// }
+///
+/// #[derive(Debug, Clone)]
+/// enum Fruit {
+/// Apple,
+/// Orange,
+/// Strawberry,
+/// Tomato,
+/// }
+///
+/// #[derive(Debug, Clone)]
+/// enum Message {
+/// FruitSelected(Fruit),
+/// }
+///
+/// fn view(state: &State) -> Element<'_, Message> {
+/// combo_box(
+/// &state.fruits,
+/// "Select your favorite fruit...",
+/// state.favorite.as_ref(),
+/// Message::FruitSelected
+/// )
+/// .into()
+/// }
+///
+/// fn update(state: &mut State, message: Message) {
+/// match message {
+/// Message::FruitSelected(fruit) => {
+/// state.favorite = Some(fruit);
+/// }
+/// }
+/// }
+///
+/// impl std::fmt::Display for Fruit {
+/// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+/// f.write_str(match self {
+/// Self::Apple => "Apple",
+/// Self::Orange => "Orange",
+/// Self::Strawberry => "Strawberry",
+/// Self::Tomato => "Tomato",
+/// })
+/// }
+/// }
+/// ```
pub fn combo_box<'a, T, Message, Theme, Renderer>(
state: &'a combo_box::State<T>,
placeholder: &str,