Skip to main content

Field class

Namespace: Arlecchino.Forms · Assembly: Arlecchino

One row of a form: a label, the value beside it, and what happens when it is confirmed. Everything is read through delegates, so a field shows what the state holds now and follows the language it runs in.

public sealed class Field

Constructors

MemberSummary
Field()

Properties

MemberSummary
ActivateWhat confirming the field does, usually opening a dialog. Returning a route navigates and ViewRoute.None stays put; without this the field is read-only.
HelpA line shown under the field while it is selected. Empty means nothing is shown.
IsActionWhether the row is a button rather than a value. Buttons have no value to align, so they are not counted when working out the label column.
IsEnabledWhether the field can be used. A disabled field is drawn muted and skipped when moving through the form.
LabelWhat the field is called.
ResetPuts the field back to its empty or lowest value. Fields whose type has no sensible empty value, such as a date, leave this out and simply cannot be cleared.
ValueThe value as the user should see it, which is not always what is stored.

Methods

MemberSummary
Action(Func<string>, Func<ViewRoute>, Func<bool>, Func<string>)A button rather than a value, for the things a form does once it has been filled in.
Choice(Func<string>, IReadOnlyList<string>, Atom<string>, Func<string>)One option out of a list, chosen in a filterable dialog.
Color(Func<string>, Atom<Rgb>, Func<string>)A color, shown as its hex code and picked on three sliders. Reopening the dialog can shift the color by one unit, since it is edited as hue, saturation and lightness.
Date(Func<string>, Atom<DateOnly>, Func<DateOnly, string>, Func<string>)A calendar date. There is no empty date, so the field cannot be cleared.
MultiChoice(Func<string>, IReadOnlyList<string>, Atom<IReadOnlyList<string>>, Func<IReadOnlyList<string>, string>, Func<string>)Any number of options out of a list.
Number(Func<string>, Atom<decimal>, decimal, decimal, Func<string>)A number that can be typed or stepped. Clearing it puts the value back to the lowest allowed.
Path(Func<string>, Atom<string>, ViewRoute, bool, Func<string>)A path on disk. It leaves the form, since the picker is a view of its own, and so it has to be told where to come back to.
PathFrom(Func<string>, Atom<string>, ViewRoute, bool, Func<string>, Func<string>)A path on disk that opens the picker somewhere in particular while the field is still empty. It is a member of its own, since another argument to Field.Path would break what ships.
Secret(Func<string>, Atom<string>, Func<string>)A secret, shown as dots both in the form and while it is typed. The atom still holds the text as it is, so treat it as sensitive.
Slider(Func<string>, Atom<decimal>, decimal, decimal, Func<string>)A number picked on a slider rather than typed, for values where the range matters more than the exact figure.
Text(Func<string>, Atom<string>, Func<string, string>, Func<string>)A line of text, edited in a dialog.
Time(Func<string>, Atom<TimeOnly>, Func<TimeOnly, string>, Func<string>)A time of day. There is no empty time, so the field cannot be cleared.
Toggle(Func<string>, Atom<bool>, Func<bool, string>, Func<string>)A yes-or-no answer.

Constructors in detail

Field()

Obsolete

Constructors of types with required members are not supported in this version of your compiler.

public Field();

Properties in detail

Activate

public Func<ArlecchinoState, ViewRoute>? Activate { get; init; }

What confirming the field does, usually opening a dialog. Returning a route navigates and ViewRoute.None stays put; without this the field is read-only.

Type Func<T, TResult><ArlecchinoState, ViewRoute>

Help

public Func<string> Help { get; init; }

A line shown under the field while it is selected. Empty means nothing is shown.

Type Func<TResult><string>

IsAction

public bool IsAction { get; init; }

Whether the row is a button rather than a value. Buttons have no value to align, so they are not counted when working out the label column.

Type bool

IsEnabled

public Func<bool> IsEnabled { get; init; }

Whether the field can be used. A disabled field is drawn muted and skipped when moving through the form.

Type Func<TResult><bool>

Label

public Func<string> Label { get; init; }

What the field is called.

Type Func<TResult><string>

Reset

public Action? Reset { get; init; }

Puts the field back to its empty or lowest value. Fields whose type has no sensible empty value, such as a date, leave this out and simply cannot be cleared.

