M7 test platform: Platform traits, Application, TestPlatform, VisualTestContext
- input: MouseExitEvent, ModifiersChangedEvent, PlatformInput, and DispatchEventResult. - platform: core Platform and PlatformWindow traits plus WindowId, WindowBounds, WindowOptions, WindowParams, and ClipboardItem. - window: Application, AnyWindowHandle, WindowHandle[V], Window::from_platform, dispatch_input, prevent_default, close/activation hooks, and replace_root_view while keeping standalone Window::new; closing a window releases its root view; hit-testing runs between prepaint and paint gated by pointer containment. - platform/test: TestPlatform, TestWindow (recording Scenes and simulating frames, input, resize, scale factor, active/hover status, and close), TestAppContext, and VisualTestContext with automatic frame pumping and a runaway-redraw guard. - Tests & example: platform tests, TestPlatform/VisualTestContext unit and panic-on-misuse tests, elements visual integration tests, and src/examples/card updated to run on TestAppContext/VisualTestContext. - Docs: updated docs/PORTING.md and README.md.
This commit is contained in:
1 parent
fbe4c081e6
commit
b388a70aa7
25 files changed
+3592
-83
No files matched your search
+51
-8
@@ -137,18 +137,18 @@ 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) |
|
||||
| `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) |
|
||||
| `input` | mouse/window input of `interactive.rs`, `Modifiers`, `PlatformInput`, `DispatchEventResult` | pure | **done** (mouse/modifiers; keys in M5) |
|
||||
| `window` | `window.rs`, `element.rs`, `view.rs`, `Style::paint`, `Application`, window handles | pure | **done** (`PlatformWindow`-backed + standalone 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 |
|
||||
| `platform` | `platform.rs` (core traits, `WindowId`, `WindowOptions`, `WindowParams`, `ClipboardItem`) | pure (interfaces) | **done** (core subset; text/atlas/IME/displays later) |
|
||||
| `platform/test` | `platform/test/*`, `app/test_context.rs` (`TestAppContext`, `VisualTestContext`) | pure | **done** |
|
||||
| `platform/web` | `gpui_web` | **js only** | planned |
|
||||
| `renderer/canvas2d` | (new) | **js only** | planned |
|
||||
| `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) |
|
||||
| `examples/*` | `examples/*` | executables | `counter` (M3–M4), `card` (headless on `TestPlatform`, prints a scene report) |
|
||||
| `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
|
||||
@@ -403,9 +403,25 @@ gantt
|
||||
- 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.
|
||||
- **M7: test platform (done).**
|
||||
- `input`: `MouseExitEvent`, `ModifiersChangedEvent`, `PlatformInput`, and
|
||||
`DispatchEventResult`.
|
||||
- `platform`: core `Platform` and `PlatformWindow` traits plus `WindowId`,
|
||||
`WindowBounds`, `WindowOptions`, `WindowParams`, and `ClipboardItem`
|
||||
(text subset).
|
||||
- `window`: `Application`, `AnyWindowHandle`, `WindowHandle[V]`,
|
||||
`Window::dispatch_input`, `prevent_default`, close/activation hooks,
|
||||
`replace_root_view`, and `PlatformWindow` callback/frame wiring (keeping
|
||||
standalone `Window::new`). Closing a window releases its root view.
|
||||
- `platform/test`: `TestPlatform` and `TestWindow` (recording presented
|
||||
`Scene`s and simulating frames, input, resize, scale factor, active/hover
|
||||
status, and close requests), plus `TestAppContext` and `VisualTestContext`
|
||||
which pump tasks and scheduled frames together with a runaway-redraw
|
||||
guard.
|
||||
- Tests: platform types, `TestPlatform`/`TestWindow`/`TestAppContext` unit
|
||||
tests, `elements` visual integration tests (`VisualTestContext`), panic
|
||||
tests on closed-window misuse and runaway redraws, and `src/examples/card`
|
||||
updated to run on `TestPlatform`/`VisualTestContext`.
|
||||
- **M8: web platform + Canvas2D renderer (first pixels).**
|
||||
- A `<canvas>` window, rAF-driven frames, resize, and DPR.
|
||||
- DOM pointer, wheel, and key events → `PlatformInput`.
|
||||
@@ -573,6 +589,28 @@ gantt
|
||||
- Drag and drop, tooltips, scroll state, and deferred draws.
|
||||
- Text (M9).
|
||||
|
||||
### Deviations taken in M7 (test platform)
|
||||
- **Core platform subset.** `Platform` and `PlatformWindow` include window
|
||||
lifecycle, frame scheduling/drawing, input/resize/focus/hover callbacks,
|
||||
executor dispatcher, cursor style, clipboard, and `open_url`. Text
|
||||
system, glyph atlas, IME, displays, menus, and screen capture come in
|
||||
later milestones.
|
||||
- **Explicit `PlatformWindow::close`.** MoonBit has no `Drop`, so
|
||||
app-driven window teardown calls `PlatformWindow::close` explicitly (without
|
||||
re-invoking `on_close`). Closing a `Window` releases its root view
|
||||
(Design Decision 1).
|
||||
- **`TestWindow` defaults to `scale_factor = 1.0`.** Matches M6's
|
||||
`Window::new` (GPUI historically defaults to `2.0`), configurable via
|
||||
`TestPlatform::new(default_scale_factor=...)` or `WindowOptions`.
|
||||
- **`Application` lives in `window`.** `Application` owns the `App`,
|
||||
`Platform`, and open windows so `app` stays independent of `platform`,
|
||||
`scene`, and `style`; `application_for(app)` looks it up via a private
|
||||
`GlobalKey`.
|
||||
- **Automatic frame pumping in tests.** `TestAppContext::run_until_parked()`
|
||||
alternates draining ready tasks on `TestDispatcher` with pumping scheduled
|
||||
frames, aborting after 100 consecutive redraws to catch runaway redraw
|
||||
loops.
|
||||
|
||||
## 7. Design decisions
|
||||
|
||||
Decided on 2026-11-24, following the recommendations below.
|
||||
@@ -623,3 +661,8 @@ Decided on 2026-11-24, following the recommendations below.
|
||||
expected. Closures that raise must say so (`fn() raise { ... }`).
|
||||
- `Ref(x)` builds a `Ref`; `{ val: x }` needs a type annotation.
|
||||
- Test-only imports go in `import { ... } for "test"` in `moon.pkg`.
|
||||
- Package import aliases in `moon.pkg` write `"path/to/pkg" @alias,` (without
|
||||
`as`).
|
||||
- Tuple destructuring cannot annotate element types inside the pattern
|
||||
(`let (a : T, b)`); annotate the whole tuple or bind afterwards
|
||||
(`let a : T = a`).
|
||||
Reference in new issue
Block a user