- 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.
moon-gpui
A port of GPUI, the GPU-accelerated UI framework of the Zed editor, to MoonBit.
Status: early. The pure-logic foundation is in place; nothing renders yet. See docs/PORTING.md for the architecture mapping and the roadmap.
| Package | GPUI source | Status |
|---|---|---|
experiments/gpui/geometry |
geometry.rs, ContentMask |
Ported (units, Point/Size/Bounds/Edges/Corners, lengths) |
experiments/gpui/color |
color.rs |
Ported (Rgba/Hsla, hex parsing, Background) |
experiments/gpui/scene |
scene.rs, bounds_tree.rs |
Ported (primitives, draw ordering, layers, batching, replay) |
experiments/gpui/font |
font descriptors in text_system.rs |
Ported (Font, weights, styles, features, fallbacks) |
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/window input of interactive.rs |
Ported (mouse events, modifiers, PlatformInput, DispatchEventResult) |
experiments/gpui/window |
window.rs, element.rs, view.rs, app.rs |
Ported, headless (Application, PlatformWindow integration, 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 (flexbox, grid, block) |
experiments/gpui/platform |
platform.rs |
Ported (core Platform/PlatformWindow traits, window options/params, clipboard) |
experiments/gpui/platform/test |
platform/test/*, app/test_context.rs |
Ported (TestPlatform, TestWindow, TestAppContext, VisualTestContext) |
Example
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 inside a
TestPlatform window; VisualTestContext simulates a hover and click while
pumping frames automatically, and prints the scene's draw batches and quads:
moon run src/examples/card --target js
@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()
.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
talking through notifications, a typed event and a global, and a task
ticking on a simulated clock (moon run src/examples/counter --target js).
The first example that renders in the browser comes with milestone M8; see the roadmap.
Generated code
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:
python3 tools/gen_style.py && moon fmt
Layout conformance
conformance/chicle is a standalone module with 1,038 taffy layout fixtures
for the layout engine dependency. Run it before changing the chicle version:
cd conformance/chicle && moon test --target all.
Testing
All packages are pure MoonBit and are tested on every backend:
moon check --target all
moon test --target all
moon fmt