Skip to main content

PaneTree class

Namespace: Arlecchino.Layout · Assembly: Arlecchino

A screen described once, by binary space partitioning: every branch hands its region to two halves, and every leaf is what goes in that half. It is built from PaneTree.Branch and PaneTree.Leaf.

_layout = Branch(Rows, 3,
Leaf(_toolbar),
Branch(Columns, 0.25,
Leaf(_tree, () => "files"),
Branch(Leaf(_editor, () => "editor"), Leaf(_log, () => "log")))).Gaps(inner: 1);

_focus = new FocusRing(options.Keymap);
_focus.AddAll(_layout.Focusables);

public void Draw() => _layout.Draw(_surface.Content);

public sealed class PaneTree

Properties

MemberSummary
CountHow many panes the tree draws.
InnerGapCells left empty between the two halves of every branch. Set by PaneTree.Gaps.
OuterGapCells left empty around the whole layout. Set by PaneTree.Gaps.

Methods

MemberSummary
AsFocusRing(ArlecchinoKeymap)Builds the focus ring of the screen from the tree, left before right and top before bottom. The tree keeps the ring, so PaneTree.HandleMouse can move the focus to the pane that was clicked.
Branch(PaneTree, PaneTree)A branch that halves the longer side of whatever region it is given, measured as the eye sees it. It can turn from columns into rows when the terminal is resized.
Branch(PaneSplit, PaneTree, PaneTree)A branch that cuts the way it is told and halves the space.
Branch(PaneSize, PaneTree, PaneTree)A branch of a given size that still cuts along the longer side, for a split that is uneven but has no reason to prefer an axis.
Branch(PaneSplit, PaneSize, PaneTree, PaneTree)A branch that says both: the space is cut the given way and each half goes to a subtree, which is itself either a branch or a leaf. Three bands is therefore a branch inside a branch.
Draw(SurfaceRegion)Draws every pane where the branches put it. This is the whole of a view's Draw when the screen is a tree.
Gaps(int, int)Sets the spacing of the whole layout, rather than of one branch, so a screen is loosened or tightened in one place. The names are the ones a tiling window manager uses.
HandleMouse(MouseEvent)Sends a mouse event to the pane it landed in, and moves the focus there when that pane claims it. The focus follows the click only for a tree that built its ring with PaneTree.AsFocusRing. csharp public ViewRoute HandleMouse(MouseEvent mouse) => _layout.HandleMouse(mouse);
Leaf(IArlecchinoWidget)A pane holding a widget, drawn into whatever region the tree gives it.
Leaf(IArlecchinoWidget, Func<string>)A pane holding a widget, in a box with a title. The box is drawn Theme.Active while the widget holds the focus and Theme.Info while it does not.
Leaf(Action<SurfaceRegion>)A pane the view draws itself, for the parts of a screen that are not a widget — a title, a box, a row of readouts.
Leaf(Action<SurfaceRegion>, Func<string>)A pane the view draws itself, in a box with a title.
Leaf()A pane that draws nothing, for space deliberately left blank.

Properties in detail

Count

public int Count { get; }

How many panes the tree draws.

Type int

InnerGap

public int InnerGap { get; }

Cells left empty between the two halves of every branch. Set by PaneTree.Gaps.

Type int

OuterGap

public int OuterGap { get; }

Cells left empty around the whole layout. Set by PaneTree.Gaps.

Type int

Methods in detail

AsFocusRing(ArlecchinoKeymap)

public FocusRing AsFocusRing(ArlecchinoKeymap keymap);

Builds the focus ring of the screen from the tree, left before right and top before bottom. The tree keeps the ring, so PaneTree.HandleMouse can move the focus to the pane that was clicked.

Parameters

NameTypeDescription
keymapArlecchinoKeymapWhere the keys that move the focus come from.

Returns FocusRing — A ring holding the panes that take the focus.

Branch(PaneTree, PaneTree)

public static PaneTree Branch(PaneTree first, PaneTree second);

A branch that halves the longer side of whatever region it is given, measured as the eye sees it. It can turn from columns into rows when the terminal is resized.

Parameters

NameTypeDescription
firstPaneTreeThe upper half, or the left one.
secondPaneTreeThe lower half, or the right one.

Returns PaneTree — The branch.

Branch(PaneSplit, PaneTree, PaneTree)

public static PaneTree Branch(PaneSplit split, PaneTree first, PaneTree second);

A branch that cuts the way it is told and halves the space.

Parameters

