Styling
Every element is styled with native properties. You set them in PHP with an immutable Pam\Desktop\Style value, or in the <style> block of a template with CSS that compiles to the same properties. CSS in PAM Desktop is not a browser engine: there is no cascade across the whole application and no layout by the web’s rules beyond what is documented here. In return, state styles such as :hover and :focus are applied by the host with no round trip to PHP.
use Pam\Desktop\Style;
$card = new Style( padding: 16, gap: 12, borderRadius: 14, backgroundColor: 0xFFFFFFFF, borderWidth: 1, borderColor: 0xFFE5E7EB,);
Column::make( Text::make('Title')->style(new Style(fontSize: 16, fontWeight: 600, textColor: 0xFF111827)), Text::make('Subtitle')->style(new Style(fontSize: 13, textColor: 0xFF6B7280)),)->style($card);<template> <Column class="card"> <Text class="title">Title</Text> <Text class="subtitle">Subtitle</Text> </Column></template>
<style scoped> .card { padding: 16px; gap: 12px; border-radius: 14px; background-color: #FFFFFF; border-width: 1px; border-color: #E5E7EB; } .title { font-size: 16px; font-weight: 600; color: #111827; } .subtitle { font-size: 13px; color: #6B7280; }</style>The Style value
Section titled “The Style value”- Lengths are logical units; the host multiplies them by the display scale.
- Colors are
0xAARRGGBBintegers:0xFF2563EBis opaque blue,0x00000000is transparent. - A
Stylecan be created once and shared by many elements. - Calling
style()again layers the new style over the previous one: properties it sets win, the others are kept.
| Group | Properties |
|---|---|
| Size | width, height, minWidth, minHeight, maxWidth, maxHeight, widthPercent, heightPercent, maxWidthPercent, maxHeightPercent, aspectRatio |
| Flex container | flexDirection, flexWrap, alignItems, justifyContent, gap, layoutDirection |
| Flex item | flexGrow, flexShrink, alignSelf |
| Padding and margin | padding, paddingHorizontal, paddingVertical, paddingLeft…; margin, marginHorizontal, marginVertical, marginLeft…, marginLeftAuto |
| Position | positionType, left, top, right, bottom, their Percent variants, zIndex |
| Background and border | backgroundColor, borderRadius and per-corner radii, borderWidth and per-side widths, borderColor, borderStyle |
| Shadow | shadowColor, shadowOffsetX, shadowOffsetY, shadowBlurRadius, shadowSpreadRadius, elevation |
| Compositing | opacity, overflow, visible, pointerEvents, blurRadius |
| Transform | translationX, translationY, translationXPercent, scaleX, scaleY, rotation (degrees) |
| Text | textColor, fontSize, fontWeight, fontFamily, fontStyle, lineHeight, letterSpacing, textAlign, textDecoration, textTransform, numberOfLines |
| Images and inputs | imageFit, tintColor, placeholderColor |
| Grid | gridColumns, gridMinColumnWidth, gridTemplate, gridColumnGap, gridRowGap, gridSpan, gridOffset, gridOrder and breakpoint variants |
| Pointer | cursor |
Enumerated values are PHP enums in Pam\Desktop: Align, Justify, FlexDirection, FlexWrap, PositionType, Overflow, TextAlignment, TextDecoration, TextTransform, FontStyle, BorderStyle, PointerEvents, ImageFit.
Row::make(/* … */)->style(new Style( alignItems: Align::Center, justifyContent: Justify::SpaceBetween, overflow: Overflow::Hidden,));An element with opacity: 0 is invisible but still takes clicks, as in CSS. pointerEvents takes an element out of hit testing: PointerEvents::None for the element and its children, BoxNone for the element only, BoxOnly for its children only.
CSS in templates
Section titled “CSS in templates”The <style> block of a .pam.php component and the stylesheets it imports compile to the same native properties. Selectors are classes, tags and state pseudo-classes; @media and @container rules apply while their condition holds. A property with no meaning for native views (outline, appearance) is accepted and ignored; anything else that does not compile is an error that names the file and line.
src/app.css holds rules and tokens shared by every screen. The skeleton declares the design tokens there:
:root { --background: #F6F6F3; --surface: #FFFFFF; --text: #17201C; --muted: #5B655F; --accent: #2F6B55;}
Text { font-family: sans-serif; }State selectors
Section titled “State selectors”:pressed, :hover, :focus, :focus-visible, :focus-within, :disabled, :checked, :selected, :active, :loading, :error and :empty declare styles for a state. The host applies them without calling PHP:
.card { opacity: 1; }.card:pressed { opacity: 0.76; transform: scale(0.98); }
.search { border: 1px solid #CBD5E1; border-radius: 8px; }.search:focus-within { border-color: #2563EB; }The host applies opacity, scale, translation, background, text and border colors and elevation for a state. When several states are active, hover applies first, then focus, then pressed.
A hover on an ancestor styles a descendant, so row actions can appear on hover with no PHP at all:
.message .actions { opacity: 0; transition: opacity 150ms; }.message:hover .actions { opacity: 1; }Responsive rules
Section titled “Responsive rules”.aside { width: 350px; flex-basis: 0; }
@media (max-width: 1280px) { .aside { width: 100%; flex-basis: auto; }}A rule inside a query replaces an earlier declaration of the same CSS property while the query matches. A class may also be declared only inside a query; elements that use it get nothing while the condition is false.
Scrollbars
Section titled “Scrollbars”The scrollbar properties apply to ScrollView and VirtualizedList:
.page { scrollbar-gutter: stable; scrollbar-width: thin; }.column { scrollbar-gutter: stable; scrollbar-width: 8px; scrollbar-color: rgba(255, 255, 255, .08) transparent; }.strip { scrollbar-width: none; }scrollbar-gutter: stable reserves the bar’s width so content never moves when the bar appears. With a gutter and a width or color, the bar is a classic one drawn in the gutter; without a gutter the platform’s overlay scrollbar stays.
Text properties
Section titled “Text properties”overflow-wrap, word-break, hyphens: auto, white-space: nowrap and text-overflow: ellipsis follow CSS. max-width: 52ch measures ch in the element’s own font. line-height: normal is the font’s ascent plus descent, as in Chromium. placeholder-color (or ::placeholder { color }) colors input placeholders.
Support differs by backend:
| Feature | Linux | macOS | Windows |
|---|---|---|---|
font-family lists, packaged fonts |
Yes | Yes (in a VM) | Written, not run |
overflow-wrap, word-break |
Yes | No: word boundaries only | Written, not run |
hyphens: auto |
Yes | No | No |
| Scrollbar gutter, width and color | Yes | Yes | Written, not run |
backdrop-filter: blur() |
Yes | Written, not verified on screen | Written, not run |
font-family takes a CSS list; each backend uses the first family it has:
.title { font-family: "Space Grotesk", system-ui, sans-serif; }.code { font-family: ui-monospace, Menlo, "Liberation Mono", monospace; }.brand { font-family: "asset://fonts/Inter.ttf", system-ui; }| Entry | Resolves to |
|---|---|
system-ui, sans-serif |
The interface font: the GTK font setting, San Francisco, Segoe UI. |
monospace, serif |
The system’s monospace and serif fonts. |
asset://… |
A font file shipped with the application. At most 32 files, 8 MiB each. |
| Any other name | An installed family; one that is missing is skipped. |
The package ships the Lucide icon font, so icons need no asset:
<Icon name="message-square" font="Lucide" size="18" />Register another icon font once at startup with Icon::register('Ionicons', 'asset://assets/fonts/Ionicons.ttf', 'assets/fonts/Ionicons.json'), where the JSON maps names to codepoints.
Desktop additions
Section titled “Desktop additions”cursor(), tooltip(), onHoverIn() and onHoverOut() exist on every element:
Pressable::make(Text::make('Export')) ->cursor('pointer') ->tooltip('Export (Ctrl+Shift+E)') ->onHoverIn(fn () => $this->hovered = true) ->onHoverOut(fn () => $this->hovered = false);Cursor keywords are the CSS ones: pointer, text, grab, grabbing, not-allowed, crosshair, wait, move, ew-resize and ns-resize. The tooltip is the platform’s native one.
Dark mode
Section titled “Dark mode”In CSS
Section titled “In CSS”Redeclare the tokens inside a prefers-color-scheme query. Every rule that reads them follows the scheme, state blocks included, and a change restyles the tree:
:root { --bg: #FFFFFF; --fg: #15172B; }@media (prefers-color-scheme: dark) { :root { --bg: #13141B; --fg: #F2F3F8; } }
.page { background-color: var(--bg); color: var(--fg); }oklch(), lab() and color-mix() resolve to sRGB like Chromium.
In PHP
Section titled “In PHP”Pam\Desktop\Appearance reads and sets the appearance. Reads are synchronous:
use Pam\Desktop\Appearance;use Pam\Desktop\AppearanceMode;use Pam\Desktop\UserInterfaceAppearance;
#[State]public bool $dark = false;
public function mount(): void{ $this->dark = Appearance::isDark(); Appearance::onChange(function (UserInterfaceAppearance $scheme): void { $this->dark = $scheme === UserInterfaceAppearance::Dark; });}
public function useDarkTheme(): void{ Appearance::set(AppearanceMode::Dark); // stored and restored at the next launch}| Call | Meaning |
|---|---|
Appearance::isDark() |
Whether the effective scheme is dark. |
Appearance::current() |
UserInterfaceAppearance::Light or Dark. |
Appearance::mode() |
The stored preference: AppearanceMode::System, Light or Dark. |
Appearance::set($mode) |
Chooses and persists the preference; native chrome follows it. |
Appearance::onChange($listener) |
Runs on every change of the scheme or the preference. Returns an id for unsubscribe(). |
With AppearanceMode::System the application follows the operating system while it runs. On Linux the setting is the desktop portal’s color-scheme, with the GTK theme as fallback.
Text scale
Section titled “Text scale”Text renders at its font size multiplied by a text scale: the system’s accessibility scale times a multiplier your application may set.
use Pam\Desktop\System\Accessibility;
Accessibility::setTextScale(1.25); // an in-app "text size" setting
Text::make('12')->allowFontScaling(false);Text::make('Heading')->maxFontSizeMultiplier(1.3);setTextScale($multiplier, $maxSystemScale) accepts 0.5 to 3. On desktop the scale is stored and applied at once. TextScalePolicy::set(maximum: 1.6, display: 1.3, displayFontSize: 18) sets application-wide caps once, before the first render.
Next steps
Section titled “Next steps”- Layout for grids, tables and inline formatting.
- Animation & Gestures to animate style changes.
- Accessibility for roles, labels and focus.