Skip to main content

ArlecchinoState class

Namespace: Arlecchino.State · Assembly: Arlecchino

State that outlives a single screen: the output line, the dialogs that are open, and a pending file picker request. All of it is written on the drawing thread, and only ArlecchinoState.Invalidate from anywhere.

public class ArlecchinoState

Constructors

MemberSummary
ArlecchinoState(Repaint, Notifications)Creates the state.

Properties

MemberSummary
FilePickerWhat the file picker should show: fill it in, then navigate to Routes.FilePicker. It is written on the drawing thread and cleared however the picker finishes.
ModalThe dialog on top, or null when none is open, taking every key while it is there. Assigning replaces the whole stack, where ArlecchinoState.PushModal opens one over another.
ModalsEvery open dialog, bottom first, as a live read-only view. Drawing goes through this, so the ones underneath stay visible behind the top one.
NotificationsWhat the application has said lately, and the screen behind the output row.
OutputThe status line at the bottom of the frame. Writing to it raises a notification, so the line clears itself and the message stays on the notifications screen; an empty string clears it at once.
PickerLastFolderFolder the picker ended in, to be passed as the next starting path. It is written on the drawing thread, as ArlecchinoState.Modal is.

Methods

MemberSummary
CloseAllModals()Closes every open dialog at once, however deep they are stacked.
CloseModal()Closes the dialog on top, uncovering whatever it was opened over. Submitting, picking and canceling already do this, so it is only needed to dismiss one from the outside.
Invalidate()Asks for a repaint. Needed only for changes the framework cannot see — a field mutated from outside, or data that arrived on a timer.
PushModal(Modal)Opens a dialog over whatever is already open, which is how a callback asks a follow-up question without losing what the user was in the middle of. Closing it uncovers the one underneath.
RequestChoice(string, IReadOnlyList<string>, Action<string>, string)Asks for one option out of a list that can be filtered by typing.
RequestColor(string, Rgb, Action<Rgb>)Asks for a color with a swatch and three sliders. Channels are whole numbers, so a color that goes in can come back shifted by a unit or two.
RequestConfirmation(string, Action)Asks a question that has to be confirmed before something happens. The negative answer starts selected, so a stray Enter cancels rather than deletes.
RequestDate(string, DateOnly, Action<DateOnly>)Asks for a date, edited one segment at a time.
RequestEmail(string, string, Action<string>)Asks for an email address, checked before the dialog will close.
RequestMessage(string, string, Action)Shows a message with nothing to fill in; any of the closing keys dismisses it.
RequestMultiChoice(string, IReadOnlyList<string>, IReadOnlyList<string>, Action<IReadOnlyList<string>>)Asks for any number of options. Marks survive filtering, and the result comes back in the order of options rather than the order they were marked.
RequestNumber(string, decimal, decimal, decimal, Action<decimal>)Asks for a number within bounds. Typing is restricted to digits, and stepping keys clamp to the range.
RequestPassword(string, Action<string>)Asks for a secret. The field shows dots, but the text handed to the callback is untouched.
RequestSlider(string, decimal, decimal, decimal, Action<decimal>)Asks for a number on a track, adjusted with the arrows rather than typed.
RequestText(string, string, Func<string, string>, Action<string>)Asks for a line of text.
RequestTextArea(string, string, Action<string>, Func<string, string>, int)Asks for several lines of text. Enter starts a new line, so the text is confirmed with the Submit key — Ctrl+Enter unless the keymap says otherwise.
RequestTime(string, TimeOnly, Action<TimeOnly>)Asks for a time of day, edited one segment at a time.
RequestToggle(string, bool, Action<bool>)Asks a yes-or-no question.
RequestUrl(string, string, Action<string>)Asks for an http or https link, checked before the dialog will close.

Constructors in detail

ArlecchinoState(Repaint, Notifications)

public ArlecchinoState(Repaint repaint, Notifications notifications);

Creates the state.

Parameters

NameTypeDescription
repaintRepaintSignal raised whenever anything here changes.
notificationsNotificationsHolds the output row and the notifications screen behind it.

Properties in detail

FilePicker

public FilePickerRequest? FilePicker { get; set; }

What the file picker should show: fill it in, then navigate to Routes.FilePicker. It is written on the drawing thread and cleared however the picker finishes.

Type FilePickerRequest

Exceptions

