Struct kas_widgets::ComboBox
source · pub struct ComboBox<A, V: Clone + Debug + Eq + 'static> { /* private fields */ }
Expand description
A pop-up multiple choice menu
Messages
A combobox presents a menu with a fixed set of choices when clicked.
Each choice has an associated value of type V
.
If no selection handler exists, then the choice’s message is emitted
when selected. If a handler is specified via Self::with
or
Self::with_msg
then this message is passed to the handler and not emitted.
Implementations§
source§impl<A, V: Clone + Debug + Eq + 'static> ComboBox<A, V>
impl<A, V: Clone + Debug + Eq + 'static> ComboBox<A, V>
sourcepub fn new<T, I>(
iter: I,
state_fn: impl Fn(&ConfigCx<'_>, &A) -> V + 'static
) -> Self
pub fn new<T, I>( iter: I, state_fn: impl Fn(&ConfigCx<'_>, &A) -> V + 'static ) -> Self
Construct a combobox
Constructs a combobox with labels derived from an iterator over string types. For example:
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum Select { A, B, C }
let combobox = ComboBox::new(
[("A", Select::A), ("B", Select::B), ("C", Select::C)],
|_, selection| *selection,
);
The closure state_fn
selects the active entry from input data.
sourcepub fn new_vec(
entries: Vec<MenuEntry<V>>,
state_fn: impl Fn(&ConfigCx<'_>, &A) -> V + 'static
) -> Self
pub fn new_vec( entries: Vec<MenuEntry<V>>, state_fn: impl Fn(&ConfigCx<'_>, &A) -> V + 'static ) -> Self
Construct a combobox with the given menu entries
A combobox presents a menu with a fixed set of choices when clicked.
The closure state_fn
selects the active entry from input data.
sourcepub fn with_msg<M: Debug + 'static>(self, f: impl Fn(V) -> M + 'static) -> Self
pub fn with_msg<M: Debug + 'static>(self, f: impl Fn(V) -> M + 'static) -> Self
Send the message generated by f
on selection
sourcepub fn with<F>(self, f: F) -> ComboBox<A, V>
pub fn with<F>(self, f: F) -> ComboBox<A, V>
Call the handler f
on selection
On selection of a new choice the closure f
is called with the choice’s
message.
source§impl<A, V: Clone + Debug + Eq + 'static> ComboBox<A, V>
impl<A, V: Clone + Debug + Eq + 'static> ComboBox<A, V>
sourcepub fn active(&self) -> usize
pub fn active(&self) -> usize
Get the index of the active choice
This index is normally less than the number of choices (self.len()
),
but may not be if set programmatically or there are no choices.
sourcepub fn with_active(self, index: usize) -> Self
pub fn with_active(self, index: usize) -> Self
Set the active choice (inline style)
sourcepub fn set_active(&mut self, index: usize) -> Action
pub fn set_active(&mut self, index: usize) -> Action
Set the active choice
sourcepub fn push<T: Into<AccessString>>(
&mut self,
cx: &mut ConfigCx<'_>,
label: T,
msg: V
) -> usize
pub fn push<T: Into<AccessString>>( &mut self, cx: &mut ConfigCx<'_>, label: T, msg: V ) -> usize
Add a choice to the combobox, in last position
Returns the index of the new choice
sourcepub fn pop(&mut self, cx: &mut EventState) -> Option<()>
pub fn pop(&mut self, cx: &mut EventState) -> Option<()>
Pops the last choice from the combobox
sourcepub fn insert<T: Into<AccessString>>(
&mut self,
cx: &mut ConfigCx<'_>,
index: usize,
label: T,
msg: V
)
pub fn insert<T: Into<AccessString>>( &mut self, cx: &mut ConfigCx<'_>, index: usize, label: T, msg: V )
Add a choice at position index
Panics if index > len
.
sourcepub fn remove(&mut self, cx: &mut EventState, index: usize)
pub fn remove(&mut self, cx: &mut EventState, index: usize)
Removes the choice at position index
Panics if index
is out of bounds.
Trait Implementations§
source§impl<A, V: Clone + Debug + Eq + 'static> AutoLayout for ComboBox<A, V>
impl<A, V: Clone + Debug + Eq + 'static> AutoLayout for ComboBox<A, V>
source§impl<A, V: Clone + Debug + Eq + 'static> Events for ComboBox<A, V>
impl<A, V: Clone + Debug + Eq + 'static> Events for ComboBox<A, V>
source§fn handle_messages(&mut self, cx: &mut EventCx<'_>, _: &Self::Data)
fn handle_messages(&mut self, cx: &mut EventCx<'_>, _: &Self::Data)
source§fn handle_hover(&mut self, cx: &mut EventCx<'_>, _: bool) -> IsUsed
fn handle_hover(&mut self, cx: &mut EventCx<'_>, _: bool) -> IsUsed
source§fn steal_event(
&mut self,
_: &mut EventCx<'_>,
_: &Self::Data,
_: &Id,
_: &Event
) -> IsUsed
fn steal_event( &mut self, _: &mut EventCx<'_>, _: &Self::Data, _: &Id, _: &Event ) -> IsUsed
source§fn configure_recurse(&mut self, cx: &mut ConfigCx<'_>, data: &Self::Data)
fn configure_recurse(&mut self, cx: &mut ConfigCx<'_>, data: &Self::Data)
source§impl<A, V: Clone + Debug + Eq + 'static> Layout for ComboBox<A, V>
impl<A, V: Clone + Debug + Eq + 'static> Layout for ComboBox<A, V>
source§fn widget_name(&self) -> &'static str
fn widget_name(&self) -> &'static str
source§fn num_children(&self) -> usize
fn num_children(&self) -> usize
source§fn get_child(&self, index: usize) -> Option<&dyn Layout>
fn get_child(&self, index: usize) -> Option<&dyn Layout>
dyn Layout
Read moresource§fn size_rules(&mut self, sizer: SizeCx<'_>, axis: AxisInfo) -> SizeRules
fn size_rules(&mut self, sizer: SizeCx<'_>, axis: AxisInfo) -> SizeRules
source§fn find_child_index(&self, id: &Id) -> Option<usize>
fn find_child_index(&self, id: &Id) -> Option<usize>
id
, if any Read moresource§fn translation(&self) -> Offset
fn translation(&self) -> Offset
Auto Trait Implementations§
impl<A, V> !RefUnwindSafe for ComboBox<A, V>
impl<A, V> !Send for ComboBox<A, V>
impl<A, V> !Sync for ComboBox<A, V>
impl<A, V> Unpin for ComboBox<A, V>where
V: Unpin,
impl<A, V> !UnwindSafe for ComboBox<A, V>
Blanket Implementations§
source§impl<W> AdaptWidget for Wwhere
W: Widget,
impl<W> AdaptWidget for Wwhere
W: Widget,
source§fn on_configure<F>(self, f: F) -> AdaptEvents<Self>
fn on_configure<F>(self, f: F) -> AdaptEvents<Self>
Events::configure
Read moresource§fn on_update<F>(self, f: F) -> AdaptEvents<Self>
fn on_update<F>(self, f: F) -> AdaptEvents<Self>
Events::update
Read moresource§fn on_message<M, H>(self, handler: H) -> AdaptEvents<Self>
fn on_message<M, H>(self, handler: H) -> AdaptEvents<Self>
M
Read moresource§fn on_messages<H>(self, handler: H) -> AdaptEvents<Self>
fn on_messages<H>(self, handler: H) -> AdaptEvents<Self>
source§fn with_min_size_px(self, w: i32, h: i32) -> Reserve<Self>
fn with_min_size_px(self, w: i32, h: i32) -> Reserve<Self>
source§fn with_min_size_em(self, w: f32, h: f32) -> Reserve<Self>
fn with_min_size_em(self, w: f32, h: f32) -> Reserve<Self>
source§fn with_label<D, T>(self, direction: D, label: T) -> WithLabel<Self, D>
fn with_label<D, T>(self, direction: D, label: T) -> WithLabel<Self, D>
source§impl<W> AdaptWidgetAny for W
impl<W> AdaptWidgetAny for W
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
§impl<S, T> Cast<T> for Swhere
T: Conv<S>,
impl<S, T> Cast<T> for Swhere
T: Conv<S>,
§impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
§fn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
§fn cast_approx(self) -> T
fn cast_approx(self) -> T
§impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
§fn cast_trunc(self) -> T
fn cast_trunc(self) -> T
§fn cast_nearest(self) -> T
fn cast_nearest(self) -> T
§fn cast_floor(self) -> T
fn cast_floor(self) -> T
§fn try_cast_trunc(self) -> Result<T, Error>
fn try_cast_trunc(self) -> Result<T, Error>
§fn try_cast_nearest(self) -> Result<T, Error>
fn try_cast_nearest(self) -> Result<T, Error>
§fn try_cast_floor(self) -> Result<T, Error>
fn try_cast_floor(self) -> Result<T, Error>
§fn try_cast_ceil(self) -> Result<T, Error>
fn try_cast_ceil(self) -> Result<T, Error>
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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
.§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
.§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.§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.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<W> LayoutExt for W
impl<W> LayoutExt for W
source§fn identify(&self) -> IdentifyWidget<'_>
fn identify(&self) -> IdentifyWidget<'_>
source§fn is_strict_ancestor_of(&self, id: &Id) -> bool
fn is_strict_ancestor_of(&self, id: &Id) -> bool
id
is not self and is a descendant Read more