NumberBox
struct · ferroui-controls · v0.5.0
struct NumberBox
A text box for numbers (WinUI's NumberBox): a value of type f64, NaN when the box is
empty, with a range, steps, wrapping, expressions and spin buttons.
The text is committed when the box loses the focus, on Enter and before a step: it is parsed
with the NumberFormatter, or evaluated as an expression
(utils::number_expression) when AcceptsExpression is
set. Up and Down (and the spin buttons and the mouse wheel) step by SmallChange, PageUp and
PageDown by LargeChange; Escape restores the text of the value.
The template is the control theme of the WinUI theme (Controls/NumberBox.xaml, from WinUI's
NumberBox.xaml), with WinUI's parts: the text box InputBox, the spin buttons UpSpinButton
and DownSpinButton, the popup UpDownPopup with PopupUpSpinButton and
PopupDownSpinButton, and HeaderContentPresenter. The control sets WinUI's visual states as
pseudo-classes: :spinbuttonsvisible and :spinbuttonspopup (SpinButtonStates; neither is
SpinButtonsCollapsed), :upspinbuttondisabled and :downspinbuttondisabled. The Fluent and
Simple themes have no template for it (docs/porting/winui-controls.md, section 5.1).
Missing (docs/porting/winui-controls.md, Input): InputScope, SelectionFlyout,
SelectionHighlightColor, TextReadingOrder and PreventKeyboardDisplayOnProgrammaticFocus.
Members
TYPEto_refminimum_propertymaximum_propertyvalue_propertysmall_change_propertylarge_change_propertytext_propertyheader_propertyheader_template_propertyplaceholder_text_propertytext_alignment_propertydescription_propertyvalidation_mode_propertyspin_button_placement_mode_propertyis_wrap_enabled_propertyaccepts_expression_propertynumber_formatter_propertyconstructnewminimumset_minimummaximumset_maximumvalueset_numeric_valuesmall_changeset_small_changelarge_changeset_large_changetextset_textheaderset_headerheader_templateset_header_templateplaceholder_textset_placeholder_texttext_alignmentset_text_alignmentdescriptionset_descriptionvalidation_modeset_validation_modespin_button_placement_modeset_spin_button_placement_modeis_wrap_enabledset_is_wrap_enabledaccepts_expressionset_accepts_expressionnumber_formatterset_number_formattervalue_changedvalidate_inputstep_value
TYPE
const TYPE: &'static $crate::TypeInfo
The runtime type of this class.
to_ref
fn to_ref(self: &Self) -> $crate::Ref<NumberBox>
Returns a strong reference to this object.
minimum_property
fn minimum_property() -> &'static StyledProperty<f64>
Defines the Minimum property: the smallest value. The largest negative f64 by
default.
maximum_property
fn maximum_property() -> &'static StyledProperty<f64>
Defines the Maximum property: the largest value. The largest f64 by default.
value_property
fn value_property() -> &'static StyledProperty<f64>
Defines the Value property: the number, NaN when the box is empty (the default).
small_change_property
fn small_change_property() -> &'static StyledProperty<f64>
Defines the SmallChange property: the step of the arrow keys, the spin buttons and
the mouse wheel. 1 by default.
large_change_property
fn large_change_property() -> &'static StyledProperty<f64>
Defines the LargeChange property: the step of PageUp and PageDown. 10 by default.
text_property
fn text_property() -> &'static StyledProperty<String>
Defines the Text property: the text of the value. Setting it commits it as input.
header_property
fn header_property() -> &'static StyledProperty<Option<BoxedValue>>
Defines the Header property: the content above the box.
header_template_property
fn header_template_property() -> &'static StyledProperty<Option<Rc<dyn IDataTemplate>>>
Defines the HeaderTemplate property: the template of the header.
placeholder_text_property
fn placeholder_text_property() -> &'static StyledProperty<String>
Defines the PlaceholderText property: the text shown while the box is empty.
text_alignment_property
fn text_alignment_property() -> &'static StyledProperty<TextAlignment>
Defines the TextAlignment property: the alignment of the text. Left by default.
description_property
fn description_property() -> &'static StyledProperty<Option<BoxedValue>>
Defines the Description property: the content below the box.
validation_mode_property
fn validation_mode_property() -> &'static StyledProperty<NumberBoxValidationMode>
Defines the ValidationMode property. InvalidInputOverwritten by default.
spin_button_placement_mode_property
fn spin_button_placement_mode_property() -> &'static StyledProperty<NumberBoxSpinButtonPlacementMode>
Defines the SpinButtonPlacementMode property. Hidden by default.
is_wrap_enabled_property
fn is_wrap_enabled_property() -> &'static StyledProperty<bool>
Defines the IsWrapEnabled property: whether a step past one end of the range goes
to the other end. false by default.
accepts_expression_property
fn accepts_expression_property() -> &'static StyledProperty<bool>
Defines the AcceptsExpression property: whether the text is evaluated as an
arithmetic expression. false by default.
number_formatter_property
fn number_formatter_property() -> &'static StyledProperty<Rc<dyn INumberBoxNumberFormatter>>
Defines the NumberFormatter property: the formatter of the value and parser of the
text. InvariantNumberBoxNumberFormatter by default.
construct
fn construct() -> Self
Creates the class data; see ferroui_base::FerroObject::construct.
new
fn new() -> Ref<Self>
minimum
fn minimum(self: &Self) -> f64
Gets the smallest value.
set_minimum
fn set_minimum(self: &Self, value: f64)
Sets the smallest value.
maximum
fn maximum(self: &Self) -> f64
Gets the largest value.
set_maximum
fn set_maximum(self: &Self, value: f64)
Sets the largest value.
value
fn value(self: &Self) -> f64
Gets the value: NaN when the box is empty.
set_numeric_value
fn set_numeric_value(self: &Self, value: f64)
Sets the value (WinUI's Value setter). Setting NaN while the value is NaN does nothing:
"we are using nan as a value to represent value not set (cleared)", and NaN is not equal to
itself.
small_change
fn small_change(self: &Self) -> f64
Gets the step of the arrow keys, the spin buttons and the mouse wheel.
set_small_change
fn set_small_change(self: &Self, value: f64)
Sets the step of the arrow keys, the spin buttons and the mouse wheel.
large_change
fn large_change(self: &Self) -> f64
Gets the step of PageUp and PageDown.
set_large_change
fn set_large_change(self: &Self, value: f64)
Sets the step of PageUp and PageDown.
text
fn text(self: &Self) -> String
Gets the text of the value.
set_text
fn set_text(self: &Self, value: impl Into<String>)
Sets the text; it is committed as input.
header
fn header(self: &Self) -> Option<BoxedValue>
Gets the header.
set_header
fn set_header(self: &Self, value: Option<BoxedValue>)
Sets the header.
header_template
fn header_template(self: &Self) -> Option<Rc<dyn IDataTemplate>>
Gets the template of the header.
set_header_template
fn set_header_template(self: &Self, value: Option<Rc<dyn IDataTemplate>>)
Sets the template of the header.
placeholder_text
fn placeholder_text(self: &Self) -> String
Gets the text shown while the box is empty.
set_placeholder_text
fn set_placeholder_text(self: &Self, value: impl Into<String>)
Sets the text shown while the box is empty.
text_alignment
fn text_alignment(self: &Self) -> TextAlignment
Gets the alignment of the text.
set_text_alignment
fn set_text_alignment(self: &Self, value: TextAlignment)
Sets the alignment of the text.
description
fn description(self: &Self) -> Option<BoxedValue>
Gets the content below the box.
set_description
fn set_description(self: &Self, value: Option<BoxedValue>)
Sets the content below the box.
validation_mode
fn validation_mode(self: &Self) -> NumberBoxValidationMode
Gets the validation mode.
set_validation_mode
fn set_validation_mode(self: &Self, value: NumberBoxValidationMode)
Sets the validation mode.
spin_button_placement_mode
fn spin_button_placement_mode(self: &Self) -> NumberBoxSpinButtonPlacementMode
Gets where the spin buttons are.
set_spin_button_placement_mode
fn set_spin_button_placement_mode(self: &Self, value: NumberBoxSpinButtonPlacementMode)
Sets where the spin buttons are.
is_wrap_enabled
fn is_wrap_enabled(self: &Self) -> bool
Gets whether a step past one end of the range goes to the other end.
set_is_wrap_enabled
fn set_is_wrap_enabled(self: &Self, value: bool)
Sets whether a step past one end of the range goes to the other end.
accepts_expression
fn accepts_expression(self: &Self) -> bool
Gets whether the text is evaluated as an arithmetic expression.
set_accepts_expression
fn set_accepts_expression(self: &Self, value: bool)
Sets whether the text is evaluated as an arithmetic expression.
number_formatter
fn number_formatter(self: &Self) -> Rc<dyn INumberBoxNumberFormatter>
Gets the formatter of the value and parser of the text.
set_number_formatter
fn set_number_formatter(self: &Self, value: Rc<dyn INumberBoxNumberFormatter>)
Sets the formatter of the value and parser of the text.
value_changed
fn value_changed(self: &Self, handler: impl Fn(&NumberBoxValueChangedEventArgs) -> () + 'static) -> Subscription
Adds a handler of the ValueChanged event, raised after a change of the value with the
value before it and the coerced new value.
Dropping the returned guard removes the handler; Subscription::detach keeps it for
the life of the box.
validate_input
fn validate_input(self: &Self) -> bool
Commits the text of the box (WinUI's ValidateInput): empty text clears the value; text
that is a number (or, with AcceptsExpression, an expression) becomes the value and is
formatted again; other text is replaced with the text of the value unless validation is
disabled. Returns whether the text was a number or empty.
Deviation (docs/porting/winui-controls.md, Input): without a template (no text box) the
text committed is the Text property.
step_value
fn step_value(self: &Self, change: f64)
Commits the text and adds change to the value (WinUI's StepValue), wrapping past the
ends of the range when IsWrapEnabled is set. Nothing happens while the box is empty.
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeTemplatedControlImplExtControlImplExtBorrow<T>BorrowMut<T>Into<U>From<T>TryInto<U>TryFrom<U>ReceiverAnyInputElementImplExtInteractiveImplExtLayoutableImplExtFerroObjectImplExtStyledElementImplExtClassDefaultsVisualImplExtErasedDestructorIntoEitherDerefUpcast<T>Upcast<NumberBox>StaticTypeObjectTypeSubclassable<T>DefaultConstructibleStyledElementImplVisualImplLayoutableImplInteractiveImplFerroObjectImplControlImplInputElementImplTemplatedControlImpl
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.