M6 elements and window: Element/Render/views, headless Window, div, canvas

- input: mouse events, modifiers, dispatch phases.
- window: Element / AnyElement / IntoElement, Render / AnyView (entities
  render as elements), listener(), empty(); Window with the draw cycle
  (render, layout to fill the viewport, prepaint, paint, finish) and phase
  checks; content-mask / element-offset / opacity / element-id stacks;
  element state across frames (ElementStateKey); hitboxes, hit testing,
  occlusion; mouse dispatch (capture + bubble, stop_propagation); hover-
  and notify-driven invalidation of rendered views; painting: paint_quad
  with device-pixel snapping, drop/inset shadows, paint_path, paint_style
  (port of Style::paint).
- elements: div() (Styled, children, hover, mouse down/up/move/scroll,
  clicks with element state, occlude, overflow clipping, opacity) and
  canvas(); Styled extend lists generated by tools/gen_style.py.
- app: observe_notifications hook used by windows.
- Tests: end-to-end views -> scene, clicks, hover, invalidation, nested
  views, bubbling, occlusion, shadows/borders/clipping, canvas, resize,
  and aborts on misuse. The card example now renders a real view and
  simulates hover and click.
- Docs: PORTING.md M6 status and deviations; README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SpriteandClaude Opus 5.5 committed 2026-11-24 22:55:17 +00:00
1 parent eeab51348e
commit fbe4c081e6
24 files changed
+15532 -204

No files matched your search

+18 -8
View File
@@ -17,26 +17,35 @@ roadmap.
| `experiments/gpui/style` | `style.rs`, `styled.rs`, Refineable, gpui_macros style helpers | Ported (`Style`/`StyleRefinement`, the full `Styled` fluent API) |
| `experiments/gpui/app` | `app.rs`, `entity_map.rs`, `context.rs`, `subscription.rs` | Ported (entities, contexts, notify/observe, typed events and globals, effect flushing) |
| `experiments/gpui/executor` | `executor.rs`, `scheduler` crate | Ported (tasks, timers, cancellation, deterministic test dispatcher; single thread) |
| `experiments/gpui/input` | mouse events of `interactive.rs` | Ported (mouse events, modifiers) |
| `experiments/gpui/window` | `window.rs`, `element.rs`, `view.rs` | Ported, headless (frame lifecycle, views, hitboxes, mouse dispatch, painting) |
| `experiments/gpui/elements` | `elements/div.rs`, `elements/canvas.rs` | Ported (`div` with styles, hover, clicks and mouse listeners; `canvas`) |
| `experiments/gpui/layout` | `taffy.rs` | Ported on [`Milky2018/chicle`](https://mooncakes.io/docs/Milky2018/chicle) (flexbox, grid, block) |
## Example
Nothing renders yet. `src/examples/card` resolves a style written with
GPUI's fluent API, lays the card and its (fake-measured) text out with the
layout engine, paints it into a `Scene`, and prints the layout and the draw
batches:
Nothing is shown on screen yet (the renderer comes with M8). `src/examples/card`
is a view rendering a `div()` card with GPUI's fluent API; a headless window
lays it out, paints it into a `Scene`, and dispatches a simulated hover and
click (which expands the card). It prints the scene's draw batches and
quads:
```sh
moon run src/examples/card --target js
```
```moonbit
@style.StyleRefinement::new()
@elements.div()
.id("card")
.flex().flex_col().gap_2().p_4()
.w(@geometry.px(320.0))
.rounded_lg().border_1().border_color(@color.rgb(0xd0d7de))
.bg(@color.rgb(0xffffff)).shadow_md()
.text_color(@color.rgb(0x1f2328)).text_sm()
.hover(fn(style) { style.border_color(@color.rgb(0x0969da)) })
.on_click(@window.listener(cx, fn(card, _, _, cx) {
card.expanded = !card.expanded
cx.notify()
}))
```
`src/examples/counter` shows the app model and executors: two entities
@@ -48,8 +57,9 @@ the roadmap.
## Generated code
`src/style/style_generated.mbt`, `styled_generated.mbt` and
`styled_extend_generated.mbt` are generated by `tools/gen_style.py`, which
`src/style/style_generated.mbt`, `styled_generated.mbt`,
`styled_extend_generated.mbt`, and the `*_styled_generated.mbt` files in
`src/elements` are generated by `tools/gen_style.py`, which
stands in for GPUI's Rust macros. Do not edit them by hand; change the
script or `src/style/styled.mbt`, then run: