Skip to main content

FocusRing class

Namespace: Arlecchino.Focus · Assembly: Arlecchino

The cycle of focusable elements inside one view: Tab and Shift+Tab move between them, and everything else goes to the one holding the focus. A ring is itself focusable, so rings nest.

public sealed class FocusRing : IArlecchinoFocusable

Implements IArlecchinoFocusable

Constructors

MemberSummary
FocusRing(ArlecchinoKeymap)Creates an empty ring.

Properties

MemberSummary
CurrentThe focused element, or null when the ring is empty.
IndexPosition of the focused element.
IsFocusedWhether the ring itself holds the focus, which a view's own ring does from the start. It passes that on to the element it left the focus with, so nothing inside an unfocused ring draws as active.
ItemsThe elements, in the order they were added.

Methods

MemberSummary
Add(IArlecchinoFocusable)Adds an element. The first one added starts focused.
Focus(IArlecchinoFocusable)Moves the focus to a particular element, if it belongs to this ring.
FocusNext()Moves the focus to the next element, wrapping around at the end.
FocusPrevious()Moves the focus to the previous element, wrapping around at the start.
Handle(KeyPress)Moves the focus on the field keys, and otherwise hands the key to the focused element.
HandleMouse(MouseEvent)Offers the event to each element and moves the focus to whichever one claims it, so a click both selects a pane and acts inside it.
Hints()What the focused element wants the hints box to show, asked down the chain: a ring answers for the ring inside it, which answers for the widget inside that.
MoveFocus(FocusDirection)Moves the focus one element along without wrapping, for a ring nested in another one. At either end the step is left to the ring outside, and this one keeps its place.

Constructors in detail

FocusRing(ArlecchinoKeymap)

public FocusRing(ArlecchinoKeymap keymap);

Creates an empty ring.

Parameters

NameTypeDescription
keymapArlecchinoKeymapWhere the keys that move the focus come from.

Properties in detail

Current

public IArlecchinoFocusable? Current { get; }

The focused element, or null when the ring is empty.

Type IArlecchinoFocusable

Index

public int Index { get; }

Position of the focused element.

Type int

IsFocused

public bool IsFocused { get; set; }

Whether the ring itself holds the focus, which a view's own ring does from the start. It passes that on to the element it left the focus with, so nothing inside an unfocused ring draws as active.

Type bool

Items

public IReadOnlyList<IArlecchinoFocusable> Items { get; }

The elements, in the order they were added.

Type IReadOnlyList<T><IArlecchinoFocusable>

Methods in detail

Add(IArlecchinoFocusable)

public void Add(IArlecchinoFocusable item);

Adds an element. The first one added starts focused.

Parameters

NameTypeDescription
itemIArlecchinoFocusableThe element to add.

Focus(IArlecchinoFocusable)

public void Focus(IArlecchinoFocusable item);

Moves the focus to a particular element, if it belongs to this ring.

Parameters

NameTypeDescription
itemIArlecchinoFocusableThe element to focus.

FocusNext()

public void FocusNext();

Moves the focus to the next element, wrapping around at the end.

FocusPrevious()

public void FocusPrevious();

Moves the focus to the previous element, wrapping around at the start.

Handle(KeyPress)

public ViewRoute Handle(KeyPress key);

Moves the focus on the field keys, and otherwise hands the key to the focused element.

Parameters

NameTypeDescription
keyKeyPressThe key that was pressed.

Returns ViewRoute — The route the element asked for, or ViewRoute.None.

HandleMouse(MouseEvent)

public ViewRoute HandleMouse(MouseEvent mouse);

Offers the event to each element and moves the focus to whichever one claims it, so a click both selects a pane and acts inside it.

Parameters

NameTypeDescription
mouseMouseEventThe event, in frame coordinates.

Returns ViewRoute — The route the element asked for, or ViewRoute.None.

Hints()

public ValueTuple<string, string>[] Hints();

What the focused element wants the hints box to show, asked down the chain: a ring answers for the ring inside it, which answers for the widget inside that.

Returns ValueTuple<T1, T2><string, string>[] — The hints of the focused element, empty when there are none.

MoveFocus(FocusDirection)

public bool MoveFocus(FocusDirection direction);

Moves the focus one element along without wrapping, for a ring nested in another one. At either end the step is left to the ring outside, and this one keeps its place.

Parameters

NameTypeDescription
directionFocusDirectionWhich way the focus is going.

Returns bool — Whether the focus moved inside this ring.