Skip to main content

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

MemberSummary
NumberModal()

Properties

MemberSummary
AnchorWhere the selection was started from, on the caret while nothing is selected.
CaretWhere the caret sits, pulled into the text when it would fall outside.
MaskedNumbers are never masked.
MaximumHighest value allowed.
MessageValidation message shown under the field.
MinimumLowest value allowed. A negative bound is also what allows a minus sign to be typed.
OnSubmitCalled with the accepted number.
TextWhatever 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.
TypingThe line being typed into, which for a field of one line is the field itself.
ValidateYour own check, run after parsing and bounds. Return a message to keep the dialog open.

Methods

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

Obsolete

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

NameTypeDescription
charactercharThe character resolved from the key press.

Returns booltrue 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

NameTypeDescription
deltadecimalHow far to move; negative goes down.

Draw(ModalFrame)

public override void Draw(ModalFrame frame);

Parameters

NameTypeDescription
frameModalFrame

Handle(ModalFrame, KeyPress)

public override void Handle(ModalFrame frame, KeyPress key);

Parameters

NameTypeDescription
frameModalFrame
keyKeyPress

TryGetValue(out decimal)

public bool TryGetValue(out decimal value);

Reads what has been typed as a number. Both . and , are accepted.

Parameters

NameTypeDescription
valuedecimalThe parsed value, when the text is a number.

Returns booltrue when the text parses.