Skip to content

ElementRef

A ref is a handle on a rendered element, and the only way to read where an element ended up on screen or to move a container's scroll position. Every class on this page is reached through one.

ElementRef

final class Phui\Refs\ElementRef

A handle on a rendered element. Declared with the #[Ref] attribute and attached to a node with ref().

php
isBound(): bool

Returns whether the ref is attached to a rendered element. False before the first render.

php
scroll(): ScrollApi

Returns the ScrollApi for the bound element.

php
layout(): LayoutApi

Returns the LayoutApi for the bound element.

ScrollApi

final class Phui\Layout\ScrollApi

Reads and moves a scrollable container's viewport.

php
offset(): Point

Returns the current scroll offset.

php
viewport(): Size

Returns the size of the visible region.

php
content(): Size

Returns the size of the full scrollable content.

php
by(int $dx, int $dy): void

Moves the offset by $dx columns and $dy rows.

php
to(int $x, int $y): void

Moves the offset to an absolute position.

php
intoView(int $index, ?AlignmentType $align = null): void

Scrolls the child at $index into the visible region. By default it scrolls the least it can, leaving a child that is already visible where it is. Pass an AlignmentType to place the child at a fixed spot instead.

LayoutApi

final readonly class Phui\Layout\LayoutApi

php
rect(): Rect

Returns the element's box on screen, including its border and padding.

php
contentRect(): Rect

Returns the box available to the element's content, inside its border and padding.

Rect

final class Phui\Layout\Rect

php
__construct(
    public Point $position,
    public Size $size,
    public ?Size $minSize = null,
    public ?Size $maxSize = null,
)

Creates a rectangle from a position and size, with optional clamps.

php
contains(int $x, int $y): bool

Returns whether the cell at $x, $y falls inside the rectangle.

php
intersect(Rect $other): Rect

Returns the overlap between this rectangle and $other.

Point

final class Phui\Layout\Point

php
__construct(
    public int $x = 0,
    public int $y = 0,
)

Creates a column and row position.

Size

final class Phui\Layout\Size

php
__construct(
    public ?int $width = null,
    public ?int $height = null,
)

Creates a width in columns and height in rows. Either may be null when undetermined.

Released under the MIT License.