Components
The interface of a PAM Desktop application is a tree of elements returned by components. A component is a PHP class with reactive state; its render() method returns elements such as Column, Text and Button, which the host turns into native views. You can build that tree in plain PHP or write it as a .pam.php template with tags and scoped CSS. Both compile to the same immutable elements.
Writing a component
Section titled “Writing a component”<?php
declare(strict_types=1);
namespace App\Components;
use Pam\Desktop\Attributes\State;use Pam\Desktop\Component;use Pam\Desktop\Style;use Pam\Desktop\UI\Button;use Pam\Desktop\UI\Column;use Pam\Desktop\UI\Text;
final class Counter extends Component{ #[State] public int $count = 0;
public function render(): Column { return Column::make( Text::make("Count: {$this->count}")->style(new Style(fontSize: 18)), Button::make('Increment')->onPress(function (): void { $this->count++; }), )->style(new Style(padding: 24, gap: 16)); }}<?php
declare(strict_types=1);
namespace App\Components;
use Pam\Desktop\Attributes\State;use Pam\Desktop\Component;
final class Counter extends Component{ #[State] public int $count = 0;
public function increment(): void { $this->count++; }}?>
<template> <Column class="counter"> <Text class="value">Count: {{ $count }}</Text> <Button label="Increment" on:press="increment" /> </Column></template>
<style scoped> .counter { padding: 24px; gap: 16px; } .value { font-size: 18px; }</style>A template component is registered as a tag by App::components(), so other templates can use it as <Counter />. The Templates page is the full reference for the template syntax.
Conventions
Section titled “Conventions”-
Elements are created with a static
make()and are immutable: every method returns a modified copy, so calls chain. -
Containers take their children as arguments.
nullandfalsechildren are skipped, so conditions read naturally:Column::make(Text::make('Always here'),$this->loading ? ActivityIndicator::make() : null,); -
Give elements built in a loop a stable
key(), so they keep their identity and their native view when the list changes:$rows = [];foreach ($this->documents as $document) {$rows[] = Text::make($document->name)->key($document->id);} -
Sizes are logical units, independent of the display scale. Colors in PHP are
0xAARRGGBBintegers. -
Event handlers are closures or first-class callables (
$this->save(...)). They may change#[State]properties; the component renders again after the handler returns.
The elements live in Pam\Desktop\UI; Style and the enums (Align, Justify, ImageFit…) live in Pam\Desktop.
Layout
Section titled “Layout”Column stacks its children vertically, Row horizontally, and View is a plain box. All three take a Style with flexbox properties. Spacer::make(8) is an empty box of the given height, and Screen::make(...) is the root box of a route in a navigator.
Row::make( Column::make( Text::make('Timer'), Text::make("{$this->seconds} s"), )->style(new Style(flexGrow: 1)), View::make()->style(new Style(width: 56, height: 56, borderRadius: 16, backgroundColor: 0xFF2563EB)),)->style(new Style(padding: 16, gap: 12, alignItems: Align::Center));A box with flexGrow: 1 takes the space its siblings leave; the root of a screen uses it to fill the window. Grids, tables and inline formatting are covered in Layout.
Text::make('Invoices')->style(new Style(fontSize: 24, fontWeight: 700, textColor: 0xFF12161C));
Text::make($this->description) ->numberOfLines(2) ->selectable() ->style(new Style(fontSize: 16, lineHeight: 25));Text is shaped and drawn by the platform’s text engine. selectable() lets the user select and copy it. A paragraph limited with numberOfLines() ends with an ellipsis; ellipsize() moves it (TextEllipsizeMode::Head, Middle), drops it (Clip), or makes a single line that does not fit slide back and forth (Marquee). The host moves a marquee line; PHP runs nothing, and it stays still under reduced motion.
Text::rich() builds one paragraph from several runs, each with its own style:
Text::rich( 'Total: ', Text::make('$42.00')->style(new Style(fontWeight: 700)),);A nested run with padding, a border, or a background and a radius becomes an inline box, like a CSS <kbd>:
<Text>Press <Text class="kbd">Ctrl</Text>+<Text class="kbd">Enter</Text> to send</Text>Buttons and pressables
Section titled “Buttons and pressables”Button is a labelled push button. Without a background, border or text color of your own it gets a neutral native look that follows light and dark mode and reacts to hover and press.
Button::make('Delete') ->onPress($this->delete(...)) ->style(new Style(backgroundColor: 0xFFDC2626, textColor: 0xFFFFFFFF, borderRadius: 8));Pressable makes any content react to presses:
Pressable::make(Text::make($name)) ->onPress(fn () => $this->select($index)) ->onLongPress($this->rename(...)) ->cursor('pointer') ->tooltip("Open {$name}") ->style(new Style(paddingHorizontal: 12, height: 36, justifyContent: Justify::Center, borderRadius: 8));| Method | Meaning |
|---|---|
onPress, onLongPress, onDoubleTap |
The three press gestures. A handler that declares a PressEvent parameter receives the pointer position. |
onPressIn, onPressOut |
The pointer went down or up on the element. |
pressedOpacity, pressedScale, pressedBackgroundColor |
Feedback while pressed, animated by the host. |
hitSlop |
Extends the area that reacts beyond the box. |
delayLongPress |
How long a press is held before onLongPress (500 ms by default). |
A focused pressable is activated with Enter or Space. Hover events, tooltips, cursors and context menus work on every element.
Inputs
Section titled “Inputs”Input is a native text control: typing, selection, the clipboard and input methods are the system’s. PHP receives the text through onChange. Masks, currency and decimal formatting are applied by the host as the user types.
Input::make($this->name) ->placeholder('Your name') ->onChange(fn (string $value) => $this->name = $value) ->onSubmit($this->save(...));Forms & Input covers every option, keyboard handling and validation.
Switch and activity indicator
Section titled “Switch and activity indicator”Both are drawn and animated by the host:
Toggle::make($this->notifications)->onToggle(function (string $value): void { $this->notifications = $value === '1';});
ActivityIndicator::make($this->syncing);onToggle receives '1' or '0'. ActivityIndicator::make(false) stops and hides the indicator.
Images
Section titled “Images”Image::make('https://example.com/cover.jpg') ->fit(ImageFit::Cover) ->style(new Style(width: 200, height: 130, borderRadius: 14));
ImageBackground::make( 'asset://assets/header.jpg', Text::make('Children are laid out above the picture'),)->style(new Style(height: 150, padding: 20));Always give an image a size: it is decoded no larger than its box. Sources, caching and events are in Media & Web.
Scroll views
Section titled “Scroll views”Scroll (alias ScrollView) scrolls one child with the platform’s native scroll view: wheel, trackpad, scrollbars and keyboard all behave natively.
Scroll::make( Column::make(...$paragraphs)->style(new Style(padding: 24, gap: 12)),) ->onScroll(fn (string $offset) => $this->offset = (float) $offset) ->style(new Style(flexGrow: 1));| Method | Meaning |
|---|---|
horizontal() |
Scrolls horizontally. |
scrollEnabled(false) |
Disables user scrolling. |
showsIndicator(false) |
Hides the scrollbars. |
scrollRequest($serial, targetOffset: $y, animated: true) |
Scrolls from code each time $serial changes. |
onScroll, onEndReached |
The offset changed; the end of the content is near. |
refreshing(bool), onRefresh |
Refresh: on desktop the user asks for it with F5 or Ctrl+R (Cmd+R). |
A child marked stickyHeader() stays pinned to the top once scrolled past. For long collections use a virtualized list instead of a scroll view with thousands of children.
Modals and bottom sheets
Section titled “Modals and bottom sheets”A Modal is presented above the window content, with a backdrop. It stays in the tree; its second argument says whether it is visible.
Modal::make( Column::make( Text::make('Delete this project?'), Button::make('Keep')->onPress(fn () => $this->dialog = false), )->style(new Style(width: 340, padding: 20, gap: 12, borderRadius: 16, backgroundColor: 0xFFFFFFFF)), $this->dialog, ModalPresentation::Dialog,) ->animationType(ModalAnimationType::Fade) ->onRequestClose(fn () => $this->dialog = false);onRequestClose runs when the user presses Escape, goes back or clicks the backdrop. The host starts the exit animation at once and then tells PHP, which must clear the state that shows the modal. ModalPresentation is Dialog, FullScreen or Sheet. backdropBlurRadius frosts what is behind the backdrop (verified on Linux).
A BottomSheet is a modal anchored to the bottom edge; its snap points are fractions of the available height:
BottomSheet::make( Column::make( Text::make('Share with'), Button::make('Done')->onPress(fn () => $this->sheet = false), )->style(new Style(padding: 24, gap: 12, backgroundColor: 0xFFFFFFFF)), [0.45], 0, $this->sheet,)->onDismiss(fn () => $this->sheet = false);For a separate native window instead of an overlay, use the Window element; see Windows, Menus & Tray.
Elements described elsewhere
Section titled “Elements described elsewhere”| Element | Page |
|---|---|
Navigator, TabNavigator, shared transitions |
Navigation |
VirtualizedList, VirtualGrid, FlatList, SectionList |
Lists |
Image, ImageBackground, MediaPlayer, WebView, Canvas, DrawingCanvas |
Media & Web |
GestureDetector, Swipeable |
Animation & Gestures |
UI\Window, InteractionRegion, DragSource, DropTarget |
Windows, Menus & Tray |
Select, Autocomplete, DatePicker, Toast, SplitView, TreeView, CodeEditor, charts, Markdown, Terminal |
Bundled Packages |