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).
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)
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
This PR is stacked on #1. Its base is
feat/geometry-color-scene, so the diff shows only M1. Retarget it tomainonce #1 is merged.What's here
style(gpuistyle.rs,styled.rs,refineable, and thegpui_macrosstyle macros):StyleandTextStyle, immutable, with gpui's defaults.StyleRefinement(the mutable builder) andTextStyleRefinement, withrefine,refined,copyandis_some.Styledtrait with all 3,213 fluent methods:src/style/styled.mbt.w/h/m*/p*/gap*/insetfamilies with_neg_variants,rounded*,border*, andcursor_*.BoxShadow,Fill,HighlightStylewithcombine_highlights, andObjectFit.overflow_maskandis_border_visible.font:Font,FontWeight,FontStyle,FontFeaturesandFontFallbacks(descriptors only).geometry:IntoLength,IntoDefiniteLengthandIntoAbsoluteLength, which stand in for gpui'simpl 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.GridPlacementandGridLocation.color:IntoHsla, andHashforHsla.tools/gen_style.pyreplaces gpui's Rust macros. Its output is committed, and regenerating followed bymoon fmtgives no diff.src/examples/cardis a runnable headless example (moon run src/examples/card --target js). It resolves a card styled with the fluent API, paints it into aSceneand prints the batches. It is snapshot-tested.Testing
moon check --target allandmoon test --target allpass: 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_combinationandtest_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
styled_generated.mbtis about 31k lines and the package.mbtiabout 6.8k lines. Checking all four targets still takes about 5 seconds.CascadeandStyle::paintneedWindow(M6).🤖 Generated with Claude Code