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
| Member | Summary |
|---|---|
Field() |
Properties
| Member | Summary |
|---|---|
Activate | 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. |
Help | A line shown under the field while it is selected. Empty means nothing is shown. |
IsAction | 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. |
IsEnabled | Whether the field can be used. A disabled field is drawn muted and skipped when moving through the form. |
Label | What the field is called. |
Reset | 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. |
Value | The value as the user should see it, which is not always what is stored. |
Methods
| Member | Summary |
|---|---|
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()
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
| Name | Type | Description |
|---|---|---|
label | Func<TResult><string> | What the button says. |
run | Func<TResult><ViewRoute> | What pressing it does. Returning a route navigates. |
enabled | Func<TResult><bool> | Whether it can be pressed; use it to require the form to be complete. |
help | Func<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
| Name | Type | Description |
|---|---|---|
label | Func<TResult><string> | What the field is called. |
options | IReadOnlyList<T><string> | Everything that can be chosen. |
value | Atom<string> | The atom to read and write. |
help | Func<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
| Name | Type | Description |
|---|---|---|
label | Func<TResult><string> | What the field is called. |
value | Atom<Rgb> | The atom to read and write. |
help | Func<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
| Name | Type | Description |
|---|---|---|
label | Func<TResult><string> | What the field is called. |
value | Atom<DateOnly> | The atom to read and write. |
render | Func<T, TResult><DateOnly, string> | Formats the date for the form, where a local format usually beats the ISO one. |
help | Func<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
| Name | Type | Description |
|---|---|---|
label | Func<TResult><string> | What the field is called. |
options | IReadOnlyList<T><string> | Everything that can be chosen. |
value | Atom<IReadOnlyList<T><string>> | The atom to read and write. |
render | Func<T, TResult><IReadOnlyList<T><string>, string> | Sums up what is chosen for the one row the form has to show it in. |
help | Func<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
| Name | Type | Description |
|---|---|---|
label | Func<TResult><string> | What the field is called. |
value | Atom<decimal> | The atom to read and write. |
minimum | decimal | Lowest value allowed. |
maximum | decimal | Highest value allowed. |
help | Func<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
| Name | Type | Description |
|---|---|---|
label | Func<TResult><string> | What the field is called. |
value | Atom<string> | The atom to read and write. |
returnView | ViewRoute | The view to return to once the picker is done. |
pickFolder | bool | Whether a folder is being chosen rather than a file. |
help | Func<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
| Name | Type | Description |
|---|---|---|
label | Func<TResult><string> | What the field is called. |
value | Atom<string> | The atom to read and write. |
returnView | ViewRoute | The view to return to once the picker is done. |
pickFolder | bool | Whether a folder is being chosen rather than a file. |
start | Func<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. |
help | Func<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
| Name | Type | Description |
|---|---|---|
label | Func<TResult><string> | What the field is called. |
value | Atom<string> | The atom to read and write. |
help | Func<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
| Name | Type | Description |
|---|---|---|
label | Func<TResult><string> | What the field is called. |
value | Atom<decimal> | The atom to read and write. |
minimum | decimal | Value at the left end. |
maximum | decimal | Value at the right end. |
help | Func<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
| Name | Type | Description |
|---|---|---|
label | Func<TResult><string> | What the field is called. |
value | Atom<string> | The atom to read and write. |
validate | Func<T, TResult><string, string> | Checked when the dialog is confirmed; return a message to keep it open. |
help | Func<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
| Name | Type | Description |
|---|---|---|
label | Func<TResult><string> | What the field is called. |
value | Atom<TimeOnly> | The atom to read and write. |
render | Func<T, TResult><TimeOnly, string> | Formats the time for the form. |
help | Func<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
| Name | Type | Description |
|---|---|---|
label | Func<TResult><string> | What the field is called. |
value | Atom<bool> | The atom to read and write. |
render | Func<T, TResult><bool, string> | Words for the two answers, since "on" and "off" do not suit every question. |
help | Func<TResult><string> | A line shown under the field while it is selected. |
Returns Field — The field.