Struct native_windows_gui::ComboBox
source · [−]pub struct ComboBox<D: Display + Default> {
pub handle: ControlHandle,
/* private fields */
}
Expand description
A combo box consists of a list and a selection field. The list presents the options that a user can select, and the selection field displays the current selection.
Requires the combobox
feature.
Builder parameters:
parent
: Required. The combobox parent container.size
: The combobox size.position
: The combobox position.enabled
: If the combobox can be used by the user. It also has a grayed out look if disabled.flags
: A combination of the ComboBoxFlags values.ex_flags
: A combination of win32 window extended flags. Unlikeflags
, ex_flags must be used straight from winapifont
: The font used for the combobox textcollection
: The default collection of the comboboxselected_index
: The default selected index. None means no values are selected.focus
: The control receive focus after being created
Control events:
OnComboBoxClosed
: When the combobox dropdown is closedOnComboBoxDropdown
: When the combobox dropdown is openedOnComboxBoxSelection
: When a new value in a combobox is choosenMousePress(_)
: Generic mouse press events on the checkboxOnMouseMove
: Generic mouse mouse eventOnMouseWheel
: Generic mouse wheel event
use native_windows_gui as nwg;
fn build_combobox(combo: &mut nwg::ComboBox<&'static str>, window: &nwg::Window) {
let data = vec!["one", "two"];
nwg::ComboBox::builder()
.size((200, 300))
.collection(data)
.selected_index(Some(0))
.parent(window)
.build(combo);
}
Fields
handle: ControlHandle
Implementations
sourceimpl<D: Display + Default> ComboBox<D>
impl<D: Display + Default> ComboBox<D>
pub fn builder<'a>() -> ComboBoxBuilder<'a, D>
sourcepub fn remove(&self, index: usize) -> D
pub fn remove(&self, index: usize) -> D
Remove the item at the selected index and returns it. Panic of the index is out of bounds
sourcepub fn sort(&self)
pub fn sort(&self)
Sort the inner collection by the display value of it’s items and update the view
Internally this uses Vec.sort_unstable_by
.
sourcepub fn selection(&self) -> Option<usize>
pub fn selection(&self) -> Option<usize>
Return the index of the currencty selected item. Return None
if no item is selected.
sourcepub fn selection_string(&self) -> Option<String>
pub fn selection_string(&self) -> Option<String>
Return the display value of the currenctly selected item
Return None
if no item is selected. This reads the visual value.
sourcepub fn set_selection(&self, index: Option<usize>)
pub fn set_selection(&self, index: Option<usize>)
Set the currently selected item in the combobox. Does nothing if the index is out of bound If the value is None, remove the selected value
sourcepub fn set_selection_string(&self, value: &str) -> Option<usize>
pub fn set_selection_string(&self, value: &str) -> Option<usize>
Search an item that begins by the value and select the first one found. The search is not case sensitive, so this string can contain any combination of uppercase and lowercase letters. Return the index of the selected string or None if the search was not successful
sourcepub fn push(&self, item: D)
pub fn push(&self, item: D)
Add a new item to the combobox. Sort the collection if the combobox is sorted.
sourcepub fn insert(&self, index: usize, item: D)
pub fn insert(&self, index: usize, item: D)
Insert an item in the collection and the control.
SPECIAL behaviour! If index is std::usize::MAX
, the item is added at the end of the collection.
The method will still panic if index > len
with every other values.
sourcepub fn sync(&self)
pub fn sync(&self)
Update the visual of the control with the inner collection. This rebuild every item in the combobox and can take some time on big collections.
sourcepub fn set_collection(&self, col: Vec<D>) -> Vec<D>
pub fn set_collection(&self, col: Vec<D>) -> Vec<D>
Set the item collection of the combobox. Return the old collection
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Return the number of items in the control. NOT the inner rust collection
sourcepub fn enabled(&self) -> bool
pub fn enabled(&self) -> bool
Return true if the control user can interact with the control, return false otherwise
sourcepub fn set_enabled(&self, v: bool)
pub fn set_enabled(&self, v: bool)
Enable or disable the control
sourcepub fn visible(&self) -> bool
pub fn visible(&self) -> bool
Return true if the control is visible to the user. Will return true even if the control is outside of the parent client view (ex: at the position (10000, 10000))
sourcepub fn set_visible(&self, v: bool)
pub fn set_visible(&self, v: bool)
Show or hide the control to the user
sourcepub fn set_position(&self, x: i32, y: i32)
pub fn set_position(&self, x: i32, y: i32)
Set the position of the button in the parent window
sourcepub fn collection(&self) -> Ref<'_, Vec<D>>
pub fn collection(&self) -> Ref<'_, Vec<D>>
Get read-only access to the inner collection of the combobox This call refcell.borrow under the hood. Be sure to drop the value before calling other combobox methods
sourcepub fn collection_mut(&self) -> RefMut<'_, Vec<D>>
pub fn collection_mut(&self) -> RefMut<'_, Vec<D>>
Get mutable access to the inner collection of the combobox. Does not update the visual
control. Call sync
to update the view. This call refcell.borrow_mut under the hood.
Be sure to drop the value before calling other combobox methods
sourcepub fn class_name(&self) -> &'static str
pub fn class_name(&self) -> &'static str
Winapi class name used during control creation
sourcepub fn forced_flags(&self) -> u32
pub fn forced_flags(&self) -> u32
Winapi flags required by the control
Trait Implementations
sourceimpl<D: Display + Default> PartialEq<ComboBox<D>> for ComboBox<D>
impl<D: Display + Default> PartialEq<ComboBox<D>> for ComboBox<D>
sourceimpl<D: Display + Default> PartialEq<ComboBox<D>> for ControlHandle
impl<D: Display + Default> PartialEq<ComboBox<D>> for ControlHandle
Auto Trait Implementations
impl<D> !RefUnwindSafe for ComboBox<D>
impl<D> !Send for ComboBox<D>
impl<D> !Sync for ComboBox<D>
impl<D> Unpin for ComboBox<D>where
D: Unpin,
impl<D> UnwindSafe for ComboBox<D>where
D: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more