feat(gfx): integrate wasi-gfx for loading and presenting GUI
CI / test (push) Successful in 24s

This commit is contained in:
Antigravity committed 2026-11-25 02:54:03 +00:00
1 parent ccb809bdc3
commit 7caadb3f7f
59 files changed
+7495 -16

No files matched your search

@@ -0,0 +1,51 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
#doc(hidden)
pub fn wasmExportInitGui(p0 : Int, p1 : Int) -> Unit {
let _ = init_gui((p0).reinterpret_as_uint(), (p1).reinterpret_as_uint());
}
///|
#doc(hidden)
pub fn wasmExportRenderFrame() -> Unit {
let _ = render_frame();
}
///|
#doc(hidden)
pub fn wasmExportOnResize(p0 : Int, p1 : Int) -> Unit {
let _ = on_resize((p0).reinterpret_as_uint(), (p1).reinterpret_as_uint());
}
///|
#doc(hidden)
pub fn wasmExportOnPointer(p0 : Int, p1 : Double, p2 : Double) -> Unit {
let _ = on_pointer((p0).to_byte(), p1, p2);
}
///|
#doc(hidden)
pub fn wasmExportOnKey(p0 : Int, p1 : Int, p2 : Int) -> Unit {
let result = mbt_ffi_ptr2str(p1, p2)
let _ = on_key((p0 != 0), result);
}
///|
extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
#|(func (param i32) (param i32) (result i32)
#| local.get 0
#| local.get 1 call $moonbit.init_array16
#| local.get 0)
@@ -0,0 +1,8 @@
import {
"moonplasma/desktop/interface/wasi-gfx/surface/surface" @surface,
"moonplasma/desktop/interface/wasi-gfx/surface/surface-frame-buffer" @sfb,
"moonplasma/desktop/compositor/scene" @scene,
"moonplasma/desktop/compositor/renderer" @renderer,
}
warnings = "-44"
@@ -0,0 +1,21 @@
// Generated using `moon info`, DON'T EDIT IT
package "moonplasma/desktop/components/gfx-gui/gen/world/gui-loader"
// Values
pub fn init_gui(UInt32, UInt32) -> Unit
pub fn on_key(Bool, String) -> Unit
pub fn on_pointer(Byte, Double, Double) -> Unit
pub fn on_resize(UInt32, UInt32) -> Unit
pub fn render_frame() -> Unit
// Errors
// Types and methods
// Type aliases
// Traits
@@ -0,0 +1,164 @@
///| Moon-Plasma GUI loader component backed by wasi-gfx (surface + frame-buffer).
priv struct GfxGuiState {
mut surface : @surface.Surface?
mut context : @sfb.Context?
mut width : Int
mut height : Int
mut launcher_open : Bool
mut pointer_x : Double
mut pointer_y : Double
mut last_key : String
mut frame_count : Int
}
let state : GfxGuiState = {
surface: None,
context: None,
width: 640,
height: 360,
launcher_open: false,
pointer_x: 0.0,
pointer_y: 0.0,
last_key: "",
frame_count: 0,
}
///|
pub fn init_gui(width : UInt, height : UInt) -> Unit {
let w = if width < 1U { 1U } else { width }
let h = if height < 1U { 1U } else { height }
state.width = w.reinterpret_as_int()
state.height = h.reinterpret_as_int()
let surf = @surface.Surface::surface({
height: Some(h),
width: Some(w),
})
let ctx = @sfb.Context::context(surf)
state.surface = Some(surf)
state.context = Some(ctx)
render_frame()
}
///|
pub fn render_frame() -> Unit {
match state.context {
None => ()
Some(ctx) => {
state.frame_count = state.frame_count + 1
let w = state.width
let h = state.height
let theme = @scene.ThemeTokens::moon_night()
let sg = @scene.SceneGraph::new(w, h)
let titles : Array[String] = ["wasi-gfx Desktop"]
let (bg_ops, panel_ops) = @scene.build_shell_ops(
w,
h,
theme,
"wasi-gfx",
titles,
)
sg.background_ops = bg_ops
sg.panel_ops = panel_ops
// Add a sample Breeze-decorated window so the GUI surface is rich and verifiable.
let win_w = if w > 320 { w / 2 } else { w - 32 }
let win_h = if h > 220 { h / 2 } else { h - 64 }
let (insets, deco_ops) = @scene.build_breeze_decoration(
"moon-plasma (wasi-gfx)",
"org.moonplasma.gfx",
true,
false,
win_w + 4,
win_h + 34,
theme,
)
sg.windows.push({
id: 1UL,
title: "moon-plasma (wasi-gfx)",
app_id: "org.moonplasma.gfx",
focused: true,
fullscreen: false,
geometry: @scene.Rect::new(24, 24, win_w, win_h),
deco_insets: insets,
deco_ops,
surface: None,
})
if state.launcher_open {
sg.widgets.push({
id: "launcher",
rect: @scene.Rect::new(8, h - theme.panel_height - 168, 220, 160),
ops: [
@scene.DrawOp::FillRect(
@scene.Rect::new(0, 0, 220, 160),
theme.palette.surface_popup,
theme.radius,
),
@scene.DrawOp::StrokeRect(
@scene.Rect::new(0, 0, 220, 160),
theme.palette.border,
theme.radius,
1,
),
@scene.DrawOp::Text(
14,
24,
"Applications (wasi-gfx)",
theme.font_size,
theme.palette.foreground,
@scene.TextAlign::Left,
true,
),
],
popup: None,
})
}
let pixmap = @renderer.render_scene(sg)
let buf = ctx.get_current_buffer()
buf.set_with_copy(pixmap.data)
ctx.present()
}
}
}
///|
pub fn on_resize(width : UInt, height : UInt) -> Unit {
let w = if width < 1U { 1U } else { width }
let h = if height < 1U { 1U } else { height }
state.width = w.reinterpret_as_int()
state.height = h.reinterpret_as_int()
match state.surface {
Some(surf) => surf.request_set_size(Some(h), Some(w))
None => ()
}
render_frame()
}
///|
pub fn on_pointer(kind : Byte, x : Double, y : Double) -> Unit {
state.pointer_x = x
state.pointer_y = y
// kind == 1: pointer down
if kind == b'\x01' {
let theme = @scene.ThemeTokens::moon_night()
if y.to_int() >= state.height - theme.panel_height && x.to_int() <= 120 {
state.launcher_open = !state.launcher_open
}
render_frame()
}
}
///|
pub fn on_key(pressed : Bool, text : String) -> Unit {
if pressed {
state.last_key = text
if text == "Escape" {
state.launcher_open = false
} else if text == "Super" || text == "Meta" {
state.launcher_open = !state.launcher_open
}
render_frame()
}
}
@@ -0,0 +1,12 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
declare pub fn init_gui(width : UInt, height : UInt) -> Unit
///|
declare pub fn render_frame() -> Unit
///|
declare pub fn on_resize(width : UInt, height : UInt) -> Unit
///|
declare pub fn on_pointer(kind : Byte, x : Double, y : Double) -> Unit
///|
declare pub fn on_key(pressed : Bool, text : String) -> Unit