Table of Contents

Class FormBuilder

Namespace
SharpConsoleUI.Builders
Assembly
SharpConsoleUI.dll

Fluent builder for FormControl instances. Holds a live FormControl and delegates all Add* / section / row / button methods to it, returning this for chaining. Build() returns the underlying form; the implicit operator allows passing a builder wherever a FormControl is expected.

public sealed class FormBuilder : IControlBuilder<FormControl>
Inheritance
FormBuilder
Implements
Inherited Members
Extension Methods

Methods

AddCheckbox(string, string, bool, string?)

Adds a boolean field backed by a CheckboxControl. The value is "true" or "false".

public FormBuilder AddCheckbox(string name, string label, bool initial = false, string? hint = null)

Parameters

name string
label string
initial bool
hint string

Returns

FormBuilder

AddDropdown(string, string, IEnumerable<string>, string?, string?)

Adds a single-select field backed by a DropdownControl.

public FormBuilder AddDropdown(string name, string label, IEnumerable<string> options, string? initial = null, string? hint = null)

Parameters

name string
label string
options IEnumerable<string>
initial string
hint string

Returns

FormBuilder

AddField(string, string, IWindowControl, Func<string?>, Func<string?, string?>?, bool, string?)

Adds a field with a caller-supplied editor and value getter.

public FormBuilder AddField(string name, string label, IWindowControl editor, Func<string?> valueGetter, Func<string?, string?>? validate = null, bool required = false, string? hint = null)

Parameters

name string
label string
editor IWindowControl
valueGetter Func<string>
validate Func<string, string>
required bool
hint string

Returns

FormBuilder

AddMultilineEdit(string, string, string, int, string?)

Adds a multi-line text field backed by a MultilineEditControl.

public FormBuilder AddMultilineEdit(string name, string label, string initial = "", int height = 3, string? hint = null)

Parameters

name string
label string
initial string
height int
hint string

Returns

FormBuilder

AddRadio(string, string, params string[])

Adds a string radio-group field where each option string is both value and display label.

public FormBuilder AddRadio(string name, string label, params string[] options)

Parameters

name string
label string
options string[]

Returns

FormBuilder

AddRadio<T>(string, string, IEnumerable<(T Value, string Label)>, string?)

Adds a typed radio-group field.

public FormBuilder AddRadio<T>(string name, string label, IEnumerable<(T Value, string Label)> options, string? hint = null)

Parameters

name string
label string
options IEnumerable<(T Value, string Label)>
hint string

Returns

FormBuilder

Type Parameters

T

AddRow(params Action<FormControl>[])

Adds several fields onto a single grid row, packed side by side.

public FormBuilder AddRow(params Action<FormControl>[] fieldAdders)

Parameters

fieldAdders Action<FormControl>[]

Returns

FormBuilder

AddSection(string?, bool, bool)

Starts a collapsible (or plain) field group as a full-width header row. Pass null to end the current section.

public FormBuilder AddSection(string? title, bool collapsible = false, bool startCollapsed = false)

Parameters

title string
collapsible bool
startCollapsed bool

Returns

FormBuilder

AddSlider(string, string, double, double, double, string?)

Adds a numeric slider field.

public FormBuilder AddSlider(string name, string label, double min, double max, double initial, string? hint = null)

Parameters

name string
label string
min double
max double
initial double
hint string

Returns

FormBuilder

AddText(string, string, string, Func<string?, string?>?, bool, string?)

Adds a single-line text field backed by a PromptControl.

public FormBuilder AddText(string name, string label, string initial = "", Func<string?, string?>? validate = null, bool required = false, string? hint = null)

Parameters

name string
label string
initial string
validate Func<string, string>
required bool
hint string

Returns

FormBuilder

Build()

Wires any registered event handlers, applies deferred bindings, and returns the underlying FormControl.

public FormControl Build()

Returns

FormControl

OnCancel(Action)

Registers a callback to invoke when the form is cancelled. Subscribed to Cancelled immediately.

public FormBuilder OnCancel(Action handler)

Parameters

handler Action

Returns

FormBuilder

OnSubmit(Action<IReadOnlyDictionary<string, string?>>)

Registers a callback to invoke when the form is submitted successfully. Subscribed to Submitted immediately.

public FormBuilder OnSubmit(Action<IReadOnlyDictionary<string, string?>> handler)

Parameters

handler Action<IReadOnlyDictionary<string, string>>

Returns

FormBuilder

WithButtons(string, string, bool)

Adds a final, full-width button row (OK + optional Cancel).

public FormBuilder WithButtons(string ok = "OK", string cancel = "Cancel", bool showCancel = true)

Parameters

ok string
cancel string
showCancel bool

Returns

FormBuilder

WithColumnGap(int)

Sets the grid column gap.

public FormBuilder WithColumnGap(int gap)

Parameters

gap int

Returns

FormBuilder

WithName(string)

Sets the control's Name for lookup.

public FormBuilder WithName(string name)

Parameters

name string

Returns

FormBuilder

WithRowGap(int)

Sets the grid row gap.

public FormBuilder WithRowGap(int gap)

Parameters

gap int

Returns

FormBuilder

Operators

implicit operator FormControl(FormBuilder)

Implicit conversion so a FormBuilder can be used wherever a FormControl is expected.

public static implicit operator FormControl(FormBuilder builder)

Parameters

builder FormBuilder

Returns

FormControl