Add style, font, and card example packages; extend geometry and color

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
SpriteandClaude Sonnet 5.5 committed 2026-11-24 21:44:05 +00:00
1 parent 8c0685fe01
commit 1e2bcde532
26 files changed
+45666 -30

No files matched your search

+56 -28
View File
@@ -130,7 +130,8 @@ stays isolated.
| `geometry` | `geometry.rs`, `ContentMask` (window.rs) | pure | **done** |
| `color` | `color.rs`, `colors.rs` | pure | **done** (`colors.rs` theme defaults pending) |
| `scene` | `scene.rs`, `bounds_tree.rs`, `AtlasTile` (platform.rs) | pure | **done** (see deviations) |
| `style` | `style.rs`, `styled.rs`, Refineable | pure | next |
| `font` | `Font`, `FontWeight`, `FontStyle`, `FontFeatures`, `FontFallbacks` (text_system.rs) | pure | **done** (descriptors only) |
| `style` | `style.rs`, `styled.rs`, Refineable, gpui_macros style helpers | pure | **done** (generated by `tools/gen_style.py`) |
| `layout` | `taffy.rs` (+ a taffy port) | pure | next |
| `keymap` | `keymap.rs`, `keymap/*`, `platform/keystroke.rs` | pure | planned |
| `action` | `action.rs` | pure | planned |
@@ -146,6 +147,7 @@ stays isolated.
| `renderer/software` | (new; optional) | pure | candidate |
| `renderer/wgpu` | `gpui_wgpu` | native (+ js WebGPU) | later |
| `platform/native/*` | `gpui_macos`, `gpui_linux`, `gpui_windows` | native only | later |
| `examples/*` | `examples/*` | executables | `card` (headless, prints a scene report) |
| `elements/*` | `elements/{text,img,svg,list,uniform_list,anchored,deferred,canvas,animation}.rs` | pure | later |
A facade package (`experiments/gpui` re-exporting the common API, similar to
@@ -331,7 +333,7 @@ gantt
- **M0 (this PR).** `geometry`, `color`, and `scene`: units, rects, colors,
primitives, the bounds tree, layers, batching, and replay.
- **M1: style.**
- **M1: style (done).**
- `Style`, `TextStyle`, `Fill`, `BoxShadow`, and the enums (`Display`,
`Position`, `Overflow`, flex and alignment enums, `Visibility`,
`CursorStyle`, `WhiteSpace`, and so on).
@@ -423,30 +425,56 @@ gantt
---
## 7. Open design questions
### Deviations taken in M1 (style)
- `Style`, `TextStyle` and all nested refinements are immutable values.
`Style::refined` returns a new style. Only `StyleRefinement` (what
`Styled::style()` returns) is mutable, because it is the builder.
Nested updates are written as `style.text = { ..style.text, color: ... }`.
- `Styled` is one trait with 3,213 methods: about 140 hand-written in
`src/style/styled.mbt`, the rest generated as GPUI's macros would generate
them. GPUI's `text_style()` accessor (`&mut TextStyleRefinement`) is
omitted.
- `impl Into<X>` parameters became trait objects: `&IntoLength`,
`&IntoDefiniteLength`, `&IntoAbsoluteLength`, `&IntoHsla`, and `&IntoFill`.
- `AlignSelf`, `JustifyContent`, and the other alias types are not separate
types. Fields use `AlignItems` and `AlignContent` directly.
- `combine_highlights` takes and returns `Array[HighlightRange]` rather than
iterators. Ranges covered by several highlights combine them in the order
the highlights were given; GPUI uses HashSet iteration order.
- The refinement `Cascade` and `Style::paint` (which needs `Window`) wait for
M6. The conversion to taffy styles waits for M2.
1. **Entity liveness without `Drop`.** Should entities be released explicitly
(`release()`, or ownership through windows and views)? The alternative is
for strong handles to be ordinary GC references and drop GPUI's release
semantics (`on_release`, dropped-entity cleanup), which is simpler but
diverges. *Recommendation: explicit release for entities that have release
listeners or are observed, with views released when their window closes.*
2. **Text shaping on the web.** Shape with `moon_cosmic`, which is pure,
deterministic, the same on every backend, matches upstream `gpui_web`, and
needs bundled fonts. Or use browser Canvas `measureText`/`fillText`, which
gives system fonts and is quick to build, but has no glyph-level shaping
output and cannot be tested headless. *Recommendation: `moon_cosmic`, with
Canvas text only as an emoji/CJK fallback, as upstream does.*
3. **Layout engine.** Vendor and fix `moon_taffy` 0.5 (which needs toolchain
fixes, and whose API differs from taffy 0.15), or port taffy 0.15's
algorithms directly. *Recommendation: vendor `moon_taffy` now and upstream
the fixes.*
4. **First renderer.** Canvas2D on js (fastest to pixels), WebGPU on js
(closest to GPUI, reusing the WGSL shaders), or a pure software rasterizer
(golden-image tests on every backend). *Recommendation: Canvas2D first,
WebGPU second.*
5. **API surface naming.** Keep GPUI names verbatim where possible (`div()`,
`px()`, `rems()`, `.flex().p_2().bg(...)`), so Rust GPUI code ports
mechanically? *Recommendation: yes.*
6. **Module name.** `experiments/gpui` for now; publishing to mooncakes would
need an owner namespace.
## 7. Design decisions
Decided on 2026-11-24, following the recommendations below.
1. **Entity liveness without `Drop`.** Entities with release listeners or
observers are released explicitly. Views are released when their window
closes.
2. **Text shaping on the web.** Shape with `moon_cosmic`, which is pure, the
same on every backend, and matches upstream `gpui_web`, using bundled
fonts. Canvas text is used only as an emoji/CJK fallback, as upstream does.
3. **Layout engine.** Vendor `moon_taffy`, fix it for the current toolchain,
and send the fixes upstream.
4. **First renderer.** Canvas2D on js first, then WebGPU reusing GPUI's WGSL
shaders.
5. **API surface naming.** Keep GPUI names verbatim (`div()`, `px()`,
`rems()`, `.flex().p_2().bg(...)`), so GPUI code ports mechanically.
6. **Module name.** `experiments/gpui` for now. Publishing to mooncakes
needs an owner namespace; revisit before the first release.
## 8. Toolchain notes (moon 0.1.20261119)
- Trait methods are callable with dot syntax only after an explicit
`pub extend Type with Trait::{m1, m2}`. A type parameter with several
bounds needs `Trait::method(x)`. This is why every `Styled` implementor
needs the generated `extend` list.
- Derives use `#derive(...)` before the declaration.
- `extend` is a keyword (so `Bounds::extend` became `Bounds::extend_by`), and
`try?` was removed.
- `moon fmt` migrates code to the newest syntax: it writes `impl T with fn m`
and turns `Int` into `Int32`. Generators must accept the formatted form.
Always run `python3 tools/gen_style.py && moon fmt` together.
- A value converts implicitly to a trait object (`&IntoLength`) at a call
site. That is how GPUI's `impl Into<Length>` parameters are expressed.
- Test-only imports go in `import { ... } for "test"` in `moon.pkg`.