Class Component
- Namespace
- MiniTui
- Assembly
- MiniTui.dll
A piece of UI that holds state, handles keys and renders itself every frame (§9.1). Components stay
immediate-mode: a parent renders its children explicitly with ctx.Render(child, buf, rect), which also
records where the child is for the mouse.
[SuppressMessage("Design", "CA1001:Types that own disposable fields should be disposable", Justification = "The lifetime source is disposed at unmount, which the screen and overlay stacks control.")]
public abstract class Component
- Inheritance
-
Component
- Derived
- Inherited Members
Remarks
Every callback runs on the UI thread. A parent mounts before its children; children unmount before their parent, in reverse add order, and Lifetime is cancelled before OnUnmount() runs.
Constructors
Component()
Create a component.
protected Component()
Properties
App
The app, from mount to unmount.
protected App App { get; }
Property Value
Exceptions
- InvalidOperationException
The component isn't mounted.
Area
The area the component was last rendered in through Render(Component, Buffer, Rect), or by the app (the
top screen and overlays). default (an empty rect) until then.
public Rect Area { get; }
Property Value
CapturesText
True for text inputs: while this component is the innermost focused one, its ancestors' and the app's
single-character bindings (without Ctrl or Alt) are skipped, so typing q doesn't quit.
public virtual bool CapturesText { get; }
Property Value
Focus
This component's focusable children, in tab order. Empty by default.
protected FocusScope Focus { get; }
Property Value
HasSelection
True while the component has something selected to copy, such as a selectable ScrollState: Ctrl+C then goes to its HandleKey(ConsoleKeyInfo) instead of quitting, as it does for one that captures text.
public virtual bool HasSelection { get; }
Property Value
Keys
This component's key bindings, tried after HandleKey(ConsoleKeyInfo).
public KeyMap Keys { get; }
Property Value
KeysGroup
The heading for this component's bindings in the help overlay.
public virtual string KeysGroup { get; }
Property Value
Lifetime
Cancelled when the component unmounts.
protected CancellationToken Lifetime { get; }
Property Value
Exceptions
- InvalidOperationException
The component isn't mounted.
Methods
AddChild<T>(T)
Add a child. If this component is mounted, the child mounts now (and activates, if this one is active).
protected T AddChild<T>(T child) where T : Component
Parameters
childT
Returns
- T
Type Parameters
T
Exceptions
- InvalidOperationException
The child already has a parent.
From(Action<Buffer, Rect, RenderContext>, Func<ConsoleKeyInfo, bool>?, bool)
An inline component, for small apps that want focus handling without writing a class.
public static Component From(Action<Buffer, Rect, RenderContext> render, Func<ConsoleKeyInfo, bool>? handleKey = null, bool capturesText = false)
Parameters
renderAction<Buffer, Rect, RenderContext>handleKeyFunc<ConsoleKeyInfo, bool>capturesTextbool
Returns
HandleKey(ConsoleKeyInfo)
Handle a key before Keys. Return true if handled.
public virtual bool HandleKey(ConsoleKeyInfo key)
Parameters
keyConsoleKeyInfo
Returns
HandleMouse(MouseEvent)
Handle a mouse event inside this component's Area (1.x spec §4.7). Return true if handled; otherwise the event goes on to the component's parent, and is dropped if nothing handles it. A press has already focused the component when this runs.
public virtual bool HandleMouse(MouseEvent mouse)
Parameters
mouseMouseEvent
Returns
HandlePaste(string)
Handle pasted text, such as with Paste(string). Return true if handled; otherwise the paste goes on to the component's parent, and is dropped if nothing handles it.
public virtual bool HandlePaste(string text)
Parameters
textstring
Returns
Load<T>(Loadable<T>, Func<CancellationToken, Task<T>>)
Start a load that's cancelled, and whose result is ignored, once this component unmounts.
protected void Load<T>(Loadable<T> target, Func<CancellationToken, Task<T>> fetch)
Parameters
targetLoadable<T>fetchFunc<CancellationToken, Task<T>>
Type Parameters
T
OnActivated()
Called when its screen (or overlay) becomes the top one.
protected virtual void OnActivated()
OnDeactivated()
Called when its screen is covered or popped (or its overlay closes).
protected virtual void OnDeactivated()
OnMount()
Called when the component is mounted, before its children.
protected virtual void OnMount()
OnUnmount()
Called when the component unmounts, after its children and after Lifetime is cancelled.
protected virtual void OnUnmount()
RemoveChild(Component)
Remove a child: it deactivates, unmounts and leaves Focus.
protected void RemoveChild(Component child)
Parameters
childComponent
Exceptions
- InvalidOperationException
It isn't a child of this component.
Render(Buffer, Rect, RenderContext)
Draw the component. Called every frame its parent renders it.
public abstract void Render(Buffer buf, Rect area, RenderContext ctx)
Parameters
bufBufferareaRectctxRenderContext