Layout
The host lays every frame out in Rust before it touches a native view. Flexbox is the default model, as in React Native: every box is a flex container, columns stack vertically and rows horizontally. On top of it PAM Desktop implements the CSS features that screens ported from the web rely on most: fractional grid tracks, tables, inline formatting and sticky positioning. Text is measured by the platform, so a box always fits exactly the text that is painted.
Flexbox
Section titled “Flexbox”use Pam\Desktop\Align;use Pam\Desktop\Justify;use Pam\Desktop\Style;use Pam\Desktop\UI\Button;use Pam\Desktop\UI\Column;use Pam\Desktop\UI\Row;use Pam\Desktop\UI\Text;
Column::make( Row::make( Text::make('Invoices')->style(new Style(fontSize: 20, fontWeight: 700, flexGrow: 1)), Button::make('New')->onPress($this->create(...)), )->style(new Style(alignItems: Align::Center, gap: 12)), $this->table(),)->style(new Style(flexGrow: 1, padding: 24, gap: 16));The same in a stylesheet:
.page { flex: 1; padding: 24px; gap: 16px; }.toolbar { flex-direction: row; align-items: center; gap: 12px; }.toolbar-title { flex: 1; font-size: 20px; font-weight: 700; }Columnstacks children vertically andRowhorizontally; in CSS,flex-directionchooses.flexGrow: 1takes the space siblings leave. Give the root of a screenflexGrow: 1so it fills the window.- Native boxes default to a 0 minimum size. Author
min-width: autowhere a flex item must not shrink below its content, as in a browser. - Percentages need a parent with a definite size:
widthPercent: 50in PHP,width: 50%in CSS.
Fractional tracks
Section titled “Fractional tracks”grid-template-columns accepts bounded fractional tracks:
.form-layout { grid-template-columns: minmax(0, 1.8fr) minmax(300px, .9fr); gap: 12px;}
@media (max-width: 900px) { .form-layout { grid-template-columns: 1fr; }}Weights are proportional after gutters are subtracted. A track whose share falls below its minimum stays at that minimum and the rest is redistributed. The grammar is positive <number>fr, minmax(<length>, <number>fr) and repeat(count, track), at most 64 tracks. Intrinsic tracks (auto, min-content, max-content, percentages, subgrid) fail explicitly instead of silently becoming equal columns.
In PHP:
use Pam\Desktop\GridTracks;use Pam\Desktop\UI\Grid;
Grid::make($details, $summary) ->tracks(GridTracks::fromCss('2fr 1fr')) ->gutter(12);Equal columns
Section titled “Equal columns”For equal columns, Grid::make(...)->columns(3) or Style(gridColumns: 3); gridMinColumnWidth reduces the column count when the container is too narrow. For a long, scrolling grid of items, use a virtualized grid so only the visible cells are built.
Tables
Section titled “Tables”display: table and its row, row-group and cell values lay a container out as a CSS table, so a screen ported from HTML keeps its rules:
.table { display: table; border-collapse: collapse; }.head { display: table-row; }.th { display: table-cell; padding: 9px 14px; font-weight: 600; }.body { display: table-row-group; } /* a VirtualizedList works too */.tr { display: table-row; }.td { display: table-cell; padding: 9px 14px; border-top: 1px solid #E5E7EB; vertical-align: middle; }<Column class="table"> <Row class="head"> <Text class="th">Customer</Text> <Text class="th">Total</Text> </Row> <Column class="body"> <Row p-for="$order in $orders" p-key="$order->id" class="tr"> <Text class="td">{{ $order->customer }}</Text> <Text class="td">{{ $order->total }}</Text> </Row> </Column></Column>table-layout: auto(the default) sizes columns like browsers do;fixedtakes the widths of the first row.- A row is as tall as its tallest cell;
vertical-align: top | middle | bottomplaces a cell’s content. border-collapse: collapsefollows CSS 2.1: each grid line is the widest of the borders meeting on it, painted once.- A virtualized row group measures only the rows that are mounted.
Inline formatting
Section titled “Inline formatting”display: inline, inline-block and inline-flex make a box inline-level, so a parent lays it on lines like a browser’s block container. Chips, badges and <kbd>-style keys stay on the line of text around them:
.cell { padding: 10px 14px; font-size: 16px; line-height: 24px; }.code { display: inline; padding: 4px 8px; font-size: 12px; background-color: #314158; }.status { display: inline-flex; padding: 4px 12px; align-items: center; }vertical-align accepts baseline, middle, text-top, text-bottom, top and bottom.
Positioning
Section titled “Positioning”position: absolute with top, right, bottom and left places a box relative to its parent, as in React Native. zIndex orders siblings.
position: sticky keeps a box in flow and holds it at its top inset while its parent is on screen, like a table header that stays above the rows:
.head { position: sticky; top: 0; background-color: #FFFFFF; }The box moves with a transform when the scroll offset changes, with no layout pass.
Scroll views
Section titled “Scroll views”A ScrollView scrolls one axis. overflow: auto on a ScrollView scrolls its content on both axes in the same viewport, like a browser element, which suits wide tables:
<ScrollView class="grid-viewport"> <Column class="table">…</Column></ScrollView>.grid-viewport { flex: 1; overflow: auto; scrollbar-gutter: stable; }Window size
Section titled “Window size”Read the window size reactively in a component with useWindowDimensions(), or style by width with @media (max-width: …) and @container queries. Prefer queries: they are evaluated by the framework on resize, with no handler of yours involved.
Checking layout against a web build
Section titled “Checking layout against a web build”When a screen reimplements a web page, start the application with PAM_DESKTOP_DUMP_FRAMES=/tmp/frames.json to write every node’s frame after each layout change, and compare it with Chromium’s boxes. See Debugging.