Skip to content

Commit 8190ec6

Browse files
committed
fix(ui-macos): #185 CALayer shadow + visual_test infrastructure (v0.5.324)
CALayer shadows on macOS were invisible because set_shadow() never set masksToBounds:false. iOS/tvOS/visionOS mirror impls all set it; macOS was the lone outlier. One-line fix in widgets/mod.rs::set_shadow. Also adds: - docs/examples/ui/styling/visual_test.ts: comprehensive 13-section visual styling test (colors, borders, padding, shadow, gradient, opacity, typography, buttons, inputs, controls, image symbols, states, runtime colors) - docs/examples/ui/styling/visual_test.spec.md: LLM-debuggable per-cell expected-values manifest with "Visible signature" strings for screenshot verification - scripts/run_visual_test_check.sh: drift check that asserts the .ts's labeled() rows and the spec's '### N.' headers stay 1:1 - .github/workflows/test.yml: wire drift check into CI after the existing UI styling matrix step Verified via 3-round shadow_repro.ts (high-contrast yellow shadow): round 1 inconclusive low-contrast, round 2 confirmed missing, round 3 post-fix confirmed working. Web/wasm + iOS-sim cross-compile clean.
1 parent a976a99 commit 8190ec6

7 files changed

Lines changed: 540 additions & 2 deletions

File tree

.github/workflows/test.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,18 @@ jobs:
368368
git diff --exit-code -- docs/src/ui/styling-matrix.md \
369369
|| (echo "docs/src/ui/styling-matrix.md regenerated; commit the diff" && exit 1)
370370
371+
# Visual styling test ↔ spec consistency (#185 follow-up).
372+
# `docs/examples/ui/styling/visual_test.ts` is the canonical
373+
# comprehensive visual test app; `visual_test.spec.md` documents
374+
# each cell's expected visible signature for human/LLM-aided
375+
# screenshot verification. The two files must stay in lockstep
376+
# — adding a row to the .ts without updating the spec silently
377+
# breaks the verification flow. The actual cross-platform
378+
# compile-test of visual_test.ts is handled by the existing
379+
# run_doc_tests.sh loop downstream.
380+
- name: Visual styling test ↔ spec consistency
381+
run: ./scripts/run_visual_test_check.sh
382+
371383
# Fastify end-to-end integration (#174): launches a Perry-compiled
372384
# Fastify server as a background process, curls four routes covering
373385
# simple GET, path params, POST with JSON body + reply.code(), and

CLAUDE.md

Lines changed: 2 additions & 1 deletion
Large diffs are not rendered by default.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ opt-level = "s" # Optimize for size in stdlib
109109
opt-level = 3
110110

111111
[workspace.package]
112-
version = "0.5.323"
112+
version = "0.5.324"
113113
edition = "2021"
114114
license = "MIT"
115115
repository = "https://github.com/PerryTS/perry"

crates/perry-ui-macos/src/widgets/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,13 @@ pub fn set_shadow(
754754
// already provides this layout-compatible struct.
755755
let offset = objc2_core_foundation::CGSize::new(offset_x, offset_y);
756756
let _: () = objc2::msg_send![layer, setShadowOffset: offset];
757+
// CALayer shadows are clipped by `masksToBounds`. iOS
758+
// sets this in its mirror impl; the macOS version was
759+
// missing it — the bug visible in
760+
// `docs/examples/ui/styling/visual_test.ts` section 4
761+
// before this fix landed (FFI args correct per the IR
762+
// dump but no visible shadow).
763+
let _: () = objc2::msg_send![layer, setMasksToBounds: false];
757764
}
758765
}
759766
}
Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
# Visual styling test — verification spec
2+
3+
Companion to `visual_test.ts`. This document describes every cell in
4+
the test app along with its **expected visual signature** so a tester
5+
(human or LLM) can mechanically compare a screenshot against
6+
expectations and flag regressions cell-by-cell.
7+
8+
## How to use
9+
10+
1. Compile + run the test on the platform you want to verify:
11+
```bash
12+
./target/release/perry compile docs/examples/ui/styling/visual_test.ts -o /tmp/styling_test
13+
./tmp/styling_test
14+
```
15+
2. Capture the window (any screenshot tool, or via geisterhand's
16+
`/screenshot` endpoint where wired).
17+
3. Walk this spec top-to-bottom. For each cell, confirm the screenshot
18+
matches the visible signature. Anything that doesn't match → file
19+
an issue against the underlying styling matrix row.
20+
21+
For LLM-assisted verification, send the screenshot + this file to
22+
the model and ask "for each row, list any cells that don't match
23+
their expected visible signature."
24+
25+
## Window meta
26+
27+
- **Title bar:** "Perry Styling Visual Test"
28+
- **Dimensions:** 880 × 940 (resizable on platforms that support it)
29+
- **Header:** large bold black "Perry Styling Visual Test" (20pt),
30+
followed by a small gray subtitle, then a horizontal divider line.
31+
- **Body:** vertical stack of 13 numbered sections, each with a small
32+
gray label above and a horizontal row of widgets below.
33+
34+
## Section-by-section expectations
35+
36+
### 1. Colors
37+
38+
Five horizontally-arranged labels, all with white text, padding 8,
39+
border-radius 4. Every cell should be a clearly-distinct solid color:
40+
41+
| # | Text | Expected background | Visible signature |
42+
|---|------|---|---|
43+
| 1 | `hex` | pure red `#FF0000` | white "hex" on FULL red box |
44+
| 2 | `named` | pure blue `#0000FF` | white "named" on FULL blue box |
45+
| 3 | `object` | medium green `(0, 0.6, 0, 1)` | white "object" on green box, slightly darker than pure green |
46+
| 4 | `alpha` | red @ 50% alpha — composited over window background | white "alpha" on PINK / muted-red box (alpha shows through) |
47+
| 5 | `runtime` | `#3B82F6` from a `themeBlue` variable | white "runtime" on bright cobalt-blue box (Phase C step 7 path) |
48+
49+
If cell 5 renders as anything other than the same blue as cell 2 of
50+
gradient row, the runtime parseColor path is broken — cells 1-4 use
51+
compile-time, cell 5 uses runtime, both should produce identical
52+
visual results for the same color value.
53+
54+
### 2. Borders + corners
55+
56+
Four labels with transparent background + visible border, varying
57+
width and corner-radius:
58+
59+
| # | Text | Border | Radius | Visible signature |
60+
|---|------|---|---|---|
61+
| 1 | `1px-4r` | thin black | slightly rounded | thin black outline, gentle corners |
62+
| 2 | `3px-12r` | medium blue | well-rounded | thicker blue outline, pronounced rounding |
63+
| 3 | `heavy` | thick red | square | bold red outline, sharp 90° corners |
64+
| 4 | `pill` | thin gray | very rounded | nearly pill-shaped, hairline outline |
65+
66+
**Windows note:** issue [#210](https://github.com/PerryTS/perry/issues/210) — borders are stub-with-state on Windows
67+
(FFI accepts the params, no paint pass). Cells 1-4 may render as
68+
plain text labels with no visible border on Windows until #210
69+
lands. **GTK4:** all 4 should render correctly.
70+
71+
### 3. Padding
72+
73+
Two labels with `#EEE` light-gray background:
74+
75+
| # | Text | Padding | Visible signature |
76+
|---|------|---|---|
77+
| 1 | `p:12` | uniform 12px | text centered with even gap on all sides |
78+
| 2 | `p:4-24` | top:4 right:24 bottom:4 left:24 | text vertically tight, wide horizontal margins |
79+
80+
Cell 2's box should be visibly WIDER than cell 1 (more horizontal
81+
padding) but SHORTER (less vertical padding).
82+
83+
### 4. Shadow
84+
85+
Three light-gray labels with rounded corners + black/colored shadows.
86+
The shadow visibility test — if no shadow is visible, the platform's
87+
shadow path isn't wired.
88+
89+
> **Note on bg color choice:** these cells use light gray `#F3F4F6` rather than
90+
> pure white intentionally. CALayer's drop shadow is visually invisible when
91+
> the card is the same color as the window background, even when the FFI is
92+
> correctly applied — the bug originally observed before the macOS
93+
> `setMasksToBounds: false` fix landed.
94+
95+
| # | Text | Shadow color | Blur | Offset | Visible signature |
96+
|---|------|---|---|---|---|
97+
| 1 | `soft` | black @ 100% (full alpha) | 12 | (0, 4) | soft dark blur below light-gray box |
98+
| 2 | `hard` | black | 0 | (4, 4) | sharp dark offset to bottom-right of light-gray box |
99+
| 3 | `blue` | blue | 16 | (0, 6) | soft blue glow below light-gray box |
100+
101+
**Windows note:** issue [#210](https://github.com/PerryTS/perry/issues/210) — shadow is stub-with-state on
102+
Windows. Cells 1-3 will look like plain white boxes with no shadow
103+
until #210 lands. **Android:** shadow direction may differ from
104+
iOS/macOS (Android's elevation derives direction from device-level
105+
light source, not the offset; the offset is intentionally ignored —
106+
same shadow color/blur should appear under all 3 cells).
107+
108+
### 5. Gradient
109+
110+
Three labels with linear gradients at different angles. White text:
111+
112+
| # | Text | Gradient | Angle | Visible signature |
113+
|---|------|---|---|---|
114+
| 1 | `` | blue→purple | 90° (left to right) | left edge blue, right edge purple, smooth horizontal blend |
115+
| 2 | `` | red→orange | 180° (top to bottom) | top edge red, bottom edge orange, smooth vertical blend |
116+
| 3 | `` | green→cyan | 135° (diagonal) | top-left green, bottom-right cyan, diagonal blend |
117+
118+
### 6. Opacity
119+
120+
Four `#3B82F6` blue labels at decreasing opacity:
121+
122+
| # | Text | Opacity | Visible signature |
123+
|---|------|---|---|
124+
| 1 | `100` | 1.0 | full bright cobalt blue |
125+
| 2 | `75` | 0.75 | slightly faded, still clearly blue |
126+
| 3 | `50` | 0.5 | half-transparent, washed-out blue |
127+
| 4 | `25` | 0.25 | very faint, almost ghosted |
128+
129+
**GTK4 / Windows:** opacity is wired on GTK4 (real `Widget::set_opacity`)
130+
but stub-with-state on Windows ([#210](https://github.com/PerryTS/perry/issues/210)) — Windows cells 2-4
131+
will all render at full opacity until #210 lands.
132+
133+
### 7. Typography
134+
135+
Seven text labels in a row, all black text, demonstrating font axes:
136+
137+
| # | Text | Style | Visible signature |
138+
|---|------|---|---|
139+
| 1 | `normal` | regular 14pt | baseline reference |
140+
| 2 | `bold` | weight 700 | visibly heavier strokes than cell 1 |
141+
| 3 | `under` | underline | "under" with horizontal line below |
142+
| 4 | `strike` | strikethrough | "strike" with horizontal line through middle |
143+
| 5 | `12pt` | smaller | visibly smaller than cell 1 |
144+
| 6 | `18pt` | larger | visibly larger than cell 1 |
145+
| 7 | `mono` | monospaced | distinctive monospace glyph shapes |
146+
147+
**Windows:** text decoration is stub-with-state ([#210](https://github.com/PerryTS/perry/issues/210)) — cells 3
148+
and 4 will render as plain "under" / "strike" without the line
149+
decoration until #210 lands.
150+
151+
### 8. Buttons
152+
153+
Four buttons in a row:
154+
155+
| # | Label | Style | Visible signature |
156+
|---|------|---|---|
157+
| 1 | `Default` | none | platform-native button (rounded rect on macOS, square on Windows, etc.) |
158+
| 2 | `Styled` | blue bg, white text, 6r radius, 8 padding | flat blue rectangle, white "Styled" |
159+
| 3 | `Outlined` | 2px blue border, 6r, 8 padding | transparent rectangle with blue outline |
160+
| 4 | `Disabled` | enabled: false | grayed out, won't respond to clicks |
161+
162+
### 9. Inputs
163+
164+
Two text input controls. Verify both render at all + accept focus:
165+
166+
| # | Type | Placeholder | Visible signature |
167+
|---|------|---|---|
168+
| 1 | `TextField` | "Type here…" | single-line input box with gray placeholder |
169+
| 2 | `SecureField` | "Password" | single-line input that masks typed chars |
170+
171+
### 10. Controls
172+
173+
Three control widgets:
174+
175+
| # | Type | Setup | Visible signature |
176+
|---|------|---|---|
177+
| 1 | `Toggle` | label "Enable" | iOS-style switch (on macOS: checkbox-style; iOS: pill switch) |
178+
| 2 | `Slider` | min 0, max 100 | horizontal slider track with movable thumb |
179+
| 3 | `ProgressView` | indeterminate | spinning indicator OR horizontal bar showing progress |
180+
181+
### 11. Image (SF Symbols)
182+
183+
Three symbol icons. SF Symbols only render on Apple platforms; on
184+
GTK4 / Android / Web you'll get a fallback or empty space.
185+
186+
| # | Symbol | Visible signature |
187+
|---|------|---|
188+
| 1 | `star.fill` | filled 5-pointed star |
189+
| 2 | `heart.fill` | filled heart shape |
190+
| 3 | `circle.fill` | filled circle |
191+
192+
**Non-Apple platforms:** these may render as empty placeholders or
193+
default fallback icons. That's expected; Perry's image-by-symbol is
194+
SF-Symbols-specific.
195+
196+
### 12. States
197+
198+
Three labels demonstrating visibility flags:
199+
200+
| # | Text | State | Visible signature |
201+
|---|------|---|---|
202+
| 1 | `visible` | normal | green box with white "visible" |
203+
| 2 | `hidden!` | hidden: true | **NOTHING — should NOT appear** |
204+
| 3 | `opacity-0` | opacity: 0 | **NOTHING — should NOT appear** (or invisible blue box that takes layout space) |
205+
206+
If cells 2 or 3 are visible, the state-based hiding is broken on
207+
that platform. Note: cell 3 (`opacity: 0`) may still occupy layout
208+
space on some backends (the box is invisible but pushes siblings).
209+
That's correct behavior — opacity-0 ≠ hidden.
210+
211+
### 13. Runtime colors
212+
213+
Two runtime-resolved color cells (Phase C step 7 path):
214+
215+
| # | Text | Color source | Visible signature |
216+
|---|------|---|---|
217+
| 1 | `var-hex` | `themeBlue` = `"#3B82F6"` | white text on cobalt-blue box (matches color row cell 5) |
218+
| 2 | `var-bad` | `themePurple` = `"rebeccapurple"` (NOT a Perry-supported named color) | white text on box with **fallback color** — black with alpha 1.0 because `parse_css_color` returns None for unknown named colors and the runtime returns 0.0 for r/g/b channels and 1.0 for alpha (see `crates/perry-runtime/src/color_parse.rs::js_color_parse_channel`) |
219+
220+
If cell 2 renders as the actual purple color of `rebeccapurple`,
221+
that means the runtime path supports MORE named colors than the spec
222+
documents (good — file a docs update). If cell 2 renders as
223+
something else entirely, the runtime path is broken.
224+
225+
## Per-platform expected status
226+
227+
Platform → Expected sections rendering correctly, given the matrix
228+
state at v0.5.310+:
229+
230+
| Platform | Sections expected fully ✓ | Sections expected ✗ (with reason) |
231+
|----------|--------------------------|-----------------------------------|
232+
| **macOS / iOS / tvOS / visionOS / watchOS** | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 | none |
233+
| **Android** | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13 | 11 (no SF Symbols), 4 (shadow direction may differ — offset ignored on Android by design) |
234+
| **GTK4** | 1, 2, 3, 5, 6, 7, 9, 10, 12, 13 | 4 (some cells may be flat — depends on GTK theme), 8 (cell 3 outlined button may not show border due to [#202](https://github.com/PerryTS/perry/issues/202) `widget.on_click` etc gaps), 11 (no SF Symbols) |
235+
| **Windows** | 1, 3, 5, 7 (cells 1, 2, 5, 6, 7), 9, 10, 12 (cell 1), 13 cell 1 | 2 (border stubs), 4 (shadow stubs), 6 (opacity stubs), 7 cells 3-4 (text decoration stubs), 8 cell 3 (border stub) — all blocked by [#210](https://github.com/PerryTS/perry/issues/210) |
236+
| **Web** | 1, 2, 3, 4, 5, 6, 7, 9, 10, 12, 13 | 11 (no SF Symbols, fallback may show empty boxes) |
237+
238+
## When something fails
239+
240+
If a cell doesn't match its visible signature on a platform where
241+
the matrix says it should:
242+
243+
1. Confirm the matrix entry: `./target/debug/styling-matrix --gen` then
244+
inspect `docs/src/ui/styling-matrix.md` for the relevant prop row.
245+
2. If matrix says `Wired` but visual fails → file a new issue
246+
referencing this spec section + the platform.
247+
3. If matrix says `Stub` (Windows deferred-paint family) → expected,
248+
tracked in [#210](https://github.com/PerryTS/perry/issues/210).
249+
4. If matrix says `Missing` (GTK4 4 rows) → expected, tracked in [#202](https://github.com/PerryTS/perry/issues/202).

0 commit comments

Comments
 (0)