Type Action

Value

public Func<string> Value { get; init; }

The value as the user should see it, which is not always what is stored.

Type Func<TResult><string>

Methods in detail

Action(Func<string>, Func<ViewRoute>, Func<bool>, Func<string>)

public static Field Action(
Func<string> label,
Func<ViewRoute> run,
Func<bool>? enabled = null,
Func<string>? help = null);

A button rather than a value, for the things a form does once it has been filled in.

Parameters

NameTypeDescription
labelFunc<TResult><string>What the button says.
runFunc<TResult><ViewRoute>What pressing it does. Returning a route navigates.
enabledFunc<TResult><bool>Whether it can be pressed; use it to require the form to be complete.
helpFunc<TResult><string>A line shown under the button while it is selected.

Returns Field — The field.

Choice(Func<string>, IReadOnlyList<string>, Atom<string>, Func<string>)

public static Field Choice(
Func<string> label,
IReadOnlyList<string> options,
Atom<string> value,
Func<string>? help = null);

One option out of a list, chosen in a filterable dialog.

Parameters

NameTypeDescription
labelFunc<TResult><string>What the field is called.
optionsIReadOnlyList<T><string>Everything that can be chosen.
valueAtom<string>The atom to read and write.
helpFunc<TResult><string>A line shown under the field while it is selected.

Returns Field — The field.

Color(Func<string>, Atom<Rgb>, Func<string>)

public static Field Color(Func<string> label, Atom<Rgb> value, Func<string>? help = null);

A color, shown as its hex code and picked on three sliders. Reopening the dialog can shift the color by one unit, since it is edited as hue, saturation and lightness.

Parameters

NameTypeDescription
labelFunc<TResult><string>What the field is called.
valueAtom<Rgb>The atom to read and write.
helpFunc<TResult><string>A line shown under the field while it is selected.

Returns Field — The field.

Date(Func<string>, Atom<DateOnly>, Func<DateOnly, string>, Func<string>)

public static Field Date(
Func<string> label,
Atom<DateOnly> value,
Func<DateOnly, string> render,
Func<string>? help = null);

A calendar date. There is no empty date, so the field cannot be cleared.

Parameters

NameTypeDescription
labelFunc<TResult><string>What the field is called.
valueAtom<DateOnly>The atom to read and write.
renderFunc<T, TResult><DateOnly, string>Formats the date for the form, where a local format usually beats the ISO one.
helpFunc<TResult><string>A line shown under the field while it is selected.

Returns Field — The field.

MultiChoice(Func<string>, IReadOnlyList<string>, Atom<IReadOnlyList<string>>, Func<IReadOnlyList<string>, string>, Func<string>)

public static Field MultiChoice(
Func<string> label,
IReadOnlyList<string> options,
Atom<IReadOnlyList<string>> value,
Func<IReadOnlyList<string>, string> render,
Func<string>? help = null);

Any number of options out of a list.

Parameters

NameTypeDescription
labelFunc<TResult><string>What the field is called.
optionsIReadOnlyList<T><string>Everything that can be chosen.
valueAtom<IReadOnlyList<T><string>>The atom to read and write.
renderFunc<T, TResult><IReadOnlyList<T><string>, string>Sums up what is chosen for the one row the form has to show it in.
helpFunc<TResult><string>A line shown under the field while it is selected.

Returns Field — The field.

Number(Func<string>, Atom<decimal>, decimal, decimal, Func<string>)

public static Field Number(
Func<string> label,
Atom<decimal> value,
decimal minimum,
decimal maximum,
Func<string>? help = null);

A number that can be typed or stepped. Clearing it puts the value back to the lowest allowed.

Parameters

NameTypeDescription
labelFunc<TResult><string>What the field is called.
valueAtom<decimal>The atom to read and write.
minimumdecimalLowest value allowed.
maximumdecimalHighest value allowed.
helpFunc<TResult><string>A line shown under the field while it is selected.

Returns Field — The field.

Path(Func<string>, Atom<string>, ViewRoute, bool, Func<string>)

public static Field Path(
Func<string> label,
Atom<string> value,
ViewRoute returnView,
bool pickFolder,
Func<string>? help = null);

