The browser host for moonegui: one frame painted on a canvas or built as DOM elements.
| Package | What it does |
|---|---|
| web | What both backends share: the surface, its size and pixel ratio, the text metrics, and the input coming the other way |
| canvas | A frame painted on a 2D context: rectangles, circles, paths and rows of text |
| html | The same frame as elements in the document: a div per shape, an svg per path, a row of text per row |
moon add moonbitstack/moonpane<canvas id="moonegui" tabindex="0"></canvas>let surface : @canvas.Canvas = @canvas.Canvas::new()
let context = @ctx.Ctx::new(surface)
surface.listen()
let out = context.run(surface.raw(now, dt), fn(ui) {
@widget.heading(ui, "moonpane") |> ignore
if @widget.button(ui, "Press me").clicked {
clicks = clicks + 1
}
})
surface.clear(context.style().background)
@back.play(out.shapes, surface)let surface : @html.Html = @html.Html::new()
let context = @ctx.Ctx::new(surface)
surface.listen()
let out = context.run(surface.raw(now, dt), fn(ui) {
@widget.heading(ui, "moonpane") |> ignore
})
surface.begin(context.style().background)
@back.play(out.shapes, surface)
surface.end()import {
"moonbitstack/moonegui/back",
"moonbitstack/moonegui/ctx",
"moonbitstack/moonegui/widget",
"moonbitstack/moonpane/canvas",
}| canvas | html | |
|---|---|---|
| A rectangle | one fillRect | one div |
| A circle | one arc | one div with a round border |
| A path | a few lineTo | one svg over the page |
| A row of text | fillText | one div the browser lays out |
| Text selection | no | yes, the document's own |
| Reuse between frames | the canvas is repainted | elements are re-used by kind |
| Cost | one surface | one element per shape |
moon build --target js
python -m http.server 8741
# open http://127.0.0.1:8741/hosts/pane/src/examples/browser/index.html
# ?html for elements instead of a canvas, ?view for the tree,
# ?view&html for the tree as elementsInstall
Download zipThe browser host for moonegui: one frame painted on a canvas or built as DOM elements.