Struct 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. Unlike flags, ex_flags must be used straight from winapi
  • font: The font used for the combobox text
  • collection: The default collection of the combobox
  • selected_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 closed
  • OnComboBoxDropdown: When the combobox dropdown is opened
  • OnComboxBoxSelection: When a new value in a combobox is choosen
  • MousePress(_): Generic mouse press events on the checkbox
  • OnMouseMove: Generic mouse mouse event
  • OnMouseWheel: 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§

Source§

impl<D: Display + Default> ComboBox<D>

Source

pub fn builder<'a>() -> ComboBoxBuilder<'a, D>

Examples found in repository?
examples/partials.rs (line 357)
331        fn build_partial<W: Into<ControlHandle>>(data: &mut AnimalUi, parent: Option<W>) -> Result<(), NwgError> {
332            let parent = parent.unwrap().into();
333
334            nwg::Label::builder()
335                .text("Name:")
336                .h_align(nwg::HTextAlign::Right)
337                .parent(&parent)
338                .build(&mut data.label1)?;
339
340            nwg::Label::builder()
341                .text("Race:")
342                .h_align(nwg::HTextAlign::Right)
343                .parent(&parent)
344                .build(&mut data.label2)?;
345
346            nwg::Label::builder()
347                .text("Is fluffy:")
348                .h_align(nwg::HTextAlign::Right)
349                .parent(&parent)
350                .build(&mut data.label3)?;
351
352            nwg::TextInput::builder()
353                .text("Mittens")
354                .parent(&parent)
355                .build(&mut data.name_input)?;
356
357            nwg::ComboBox::builder()
358                .collection(vec!["Cat", "Dog", "Pidgeon", "Monkey"])
359                .selected_index(Some(0))
360                .parent(&parent)
361                .build(&mut data.race_input)?;
362
363            nwg::CheckBox::builder()
364                .text("")
365                .check_state(nwg::CheckBoxState::Checked)
366                .parent(&parent)
367                .build(&mut data.is_soft_input)?;
368
369            nwg::Button::builder()
370                .text("Save")
371                .parent(&parent)
372                .build(&mut data.save_btn)?;
373
374            nwg::GridLayout::builder()
375                .parent(&parent)
376                .max_size([1000, 150])
377                .min_size([100, 120])
378                .child(0, 0, &data.label1)
379                .child(0, 1, &data.label2)
380                .child(0, 2, &data.label3)
381                .child(1, 0, &data.name_input)
382                .child(1, 1, &data.race_input)
383                .child(1, 2, &data.is_soft_input)
384                .build(&data.layout)?;
385
386            nwg::GridLayout::builder()
387                .min_size([100, 200])
388                .max_column(Some(2))
389                .max_row(Some(6))
390                .child(1, 5, &data.save_btn)
391                .parent(&parent)
392                .build(&data.layout2)?;
393
394            Ok(())
395        }
Source

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

Source

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.

Source

pub fn dropdown(&self, v: bool)

Show or hide the dropdown of the combox

Source

pub fn selection(&self) -> Option<usize>

Return the index of the currencty selected item. Return None if no item is selected.

Source

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.

Source

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

Source

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

Source

pub fn push(&self, item: D)

Add a new item to the combobox. Sort the collection if the combobox is sorted.

Source

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.

Source

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.

Source

pub fn set_collection(&self, col: Vec<D>) -> Vec<D>

Set the item collection of the combobox. Return the old collection

Source

pub fn len(&self) -> usize

Return the number of items in the control. NOT the inner rust collection

Source

pub fn font(&self) -> Option<Font>

Return the font of the control

Source

pub fn set_font(&self, font: Option<&Font>)

Set the font of the control

Source

pub fn focus(&self) -> bool

Return true if the control currently has the keyboard focus

Source

pub fn set_focus(&self)

Set the keyboard focus on the button.

Source

pub fn enabled(&self) -> bool

Return true if the control user can interact with the control, return false otherwise

Source

pub fn set_enabled(&self, v: bool)

Enable or disable the control

Source

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))

Source

pub fn set_visible(&self, v: bool)

Show or hide the control to the user

Source

pub fn size(&self) -> (u32, u32)

Return the size of the button in the parent window

Source

pub fn set_size(&self, x: u32, y: u32)

Set the size of the button in the parent window

Source

pub fn position(&self) -> (i32, i32)

Return the position of the button in the parent window

Source

pub fn set_position(&self, x: i32, y: i32)

Set the position of the button in the parent window

Source

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

Source

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

Source

pub fn class_name(&self) -> &'static str

Winapi class name used during control creation

Source

pub fn flags(&self) -> u32

Winapi base flags used during window creation

Source

pub fn forced_flags(&self) -> u32

Winapi flags required by the control

Trait Implementations§

Source§

impl<D: Default + Display + Default> Default for ComboBox<D>

Source§

fn default() -> ComboBox<D>

Returns the “default value” for a type. Read more
Source§

impl<D: Display + Default> Drop for ComboBox<D>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<D: Display + Default> From<&ComboBox<D>> for ControlHandle

Source§

fn from(control: &ComboBox<D>) -> Self

Converts to this type from the input type.
Source§

impl<D: Display + Default> PartialEq<ComboBox<D>> for ControlHandle

Source§

fn eq(&self, other: &ComboBox<D>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<D: Display + Default> PartialEq<ControlHandle> for ComboBox<D>

Source§

fn eq(&self, other: &ControlHandle) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<D: Display + Default> PartialEq for ComboBox<D>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<D> !Freeze for ComboBox<D>

§

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§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.