Struct DatePicker

Source
pub struct DatePicker {
    pub handle: ControlHandle,
}
Expand description

A date and time picker (DTP) control provides a simple and intuitive interface through which to exchange date and time information with a user. For example, with a DTP control you can ask the user to enter a date and then easily retrieve the selection.

Requires the datetime-picker feature.

Builder parameters:

  • parent: Required. The dtp parent container.
  • size: The dtp size.
  • position: The dtp position.
  • enabled: If the dtp can be used by the user. It also has a grayed out look if disabled.
  • flags: A combination of the DatePickerFlags 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 dtp text
  • date: The default date as a DatePickerValue value
  • format: The format of the date. See the set_format method.
  • range: The accepted range of dates. The value is inclusive.
  • focus: The control receive focus after being created

Control events:

  • OnDatePickerClosed: When the datepicker dropdown is closed
  • OnDatePickerDropdown: When the datepicker dropdown is opened
  • OnDatePickerChanged: When a new value in a datepicker 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_dtp(date: &mut nwg::DatePicker, window: &nwg::Window) {
    let v = nwg::DatePickerValue { year: 2000, month: 10, day: 5 };
    let v1 = nwg::DatePickerValue { year: 2000, month: 10, day: 5 };
    let v2 = nwg::DatePickerValue { year: 2012, month: 10, day: 5 };
    
    nwg::DatePicker::builder()
        .size((200, 300))
        .position((0, 0))
        .date(Some(v))
        .format(Some("'YEAR: 'yyyy"))
        .range(Some([v1, v2]))
        .parent(window)
        .build(date);
}

Fields§

§handle: ControlHandle

Implementations§

Source§

impl DatePicker

Source

pub fn builder<'a>() -> DatePickerBuilder<'a>

Source

pub fn set_format<'a>(&self, format: Option<&'a str>)

Sets the date format of the control

About the format string:

  • d The one- or two-digit day.

  • dd The two-digit day. Single-digit day values are preceded by a zero.

  • ddd The three-character weekday abbreviation.

  • dddd The full weekday name.

  • M The one- or two-digit month number.

  • MM The two-digit month number. Single-digit values are preceded by a zero.

  • MMM The three-character month abbreviation.

  • MMMM The full month name.

  • t The one-letter AM/PM abbreviation (that is, AM is displayed as “A”).

  • tt The two-letter AM/PM abbreviation (that is, AM is displayed as “AM”).

  • yy The last two digits of the year (that is, 1996 would be displayed as “96”).

  • yyyy The full year (that is, 1996 would be displayed as “1996”).

  • h The one- or two-digit hour in 12-hour format.

  • hh The two-digit hour in 12-hour format. Single-digit values are preceded by a zero.

  • H The one- or two-digit hour in 24-hour format.

  • HH The two-digit hour in 24-hour format. Single-digit values are preceded by a zero.

  • m The one- or two-digit minute.

  • mm The two-digit minute. Single-digit values are preceded by a zero.

Furthermore, any string enclosed in ' can be used in the format to display text.
For example, to display the current date with the format 'Today is: Tuesday Mar 23, 1996, the format string is 'Today is: 'dddd MMM dd', 'yyyy.

If format is set to None, use the default system format.

Source

pub fn checked(&self) -> bool

Return the check state of the checkbox of the control.
If the date time picker is not optional, return false.

To set the check state of the control, use set_value method

Source

pub fn close_calendar(&self)

Close the calendar popup if it is open. Note that there is no way to force the calendar to drop down

Source

pub fn value(&self) -> Option<DatePickerValue>

Return the time set in the control in a PickerDate structure.
Return None if optional was set and the checkbox is not checked.
Note: use get_text to get the text value of the control.

Source

pub fn set_value(&self, date: Option<DatePickerValue>)

Set the time set in the control in a PickerDate structure.
If None is passed, this clears the checkbox.

Source

pub fn range(&self) -> [DatePickerValue; 2]

Gets the current minimum and maximum allowable system times for a date and time picker control.

Source

pub fn set_range(&self, r: &[DatePickerValue; 2])

Sets the minimum and maximum allowable system times for a date and time picker control.

Source

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

Return the font of the control

Source

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

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

Sets 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 date picker in the parent window

Source

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

Set the size of the date picker in the parent window

Source

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

Return the position of the date picker in the parent window

Source

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

Set the position of the date picker in the parent window

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 Default for DatePicker

Source§

fn default() -> DatePicker

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

impl Drop for DatePicker

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl From<&DatePicker> for ControlHandle

Source§

fn from(control: &DatePicker) -> Self

Converts to this type from the input type.
Source§

impl From<&mut DatePicker> for ControlHandle

Source§

fn from(control: &mut DatePicker) -> Self

Converts to this type from the input type.
Source§

impl PartialEq<ControlHandle> for DatePicker

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 PartialEq<DatePicker> for ControlHandle

Source§

fn eq(&self, other: &DatePicker) -> 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 PartialEq for DatePicker

Source§

fn eq(&self, other: &DatePicker) -> 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 Eq for DatePicker

Source§

impl StructuralPartialEq for DatePicker

Auto Trait Implementations§

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.