Skip to content

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);
  • Lengths are logical units; the host multiplies them by the display scale.
  • Colors are 0xAARRGGBB integers: 0xFF2563EB is opaque blue, 0x00000000 is transparent.
  • A Style can 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.

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:

src/app.css
:root {
--background: #F6F6F3;
--surface: #FFFFFF;
--text: #17201C;
--muted: #5B655F;
--accent: #2F6B55;
}
Text { font-family: sans-serif; }

: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; }
.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.

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.

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.

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.

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:

src/app.css
: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.

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 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.