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

+53 -12
View File
@@ -137,8 +137,9 @@ stays isolated.
| `action` | `action.rs` | pure | planned |
| `app` | `app.rs`, `app/entity_map.rs`, `app/context.rs`, `subscription.rs`, `global.rs` | pure | **done** (no windows, executors or actions yet) |
| `executor` | `executor.rs`, `scheduler` crate (`executor.rs`, `test_scheduler.rs`) | pure core + `Dispatcher` platform hook | **done** (single thread) |
| `element` | `element.rs`, `view.rs`, `elements/div.rs`, `interactive.rs` | pure | planned |
| `window` | `window.rs`, `key_dispatch.rs`, `tab_stop.rs` | pure (talks to platform traits) | planned |
| `input` | mouse events of `interactive.rs`, `Modifiers` | pure | **done** (mouse only; keys in M5) |
| `window` | `window.rs`, `element.rs`, `view.rs`, `Style::paint` | pure | **done** (headless; no focus/keys/caching yet) |
| `elements` | `elements/div.rs` (+ `Interactivity`), `elements/canvas.rs` | pure | **done** (`div`, `canvas`) |
| `text` | `text_system.rs`, `text_system/*` | mixed: wrapping/caching pure, shaping platform | planned |
| `platform` | `platform.rs` (traits only), `interactive.rs` input types | pure (interfaces) | planned |
| `platform/test` | `platform/test/*` | pure | planned: headless platform for tests |
@@ -148,7 +149,7 @@ stays isolated.
| `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 |
| `elements/*` | `elements/{text,img,svg,list,uniform_list,anchored,deferred,animation}.rs` | pure | later |
A facade package (`experiments/gpui` re-exporting the common API, similar to
GPUI's `prelude.rs`) should come once there are enough packages to make
@@ -378,15 +379,30 @@ gantt
multi-stroke matching.
- `ActionRegistry`.
- Tests ported from `keymap.rs` and `keymap/context.rs`.
- **M6: elements and window.**
- `Element`/`AnyElement`/`IntoElement`/`ParentElement`, `Render`, and
views.
- `div` with styles, hover and active styles, mouse listeners, and
scrolling.
- `Window::draw` (request_layout → prepaint → paint), element ids and
state, hitboxes, the content-mask stack, and the dispatch tree.
- Tests: build a tree, draw against the test platform, assert on the
Scene.
- **M6: elements and window (done).**
- `Element`/`AnyElement`/`IntoElement`, `Render`, `AnyView`, views as
elements, `listener`, and `empty`.
- `Window`:
- `draw` (render, then layout to fill the viewport, prepaint, paint,
`Scene::finish`) with phase checks, and `draw_if_dirty`.
- The content-mask, element-offset, opacity, and element-id stacks.
- Element state across frames (`ElementStateKey`), hitboxes and hit
testing, occlusion, and mouse dispatch (capture and bubble,
`stop_propagation`).
- Hover-driven and notify-driven invalidation, with only rendered views
invalidating the window, plus `resize`.
- Painting: `paint_quad` with device-pixel snapping, drop and inset
shadows, `paint_path`, and `paint_style` (a port of `Style::paint`).
- `div()`:
- Styles through the generated `Styled` list, plus children and hover
styles.
- Mouse down, up, move and scroll listeners, and clicks (with element
state).
- `occlude`, overflow clipping, and opacity.
- `canvas()`.
- Tests: end-to-end views to scene, clicks, hover, invalidation, nested
views, bubbling, occlusion, shadows and borders, clipping, canvas,
resize, and the aborts expected on misuse.
- **M7: test platform.** A headless `Platform`/`PlatformWindow` that records
scenes and injects input events, mirroring GPUI's `TestPlatform` and
`VisualTestContext`. This is the base for most later tests.
@@ -532,6 +548,31 @@ gantt
- **`AsyncApp` methods return values, not `Result`s.** An app is never
dropped while a task references it.
### Deviations taken in M6 (elements and window)
- **Element state lives in the element.** `Element` has no associated state
types. Elements keep per-frame state in their own fields and are rebuilt
every frame. `render` returns `AnyElement`.
- **Element ids are strings, and state is keyed by `ElementStateKey[S]`**
(the same key pattern as globals). `Div::id` makes a div stateful, and
`on_click` aborts without an id. There is no separate `Stateful<Div>` type.
- **Hover styles apply at paint time only.** Hovering cannot change layout.
Any change in the hovered hitboxes marks the window dirty, not only for
elements with hover styles.
- **The window is headless.** It is created directly with a viewport size,
scale factor, and rem size, and `draw` returns the `Scene`. There is no
platform window or frame scheduling yet (M7/M8).
- **Invalidation without accessed-entity tracking.** A window re-renders when
a view it rendered in the last frame is notified, through
`App::observe_notifications`. There is no view caching or `Scene::replay`
reuse yet; every frame renders everything.
- **Quads are not split.** GPUI splits bordered quads into a fill and border
strips; that renderer optimization is not ported.
- **Not yet ported:**
- Focus and the key dispatch tree (M5/M10).
- Active and group styles.
- Drag and drop, tooltips, scroll state, and deferred draws.
- Text (M9).
## 7. Design decisions
Decided on 2026-11-24, following the recommendations below.