NumberModal class
Namespace: Arlecchino.Modals.Asking · Assembly: Arlecchino
A number that can be both typed and stepped. Bounds are checked before your validator runs, and the message reports them with affixes, so the user sees the same form they are editing.
public sealed class NumberModal :
NumericModal,
IAffixedModal,
ITextEntryModal,
ITextEntry,
IBoundedModal
Inherits from NumericModal
Implements IAffixedModal, ITextEntryModal, ITextEntry, IBoundedModal
Constructors
| Member | Summary |
|---|---|
NumberModal() |
Properties
| Member | Summary |
|---|---|
Anchor | Where the selection was started from, on the caret while nothing is selected. |
Caret | Where the caret sits, pulled into the text when it would fall outside. |
Masked | Numbers are never masked. |
Maximum | Highest value allowed. |
Message | Validation message shown under the field. |
Minimum | Lowest value allowed. A negative bound is also what allows a minus sign to be typed. |
OnSubmit | Called with the accepted number. |
Text | Whatever has been typed so far, which may not parse yet. Assigning it puts the caret at the end, which is what makes stepping leave the caret after the new number. |
Typing | The line being typed into, which for a field of one line is the field itself. |
Validate | Your own check, run after parsing and bounds. Return a message to keep the dialog open. |
Methods
| Member | Summary |
|---|---|
AcceptsCharacter(char) | Whether a character belongs in a number here: digits always, a separator only when decimals are allowed, a minus only when the range goes below zero. |
Add(decimal) | Steps the value and rewrites the text with it. Text that does not parse is treated as zero, so stepping always leaves a valid number behind. |
Draw(ModalFrame) | |
Handle(ModalFrame, KeyPress) | |
TryGetValue(out decimal) | Reads what has been typed as a number. Both . and , are accepted. |
Constructors in detail
NumberModal()
Constructors of types with required members are not supported in this version of your compiler.
public NumberModal();
Properties in detail
Anchor
public int Anchor { get; set; }
Where the selection was started from, on the caret while nothing is selected.
Type int
Caret
public int Caret { get; set; }
Where the caret sits, pulled into the text when it would fall outside.
Type int
Masked
public bool Masked { get; }
Numbers are never masked.
Type bool
Maximum
public decimal Maximum { get; init; }
Highest value allowed.
Type decimal
Message
public string? Message { get; set; }
Validation message shown under the field.
Type string
Minimum
public decimal Minimum { get; init; }
Lowest value allowed. A negative bound is also what allows a minus sign to be typed.
Type decimal
OnSubmit
public Action<decimal> OnSubmit { get; init; }
Called with the accepted number.
Type Action<T><decimal>
Text
public string Text { get; set; }
Whatever has been typed so far, which may not parse yet. Assigning it puts the caret at the end, which is what makes stepping leave the caret after the new number.
Type string
Typing
public override ITextEntry Typing { get; }
The line being typed into, which for a field of one line is the field itself.
Type ITextEntry
Validate
public Func<decimal, string?>? Validate { get; init; }
Your own check, run after parsing and bounds. Return a message to keep the dialog open.
Type Func<T, TResult><decimal, string>
Methods in detail
AcceptsCharacter(char)
public bool AcceptsCharacter(char character);
Whether a character belongs in a number here: digits always, a separator only when decimals are allowed, a minus only when the range goes below zero.
Parameters
| Name | Type | Description |
|---|---|---|
character | char | The character resolved from the key press. |
Returns bool — true when it should be inserted.
Add(decimal)
public void Add(decimal delta);
Steps the value and rewrites the text with it. Text that does not parse is treated as zero, so stepping always leaves a valid number behind.
Parameters
| Name | Type | Description |
|---|---|---|
delta | decimal | How far to move; negative goes down. |
Draw(ModalFrame)
public override void Draw(ModalFrame frame);
Parameters
| Name | Type | Description |
|---|---|---|
frame | ModalFrame |
Handle(ModalFrame, KeyPress)
public override void Handle(ModalFrame frame, KeyPress key);
Parameters
| Name | Type | Description |
|---|---|---|
frame | ModalFrame | |
key | KeyPress |
TryGetValue(out decimal)
public bool TryGetValue(out decimal value);
Reads what has been typed as a number. Both . and , are accepted.
Parameters
| Name | Type | Description |
|---|---|---|
value | decimal | The parsed value, when the text is a number. |
Returns bool — true when the text parses.