pub struct SuggestionTextInput<'a, T, Message, Theme = Theme, Renderer = Renderer>{Show 14 fields
state: &'a State<T>,
text_input: TextInput<'a, TextInputEvent, Theme, Renderer>,
font: Option<Renderer::Font>,
selection: Value,
on_selected: Box<dyn Fn(T) -> Message>,
on_option_hovered: Option<Box<dyn Fn(T) -> Message>>,
on_open: Option<Message>,
on_close: Option<Message>,
on_input: Option<Box<dyn Fn(String) -> Message>>,
padding: Padding,
size: Option<f32>,
text_shaping: Shaping,
menu_class: <Theme as Catalog>::Class<'a>,
menu_height: Length,
}Expand description
A widget for searching and selecting a single value from a list of options.
§Example
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",
})
}
}Fields§
§state: &'a State<T>§text_input: TextInput<'a, TextInputEvent, Theme, Renderer>§font: Option<Renderer::Font>§selection: Value§on_selected: Box<dyn Fn(T) -> Message>§on_option_hovered: Option<Box<dyn Fn(T) -> Message>>§on_open: Option<Message>§on_close: Option<Message>§on_input: Option<Box<dyn Fn(String) -> Message>>§padding: Padding§size: Option<f32>§text_shaping: ShapingImplementations§
Source§impl<'a, T, Message, Theme, Renderer> SuggestionTextInput<'a, T, Message, Theme, Renderer>
impl<'a, T, Message, Theme, Renderer> SuggestionTextInput<'a, T, Message, Theme, Renderer>
Sourcepub fn new(
state: &'a State<T>,
placeholder: &str,
selection: Option<&T>,
on_selected: impl Fn(T) -> Message + 'static,
) -> Self
pub fn new( state: &'a State<T>, placeholder: &str, selection: Option<&T>, on_selected: impl Fn(T) -> Message + 'static, ) -> Self
Creates a new SuggestionTextInput with the given list of options, a placeholder,
the current selected value, and the message to produce when an option is
selected.
Sourcepub fn on_input(self, on_input: impl Fn(String) -> Message + 'static) -> Self
pub fn on_input(self, on_input: impl Fn(String) -> Message + 'static) -> Self
Sets the message that should be produced when some text is typed into
the TextInput of the SuggestionTextInput.
Sourcepub fn on_option_hovered(
self,
on_option_hovered: impl Fn(T) -> Message + 'static,
) -> Self
pub fn on_option_hovered( self, on_option_hovered: impl Fn(T) -> Message + 'static, ) -> Self
Sets the message that will be produced when an option of the
SuggestionTextInput is hovered using the arrow keys.
Sourcepub fn on_open(self, message: Message) -> Self
pub fn on_open(self, message: Message) -> Self
Sets the message that will be produced when the SuggestionTextInput is
opened.
Sourcepub fn on_close(self, message: Message) -> Self
pub fn on_close(self, message: Message) -> Self
Sets the message that will be produced when the outside area
of the SuggestionTextInput is pressed.
Sourcepub fn padding(self, padding: impl Into<Padding>) -> Self
pub fn padding(self, padding: impl Into<Padding>) -> Self
Sets the Padding of the SuggestionTextInput.
Sourcepub fn font(self, font: Renderer::Font) -> Self
pub fn font(self, font: Renderer::Font) -> Self
Sets the Renderer::Font of the SuggestionTextInput.
Sourcepub fn icon(self, icon: Icon<Renderer::Font>) -> Self
pub fn icon(self, icon: Icon<Renderer::Font>) -> Self
Sets the text_input::Icon of the SuggestionTextInput.
Sourcepub fn size(self, size: impl Into<Pixels>) -> Self
pub fn size(self, size: impl Into<Pixels>) -> Self
Sets the text size of the SuggestionTextInput.
Sourcepub fn line_height(self, line_height: impl Into<LineHeight>) -> Self
pub fn line_height(self, line_height: impl Into<LineHeight>) -> Self
Sets the LineHeight of the SuggestionTextInput.
Sourcepub fn width(self, width: impl Into<Length>) -> Self
pub fn width(self, width: impl Into<Length>) -> Self
Sets the width of the SuggestionTextInput.
Sets the height of the menu of the SuggestionTextInput.
Sourcepub fn text_shaping(self, shaping: Shaping) -> Self
pub fn text_shaping(self, shaping: Shaping) -> Self
Sets the text::Shaping strategy of the SuggestionTextInput.
Sourcepub fn input_style(self, style: impl Fn(&Theme, Status) -> Style + 'a) -> Self
pub fn input_style(self, style: impl Fn(&Theme, Status) -> Style + 'a) -> Self
Sets the style of the input of the SuggestionTextInput.
Sets the style of the menu of the SuggestionTextInput.
Sourcepub fn input_class(
self,
class: impl Into<<Theme as Catalog>::Class<'a>>,
) -> Self
pub fn input_class( self, class: impl Into<<Theme as Catalog>::Class<'a>>, ) -> Self
Sets the style class of the input of the SuggestionTextInput.
Sets the style class of the menu of the SuggestionTextInput.
Trait Implementations§
Source§impl<'a, T, Message, Theme, Renderer> From<SuggestionTextInput<'a, T, Message, Theme, Renderer>> for Element<'a, Message, Theme, Renderer>
impl<'a, T, Message, Theme, Renderer> From<SuggestionTextInput<'a, T, Message, Theme, Renderer>> for Element<'a, Message, Theme, Renderer>
Source§fn from(
suggestion_text_input: SuggestionTextInput<'a, T, Message, Theme, Renderer>,
) -> Self
fn from( suggestion_text_input: SuggestionTextInput<'a, T, Message, Theme, Renderer>, ) -> Self
Source§impl<T, Message, Theme, Renderer> Widget<Message, Theme, Renderer> for SuggestionTextInput<'_, T, Message, Theme, Renderer>
impl<T, Message, Theme, Renderer> Widget<Message, Theme, Renderer> for SuggestionTextInput<'_, T, Message, Theme, Renderer>
Source§fn draw(
&self,
tree: &Tree,
renderer: &mut Renderer,
theme: &Theme,
_style: &Style,
layout: Layout<'_>,
cursor: Cursor,
viewport: &Rectangle,
)
fn draw( &self, tree: &Tree, renderer: &mut Renderer, theme: &Theme, _style: &Style, layout: Layout<'_>, cursor: Cursor, viewport: &Rectangle, )
Widget using the associated Renderer.Source§fn update(
&mut self,
tree: &mut Tree,
event: &Event,
layout: Layout<'_>,
cursor: Cursor,
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
viewport: &Rectangle,
)
fn update( &mut self, tree: &mut Tree, event: &Event, layout: Layout<'_>, cursor: Cursor, renderer: &Renderer, clipboard: &mut dyn Clipboard, shell: &mut Shell<'_, Message>, viewport: &Rectangle, )
Source§fn mouse_interaction(
&self,
tree: &Tree,
layout: Layout<'_>,
cursor: Cursor,
viewport: &Rectangle,
renderer: &Renderer,
) -> Interaction
fn mouse_interaction( &self, tree: &Tree, layout: Layout<'_>, cursor: Cursor, viewport: &Rectangle, renderer: &Renderer, ) -> Interaction
Auto Trait Implementations§
impl<'a, T, Message, Theme, Renderer> Freeze for SuggestionTextInput<'a, T, Message, Theme, Renderer>
impl<'a, T, Message, Theme = Theme, Renderer = Renderer<Renderer, Renderer>> !RefUnwindSafe for SuggestionTextInput<'a, T, Message, Theme, Renderer>
impl<'a, T, Message, Theme = Theme, Renderer = Renderer<Renderer, Renderer>> !Send for SuggestionTextInput<'a, T, Message, Theme, Renderer>
impl<'a, T, Message, Theme = Theme, Renderer = Renderer<Renderer, Renderer>> !Sync for SuggestionTextInput<'a, T, Message, Theme, Renderer>
impl<'a, T, Message, Theme, Renderer> Unpin for SuggestionTextInput<'a, T, Message, Theme, Renderer>
impl<'a, T, Message, Theme, Renderer> UnsafeUnpin for SuggestionTextInput<'a, T, Message, Theme, Renderer>where
<Theme as Catalog>::Class<'a>: UnsafeUnpin,
<Theme as Catalog>::Class<'a>: UnsafeUnpin,
<Renderer as Renderer>::Font: UnsafeUnpin,
Message: UnsafeUnpin,
impl<'a, T, Message, Theme = Theme, Renderer = Renderer<Renderer, Renderer>> !UnwindSafe for SuggestionTextInput<'a, T, Message, Theme, Renderer>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<State, Message> IntoBoot<State, Message> for State
impl<State, Message> IntoBoot<State, Message> for State
Source§fn into_boot(self) -> (State, Task<Message>)
fn into_boot(self) -> (State, Task<Message>)
Application.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more