Nodes
Classes in the Phui\Nodes namespace. A node is a description of part of the UI. Nodes are built with fluent setters that return static, so calls chain.
Node
abstract class Phui\Nodes\Node
Base class for every node. Extended by ElementNode and ComponentNode.
getKey(): stringReturns the node's reconciliation key.
setKey(?string $key): staticSets the reconciliation key. null restores positional identity.
static when(bool $condition, Node $node): NodeReturns $node, rendered when $condition is true and hidden when it is false. A hidden node keeps its slot among its siblings across rebuilds, so it needs no key, and it renders nothing and takes no space.
static each(
array $items,
callable $render,
callable $key,
): arrayMaps $items to an array of nodes, assigning every node a key and guaranteeing those keys are unique among siblings. Both callables receive ($item, $index), indexed from zero over the reindexed array. $render returns a node, or a falsy value to omit that item. $key returns that node's key, cast to string, and throws InvalidArgumentException if the value is empty or repeats.
Node::each(
$this->users,
fn (User $user) => Text::make($user->name),
fn (User $user) => (string) $user->id,
)ElementNode
abstract class Phui\Nodes\ElementNode extends Node
Base class for nodes that draw directly to the screen. Extended by Text, Container, Canvas and VirtualContainer.
Sizing
grow(): staticFills the available space on both axes.
growX(): staticFills the available width.
growY(): staticFills the available height.
fit(): staticSizes to the content on both axes.
fitX(): staticSizes to the content width.
fitY(): staticSizes to the content height.
fixedX(int $value): staticSets the width to $value columns.
fixedY(int $value): staticSets the height to $value rows.
percentX(int $value): staticSets the width to $value percent of the parent's content box.
percentY(int $value): staticSets the height to $value percent of the parent's content box.
minSizeX(int $value): staticClamps the width to at least $value columns.
minSizeY(int $value): staticClamps the height to at least $value rows.
maxSizeX(int $value): staticClamps the width to at most $value columns.
maxSizeY(int $value): staticClamps the height to at most $value rows.
Spacing
padding(
?int $all = null,
?int $top = null,
?int $right = null,
?int $bottom = null,
?int $left = null,
): staticSets padding inside the border. $all sets all four edges, and any named edge passed alongside it overrides that edge.
margin(
?int $all = null,
?int $top = null,
?int $right = null,
?int $bottom = null,
?int $left = null,
): staticSets margin outside the border. $all sets all four edges, and any named edge passed alongside it overrides that edge.
paddingX(int $value): staticSets the left and right padding.
paddingY(int $value): staticSets the top and bottom padding.
marginX(int $value): staticSets the left and right margin.
marginY(int $value): staticSets the top and bottom margin.
Borders
border(
BorderCharSet|string|null $chars = new BorderCharSet,
bool $top = true,
bool $right = true,
bool $bottom = true,
bool $left = true,
): staticDraws a border on each enabled edge, occupying one cell per drawn edge. $chars accepts a BorderCharSet, a string naming a preset, or null to remove the border.
borderTitle(
string|StyledString|null $title = null,
string|StyledString|null $subtitle = null,
): staticSets the border's title and subtitle. null leaves that value unchanged.
borderColour(
Colour|string|null $line = null,
Colour|string|null $bg = null,
): staticSets the border's line and background colours. null leaves that value unchanged.
Colour and utilities
bgColour(Colour|string|null $colour): staticSets the background colour. null clears it.
tw(string $classes): staticApplies space-separated Tailwind-style utilities.
Mouse handlers
onMouseDown(Closure $handler): staticRegisters a handler called with a MouseClickEvent when the mouse button presses down on the node.
onMouseUp(Closure $handler): staticRegisters a handler called with a MouseClickEvent when the mouse button releases over the node.
onScroll(Closure $handler): staticRegisters a handler called with a MouseScrollEvent.
onMouseMove(Closure $handler): staticRegisters a handler called with a MouseMoveEvent.
clearEventHandlers(?string $eventType = null): staticRemoves handlers for $eventType, or all handlers when null.
Refs
ref(ElementRef $ref): staticBinds an ElementRef to this node.
getRef(): ?ElementRefReturns the bound ref, or null when none is bound.
ContainerNode
interface Phui\Nodes\ContainerNode
Implemented by nodes that lay out children. Adds the following to the ElementNode surface.
children(array|Closure $children): staticSets the children. A Closure(Space): array is re-evaluated on each rebuild.
axis(AxisType|string $type): staticLays children out along the horizontal or vertical axis.
gap(int $value): staticSets the space between children.
alignX(AlignmentType|string $type): staticAligns children horizontally: start, center or end.
alignY(AlignmentType|string $type): staticAligns children vertically: start, center or end.
Scrolling
scroll(
ScrollType|string|null $type = ScrollType::Thin,
): staticEnables scrolling on both axes. $type selects the scrollbar style: thin, thick, double or dotted. null scrolls without drawing a scrollbar. A scrollbar is painted only when its axis overflows.
scrollX(
ScrollType|string|null $type = ScrollType::Thin,
): staticEnables scrolling on the x axis.
scrollY(
ScrollType|string|null $type = ScrollType::Thin,
): staticEnables scrolling on the y axis.
scrollColour(
Colour|string|null $thumb = null,
Colour|string|null $track = null,
): staticSets the scrollbar thumb and track colours on both axes.
scrollXColour(
Colour|string|null $thumb = null,
Colour|string|null $track = null,
): staticSets the scrollbar thumb and track colours on the x axis.
scrollYColour(
Colour|string|null $thumb = null,
Colour|string|null $track = null,
): staticSets the scrollbar thumb and track colours on the y axis.
Text
final class Phui\Nodes\Text extends ElementNode
Renders a string. Sizes to its content by default.
static make(
StyledString|string|Closure $content = '',
?string $key = null,
): selfCreates a text node. A Closure(Space) is re-evaluated on each rebuild; text built from a Space must have an externally determined width, set by growX() or fixedX().
content(
StyledString|string|Closure $content,
): staticReplaces the content.
getContent(): StyledString|stringReturns the current content.
align(
AlignmentType|string $alignment = AlignmentType::Start,
): staticAligns lines within the node's width: start, center or end.
wrap(
TextWrapType|string $type = TextWrapType::Word,
): staticSets wrapping: none, character or word.
colour(Colour|string $colour): staticSets the foreground colour.
bold(bool $enabled = true): staticToggles bold.
dim(bool $enabled = true): staticToggles dim.
italic(bool $enabled = true): staticToggles italic.
underline(bool $enabled = true): staticToggles underline.
reverse(bool $enabled = true): staticSwaps the foreground and background colours.
strikethrough(bool $enabled = true): staticToggles strikethrough.
Container
final class Phui\Nodes\Container extends ElementNode implements ContainerNode
Lays out children along an axis. Horizontal by default.
static make(
array $children = [],
?string $key = null,
): selfCreates a container node.
Container::make([
Text::make('Name'),
Text::make('Value'),
])->axis('vertical')->gap(1)Space
final readonly class Phui\Nodes\Space
The space available for content as of the last settled layout. Passed to content and children closures so they can build for the room they are given. When the available space differs from the size the content was built for, the closure is re-invoked until the two agree.
public int $widthThe available width in columns.
public int $heightThe available height in rows.
isResolved(): boolReturns false on the first pass, before the slot has been laid out. Builders can return a placeholder until it is true.
BorderCharSet
final readonly class Phui\Style\BorderCharSet
The six characters a border is drawn from, passed to border().
__construct(
public string $horizontal = '─',
public string $vertical = '│',
public string $topLeft = '┌',
public string $topRight = '┐',
public string $bottomLeft = '└',
public string $bottomRight = '┘',
)Creates a character set. Defaults to the square set.
static square(): self
static squareHeavy(): self
static rounded(): self
static roundedHeavy(): self
static double(): selfReturn the built-in character sets.
static fromString(string $name): selfReturns the built-in set named $name: square, square-heavy, rounded, rounded-heavy or double. Case-insensitive and trimmed. Throws InvalidArgumentException for any other name.
Enums
ScrollType
enum Phui\Style\ScrollType: string
The scrollbar style passed to scroll(). Cases: Thin, Thick, Double, Dotted.
getYThumbChar(): string
getYTrackChar(): string
getXThumbChar(): string
getXTrackChar(): stringReturn the characters the case draws its thumb and track from, per axis.
Value enums
enum Phui\Style\AxisType: string
The axis passed to axis(). Cases: Horizontal, Vertical.
enum Phui\Style\AlignmentType: string
The alignment passed to alignX(), align() and intoView(). Cases: Start, Center, End.
enum Phui\Style\TextWrapType: string
The wrapping mode passed to wrap(). Cases: None, Character, Word.