A path on disk. It leaves the form, since the picker is a view of its own, and so it has to be told where to come back to.

Parameters

NameTypeDescription
labelFunc<TResult><string>What the field is called.
valueAtom<string>The atom to read and write.
returnViewViewRouteThe view to return to once the picker is done.
pickFolderboolWhether a folder is being chosen rather than a file.
helpFunc<TResult><string>A line shown under the field while it is selected.

Returns Field — The field.

PathFrom(Func<string>, Atom<string>, ViewRoute, bool, Func<string>, Func<string>)

public static Field PathFrom(
Func<string> label,
Atom<string> value,
ViewRoute returnView,
bool pickFolder,
Func<string> start,
Func<string>? help = null);

A path on disk that opens the picker somewhere in particular while the field is still empty. It is a member of its own, since another argument to Field.Path would break what ships.

Parameters

NameTypeDescription
labelFunc<TResult><string>What the field is called.
valueAtom<string>The atom to read and write.
returnViewViewRouteThe view to return to once the picker is done.
pickFolderboolWhether a folder is being chosen rather than a file.
startFunc<TResult><string>Where the picker opens while the field is empty. A field that already holds a path opens there instead, and a path that no longer exists lands the picker on the drives. It is a delegate rather than a string so that "where we were last time" is answered when the picker opens rather than when the form is built: start: () => state.PickerLastFolder.
helpFunc<TResult><string>A line shown under the field while it is selected.

Returns Field — The field.

Secret(Func<string>, Atom<string>, Func<string>)

public static Field Secret(Func<string> label, Atom<string> value, Func<string>? help = null);

A secret, shown as dots both in the form and while it is typed. The atom still holds the text as it is, so treat it as sensitive.

Parameters

NameTypeDescription
labelFunc<TResult><string>What the field is called.
valueAtom<string>The atom to read and write.
helpFunc<TResult><string>A line shown under the field while it is selected.

Returns Field — The field.

Slider(Func<string>, Atom<decimal>, decimal, decimal, Func<string>)

public static Field Slider(
Func<string> label,
Atom<decimal> value,
decimal minimum,
decimal maximum,
Func<string>? help = null);

A number picked on a slider rather than typed, for values where the range matters more than the exact figure.

Parameters

NameTypeDescription
labelFunc<TResult><string>What the field is called.
valueAtom<decimal>The atom to read and write.
minimumdecimalValue at the left end.
maximumdecimalValue at the right end.
helpFunc<TResult><string>A line shown under the field while it is selected.

Returns Field — The field.

Text(Func<string>, Atom<string>, Func<string, string>, Func<string>)

public static Field Text(
Func<string> label,
Atom<string> value,
Func<string, string?>? validate = null,
Func<string>? help = null);

A line of text, edited in a dialog.

Parameters

NameTypeDescription
labelFunc<TResult><string>What the field is called.
valueAtom<string>The atom to read and write.
validateFunc<T, TResult><string, string>Checked when the dialog is confirmed; return a message to keep it open.
helpFunc<TResult><string>A line shown under the field while it is selected.

Returns Field — The field.

Time(Func<string>, Atom<TimeOnly>, Func<TimeOnly, string>, Func<string>)

public static Field Time(
Func<string> label,
Atom<TimeOnly> value,
Func<TimeOnly, string> render,
Func<string>? help = null);

A time of day. There is no empty time, so the field cannot be cleared.

Parameters

NameTypeDescription
labelFunc<TResult><string>What the field is called.
valueAtom<TimeOnly>The atom to read and write.
renderFunc<T, TResult><TimeOnly, string>Formats the time for the form.
helpFunc<TResult><string>A line shown under the field while it is selected.

Returns Field — The field.

Toggle(Func<string>, Atom<bool>, Func<bool, string>, Func<string>)

public static Field Toggle(
Func<string> label,
Atom<bool> value,
Func<bool, string> render,
Func<string>? help = null);

A yes-or-no answer.

Parameters

NameTypeDescription
labelFunc<TResult><string>What the field is called.
valueAtom<bool>The atom to read and write.
renderFunc<T, TResult><bool, string>Words for the two answers, since "on" and "off" do not suit every question.
helpFunc<TResult><string>A line shown under the field while it is selected.

Returns Field — The field.