M1: style — Style/StyleRefinement, generated Styled API, font, card example #2

Merged
nandi merged 1 commits from feat/style into feat/geometry-color-scene 2026-11-24 21:53:39 +00:00
Owner

This PR is stacked on #1. Its base is feat/geometry-color-scene, so the diff shows only M1. Retarget it to main once #1 is merged.

What's here

  • style (gpui style.rs, styled.rs, refineable, and the gpui_macros style macros):
    • Style and TextStyle, immutable, with gpui's defaults.
    • StyleRefinement (the mutable builder) and TextStyleRefinement, with refine, refined, copy and is_some.
    • The Styled trait with all 3,213 fluent methods:
      • 132 hand-written in src/style/styled.mbt.
      • The rest generated exactly as gpui's macros generate them: the w/h/m*/p*/gap*/inset families with _neg_ variants, rounded*, border*, and cursor_*.
    • Enums: display, flex, alignment, overflow, cursor and grid, plus BoxShadow, Fill, HighlightStyle with combine_highlights, and ObjectFit.
    • overflow_mask and is_border_visible.
  • font: Font, FontWeight, FontStyle, FontFeatures and FontFallbacks (descriptors only).
  • geometry:
    • IntoLength, IntoDefiniteLength and IntoAbsoluteLength, which stand in for gpui's impl Into<…> parameters. MoonBit coerces to the trait object at the call site, so .w(px(10.0)), .w(rems(2.0)) and .w(relative(0.5)) all work.
    • Point/Size/Edges/CornersRefinement.
    • GridPlacement and GridLocation.
  • color: IntoHsla, and Hash for Hsla.
  • tools/gen_style.py replaces gpui's Rust macros. Its output is committed, and regenerating followed by moon fmt gives no diff.
  • src/examples/card is a runnable headless example (moon run src/examples/card --target js). It resolves a card styled with the fluent API, paints it into a Scene and prints the batches. It is snapshot-tested.
  • Docs:
    • PORTING.md records the design decisions (§7, now decided), the M1 deviations (§6) and toolchain notes (§8).
    • The README covers the example and the generated code.

Testing

moon check --target all and moon test --target all pass: 62 tests on each of wasm, wasm-gc, js and native.

Some tests are ported from gpui: test_text_style_refinement, test_basic_highlight_style_combination and test_combine_highlights. New tests cover refinement semantics, the generated helper values against gpui's scale, overflow_mask, ObjectFit, the conversions and the geometry refinements.

Notes

  • The generated code is large: styled_generated.mbt is about 31k lines and the package .mbti about 6.8k lines. Checking all four targets still takes about 5 seconds.
  • Not ported yet:
    • The refinement Cascade and Style::paint need Window (M6).
    • The taffy conversions belong to M2.

🤖 Generated with Claude Code

This PR is stacked on #1. Its base is `feat/geometry-color-scene`, so the diff shows only M1. Retarget it to `main` once #1 is merged. ## What's here - **`style`** (gpui `style.rs`, `styled.rs`, `refineable`, and the `gpui_macros` style macros): - `Style` and `TextStyle`, immutable, with gpui's defaults. - `StyleRefinement` (the mutable builder) and `TextStyleRefinement`, with `refine`, `refined`, `copy` and `is_some`. - The `Styled` trait with all **3,213** fluent methods: - 132 hand-written in `src/style/styled.mbt`. - The rest generated exactly as gpui's macros generate them: the `w`/`h`/`m*`/`p*`/`gap*`/`inset` families with `_neg_` variants, `rounded*`, `border*`, and `cursor_*`. - Enums: display, flex, alignment, overflow, cursor and grid, plus `BoxShadow`, `Fill`, `HighlightStyle` with `combine_highlights`, and `ObjectFit`. - `overflow_mask` and `is_border_visible`. - **`font`**: `Font`, `FontWeight`, `FontStyle`, `FontFeatures` and `FontFallbacks` (descriptors only). - **`geometry`**: - `IntoLength`, `IntoDefiniteLength` and `IntoAbsoluteLength`, which stand in for gpui's `impl Into<…>` parameters. MoonBit coerces to the trait object at the call site, so `.w(px(10.0))`, `.w(rems(2.0))` and `.w(relative(0.5))` all work. - `Point`/`Size`/`Edges`/`CornersRefinement`. - `GridPlacement` and `GridLocation`. - **`color`**: `IntoHsla`, and `Hash` for `Hsla`. - **`tools/gen_style.py`** replaces gpui's Rust macros. Its output is committed, and regenerating followed by `moon fmt` gives no diff. - **`src/examples/card`** is a runnable headless example (`moon run src/examples/card --target js`). It resolves a card styled with the fluent API, paints it into a `Scene` and prints the batches. It is snapshot-tested. - **Docs:** - PORTING.md records the design decisions (§7, now decided), the M1 deviations (§6) and toolchain notes (§8). - The README covers the example and the generated code. ## Testing `moon check --target all` and `moon test --target all` pass: 62 tests on each of wasm, wasm-gc, js and native. Some tests are ported from gpui: `test_text_style_refinement`, `test_basic_highlight_style_combination` and `test_combine_highlights`. New tests cover refinement semantics, the generated helper values against gpui's scale, `overflow_mask`, `ObjectFit`, the conversions and the geometry refinements. ## Notes - The generated code is large: `styled_generated.mbt` is about 31k lines and the package `.mbti` about 6.8k lines. Checking all four targets still takes about 5 seconds. - Not ported yet: - The refinement `Cascade` and `Style::paint` need `Window` (M6). - The taffy conversions belong to M2. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
nandi added 1 commit 2026-11-24 21:52:08 +00:00
nandi merged commit ae3fd7da55 into feat/geometry-color-scene 2026-11-24 21:53:39 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: experiments/moon-gpui#2