Stacked on #6 (base feat/window); the diff shows only M7. Retarget to main once #6 is merged.
Why
Before adding the browser platform and Canvas2D renderer in M8, window needs a backend-neutral Platform / PlatformWindow boundary and a deterministic headless test harness mirroring GPUI's TestPlatform, TestAppContext, and VisualTestContext. This lets views, elements, async timers, input dispatch, and window lifecycle be tested end-to-end across all four MoonBit backends without a browser or GPU.
What's here
input: MouseExitEvent, ModifiersChangedEvent, PlatformInput, DispatchEventResult, and mouse/platform-input helpers.
platform: core Platform and PlatformWindow traits plus WindowId, WindowBounds, WindowOptions, WindowParams, and text-subset ClipboardItem / ClipboardEntry / ClipboardString.
window:
Application, application_for, AnyWindowHandle, and WindowHandle[V] connecting App, Platform, and open windows while keeping app free of platform/rendering dependencies.
Window::dispatch_input, prevent_default, replace_root_view, clipboard/cursor/title/activation methods, and automatic root-view release on Window::close (Design Decision 1).
Hitbox hit-testing moved between Prepaint and Paint (matching GPUI) and gated on pointer containment so MouseExited and on_hover_status_change(false) clear hover cleanly.
platform/test:
TestPlatform and TestWindow recording every presented Scene and providing simulation hooks for frames, input, resize, scale factor, active/hover status, and close requests.
TestAppContext and VisualTestContext pumping TestDispatcher tasks and scheduled frames together (run_until_parked, advance_clock, add_window_view, simulate_*), with a 100-pass runaway-redraw guard.
Example & docs: src/examples/card now runs through TestAppContext / VisualTestContext; docs/PORTING.md and README.md document M7 status, deviations, and toolchain notes.
Deviations
Recorded in docs/PORTING.md:
Platform and PlatformWindow cover the core subset (text system, glyph atlas, IME, menus, and displays arrive in M9/M10).
Added explicit PlatformWindow::close for app-driven teardown (no Drop in MoonBit); closing a window releases its root view.
TestWindow defaults to scale_factor = 1.0 (matching M6 Window::new; configurable via TestPlatform::new or WindowOptions).
Application lives in window and is looked up via a private GlobalKey (application_for).
Testing
moon check --target all passes with zero warnings or errors.
moon test --target all passes 157/157 tests on wasm, wasm-gc, js, and native, including:
platform type/clipboard unit tests.
platform/test unit tests covering explicit frame scheduling, resize/scale-factor changes without recursion, title/cursor/clipboard/open_url, multi-window activation, MouseExited/ModifiersChanged/DispatchEventResult, on_should_close veto and root-view release on close, async virtual-clock redraws, replace_root_view, skip_drawing, and three panic-on-misuse tests (drawing/dispatching on closed windows, runaway redraw loop).
elements/visual_test.mbt integration tests for div(), canvas(), hover, clicks, resize/2x, async ticker redraws, and close release via VisualTestContext.
moon run src/examples/card --target js prints the expected 3-frame card report.
Stacked on #6 (base `feat/window`); the diff shows only M7. Retarget to `main` once #6 is merged.
## Why
Before adding the browser platform and Canvas2D renderer in M8, `window` needs a backend-neutral `Platform` / `PlatformWindow` boundary and a deterministic headless test harness mirroring GPUI's `TestPlatform`, `TestAppContext`, and `VisualTestContext`. This lets views, elements, async timers, input dispatch, and window lifecycle be tested end-to-end across all four MoonBit backends without a browser or GPU.
## What's here
- **`input`**: `MouseExitEvent`, `ModifiersChangedEvent`, `PlatformInput`, `DispatchEventResult`, and mouse/platform-input helpers.
- **`platform`**: core `Platform` and `PlatformWindow` traits plus `WindowId`, `WindowBounds`, `WindowOptions`, `WindowParams`, and text-subset `ClipboardItem` / `ClipboardEntry` / `ClipboardString`.
- **`window`**:
- `Application`, `application_for`, `AnyWindowHandle`, and `WindowHandle[V]` connecting `App`, `Platform`, and open windows while keeping `app` free of platform/rendering dependencies.
- `Window::from_platform` wiring frame requests, input, resize/scale-factor changes, active/hover status, `on_should_close`, and `on_close` callbacks (while keeping standalone `Window::new` backwards-compatible).
- `Window::dispatch_input`, `prevent_default`, `replace_root_view`, clipboard/cursor/title/activation methods, and automatic root-view release on `Window::close` (Design Decision 1).
- Hitbox hit-testing moved between `Prepaint` and `Paint` (matching GPUI) and gated on pointer containment so `MouseExited` and `on_hover_status_change(false)` clear hover cleanly.
- **`platform/test`**:
- `TestPlatform` and `TestWindow` recording every presented `Scene` and providing simulation hooks for frames, input, resize, scale factor, active/hover status, and close requests.
- `TestAppContext` and `VisualTestContext` pumping `TestDispatcher` tasks and scheduled frames together (`run_until_parked`, `advance_clock`, `add_window_view`, `simulate_*`), with a 100-pass runaway-redraw guard.
- **Example & docs**: `src/examples/card` now runs through `TestAppContext` / `VisualTestContext`; `docs/PORTING.md` and `README.md` document M7 status, deviations, and toolchain notes.
## Deviations
Recorded in `docs/PORTING.md`:
- `Platform` and `PlatformWindow` cover the core subset (text system, glyph atlas, IME, menus, and displays arrive in M9/M10).
- Added explicit `PlatformWindow::close` for app-driven teardown (no `Drop` in MoonBit); closing a window releases its root view.
- `TestWindow` defaults to `scale_factor = 1.0` (matching M6 `Window::new`; configurable via `TestPlatform::new` or `WindowOptions`).
- `Application` lives in `window` and is looked up via a private `GlobalKey` (`application_for`).
## Testing
- `moon check --target all` passes with zero warnings or errors.
- `moon test --target all` passes 157/157 tests on `wasm`, `wasm-gc`, `js`, and `native`, including:
- `platform` type/clipboard unit tests.
- `platform/test` unit tests covering explicit frame scheduling, resize/scale-factor changes without recursion, title/cursor/clipboard/`open_url`, multi-window activation, `MouseExited`/`ModifiersChanged`/`DispatchEventResult`, `on_should_close` veto and root-view release on close, async virtual-clock redraws, `replace_root_view`, `skip_drawing`, and three panic-on-misuse tests (drawing/dispatching on closed windows, runaway redraw loop).
- `elements/visual_test.mbt` integration tests for `div()`, `canvas()`, hover, clicks, resize/2x, async ticker redraws, and close release via `VisualTestContext`.
- `moon run src/examples/card --target js` prints the expected 3-frame card report.
- 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.
nandi
merged commit 73c67825b2 into feat/window2026-11-24 23:54:56 +00:00
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.
Stacked on #6 (base
feat/window); the diff shows only M7. Retarget tomainonce #6 is merged.Why
Before adding the browser platform and Canvas2D renderer in M8,
windowneeds a backend-neutralPlatform/PlatformWindowboundary and a deterministic headless test harness mirroring GPUI'sTestPlatform,TestAppContext, andVisualTestContext. This lets views, elements, async timers, input dispatch, and window lifecycle be tested end-to-end across all four MoonBit backends without a browser or GPU.What's here
input:MouseExitEvent,ModifiersChangedEvent,PlatformInput,DispatchEventResult, and mouse/platform-input helpers.platform: corePlatformandPlatformWindowtraits plusWindowId,WindowBounds,WindowOptions,WindowParams, and text-subsetClipboardItem/ClipboardEntry/ClipboardString.window:Application,application_for,AnyWindowHandle, andWindowHandle[V]connectingApp,Platform, and open windows while keepingappfree of platform/rendering dependencies.Window::from_platformwiring frame requests, input, resize/scale-factor changes, active/hover status,on_should_close, andon_closecallbacks (while keeping standaloneWindow::newbackwards-compatible).Window::dispatch_input,prevent_default,replace_root_view, clipboard/cursor/title/activation methods, and automatic root-view release onWindow::close(Design Decision 1).PrepaintandPaint(matching GPUI) and gated on pointer containment soMouseExitedandon_hover_status_change(false)clear hover cleanly.platform/test:TestPlatformandTestWindowrecording every presentedSceneand providing simulation hooks for frames, input, resize, scale factor, active/hover status, and close requests.TestAppContextandVisualTestContextpumpingTestDispatchertasks and scheduled frames together (run_until_parked,advance_clock,add_window_view,simulate_*), with a 100-pass runaway-redraw guard.src/examples/cardnow runs throughTestAppContext/VisualTestContext;docs/PORTING.mdandREADME.mddocument M7 status, deviations, and toolchain notes.Deviations
Recorded in
docs/PORTING.md:PlatformandPlatformWindowcover the core subset (text system, glyph atlas, IME, menus, and displays arrive in M9/M10).PlatformWindow::closefor app-driven teardown (noDropin MoonBit); closing a window releases its root view.TestWindowdefaults toscale_factor = 1.0(matching M6Window::new; configurable viaTestPlatform::neworWindowOptions).Applicationlives inwindowand is looked up via a privateGlobalKey(application_for).Testing
moon check --target allpasses with zero warnings or errors.moon test --target allpasses 157/157 tests onwasm,wasm-gc,js, andnative, including:platformtype/clipboard unit tests.platform/testunit tests covering explicit frame scheduling, resize/scale-factor changes without recursion, title/cursor/clipboard/open_url, multi-window activation,MouseExited/ModifiersChanged/DispatchEventResult,on_should_closeveto and root-view release on close, async virtual-clock redraws,replace_root_view,skip_drawing, and three panic-on-misuse tests (drawing/dispatching on closed windows, runaway redraw loop).elements/visual_test.mbtintegration tests fordiv(),canvas(), hover, clicks, resize/2x, async ticker redraws, and close release viaVisualTestContext.moon run src/examples/card --target jsprints the expected 3-frame card report.