TypeThrown when
InvalidOperationExceptionCalled from off the drawing thread.
public Modal? Modal { get; set; }

The dialog on top, or null when none is open, taking every key while it is there. Assigning replaces the whole stack, where ArlecchinoState.PushModal opens one over another.

Type Modal

Exceptions

TypeThrown when
InvalidOperationExceptionCalled from off the drawing thread.

Modals

public IReadOnlyList<Modal> Modals { get; }

Every open dialog, bottom first, as a live read-only view. Drawing goes through this, so the ones underneath stay visible behind the top one.

Type IReadOnlyList<T><Modal>

Notifications

public Notifications Notifications { get; }

What the application has said lately, and the screen behind the output row.

Type Notifications

Output

public string Output { get; set; }

The status line at the bottom of the frame. Writing to it raises a notification, so the line clears itself and the message stays on the notifications screen; an empty string clears it at once.

Type string

PickerLastFolder

public string PickerLastFolder { get; set; }

Folder the picker ended in, to be passed as the next starting path. It is written on the drawing thread, as ArlecchinoState.Modal is.

Type string

Exceptions

TypeThrown when
InvalidOperationExceptionCalled from off the drawing thread.

Methods in detail

CloseAllModals()

public void CloseAllModals();

Closes every open dialog at once, however deep they are stacked.

Exceptions

TypeThrown when
InvalidOperationExceptionCalled from off the drawing thread.

CloseModal()

public void CloseModal();

Closes the dialog on top, uncovering whatever it was opened over. Submitting, picking and canceling already do this, so it is only needed to dismiss one from the outside.

Exceptions

TypeThrown when
InvalidOperationExceptionCalled from off the drawing thread.

Invalidate()

public void Invalidate();

Asks for a repaint. Needed only for changes the framework cannot see — a field mutated from outside, or data that arrived on a timer.

PushModal(Modal)

public void PushModal(Modal modal);

Opens a dialog over whatever is already open, which is how a callback asks a follow-up question without losing what the user was in the middle of. Closing it uncovers the one underneath.

Parameters

NameTypeDescription
modalModalThe dialog to open.

Exceptions

TypeThrown when
InvalidOperationExceptionCalled from off the drawing thread.

RequestChoice(string, IReadOnlyList<string>, Action<string>, string)

public void RequestChoice(
string title,
IReadOnlyList<string> options,
Action<string> onPicked,
string current = "");

Asks for one option out of a list that can be filtered by typing.

Parameters

NameTypeDescription
titlestringTitle of the dialog.
optionsIReadOnlyList<T><string>What to choose from.
onPickedAction<T><string>Called with the chosen option.
currentstringOption to start on; the first one when it is not in the list.

RequestColor(string, Rgb, Action<Rgb>)

public void RequestColor(string title, Rgb initial, Action<Rgb> onPicked);

Asks for a color with a swatch and three sliders. Channels are whole numbers, so a color that goes in can come back shifted by a unit or two.

Parameters

NameTypeDescription
titlestringTitle of the dialog.
initialRgbColor the sliders start on.
onPickedAction<T><Rgb>Called with the chosen color.

RequestConfirmation(string, Action)

public void RequestConfirmation(string title, Action onYes);

Asks a question that has to be confirmed before something happens. The negative answer starts selected, so a stray Enter cancels rather than deletes.

Parameters

NameTypeDescription
titlestringThe question.
onYesActionCalled only when the answer was yes.

RequestDate(string, DateOnly, Action<DateOnly>)

public void RequestDate(string title, DateOnly initial, Action<DateOnly> onSubmit);

Asks for a date, edited one segment at a time.

Parameters

NameTypeDescription
titlestringTitle of the dialog.
initialDateOnlyDate the field starts on.
onSubmitAction<T><DateOnly>Called with the chosen date.

RequestEmail(string, string, Action<string>)

public void RequestEmail(string title, string initial, Action<string> onSubmit);

Asks for an email address, checked before the dialog will close.

Parameters

NameTypeDescription
titlestringTitle of the dialog.
initialstringText the field starts with.
onSubmitAction<T><string>Called with the accepted address.

RequestMessage(string, string, Action)

public void RequestMessage(string title, string text, Action? onClosed = null);

Shows a message with nothing to fill in; any of the closing keys dismisses it.

Parameters

NameTypeDescription
titlestringTitle of the dialog.
textstringWhat to say. Long text wraps inside the box.
onClosedActionCalled once it is dismissed.