NameTypeDescription
splitPaneSplitWhich way to cut.
firstPaneTreeThe upper half, or the left one.
secondPaneTreeThe lower half, or the right one.

Returns PaneTree — The branch.

Branch(PaneSize, PaneTree, PaneTree)

public static PaneTree Branch(PaneSize size, PaneTree first, PaneTree second);

A branch of a given size that still cuts along the longer side, for a split that is uneven but has no reason to prefer an axis.

Parameters

NameTypeDescription
sizePaneSizeHow much of it the first half takes; the second half takes the rest. A count of cells when written as an int, a share of the space when written with a decimal point — 3 is three rows or columns, 0.3 is three tenths. See PaneSize.
firstPaneTreeThe upper half, or the left one.
secondPaneTreeThe lower half, or the right one.

Returns PaneTree — The branch.

Branch(PaneSplit, PaneSize, PaneTree, PaneTree)

public static PaneTree Branch(PaneSplit split, PaneSize size, PaneTree first, PaneTree second);

A branch that says both: the space is cut the given way and each half goes to a subtree, which is itself either a branch or a leaf. Three bands is therefore a branch inside a branch.

Parameters

NameTypeDescription
splitPaneSplitWhich way to cut.
sizePaneSizeHow much of it the first half takes; the second half takes the rest. A count of cells when written as an int, a share of the space when written with a decimal point — 3 is three rows or columns, 0.3 is three tenths. See PaneSize.
firstPaneTreeThe upper half, or the left one.
secondPaneTreeThe lower half, or the right one.

Returns PaneTree — The branch.

Draw(SurfaceRegion)

public void Draw(SurfaceRegion region);

Draws every pane where the branches put it. This is the whole of a view's Draw when the screen is a tree.

Parameters

NameTypeDescription
regionSurfaceRegionThe space to fill, usually surface.Content.

Gaps(int, int)

public PaneTree Gaps(int inner, int outer = 0);

Sets the spacing of the whole layout, rather than of one branch, so a screen is loosened or tightened in one place. The names are the ones a tiling window manager uses.

Parameters

NameTypeDescription
innerintCells left empty between the two halves of every branch.
outerintCells left empty around everything, inside the region handed to PaneTree.Draw.

Returns PaneTree — The same tree, so the call finishes the expression that built it.

HandleMouse(MouseEvent)

public ViewRoute HandleMouse(MouseEvent mouse);

Sends a mouse event to the pane it landed in, and moves the focus there when that pane claims it. The focus follows the click only for a tree that built its ring with PaneTree.AsFocusRing.

public ViewRoute HandleMouse(MouseEvent mouse) => _layout.HandleMouse(mouse);

Parameters

NameTypeDescription
mouseMouseEventThe event, in frame coordinates.

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

Leaf(IArlecchinoWidget)

public static PaneTree Leaf(IArlecchinoWidget widget);

A pane holding a widget, drawn into whatever region the tree gives it.

Parameters

NameTypeDescription
widgetIArlecchinoWidgetWhat goes in the pane.

Returns PaneTree — The leaf.

Leaf(IArlecchinoWidget, Func<string>)

public static PaneTree Leaf(IArlecchinoWidget widget, Func<string> title);

A pane holding a widget, in a box with a title. The box is drawn Theme.Active while the widget holds the focus and Theme.Info while it does not.

Parameters

NameTypeDescription
widgetIArlecchinoWidgetWhat goes in the pane.
titleFunc<TResult><string>What to write in the top border, as a delegate so a translated application translates it too.

Returns PaneTree — The leaf.

Leaf(Action<SurfaceRegion>)

public static PaneTree Leaf(Action<SurfaceRegion> draw);

A pane the view draws itself, for the parts of a screen that are not a widget — a title, a box, a row of readouts.

Parameters

NameTypeDescription
drawAction<T><SurfaceRegion>What to draw, given the region the pane was allotted.

Returns PaneTree — The leaf.

Leaf(Action<SurfaceRegion>, Func<string>)

public static PaneTree Leaf(Action<SurfaceRegion> draw, Func<string> title);

A pane the view draws itself, in a box with a title.

Parameters

NameTypeDescription
drawAction<T><SurfaceRegion>What to draw, given the room left inside the box.
titleFunc<TResult><string>What to write in the top border.

Returns PaneTree — The leaf.

Leaf()

public static PaneTree Leaf();

A pane that draws nothing, for space deliberately left blank.

Returns PaneTree — The leaf.