Calendar
struct · ferroui-controls · v0.5.0
struct Calendar
Represents a control that enables a user to select a date by using a visual calendar display.
A Calendar control can be used on its own, or as a drop-down part of a date picker control. A Calendar displays either the days of a month, the months of a year, or the years of a decade, depending on the value of the DisplayMode property. When displaying the days of a month, the user can select a date, a range of dates, or multiple ranges of dates. The kinds of selections that are allowed are controlled by the SelectionMode property.
The range of dates displayed is governed by the DisplayDateStart and DisplayDateEnd properties. If DisplayMode is Year or Decade, only months or years that contain displayable dates will be displayed.
The BlackoutDates property can be used to specify dates that cannot be selected. These dates will be displayed as dimmed and disabled.
By default, Today is highlighted. This can be disabled by setting IsTodayHighlighted to false.
The Calendar control provides basic navigation using either the mouse or keyboard. The following table summarizes keyboard navigation.
Key Combination DisplayMode Action
ARROW Any Change focused date, unselect
all selected dates, and select
new focused date.
SHIFT+ARROW Any If SelectionMode is not set to
SingleDate or None begin
selecting a range of dates.
CTRL+UP ARROW Any Switch to the next larger
DisplayMode. If DisplayMode is
already Decade, no action.
CTRL+DOWN ARROW Any Switch to the next smaller
DisplayMode. If DisplayMode is
already Month, no action.
SPACEBAR Month Select focused date.
SPACEBAR Year or Decade Switch DisplayMode to the Month
or Year represented by focused
item.
Members
TYPEto_reffirst_day_of_week_propertyis_today_highlighted_propertyheader_background_propertyis_week_number_visible_propertyweek_number_rule_propertydisplay_mode_propertyselection_mode_propertyallow_tap_range_selection_propertyselected_date_propertydisplay_date_propertydisplay_date_start_propertydisplay_date_end_propertyconstructnewfirst_day_of_weekset_first_day_of_weekis_today_highlightedset_is_today_highlightedheader_backgroundset_header_backgroundis_week_number_visibleset_is_week_number_visibleweek_number_ruleset_week_number_ruledisplay_modeset_display_modeselection_modeset_selection_modeallow_tap_range_selectionset_allow_tap_range_selectionselected_dateset_selected_dateselected_datesdisplay_dateset_display_datedisplay_date_startset_display_date_startblackout_datesdisplay_date_endset_display_date_endselected_dates_changeddisplay_date_changeddisplay_mode_changed
TYPE
const TYPE: &'static $crate::TypeInfo
The runtime type of this class.
to_ref
fn to_ref(self: &Self) -> $crate::Ref<Calendar>
Returns a strong reference to this object.
first_day_of_week_property
fn first_day_of_week_property() -> &'static StyledProperty<DayOfWeek>
Defines the FirstDayOfWeek property.
is_today_highlighted_property
fn is_today_highlighted_property() -> &'static StyledProperty<bool>
Defines the IsTodayHighlighted property.
header_background_property
fn header_background_property() -> &'static StyledProperty<Option<Rc<dyn IBrush>>>
Defines the HeaderBackground property.
is_week_number_visible_property
fn is_week_number_visible_property() -> &'static StyledProperty<bool>
Defines the IsWeekNumberVisible property.
week_number_rule_property
fn week_number_rule_property() -> &'static StyledProperty<CalendarWeekRule>
Defines the WeekNumberRule property.
display_mode_property
fn display_mode_property() -> &'static StyledProperty<CalendarMode>
Defines the DisplayMode property.
selection_mode_property
fn selection_mode_property() -> &'static StyledProperty<CalendarSelectionMode>
Defines the SelectionMode property.
allow_tap_range_selection_property
fn allow_tap_range_selection_property() -> &'static StyledProperty<bool>
Defines the AllowTapRangeSelection property.
selected_date_property
fn selected_date_property() -> &'static StyledProperty<Option<DateTime>>
Defines the SelectedDate property.
display_date_property
fn display_date_property() -> &'static StyledProperty<DateTime>
Defines the DisplayDate property.
display_date_start_property
fn display_date_start_property() -> &'static StyledProperty<Option<DateTime>>
Defines the DisplayDateStart property.
display_date_end_property
fn display_date_end_property() -> &'static StyledProperty<Option<DateTime>>
Defines the DisplayDateEnd property.
construct
fn construct() -> Self
Creates the class data; see ferroui_base::FerroObject::construct.
new
fn new() -> Ref<Self>
Initializes a new instance of the Calendar class.
first_day_of_week
fn first_day_of_week(self: &Self) -> DayOfWeek
Gets or sets the day that is considered the beginning of the week. The default is the first day of the week of the culture that was current when the class was initialised.
set_first_day_of_week
fn set_first_day_of_week(self: &Self, value: DayOfWeek)
is_today_highlighted
fn is_today_highlighted(self: &Self) -> bool
Gets or sets a value indicating whether the current date is highlighted. The default is true.
set_is_today_highlighted
fn set_is_today_highlighted(self: &Self, value: bool)
header_background
fn header_background(self: &Self) -> Option<Rc<dyn IBrush>>
The brush of the background of the header.
set_header_background
fn set_header_background(self: &Self, value: Option<Rc<dyn IBrush>>)
is_week_number_visible
fn is_week_number_visible(self: &Self) -> bool
Gets or sets a value indicating whether week numbers are shown in the month view.
set_is_week_number_visible
fn set_is_week_number_visible(self: &Self, value: bool)
week_number_rule
fn week_number_rule(self: &Self) -> CalendarWeekRule
Gets or sets the rule used to determine the first week of the year for week number display. The default is taken from the culture that was current when the class was initialised.
Use CalendarWeekRule::FirstFourDayWeek in combination with a
first day of the week of DayOfWeek::Monday for ISO 8601 week
numbering.
set_week_number_rule
fn set_week_number_rule(self: &Self, value: CalendarWeekRule)
display_mode
fn display_mode(self: &Self) -> CalendarMode
Gets or sets a value indicating whether the calendar is displayed in months, years, or decades.
set_display_mode
fn set_display_mode(self: &Self, value: CalendarMode)
selection_mode
fn selection_mode(self: &Self) -> CalendarSelectionMode
Gets or sets a value that indicates what kind of selections are
allowed. The default is CalendarSelectionMode::SingleDate.
This property determines whether the Calendar allows no selection, selection of a single date, or selection of multiple dates.
When this property is changed, all selected dates will be cleared.
set_selection_mode
fn set_selection_mode(self: &Self, value: CalendarSelectionMode)
allow_tap_range_selection
fn allow_tap_range_selection(self: &Self) -> bool
Gets or sets a value indicating whether tap-to-select range mode is enabled. When enabled, users can tap a start date and then tap an end date to select a range. The default is true.
This feature only works when SelectionMode is set to a range mode. When enabled, the first tap selects the start date, and the second tap selects the end date to complete the range. Tapping a third date starts a new range.
set_allow_tap_range_selection
fn set_allow_tap_range_selection(self: &Self, value: bool)
selected_date
fn selected_date(self: &Self) -> Option<DateTime>
Gets or sets the currently selected date. The default is None.
Setting it panics when the given date is in the blackout dates, or
when it is set to anything other than None while the selection
mode is CalendarSelectionMode::None.
Use this property when SelectionMode is set to SingleDate. In other modes, this property will always be the first date in SelectedDates.
set_selected_date
fn set_selected_date(self: &Self, value: Option<DateTime>)
selected_dates
fn selected_dates(self: &Self) -> SelectedDatesCollection
Gets a collection of selected dates. The default is an empty collection.
Dates can be added to the collection either individually or in a range using the AddRange method. Depending on the value of the SelectionMode property, adding a date or range to the collection may cause it to be cleared. The following table lists how the selection mode affects the SelectedDates property.
CalendarSelectionMode Description
None No selections are allowed. SelectedDate
cannot be set and no values can be added
to SelectedDates.
SingleDate Only a single date can be selected,
either by setting SelectedDate or the
first value in SelectedDates. AddRange
cannot be used.
SingleRange A single range of dates can be selected.
Setting SelectedDate, adding a date
individually to SelectedDates, or using
AddRange will clear all previous values
from SelectedDates.
MultipleRange Multiple non-contiguous ranges of dates
can be selected. Adding a date
individually to SelectedDates or using
AddRange will not clear SelectedDates.
Setting SelectedDate will still clear
SelectedDates, but additional dates or
range can then be added. Adding a range
that includes some dates that are
already selected or overlaps with
another range results in the union of
the ranges and does not cause an
exception.
display_date
fn display_date(self: &Self) -> DateTime
Gets or sets the date to display. The default is today.
A date that is not in the range specified by the DisplayDateStart and DisplayDateEnd properties is replaced by the nearest end of that range.
set_display_date
fn set_display_date(self: &Self, value: DateTime)
display_date_start
fn display_date_start(self: &Self) -> Option<DateTime>
Gets or sets the first date to be displayed.
set_display_date_start
fn set_display_date_start(self: &Self, value: Option<DateTime>)
blackout_dates
fn blackout_dates(self: &Self) -> CalendarBlackoutDatesCollection
Gets a collection of dates that are marked as not selectable. The default value is an empty collection.
Adding a date to this collection when it is already selected panics.
Dates in this collection will appear as disabled on the calendar.
To make all past dates not selectable, you can use the
add_dates_in_past method provided by the collection returned by
this property.
display_date_end
fn display_date_end(self: &Self) -> Option<DateTime>
Gets or sets the last date to be displayed.
set_display_date_end
fn set_display_date_end(self: &Self, value: Option<DateTime>)
selected_dates_changed
fn selected_dates_changed(self: &Self, handler: impl Fn(&SelectionChangedEventArgs) -> () + 'static) -> Subscription
Occurs when the collection returned by the SelectedDates property is changed.
Dropping the returned guard removes the handler; Subscription::detach keeps it for the
life of the calendar.
display_date_changed
fn display_date_changed(self: &Self, handler: impl Fn(&CalendarDateChangedEventArgs) -> () + 'static) -> Subscription
Occurs when the DisplayDate property is changed.
This event occurs after DisplayDate is assigned its new value.
Dropping the returned guard removes the handler; Subscription::detach keeps it for the
life of the calendar.
display_mode_changed
fn display_mode_changed(self: &Self, handler: impl Fn(&CalendarModeChangedEventArgs) -> () + 'static) -> Subscription
Occurs when the DisplayMode property is changed.
Dropping the returned guard removes the handler; Subscription::detach keeps it for the
life of the calendar.
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeTemplatedControlImplExtControlImplExtBorrow<T>BorrowMut<T>Into<U>From<T>TryInto<U>TryFrom<U>ReceiverAnyToStringInputElementImplExtInteractiveImplExtLayoutableImplExtFerroObjectImplExtStyledElementImplExtClassDefaultsVisualImplExtErasedDestructorIntoEitherDisplayDerefUpcast<T>Upcast<Calendar>StaticTypeObjectTypeSubclassable<T>DefaultConstructibleStyledElementImplVisualImplLayoutableImplInteractiveImplFerroObjectImplInputElementImplTemplatedControlImplControlImpl
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.