RequestMultiChoice(string, IReadOnlyList<string>, IReadOnlyList<string>, Action<IReadOnlyList<string>>)

public void RequestMultiChoice(
string title,
IReadOnlyList<string> options,
IReadOnlyList<string> selectedKeys,
Action<IReadOnlyList<string>> onSubmit);

Asks for any number of options. Marks survive filtering, and the result comes back in the order of options rather than the order they were marked.

Parameters

NameTypeDescription
titlestringTitle of the dialog.
optionsIReadOnlyList<T><string>What to choose from.
selectedKeysIReadOnlyList<T><string>Options marked to begin with.
onSubmitAction<T><IReadOnlyList<T><string>>Called with everything marked.

RequestNumber(string, decimal, decimal, decimal, Action<decimal>)

public void RequestNumber(
string title,
decimal initial,
decimal minimum,
decimal maximum,
Action<decimal> onSubmit);

Asks for a number within bounds. Typing is restricted to digits, and stepping keys clamp to the range.

Parameters

NameTypeDescription
titlestringTitle of the dialog.
initialdecimalValue the field starts on, clamped to the range.
minimumdecimalLowest value allowed.
maximumdecimalHighest value allowed.
onSubmitAction<T><decimal>Called with the accepted number.

RequestPassword(string, Action<string>)

public void RequestPassword(string title, Action<string> onSubmit);

Asks for a secret. The field shows dots, but the text handed to the callback is untouched.

Parameters

NameTypeDescription
titlestringTitle of the dialog.
onSubmitAction<T><string>Called with what was typed.

RequestSlider(string, decimal, decimal, decimal, Action<decimal>)

public void RequestSlider(
string title,
decimal initial,
decimal minimum,
decimal maximum,
Action<decimal> onSubmit);

Asks for a number on a track, adjusted with the arrows rather than typed.

Parameters

NameTypeDescription
titlestringTitle of the dialog.
initialdecimalValue the slider starts on, clamped to the range.
minimumdecimalLeft end of the track.
maximumdecimalRight end of the track.
onSubmitAction<T><decimal>Called with the chosen value.

RequestText(string, string, Func<string, string>, Action<string>)

public void RequestText(
string title,
string initial,
Func<string, string?>? validate,
Action<string> onSubmit);

Asks for a line of text.

Parameters

NameTypeDescription
titlestringTitle of the dialog.
initialstringText the field starts with.
validateFunc<T, TResult><string, string>Checked on confirm; return a message to keep the dialog open, or null to accept.
onSubmitAction<T><string>Called with the accepted text.

RequestTextArea(string, string, Action<string>, Func<string, string>, int)

public void RequestTextArea(
string title,
string initial,
Action<string> onSubmit,
Func<string, string?>? validate = null,
int visibleRows = 8);

Asks for several lines of text. Enter starts a new line, so the text is confirmed with the Submit key — Ctrl+Enter unless the keymap says otherwise.

Parameters

NameTypeDescription
titlestringTitle of the dialog.
initialstringText the editor starts with.
onSubmitAction<T><string>Called with the accepted text.
validateFunc<T, TResult><string, string>Checked on submit; return a message to keep the dialog open, or null to accept.
visibleRowsintHow many rows to show before the text starts scrolling.

RequestTime(string, TimeOnly, Action<TimeOnly>)

public void RequestTime(string title, TimeOnly initial, Action<TimeOnly> onSubmit);

Asks for a time of day, edited one segment at a time.

Parameters

NameTypeDescription
titlestringTitle of the dialog.
initialTimeOnlyTime the field starts on.
onSubmitAction<T><TimeOnly>Called with the chosen time.

RequestToggle(string, bool, Action<bool>)

public void RequestToggle(string title, bool initial, Action<bool> onSubmit);

Asks a yes-or-no question.

Parameters

NameTypeDescription
titlestringThe question.
initialboolWhich chip starts selected.
onSubmitAction<T><bool>Called with the answer.

RequestUrl(string, string, Action<string>)

public void RequestUrl(string title, string initial, Action<string> onSubmit);

Asks for an http or https link, checked before the dialog will close.

Parameters

NameTypeDescription
titlestringTitle of the dialog.
initialstringText the field starts with, often just the scheme.
onSubmitAction<T><string>Called with the accepted link.