WIT package, MoonBit components, Node host and tests (WIP)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
SpriteandClaude Sonnet 5.5 committed 2026-11-24 23:36:35 +00:00
1 parent e5548fc067
commit e0bde1d150
125 files changed
+8681

No files matched your search

+7
View File
@@ -0,0 +1,7 @@
_build/
build/
.tools/
node_modules/
.context/
.mooncakes/
*.log
+82
View File
@@ -0,0 +1,82 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
pub fn mbt_ffi_cabi_realloc(
src_offset : Int,
src_size : Int,
_dst_alignment : Int,
dst_size : Int,
) -> Int {
// malloc
if src_offset == 0 && src_size == 0 {
return mbt_ffi_malloc(dst_size)
}
// free
if dst_size == 0 {
mbt_ffi_free(src_offset)
return 0
}
// realloc
let dst = mbt_ffi_malloc(dst_size)
mbt_ffi_copy(dst, src_offset, if src_size < dst_size { src_size } else { dst_size })
mbt_ffi_free(src_offset)
dst
}
///|
extern "wasm" fn mbt_ffi_copy(dest : Int, src : Int, len : Int) =
#|(func (param i32) (param i32) (param i32) local.get 0 local.get 1 local.get 2 memory.copy)
///|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
#|(func (param i32) (result i32) (local i32)
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
#| local.tee 1 i32.const 0 call $moonbit.init_array8
#| local.get 1)
///|
extern "wasm" fn mbt_ffi_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
///|
#doc(hidden)
pub fn wasmExportInfo() -> Int {
@plasmoid.wasmExportInfo()
}
///|
#doc(hidden)
pub fn wasmExportRender(p0 : Int, p1 : Int) -> Int {
@plasmoid.wasmExportRender(p0, p1)
}
///|
#doc(hidden)
pub fn wasmExportInfoPostReturn(p0 : Int) -> Unit {
@plasmoid.wasmExportInfoPostReturn(p0)
}
///|
#doc(hidden)
pub fn wasmExportRenderPostReturn(p0 : Int) -> Unit {
@plasmoid.wasmExportRenderPostReturn(p0)
}
///|
#doc(hidden)
pub fn wasmExportPopup() -> Int {
@plasmoid.wasmExportPopup()
}
///|
#doc(hidden)
pub fn wasmExportPopupPostReturn(p0 : Int) -> Unit {
@plasmoid.wasmExportPopupPostReturn(p0)
}
///|
#doc(hidden)
pub fn wasmExportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
@plasmoid.wasmExportOnEvent(p0, p1, p2, p3)
}
@@ -0,0 +1 @@
The widget (plasmoid) contract.
@@ -0,0 +1,409 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
#doc(hidden)
pub fn wasmExportInfo() -> Int {
let (result) : (PlasmoidInfo) = info();
let return_area = mbt_ffi_malloc(32)
let ptr = mbt_ffi_str2ptr((result).id)
mbt_ffi_store32((return_area) + 4, (result).id.length())
mbt_ffi_store32((return_area) + 0, ptr)
let ptr0 = mbt_ffi_str2ptr((result).name)
mbt_ffi_store32((return_area) + 12, (result).name.length())
mbt_ffi_store32((return_area) + 8, ptr0)
mbt_ffi_store32((return_area) + 16, (((result).preferred).w).reinterpret_as_int())
mbt_ffi_store32((return_area) + 20, (((result).preferred).h).reinterpret_as_int())
mbt_ffi_store32((return_area) + 24, ((result).min_width).reinterpret_as_int())
mbt_ffi_store8((return_area) + 28, (if (result).stretch { 1 } else { 0 }))
let ret = return_area
return ret
}
///|
#doc(hidden)
pub fn wasmExportInfoPostReturn(p0 : Int) -> Unit {
mbt_ffi_free(mbt_ffi_load32((p0) + 0))
mbt_ffi_free(mbt_ffi_load32((p0) + 8))
}
///|
#doc(hidden)
pub fn wasmExportRender(p0 : Int, p1 : Int) -> Int {
let (result) : (Array[@types.DrawOp]) = render(@types.Size::{w : (p0).reinterpret_as_uint(), h : (p1).reinterpret_as_uint()});
let return_area = mbt_ffi_malloc(8)
let address = mbt_ffi_malloc((result).length() * 32);
for index = 0; index < (result).length(); index = index + 1 {
let iter_elem : @types.DrawOp = (result)[(index)]
let iter_base = address + (index * 32);
match iter_elem {
FillRect(payload) => {
mbt_ffi_store8((iter_base) + 0, (0))
mbt_ffi_store32((iter_base) + 4, ((payload).rect).x)
mbt_ffi_store32((iter_base) + 8, ((payload).rect).y)
mbt_ffi_store32((iter_base) + 12, (((payload).rect).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, (((payload).rect).h).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 20, (((payload).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload).radius).reinterpret_as_int())
()
}
StrokeRect(payload0) => {
mbt_ffi_store8((iter_base) + 0, (1))
mbt_ffi_store32((iter_base) + 4, ((payload0).rect).x)
mbt_ffi_store32((iter_base) + 8, ((payload0).rect).y)
mbt_ffi_store32((iter_base) + 12, (((payload0).rect).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, (((payload0).rect).h).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 20, (((payload0).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload0).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload0).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload0).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload0).width).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 28, ((payload0).radius).reinterpret_as_int())
()
}
Line(payload1) => {
mbt_ffi_store8((iter_base) + 0, (2))
mbt_ffi_store32((iter_base) + 4, ((payload1).start).x)
mbt_ffi_store32((iter_base) + 8, ((payload1).start).y)
mbt_ffi_store32((iter_base) + 12, ((payload1).end).x)
mbt_ffi_store32((iter_base) + 16, ((payload1).end).y)
mbt_ffi_store8((iter_base) + 20, (((payload1).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload1).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload1).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload1).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload1).width).reinterpret_as_int())
()
}
Circle(payload2) => {
mbt_ffi_store8((iter_base) + 0, (3))
mbt_ffi_store32((iter_base) + 4, ((payload2).center).x)
mbt_ffi_store32((iter_base) + 8, ((payload2).center).y)
mbt_ffi_store32((iter_base) + 12, ((payload2).radius).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 16, (((payload2).color).r).to_int())
mbt_ffi_store8((iter_base) + 17, (((payload2).color).g).to_int())
mbt_ffi_store8((iter_base) + 18, (((payload2).color).b).to_int())
mbt_ffi_store8((iter_base) + 19, (((payload2).color).a).to_int())
mbt_ffi_store8((iter_base) + 20, (if (payload2).filled { 1 } else { 0 }))
()
}
Text(payload3) => {
mbt_ffi_store8((iter_base) + 0, (4))
mbt_ffi_store32((iter_base) + 4, ((payload3).origin).x)
mbt_ffi_store32((iter_base) + 8, ((payload3).origin).y)
let ptr = mbt_ffi_str2ptr((payload3).text)
mbt_ffi_store32((iter_base) + 16, (payload3).text.length())
mbt_ffi_store32((iter_base) + 12, ptr)
mbt_ffi_store32((iter_base) + 20, (((payload3).style).size).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 24, ((((payload3).style).color).r).to_int())
mbt_ffi_store8((iter_base) + 25, ((((payload3).style).color).g).to_int())
mbt_ffi_store8((iter_base) + 26, ((((payload3).style).color).b).to_int())
mbt_ffi_store8((iter_base) + 27, ((((payload3).style).color).a).to_int())
mbt_ffi_store8((iter_base) + 28, ((payload3).style).align.ordinal())
mbt_ffi_store8((iter_base) + 29, (if ((payload3).style).bold { 1 } else { 0 }))
()
}
PushClip(payload4) => {
mbt_ffi_store8((iter_base) + 0, (5))
mbt_ffi_store32((iter_base) + 4, (payload4).x)
mbt_ffi_store32((iter_base) + 8, (payload4).y)
mbt_ffi_store32((iter_base) + 12, ((payload4).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, ((payload4).h).reinterpret_as_int())
()
}
PopClip => {
mbt_ffi_store8((iter_base) + 0, (6))
()
}
}
}
mbt_ffi_store32((return_area) + 4, (result).length())
mbt_ffi_store32((return_area) + 0, address)
let ret = return_area
return ret
}
///|
#doc(hidden)
pub fn wasmExportRenderPostReturn(p0 : Int) -> Unit {
for index = 0; index < (mbt_ffi_load32((p0) + 4)); index = index + 1 {
let iter_base = (mbt_ffi_load32((p0) + 0)) + (index * 32)
match (mbt_ffi_load8_u((iter_base) + 0)) {
0 => ()
1 => ()
2 => ()
3 => ()
4 => {
mbt_ffi_free(mbt_ffi_load32((iter_base) + 12))
}
5 => ()
6 => ()
_ => panic()
}
}
mbt_ffi_free(mbt_ffi_load32((p0) + 0))
}
///|
#doc(hidden)
pub fn wasmExportPopup() -> Int {
let (result) : (PopupSurface?) = popup();
let return_area = mbt_ffi_malloc(20)
match (result) {
None => {
mbt_ffi_store8((return_area) + 0, (0))
()
}
Some(payload0) => {
mbt_ffi_store8((return_area) + 0, (1))
mbt_ffi_store32((return_area) + 4, (((payload0).size).w).reinterpret_as_int())
mbt_ffi_store32((return_area) + 8, (((payload0).size).h).reinterpret_as_int())
let address = mbt_ffi_malloc(((payload0).ops).length() * 32);
for index = 0; index < ((payload0).ops).length(); index = index + 1 {
let iter_elem : @types.DrawOp = ((payload0).ops)[(index)]
let iter_base = address + (index * 32);
match iter_elem {
FillRect(payload1) => {
mbt_ffi_store8((iter_base) + 0, (0))
mbt_ffi_store32((iter_base) + 4, ((payload1).rect).x)
mbt_ffi_store32((iter_base) + 8, ((payload1).rect).y)
mbt_ffi_store32((iter_base) + 12, (((payload1).rect).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, (((payload1).rect).h).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 20, (((payload1).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload1).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload1).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload1).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload1).radius).reinterpret_as_int())
()
}
StrokeRect(payload2) => {
mbt_ffi_store8((iter_base) + 0, (1))
mbt_ffi_store32((iter_base) + 4, ((payload2).rect).x)
mbt_ffi_store32((iter_base) + 8, ((payload2).rect).y)
mbt_ffi_store32((iter_base) + 12, (((payload2).rect).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, (((payload2).rect).h).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 20, (((payload2).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload2).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload2).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload2).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload2).width).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 28, ((payload2).radius).reinterpret_as_int())
()
}
Line(payload3) => {
mbt_ffi_store8((iter_base) + 0, (2))
mbt_ffi_store32((iter_base) + 4, ((payload3).start).x)
mbt_ffi_store32((iter_base) + 8, ((payload3).start).y)
mbt_ffi_store32((iter_base) + 12, ((payload3).end).x)
mbt_ffi_store32((iter_base) + 16, ((payload3).end).y)
mbt_ffi_store8((iter_base) + 20, (((payload3).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload3).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload3).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload3).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload3).width).reinterpret_as_int())
()
}
Circle(payload4) => {
mbt_ffi_store8((iter_base) + 0, (3))
mbt_ffi_store32((iter_base) + 4, ((payload4).center).x)
mbt_ffi_store32((iter_base) + 8, ((payload4).center).y)
mbt_ffi_store32((iter_base) + 12, ((payload4).radius).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 16, (((payload4).color).r).to_int())
mbt_ffi_store8((iter_base) + 17, (((payload4).color).g).to_int())
mbt_ffi_store8((iter_base) + 18, (((payload4).color).b).to_int())
mbt_ffi_store8((iter_base) + 19, (((payload4).color).a).to_int())
mbt_ffi_store8((iter_base) + 20, (if (payload4).filled { 1 } else { 0 }))
()
}
Text(payload5) => {
mbt_ffi_store8((iter_base) + 0, (4))
mbt_ffi_store32((iter_base) + 4, ((payload5).origin).x)
mbt_ffi_store32((iter_base) + 8, ((payload5).origin).y)
let ptr = mbt_ffi_str2ptr((payload5).text)
mbt_ffi_store32((iter_base) + 16, (payload5).text.length())
mbt_ffi_store32((iter_base) + 12, ptr)
mbt_ffi_store32((iter_base) + 20, (((payload5).style).size).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 24, ((((payload5).style).color).r).to_int())
mbt_ffi_store8((iter_base) + 25, ((((payload5).style).color).g).to_int())
mbt_ffi_store8((iter_base) + 26, ((((payload5).style).color).b).to_int())
mbt_ffi_store8((iter_base) + 27, ((((payload5).style).color).a).to_int())
mbt_ffi_store8((iter_base) + 28, ((payload5).style).align.ordinal())
mbt_ffi_store8((iter_base) + 29, (if ((payload5).style).bold { 1 } else { 0 }))
()
}
PushClip(payload6) => {
mbt_ffi_store8((iter_base) + 0, (5))
mbt_ffi_store32((iter_base) + 4, (payload6).x)
mbt_ffi_store32((iter_base) + 8, (payload6).y)
mbt_ffi_store32((iter_base) + 12, ((payload6).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, ((payload6).h).reinterpret_as_int())
()
}
PopClip => {
mbt_ffi_store8((iter_base) + 0, (6))
()
}
}
}
mbt_ffi_store32((return_area) + 16, ((payload0).ops).length())
mbt_ffi_store32((return_area) + 12, address)
()
}
}
let ret = return_area
return ret
}
///|
#doc(hidden)
pub fn wasmExportPopupPostReturn(p0 : Int) -> Unit {
match (mbt_ffi_load8_u((p0) + 0)) {
0 => ()
1 => {
for index = 0; index < (mbt_ffi_load32((p0) + 16)); index = index + 1 {
let iter_base = (mbt_ffi_load32((p0) + 12)) + (index * 32)
match (mbt_ffi_load8_u((iter_base) + 0)) {
0 => ()
1 => ()
2 => ()
3 => ()
4 => {
mbt_ffi_free(mbt_ffi_load32((iter_base) + 12))
}
5 => ()
6 => ()
_ => panic()
}
}
mbt_ffi_free(mbt_ffi_load32((p0) + 12))
}
_ => panic()
}
}
///|
#doc(hidden)
pub fn wasmExportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
let lifted = match (p1) {
0 => {
@types.InputEvent::PointerMove(@types.Point::{x : p2, y : p3})
}
1 => {
@types.InputEvent::PointerDown(@types.Point::{x : p2, y : p3})
}
2 => {
@types.InputEvent::PointerUp(@types.Point::{x : p2, y : p3})
}
3 => {
@types.InputEvent::PointerLeave
}
4 => {
@types.InputEvent::FocusLost
}
5 => {
let result = mbt_ffi_ptr2str(p2, p3)
@types.InputEvent::KeyDown(result)
}
_ => panic()
}
let (result0) : (Bool) = on_event(Surface::from(p0), lifted);
let ret = (if result0 { 1 } else { 0 })
return ret
}
///|
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
///|
extern "wasm" fn mbt_ffi_store8(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)
///|
extern "wasm" fn mbt_ffi_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
///|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
#|(func (param i32) (result i32) (local i32)
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
#| local.tee 1 i32.const 0 call $moonbit.init_array8
#| local.get 1)
///|
#owned(str)
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
#|(func (param i32) (result i32) local.get 0)
///|
extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)
///|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
///|
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/moonplasma/desktop/types" @types,
"moonplasma/desktop/interface/moonplasma/desktop/theme" @theme,
"moonplasma/desktop/interface/moonplasma/desktop/clock" @clock,
"moonplasma/desktop/lib/clock" @logic,
}
warnings = "-44"
@@ -0,0 +1,42 @@
// Generated using `moon info`, DON'T EDIT IT
package "moonplasma/desktop/components/clock-binary/gen/interface/moonplasma/desktop/plasmoid"
import {
"moonplasma/desktop/interface/moonplasma/desktop/types",
}
// Values
pub fn info() -> PlasmoidInfo
pub fn on_event(Surface, @types.InputEvent) -> Bool
pub fn popup() -> PopupSurface?
pub fn render(@types.Size) -> Array[@types.DrawOp]
// Errors
// Types and methods
pub(all) struct PlasmoidInfo {
id : String
name : String
preferred : @types.Size
min_width : UInt32
stretch : Bool
}
pub(all) struct PopupSurface {
size : @types.Size
ops : Array[@types.DrawOp]
}
pub(all) enum Surface {
WIDGET
POPUP
}
pub fn Surface::from(Int32) -> Self
pub fn Surface::ordinal(Self) -> Int32
// Type aliases
// Traits
@@ -0,0 +1,29 @@
///| Implementation of `moonplasma:desktop/plasmoid` for the binary clock.
/// All logic lives in lib/clock; this file only adapts host capabilities.
///|
pub fn info() -> PlasmoidInfo {
let (id, name, w, h, min_w) = @logic.binary_info()
{
id,
name,
preferred: { w: w.reinterpret_as_uint(), h: h.reinterpret_as_uint() },
min_width: min_w.reinterpret_as_uint(),
stretch: false,
}
}
///|
pub fn render(size : @types.Size) -> Array[@types.DrawOp] {
@logic.render_binary(size, @theme.get_tokens(), @clock.now())
}
///|
pub fn popup() -> PopupSurface? {
None
}
///|
pub fn on_event(_target : Surface, _event : @types.InputEvent) -> Bool {
false
}
@@ -0,0 +1,42 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
pub(all) struct PlasmoidInfo {
id : String; name : String; preferred : @types.Size; min_width : UInt; stretch : Bool
}
///|
pub(all) struct PopupSurface {
size : @types.Size; ops : Array[@types.DrawOp]
}
///|
pub(all) enum Surface {
WIDGET; POPUP
} derive()
///|
pub fn Surface::ordinal(self : Surface) -> Int {
match self {
WIDGET => 0
POPUP => 1
}
}
///|
pub fn Surface::from(self : Int) -> Surface {
match self {
0 => WIDGET
1 => POPUP
_ => panic()
}
}
///|
declare pub fn info() -> PlasmoidInfo
///|
/// Draw the widget into a `size` box (local coordinates).
declare pub fn render(size : @types.Size) -> Array[@types.DrawOp]
///|
/// Present when the widget wants a popup surface (e.g. a launcher menu).
declare pub fn popup() -> PopupSurface?
///|
/// Returns true when the widget's visuals changed and a redraw is needed.
declare pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool
+26
View File
@@ -0,0 +1,26 @@
import {
"moonplasma/desktop/components/clock-binary/gen/interface/moonplasma/desktop/plasmoid" @plasmoid,
}
warnings = "-44"
pkgtype(kind: "foreign_library")
options(
link: {
"wasm": {
"export-memory-name": "memory",
"heap-start-address": 16,
"exports": [
"mbt_ffi_cabi_realloc:cabi_realloc",
"wasmExportInfo:moonplasma:desktop/plasmoid@0.1.0#info",
"wasmExportInfoPostReturn:cabi_post_moonplasma:desktop/plasmoid@0.1.0#info",
"wasmExportOnEvent:moonplasma:desktop/plasmoid@0.1.0#on-event",
"wasmExportPopup:moonplasma:desktop/plasmoid@0.1.0#popup",
"wasmExportPopupPostReturn:cabi_post_moonplasma:desktop/plasmoid@0.1.0#popup",
"wasmExportRender:moonplasma:desktop/plasmoid@0.1.0#render",
"wasmExportRenderPostReturn:cabi_post_moonplasma:desktop/plasmoid@0.1.0#render"
],
},
},
)
@@ -0,0 +1,13 @@
// Generated using `moon info`, DON'T EDIT IT
package "moonplasma/desktop/components/clock-binary/gen"
// Values
pub fn mbt_ffi_cabi_realloc(Int32, Int32, Int32, Int32) -> Int32
// Errors
// Types and methods
// Type aliases
// Traits
+82
View File
@@ -0,0 +1,82 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
pub fn mbt_ffi_cabi_realloc(
src_offset : Int,
src_size : Int,
_dst_alignment : Int,
dst_size : Int,
) -> Int {
// malloc
if src_offset == 0 && src_size == 0 {
return mbt_ffi_malloc(dst_size)
}
// free
if dst_size == 0 {
mbt_ffi_free(src_offset)
return 0
}
// realloc
let dst = mbt_ffi_malloc(dst_size)
mbt_ffi_copy(dst, src_offset, if src_size < dst_size { src_size } else { dst_size })
mbt_ffi_free(src_offset)
dst
}
///|
extern "wasm" fn mbt_ffi_copy(dest : Int, src : Int, len : Int) =
#|(func (param i32) (param i32) (param i32) local.get 0 local.get 1 local.get 2 memory.copy)
///|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
#|(func (param i32) (result i32) (local i32)
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
#| local.tee 1 i32.const 0 call $moonbit.init_array8
#| local.get 1)
///|
extern "wasm" fn mbt_ffi_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
///|
#doc(hidden)
pub fn wasmExportInfo() -> Int {
@plasmoid.wasmExportInfo()
}
///|
#doc(hidden)
pub fn wasmExportRenderPostReturn(p0 : Int) -> Unit {
@plasmoid.wasmExportRenderPostReturn(p0)
}
///|
#doc(hidden)
pub fn wasmExportInfoPostReturn(p0 : Int) -> Unit {
@plasmoid.wasmExportInfoPostReturn(p0)
}
///|
#doc(hidden)
pub fn wasmExportPopupPostReturn(p0 : Int) -> Unit {
@plasmoid.wasmExportPopupPostReturn(p0)
}
///|
#doc(hidden)
pub fn wasmExportPopup() -> Int {
@plasmoid.wasmExportPopup()
}
///|
#doc(hidden)
pub fn wasmExportRender(p0 : Int, p1 : Int) -> Int {
@plasmoid.wasmExportRender(p0, p1)
}
///|
#doc(hidden)
pub fn wasmExportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
@plasmoid.wasmExportOnEvent(p0, p1, p2, p3)
}
@@ -0,0 +1 @@
The widget (plasmoid) contract.
@@ -0,0 +1,409 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
#doc(hidden)
pub fn wasmExportInfo() -> Int {
let (result) : (PlasmoidInfo) = info();
let return_area = mbt_ffi_malloc(32)
let ptr = mbt_ffi_str2ptr((result).id)
mbt_ffi_store32((return_area) + 4, (result).id.length())
mbt_ffi_store32((return_area) + 0, ptr)
let ptr0 = mbt_ffi_str2ptr((result).name)
mbt_ffi_store32((return_area) + 12, (result).name.length())
mbt_ffi_store32((return_area) + 8, ptr0)
mbt_ffi_store32((return_area) + 16, (((result).preferred).w).reinterpret_as_int())
mbt_ffi_store32((return_area) + 20, (((result).preferred).h).reinterpret_as_int())
mbt_ffi_store32((return_area) + 24, ((result).min_width).reinterpret_as_int())
mbt_ffi_store8((return_area) + 28, (if (result).stretch { 1 } else { 0 }))
let ret = return_area
return ret
}
///|
#doc(hidden)
pub fn wasmExportInfoPostReturn(p0 : Int) -> Unit {
mbt_ffi_free(mbt_ffi_load32((p0) + 0))
mbt_ffi_free(mbt_ffi_load32((p0) + 8))
}
///|
#doc(hidden)
pub fn wasmExportRender(p0 : Int, p1 : Int) -> Int {
let (result) : (Array[@types.DrawOp]) = render(@types.Size::{w : (p0).reinterpret_as_uint(), h : (p1).reinterpret_as_uint()});
let return_area = mbt_ffi_malloc(8)
let address = mbt_ffi_malloc((result).length() * 32);
for index = 0; index < (result).length(); index = index + 1 {
let iter_elem : @types.DrawOp = (result)[(index)]
let iter_base = address + (index * 32);
match iter_elem {
FillRect(payload) => {
mbt_ffi_store8((iter_base) + 0, (0))
mbt_ffi_store32((iter_base) + 4, ((payload).rect).x)
mbt_ffi_store32((iter_base) + 8, ((payload).rect).y)
mbt_ffi_store32((iter_base) + 12, (((payload).rect).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, (((payload).rect).h).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 20, (((payload).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload).radius).reinterpret_as_int())
()
}
StrokeRect(payload0) => {
mbt_ffi_store8((iter_base) + 0, (1))
mbt_ffi_store32((iter_base) + 4, ((payload0).rect).x)
mbt_ffi_store32((iter_base) + 8, ((payload0).rect).y)
mbt_ffi_store32((iter_base) + 12, (((payload0).rect).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, (((payload0).rect).h).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 20, (((payload0).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload0).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload0).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload0).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload0).width).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 28, ((payload0).radius).reinterpret_as_int())
()
}
Line(payload1) => {
mbt_ffi_store8((iter_base) + 0, (2))
mbt_ffi_store32((iter_base) + 4, ((payload1).start).x)
mbt_ffi_store32((iter_base) + 8, ((payload1).start).y)
mbt_ffi_store32((iter_base) + 12, ((payload1).end).x)
mbt_ffi_store32((iter_base) + 16, ((payload1).end).y)
mbt_ffi_store8((iter_base) + 20, (((payload1).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload1).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload1).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload1).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload1).width).reinterpret_as_int())
()
}
Circle(payload2) => {
mbt_ffi_store8((iter_base) + 0, (3))
mbt_ffi_store32((iter_base) + 4, ((payload2).center).x)
mbt_ffi_store32((iter_base) + 8, ((payload2).center).y)
mbt_ffi_store32((iter_base) + 12, ((payload2).radius).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 16, (((payload2).color).r).to_int())
mbt_ffi_store8((iter_base) + 17, (((payload2).color).g).to_int())
mbt_ffi_store8((iter_base) + 18, (((payload2).color).b).to_int())
mbt_ffi_store8((iter_base) + 19, (((payload2).color).a).to_int())
mbt_ffi_store8((iter_base) + 20, (if (payload2).filled { 1 } else { 0 }))
()
}
Text(payload3) => {
mbt_ffi_store8((iter_base) + 0, (4))
mbt_ffi_store32((iter_base) + 4, ((payload3).origin).x)
mbt_ffi_store32((iter_base) + 8, ((payload3).origin).y)
let ptr = mbt_ffi_str2ptr((payload3).text)
mbt_ffi_store32((iter_base) + 16, (payload3).text.length())
mbt_ffi_store32((iter_base) + 12, ptr)
mbt_ffi_store32((iter_base) + 20, (((payload3).style).size).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 24, ((((payload3).style).color).r).to_int())
mbt_ffi_store8((iter_base) + 25, ((((payload3).style).color).g).to_int())
mbt_ffi_store8((iter_base) + 26, ((((payload3).style).color).b).to_int())
mbt_ffi_store8((iter_base) + 27, ((((payload3).style).color).a).to_int())
mbt_ffi_store8((iter_base) + 28, ((payload3).style).align.ordinal())
mbt_ffi_store8((iter_base) + 29, (if ((payload3).style).bold { 1 } else { 0 }))
()
}
PushClip(payload4) => {
mbt_ffi_store8((iter_base) + 0, (5))
mbt_ffi_store32((iter_base) + 4, (payload4).x)
mbt_ffi_store32((iter_base) + 8, (payload4).y)
mbt_ffi_store32((iter_base) + 12, ((payload4).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, ((payload4).h).reinterpret_as_int())
()
}
PopClip => {
mbt_ffi_store8((iter_base) + 0, (6))
()
}
}
}
mbt_ffi_store32((return_area) + 4, (result).length())
mbt_ffi_store32((return_area) + 0, address)
let ret = return_area
return ret
}
///|
#doc(hidden)
pub fn wasmExportRenderPostReturn(p0 : Int) -> Unit {
for index = 0; index < (mbt_ffi_load32((p0) + 4)); index = index + 1 {
let iter_base = (mbt_ffi_load32((p0) + 0)) + (index * 32)
match (mbt_ffi_load8_u((iter_base) + 0)) {
0 => ()
1 => ()
2 => ()
3 => ()
4 => {
mbt_ffi_free(mbt_ffi_load32((iter_base) + 12))
}
5 => ()
6 => ()
_ => panic()
}
}
mbt_ffi_free(mbt_ffi_load32((p0) + 0))
}
///|
#doc(hidden)
pub fn wasmExportPopup() -> Int {
let (result) : (PopupSurface?) = popup();
let return_area = mbt_ffi_malloc(20)
match (result) {
None => {
mbt_ffi_store8((return_area) + 0, (0))
()
}
Some(payload0) => {
mbt_ffi_store8((return_area) + 0, (1))
mbt_ffi_store32((return_area) + 4, (((payload0).size).w).reinterpret_as_int())
mbt_ffi_store32((return_area) + 8, (((payload0).size).h).reinterpret_as_int())
let address = mbt_ffi_malloc(((payload0).ops).length() * 32);
for index = 0; index < ((payload0).ops).length(); index = index + 1 {
let iter_elem : @types.DrawOp = ((payload0).ops)[(index)]
let iter_base = address + (index * 32);
match iter_elem {
FillRect(payload1) => {
mbt_ffi_store8((iter_base) + 0, (0))
mbt_ffi_store32((iter_base) + 4, ((payload1).rect).x)
mbt_ffi_store32((iter_base) + 8, ((payload1).rect).y)
mbt_ffi_store32((iter_base) + 12, (((payload1).rect).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, (((payload1).rect).h).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 20, (((payload1).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload1).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload1).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload1).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload1).radius).reinterpret_as_int())
()
}
StrokeRect(payload2) => {
mbt_ffi_store8((iter_base) + 0, (1))
mbt_ffi_store32((iter_base) + 4, ((payload2).rect).x)
mbt_ffi_store32((iter_base) + 8, ((payload2).rect).y)
mbt_ffi_store32((iter_base) + 12, (((payload2).rect).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, (((payload2).rect).h).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 20, (((payload2).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload2).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload2).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload2).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload2).width).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 28, ((payload2).radius).reinterpret_as_int())
()
}
Line(payload3) => {
mbt_ffi_store8((iter_base) + 0, (2))
mbt_ffi_store32((iter_base) + 4, ((payload3).start).x)
mbt_ffi_store32((iter_base) + 8, ((payload3).start).y)
mbt_ffi_store32((iter_base) + 12, ((payload3).end).x)
mbt_ffi_store32((iter_base) + 16, ((payload3).end).y)
mbt_ffi_store8((iter_base) + 20, (((payload3).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload3).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload3).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload3).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload3).width).reinterpret_as_int())
()
}
Circle(payload4) => {
mbt_ffi_store8((iter_base) + 0, (3))
mbt_ffi_store32((iter_base) + 4, ((payload4).center).x)
mbt_ffi_store32((iter_base) + 8, ((payload4).center).y)
mbt_ffi_store32((iter_base) + 12, ((payload4).radius).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 16, (((payload4).color).r).to_int())
mbt_ffi_store8((iter_base) + 17, (((payload4).color).g).to_int())
mbt_ffi_store8((iter_base) + 18, (((payload4).color).b).to_int())
mbt_ffi_store8((iter_base) + 19, (((payload4).color).a).to_int())
mbt_ffi_store8((iter_base) + 20, (if (payload4).filled { 1 } else { 0 }))
()
}
Text(payload5) => {
mbt_ffi_store8((iter_base) + 0, (4))
mbt_ffi_store32((iter_base) + 4, ((payload5).origin).x)
mbt_ffi_store32((iter_base) + 8, ((payload5).origin).y)
let ptr = mbt_ffi_str2ptr((payload5).text)
mbt_ffi_store32((iter_base) + 16, (payload5).text.length())
mbt_ffi_store32((iter_base) + 12, ptr)
mbt_ffi_store32((iter_base) + 20, (((payload5).style).size).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 24, ((((payload5).style).color).r).to_int())
mbt_ffi_store8((iter_base) + 25, ((((payload5).style).color).g).to_int())
mbt_ffi_store8((iter_base) + 26, ((((payload5).style).color).b).to_int())
mbt_ffi_store8((iter_base) + 27, ((((payload5).style).color).a).to_int())
mbt_ffi_store8((iter_base) + 28, ((payload5).style).align.ordinal())
mbt_ffi_store8((iter_base) + 29, (if ((payload5).style).bold { 1 } else { 0 }))
()
}
PushClip(payload6) => {
mbt_ffi_store8((iter_base) + 0, (5))
mbt_ffi_store32((iter_base) + 4, (payload6).x)
mbt_ffi_store32((iter_base) + 8, (payload6).y)
mbt_ffi_store32((iter_base) + 12, ((payload6).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, ((payload6).h).reinterpret_as_int())
()
}
PopClip => {
mbt_ffi_store8((iter_base) + 0, (6))
()
}
}
}
mbt_ffi_store32((return_area) + 16, ((payload0).ops).length())
mbt_ffi_store32((return_area) + 12, address)
()
}
}
let ret = return_area
return ret
}
///|
#doc(hidden)
pub fn wasmExportPopupPostReturn(p0 : Int) -> Unit {
match (mbt_ffi_load8_u((p0) + 0)) {
0 => ()
1 => {
for index = 0; index < (mbt_ffi_load32((p0) + 16)); index = index + 1 {
let iter_base = (mbt_ffi_load32((p0) + 12)) + (index * 32)
match (mbt_ffi_load8_u((iter_base) + 0)) {
0 => ()
1 => ()
2 => ()
3 => ()
4 => {
mbt_ffi_free(mbt_ffi_load32((iter_base) + 12))
}
5 => ()
6 => ()
_ => panic()
}
}
mbt_ffi_free(mbt_ffi_load32((p0) + 12))
}
_ => panic()
}
}
///|
#doc(hidden)
pub fn wasmExportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
let lifted = match (p1) {
0 => {
@types.InputEvent::PointerMove(@types.Point::{x : p2, y : p3})
}
1 => {
@types.InputEvent::PointerDown(@types.Point::{x : p2, y : p3})
}
2 => {
@types.InputEvent::PointerUp(@types.Point::{x : p2, y : p3})
}
3 => {
@types.InputEvent::PointerLeave
}
4 => {
@types.InputEvent::FocusLost
}
5 => {
let result = mbt_ffi_ptr2str(p2, p3)
@types.InputEvent::KeyDown(result)
}
_ => panic()
}
let (result0) : (Bool) = on_event(Surface::from(p0), lifted);
let ret = (if result0 { 1 } else { 0 })
return ret
}
///|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
///|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
#|(func (param i32) (result i32) (local i32)
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
#| local.tee 1 i32.const 0 call $moonbit.init_array8
#| local.get 1)
///|
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
///|
extern "wasm" fn mbt_ffi_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
///|
extern "wasm" fn mbt_ffi_store8(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)
///|
extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)
///|
#owned(str)
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
#|(func (param i32) (result i32) local.get 0)
///|
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/moonplasma/desktop/types" @types,
"moonplasma/desktop/interface/moonplasma/desktop/theme" @theme,
"moonplasma/desktop/interface/moonplasma/desktop/clock" @clock,
"moonplasma/desktop/lib/clock" @logic,
}
warnings = "-44"
@@ -0,0 +1,42 @@
// Generated using `moon info`, DON'T EDIT IT
package "moonplasma/desktop/components/clock-digital/gen/interface/moonplasma/desktop/plasmoid"
import {
"moonplasma/desktop/interface/moonplasma/desktop/types",
}
// Values
pub fn info() -> PlasmoidInfo
pub fn on_event(Surface, @types.InputEvent) -> Bool
pub fn popup() -> PopupSurface?
pub fn render(@types.Size) -> Array[@types.DrawOp]
// Errors
// Types and methods
pub(all) struct PlasmoidInfo {
id : String
name : String
preferred : @types.Size
min_width : UInt32
stretch : Bool
}
pub(all) struct PopupSurface {
size : @types.Size
ops : Array[@types.DrawOp]
}
pub(all) enum Surface {
WIDGET
POPUP
}
pub fn Surface::from(Int32) -> Self
pub fn Surface::ordinal(Self) -> Int32
// Type aliases
// Traits
@@ -0,0 +1,29 @@
///| Implementation of `moonplasma:desktop/plasmoid` for the digital clock.
/// All logic lives in lib/clock; this file only adapts host capabilities.
///|
pub fn info() -> PlasmoidInfo {
let (id, name, w, h, min_w) = @logic.digital_info()
{
id,
name,
preferred: { w: w.reinterpret_as_uint(), h: h.reinterpret_as_uint() },
min_width: min_w.reinterpret_as_uint(),
stretch: false,
}
}
///|
pub fn render(size : @types.Size) -> Array[@types.DrawOp] {
@logic.render_digital(size, @theme.get_tokens(), @clock.now())
}
///|
pub fn popup() -> PopupSurface? {
None
}
///|
pub fn on_event(_target : Surface, _event : @types.InputEvent) -> Bool {
false
}
@@ -0,0 +1,42 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
pub(all) struct PlasmoidInfo {
id : String; name : String; preferred : @types.Size; min_width : UInt; stretch : Bool
}
///|
pub(all) struct PopupSurface {
size : @types.Size; ops : Array[@types.DrawOp]
}
///|
pub(all) enum Surface {
WIDGET; POPUP
} derive()
///|
pub fn Surface::ordinal(self : Surface) -> Int {
match self {
WIDGET => 0
POPUP => 1
}
}
///|
pub fn Surface::from(self : Int) -> Surface {
match self {
0 => WIDGET
1 => POPUP
_ => panic()
}
}
///|
declare pub fn info() -> PlasmoidInfo
///|
/// Draw the widget into a `size` box (local coordinates).
declare pub fn render(size : @types.Size) -> Array[@types.DrawOp]
///|
/// Present when the widget wants a popup surface (e.g. a launcher menu).
declare pub fn popup() -> PopupSurface?
///|
/// Returns true when the widget's visuals changed and a redraw is needed.
declare pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool
+26
View File
@@ -0,0 +1,26 @@
import {
"moonplasma/desktop/components/clock-digital/gen/interface/moonplasma/desktop/plasmoid" @plasmoid,
}
warnings = "-44"
pkgtype(kind: "foreign_library")
options(
link: {
"wasm": {
"export-memory-name": "memory",
"heap-start-address": 16,
"exports": [
"mbt_ffi_cabi_realloc:cabi_realloc",
"wasmExportInfo:moonplasma:desktop/plasmoid@0.1.0#info",
"wasmExportInfoPostReturn:cabi_post_moonplasma:desktop/plasmoid@0.1.0#info",
"wasmExportOnEvent:moonplasma:desktop/plasmoid@0.1.0#on-event",
"wasmExportPopup:moonplasma:desktop/plasmoid@0.1.0#popup",
"wasmExportPopupPostReturn:cabi_post_moonplasma:desktop/plasmoid@0.1.0#popup",
"wasmExportRender:moonplasma:desktop/plasmoid@0.1.0#render",
"wasmExportRenderPostReturn:cabi_post_moonplasma:desktop/plasmoid@0.1.0#render"
],
},
},
)
@@ -0,0 +1,13 @@
// Generated using `moon info`, DON'T EDIT IT
package "moonplasma/desktop/components/clock-digital/gen"
// Values
pub fn mbt_ffi_cabi_realloc(Int32, Int32, Int32, Int32) -> Int32
// Errors
// Types and methods
// Type aliases
// Traits
+82
View File
@@ -0,0 +1,82 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
pub fn mbt_ffi_cabi_realloc(
src_offset : Int,
src_size : Int,
_dst_alignment : Int,
dst_size : Int,
) -> Int {
// malloc
if src_offset == 0 && src_size == 0 {
return mbt_ffi_malloc(dst_size)
}
// free
if dst_size == 0 {
mbt_ffi_free(src_offset)
return 0
}
// realloc
let dst = mbt_ffi_malloc(dst_size)
mbt_ffi_copy(dst, src_offset, if src_size < dst_size { src_size } else { dst_size })
mbt_ffi_free(src_offset)
dst
}
///|
extern "wasm" fn mbt_ffi_copy(dest : Int, src : Int, len : Int) =
#|(func (param i32) (param i32) (param i32) local.get 0 local.get 1 local.get 2 memory.copy)
///|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
#|(func (param i32) (result i32) (local i32)
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
#| local.tee 1 i32.const 0 call $moonbit.init_array8
#| local.get 1)
///|
extern "wasm" fn mbt_ffi_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
///|
#doc(hidden)
pub fn wasmExportInfo() -> Int {
@plasmoid.wasmExportInfo()
}
///|
#doc(hidden)
pub fn wasmExportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
@plasmoid.wasmExportOnEvent(p0, p1, p2, p3)
}
///|
#doc(hidden)
pub fn wasmExportRenderPostReturn(p0 : Int) -> Unit {
@plasmoid.wasmExportRenderPostReturn(p0)
}
///|
#doc(hidden)
pub fn wasmExportInfoPostReturn(p0 : Int) -> Unit {
@plasmoid.wasmExportInfoPostReturn(p0)
}
///|
#doc(hidden)
pub fn wasmExportRender(p0 : Int, p1 : Int) -> Int {
@plasmoid.wasmExportRender(p0, p1)
}
///|
#doc(hidden)
pub fn wasmExportPopup() -> Int {
@plasmoid.wasmExportPopup()
}
///|
#doc(hidden)
pub fn wasmExportPopupPostReturn(p0 : Int) -> Unit {
@plasmoid.wasmExportPopupPostReturn(p0)
}
@@ -0,0 +1 @@
The widget (plasmoid) contract.
@@ -0,0 +1,409 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
#doc(hidden)
pub fn wasmExportInfo() -> Int {
let (result) : (PlasmoidInfo) = info();
let return_area = mbt_ffi_malloc(32)
let ptr = mbt_ffi_str2ptr((result).id)
mbt_ffi_store32((return_area) + 4, (result).id.length())
mbt_ffi_store32((return_area) + 0, ptr)
let ptr0 = mbt_ffi_str2ptr((result).name)
mbt_ffi_store32((return_area) + 12, (result).name.length())
mbt_ffi_store32((return_area) + 8, ptr0)
mbt_ffi_store32((return_area) + 16, (((result).preferred).w).reinterpret_as_int())
mbt_ffi_store32((return_area) + 20, (((result).preferred).h).reinterpret_as_int())
mbt_ffi_store32((return_area) + 24, ((result).min_width).reinterpret_as_int())
mbt_ffi_store8((return_area) + 28, (if (result).stretch { 1 } else { 0 }))
let ret = return_area
return ret
}
///|
#doc(hidden)
pub fn wasmExportInfoPostReturn(p0 : Int) -> Unit {
mbt_ffi_free(mbt_ffi_load32((p0) + 0))
mbt_ffi_free(mbt_ffi_load32((p0) + 8))
}
///|
#doc(hidden)
pub fn wasmExportRender(p0 : Int, p1 : Int) -> Int {
let (result) : (Array[@types.DrawOp]) = render(@types.Size::{w : (p0).reinterpret_as_uint(), h : (p1).reinterpret_as_uint()});
let return_area = mbt_ffi_malloc(8)
let address = mbt_ffi_malloc((result).length() * 32);
for index = 0; index < (result).length(); index = index + 1 {
let iter_elem : @types.DrawOp = (result)[(index)]
let iter_base = address + (index * 32);
match iter_elem {
FillRect(payload) => {
mbt_ffi_store8((iter_base) + 0, (0))
mbt_ffi_store32((iter_base) + 4, ((payload).rect).x)
mbt_ffi_store32((iter_base) + 8, ((payload).rect).y)
mbt_ffi_store32((iter_base) + 12, (((payload).rect).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, (((payload).rect).h).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 20, (((payload).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload).radius).reinterpret_as_int())
()
}
StrokeRect(payload0) => {
mbt_ffi_store8((iter_base) + 0, (1))
mbt_ffi_store32((iter_base) + 4, ((payload0).rect).x)
mbt_ffi_store32((iter_base) + 8, ((payload0).rect).y)
mbt_ffi_store32((iter_base) + 12, (((payload0).rect).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, (((payload0).rect).h).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 20, (((payload0).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload0).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload0).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload0).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload0).width).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 28, ((payload0).radius).reinterpret_as_int())
()
}
Line(payload1) => {
mbt_ffi_store8((iter_base) + 0, (2))
mbt_ffi_store32((iter_base) + 4, ((payload1).start).x)
mbt_ffi_store32((iter_base) + 8, ((payload1).start).y)
mbt_ffi_store32((iter_base) + 12, ((payload1).end).x)
mbt_ffi_store32((iter_base) + 16, ((payload1).end).y)
mbt_ffi_store8((iter_base) + 20, (((payload1).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload1).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload1).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload1).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload1).width).reinterpret_as_int())
()
}
Circle(payload2) => {
mbt_ffi_store8((iter_base) + 0, (3))
mbt_ffi_store32((iter_base) + 4, ((payload2).center).x)
mbt_ffi_store32((iter_base) + 8, ((payload2).center).y)
mbt_ffi_store32((iter_base) + 12, ((payload2).radius).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 16, (((payload2).color).r).to_int())
mbt_ffi_store8((iter_base) + 17, (((payload2).color).g).to_int())
mbt_ffi_store8((iter_base) + 18, (((payload2).color).b).to_int())
mbt_ffi_store8((iter_base) + 19, (((payload2).color).a).to_int())
mbt_ffi_store8((iter_base) + 20, (if (payload2).filled { 1 } else { 0 }))
()
}
Text(payload3) => {
mbt_ffi_store8((iter_base) + 0, (4))
mbt_ffi_store32((iter_base) + 4, ((payload3).origin).x)
mbt_ffi_store32((iter_base) + 8, ((payload3).origin).y)
let ptr = mbt_ffi_str2ptr((payload3).text)
mbt_ffi_store32((iter_base) + 16, (payload3).text.length())
mbt_ffi_store32((iter_base) + 12, ptr)
mbt_ffi_store32((iter_base) + 20, (((payload3).style).size).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 24, ((((payload3).style).color).r).to_int())
mbt_ffi_store8((iter_base) + 25, ((((payload3).style).color).g).to_int())
mbt_ffi_store8((iter_base) + 26, ((((payload3).style).color).b).to_int())
mbt_ffi_store8((iter_base) + 27, ((((payload3).style).color).a).to_int())
mbt_ffi_store8((iter_base) + 28, ((payload3).style).align.ordinal())
mbt_ffi_store8((iter_base) + 29, (if ((payload3).style).bold { 1 } else { 0 }))
()
}
PushClip(payload4) => {
mbt_ffi_store8((iter_base) + 0, (5))
mbt_ffi_store32((iter_base) + 4, (payload4).x)
mbt_ffi_store32((iter_base) + 8, (payload4).y)
mbt_ffi_store32((iter_base) + 12, ((payload4).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, ((payload4).h).reinterpret_as_int())
()
}
PopClip => {
mbt_ffi_store8((iter_base) + 0, (6))
()
}
}
}
mbt_ffi_store32((return_area) + 4, (result).length())
mbt_ffi_store32((return_area) + 0, address)
let ret = return_area
return ret
}
///|
#doc(hidden)
pub fn wasmExportRenderPostReturn(p0 : Int) -> Unit {
for index = 0; index < (mbt_ffi_load32((p0) + 4)); index = index + 1 {
let iter_base = (mbt_ffi_load32((p0) + 0)) + (index * 32)
match (mbt_ffi_load8_u((iter_base) + 0)) {
0 => ()
1 => ()
2 => ()
3 => ()
4 => {
mbt_ffi_free(mbt_ffi_load32((iter_base) + 12))
}
5 => ()
6 => ()
_ => panic()
}
}
mbt_ffi_free(mbt_ffi_load32((p0) + 0))
}
///|
#doc(hidden)
pub fn wasmExportPopup() -> Int {
let (result) : (PopupSurface?) = popup();
let return_area = mbt_ffi_malloc(20)
match (result) {
None => {
mbt_ffi_store8((return_area) + 0, (0))
()
}
Some(payload0) => {
mbt_ffi_store8((return_area) + 0, (1))
mbt_ffi_store32((return_area) + 4, (((payload0).size).w).reinterpret_as_int())
mbt_ffi_store32((return_area) + 8, (((payload0).size).h).reinterpret_as_int())
let address = mbt_ffi_malloc(((payload0).ops).length() * 32);
for index = 0; index < ((payload0).ops).length(); index = index + 1 {
let iter_elem : @types.DrawOp = ((payload0).ops)[(index)]
let iter_base = address + (index * 32);
match iter_elem {
FillRect(payload1) => {
mbt_ffi_store8((iter_base) + 0, (0))
mbt_ffi_store32((iter_base) + 4, ((payload1).rect).x)
mbt_ffi_store32((iter_base) + 8, ((payload1).rect).y)
mbt_ffi_store32((iter_base) + 12, (((payload1).rect).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, (((payload1).rect).h).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 20, (((payload1).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload1).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload1).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload1).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload1).radius).reinterpret_as_int())
()
}
StrokeRect(payload2) => {
mbt_ffi_store8((iter_base) + 0, (1))
mbt_ffi_store32((iter_base) + 4, ((payload2).rect).x)
mbt_ffi_store32((iter_base) + 8, ((payload2).rect).y)
mbt_ffi_store32((iter_base) + 12, (((payload2).rect).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, (((payload2).rect).h).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 20, (((payload2).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload2).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload2).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload2).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload2).width).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 28, ((payload2).radius).reinterpret_as_int())
()
}
Line(payload3) => {
mbt_ffi_store8((iter_base) + 0, (2))
mbt_ffi_store32((iter_base) + 4, ((payload3).start).x)
mbt_ffi_store32((iter_base) + 8, ((payload3).start).y)
mbt_ffi_store32((iter_base) + 12, ((payload3).end).x)
mbt_ffi_store32((iter_base) + 16, ((payload3).end).y)
mbt_ffi_store8((iter_base) + 20, (((payload3).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload3).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload3).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload3).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload3).width).reinterpret_as_int())
()
}
Circle(payload4) => {
mbt_ffi_store8((iter_base) + 0, (3))
mbt_ffi_store32((iter_base) + 4, ((payload4).center).x)
mbt_ffi_store32((iter_base) + 8, ((payload4).center).y)
mbt_ffi_store32((iter_base) + 12, ((payload4).radius).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 16, (((payload4).color).r).to_int())
mbt_ffi_store8((iter_base) + 17, (((payload4).color).g).to_int())
mbt_ffi_store8((iter_base) + 18, (((payload4).color).b).to_int())
mbt_ffi_store8((iter_base) + 19, (((payload4).color).a).to_int())
mbt_ffi_store8((iter_base) + 20, (if (payload4).filled { 1 } else { 0 }))
()
}
Text(payload5) => {
mbt_ffi_store8((iter_base) + 0, (4))
mbt_ffi_store32((iter_base) + 4, ((payload5).origin).x)
mbt_ffi_store32((iter_base) + 8, ((payload5).origin).y)
let ptr = mbt_ffi_str2ptr((payload5).text)
mbt_ffi_store32((iter_base) + 16, (payload5).text.length())
mbt_ffi_store32((iter_base) + 12, ptr)
mbt_ffi_store32((iter_base) + 20, (((payload5).style).size).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 24, ((((payload5).style).color).r).to_int())
mbt_ffi_store8((iter_base) + 25, ((((payload5).style).color).g).to_int())
mbt_ffi_store8((iter_base) + 26, ((((payload5).style).color).b).to_int())
mbt_ffi_store8((iter_base) + 27, ((((payload5).style).color).a).to_int())
mbt_ffi_store8((iter_base) + 28, ((payload5).style).align.ordinal())
mbt_ffi_store8((iter_base) + 29, (if ((payload5).style).bold { 1 } else { 0 }))
()
}
PushClip(payload6) => {
mbt_ffi_store8((iter_base) + 0, (5))
mbt_ffi_store32((iter_base) + 4, (payload6).x)
mbt_ffi_store32((iter_base) + 8, (payload6).y)
mbt_ffi_store32((iter_base) + 12, ((payload6).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, ((payload6).h).reinterpret_as_int())
()
}
PopClip => {
mbt_ffi_store8((iter_base) + 0, (6))
()
}
}
}
mbt_ffi_store32((return_area) + 16, ((payload0).ops).length())
mbt_ffi_store32((return_area) + 12, address)
()
}
}
let ret = return_area
return ret
}
///|
#doc(hidden)
pub fn wasmExportPopupPostReturn(p0 : Int) -> Unit {
match (mbt_ffi_load8_u((p0) + 0)) {
0 => ()
1 => {
for index = 0; index < (mbt_ffi_load32((p0) + 16)); index = index + 1 {
let iter_base = (mbt_ffi_load32((p0) + 12)) + (index * 32)
match (mbt_ffi_load8_u((iter_base) + 0)) {
0 => ()
1 => ()
2 => ()
3 => ()
4 => {
mbt_ffi_free(mbt_ffi_load32((iter_base) + 12))
}
5 => ()
6 => ()
_ => panic()
}
}
mbt_ffi_free(mbt_ffi_load32((p0) + 12))
}
_ => panic()
}
}
///|
#doc(hidden)
pub fn wasmExportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
let lifted = match (p1) {
0 => {
@types.InputEvent::PointerMove(@types.Point::{x : p2, y : p3})
}
1 => {
@types.InputEvent::PointerDown(@types.Point::{x : p2, y : p3})
}
2 => {
@types.InputEvent::PointerUp(@types.Point::{x : p2, y : p3})
}
3 => {
@types.InputEvent::PointerLeave
}
4 => {
@types.InputEvent::FocusLost
}
5 => {
let result = mbt_ffi_ptr2str(p2, p3)
@types.InputEvent::KeyDown(result)
}
_ => panic()
}
let (result0) : (Bool) = on_event(Surface::from(p0), lifted);
let ret = (if result0 { 1 } else { 0 })
return ret
}
///|
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)
///|
#owned(str)
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
#|(func (param i32) (result i32) local.get 0)
///|
extern "wasm" fn mbt_ffi_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
///|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
///|
extern "wasm" fn mbt_ffi_store8(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)
///|
extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)
///|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
#|(func (param i32) (result i32) (local i32)
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
#| local.tee 1 i32.const 0 call $moonbit.init_array8
#| local.get 1)
///|
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
@@ -0,0 +1,9 @@
import {
"moonplasma/desktop/interface/moonplasma/desktop/types" @types,
"moonplasma/desktop/interface/moonplasma/desktop/theme" @theme,
"moonplasma/desktop/interface/moonplasma/desktop/app-catalog" @app_catalog,
"moonplasma/desktop/interface/moonplasma/desktop/app-launch" @app_launch,
"moonplasma/desktop/lib/launcher" @logic,
}
warnings = "-44"
@@ -0,0 +1,42 @@
// Generated using `moon info`, DON'T EDIT IT
package "moonplasma/desktop/components/launcher/gen/interface/moonplasma/desktop/plasmoid"
import {
"moonplasma/desktop/interface/moonplasma/desktop/types",
}
// Values
pub fn info() -> PlasmoidInfo
pub fn on_event(Surface, @types.InputEvent) -> Bool
pub fn popup() -> PopupSurface?
pub fn render(@types.Size) -> Array[@types.DrawOp]
// Errors
// Types and methods
pub(all) struct PlasmoidInfo {
id : String
name : String
preferred : @types.Size
min_width : UInt32
stretch : Bool
}
pub(all) struct PopupSurface {
size : @types.Size
ops : Array[@types.DrawOp]
}
pub(all) enum Surface {
WIDGET
POPUP
}
pub fn Surface::from(Int32) -> Self
pub fn Surface::ordinal(Self) -> Int32
// Type aliases
// Traits
@@ -0,0 +1,42 @@
///| Implementation of `moonplasma:desktop/plasmoid` for the launcher.
/// The state machine lives in lib/launcher; this adapts host capabilities.
///|
let state : @logic.State = @logic.State::new()
///|
pub fn info() -> PlasmoidInfo {
{
id: "org.moonplasma.launcher",
name: "Application Launcher",
preferred: { w: 150, h: 34 },
min_width: 60,
stretch: false,
}
}
///|
pub fn render(size : @types.Size) -> Array[@types.DrawOp] {
@logic.render_button(size, @theme.get_tokens(), state)
}
///|
pub fn popup() -> PopupSurface? {
if !state.open {
return None
}
let apps = @app_catalog.list_apps()
Some({
size: @logic.popup_size(apps, state),
ops: @logic.render_popup(apps, @theme.get_tokens(), state),
})
}
///|
pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool {
let t : @logic.Target = match target {
WIDGET => Widget
POPUP => Popup
}
@logic.handle_event(@app_catalog.list_apps(), state, t, event, @app_launch.launch)
}
@@ -0,0 +1,42 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
pub(all) struct PlasmoidInfo {
id : String; name : String; preferred : @types.Size; min_width : UInt; stretch : Bool
}
///|
pub(all) struct PopupSurface {
size : @types.Size; ops : Array[@types.DrawOp]
}
///|
pub(all) enum Surface {
WIDGET; POPUP
} derive()
///|
pub fn Surface::ordinal(self : Surface) -> Int {
match self {
WIDGET => 0
POPUP => 1
}
}
///|
pub fn Surface::from(self : Int) -> Surface {
match self {
0 => WIDGET
1 => POPUP
_ => panic()
}
}
///|
declare pub fn info() -> PlasmoidInfo
///|
/// Draw the widget into a `size` box (local coordinates).
declare pub fn render(size : @types.Size) -> Array[@types.DrawOp]
///|
/// Present when the widget wants a popup surface (e.g. a launcher menu).
declare pub fn popup() -> PopupSurface?
///|
/// Returns true when the widget's visuals changed and a redraw is needed.
declare pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool
+26
View File
@@ -0,0 +1,26 @@
import {
"moonplasma/desktop/components/launcher/gen/interface/moonplasma/desktop/plasmoid" @plasmoid,
}
warnings = "-44"
pkgtype(kind: "foreign_library")
options(
link: {
"wasm": {
"export-memory-name": "memory",
"heap-start-address": 16,
"exports": [
"mbt_ffi_cabi_realloc:cabi_realloc",
"wasmExportInfo:moonplasma:desktop/plasmoid@0.1.0#info",
"wasmExportInfoPostReturn:cabi_post_moonplasma:desktop/plasmoid@0.1.0#info",
"wasmExportOnEvent:moonplasma:desktop/plasmoid@0.1.0#on-event",
"wasmExportPopup:moonplasma:desktop/plasmoid@0.1.0#popup",
"wasmExportPopupPostReturn:cabi_post_moonplasma:desktop/plasmoid@0.1.0#popup",
"wasmExportRender:moonplasma:desktop/plasmoid@0.1.0#render",
"wasmExportRenderPostReturn:cabi_post_moonplasma:desktop/plasmoid@0.1.0#render"
],
},
},
)
@@ -0,0 +1,13 @@
// Generated using `moon info`, DON'T EDIT IT
package "moonplasma/desktop/components/launcher/gen"
// Values
pub fn mbt_ffi_cabi_realloc(Int32, Int32, Int32, Int32) -> Int32
// Errors
// Types and methods
// Type aliases
// Traits
+82
View File
@@ -0,0 +1,82 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
pub fn mbt_ffi_cabi_realloc(
src_offset : Int,
src_size : Int,
_dst_alignment : Int,
dst_size : Int,
) -> Int {
// malloc
if src_offset == 0 && src_size == 0 {
return mbt_ffi_malloc(dst_size)
}
// free
if dst_size == 0 {
mbt_ffi_free(src_offset)
return 0
}
// realloc
let dst = mbt_ffi_malloc(dst_size)
mbt_ffi_copy(dst, src_offset, if src_size < dst_size { src_size } else { dst_size })
mbt_ffi_free(src_offset)
dst
}
///|
extern "wasm" fn mbt_ffi_copy(dest : Int, src : Int, len : Int) =
#|(func (param i32) (param i32) (param i32) local.get 0 local.get 1 local.get 2 memory.copy)
///|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
#|(func (param i32) (result i32) (local i32)
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
#| local.tee 1 i32.const 0 call $moonbit.init_array8
#| local.get 1)
///|
extern "wasm" fn mbt_ffi_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
///|
#doc(hidden)
pub fn wasmExportPopupPosition(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int, p6 : Int, p7 : Int, p8 : Int, p9 : Int, p10 : Int, p11 : Int) -> Int {
@panel-layout.wasmExportPopupPosition(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11)
}
///|
#doc(hidden)
pub fn wasmExportRenderBackgroundPostReturn(p0 : Int) -> Unit {
@desktop-surface.wasmExportRenderBackgroundPostReturn(p0)
}
///|
#doc(hidden)
pub fn wasmExportRenderPanelPostReturn(p0 : Int) -> Unit {
@panel-layout.wasmExportRenderPanelPostReturn(p0)
}
///|
#doc(hidden)
pub fn wasmExportComputeLayoutPostReturn(p0 : Int) -> Unit {
@panel-layout.wasmExportComputeLayoutPostReturn(p0)
}
///|
#doc(hidden)
pub fn wasmExportComputeLayout(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
@panel-layout.wasmExportComputeLayout(p0, p1, p2, p3)
}
///|
#doc(hidden)
pub fn wasmExportRenderPanel(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int) -> Int {
@panel-layout.wasmExportRenderPanel(p0, p1, p2, p3, p4, p5)
}
///|
#doc(hidden)
pub fn wasmExportRenderBackground(p0 : Int, p1 : Int) -> Int {
@desktop-surface.wasmExportRenderBackground(p0, p1)
}
@@ -0,0 +1 @@
Desktop surface contract (wallpaper / desktop containment).
@@ -0,0 +1,171 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
#doc(hidden)
pub fn wasmExportRenderBackground(p0 : Int, p1 : Int) -> Int {
let (result) : (Array[@types.DrawOp]) = render_background(@types.Size::{w : (p0).reinterpret_as_uint(), h : (p1).reinterpret_as_uint()});
let return_area = mbt_ffi_malloc(8)
let address = mbt_ffi_malloc((result).length() * 32);
for index = 0; index < (result).length(); index = index + 1 {
let iter_elem : @types.DrawOp = (result)[(index)]
let iter_base = address + (index * 32);
match iter_elem {
FillRect(payload) => {
mbt_ffi_store8((iter_base) + 0, (0))
mbt_ffi_store32((iter_base) + 4, ((payload).rect).x)
mbt_ffi_store32((iter_base) + 8, ((payload).rect).y)
mbt_ffi_store32((iter_base) + 12, (((payload).rect).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, (((payload).rect).h).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 20, (((payload).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload).radius).reinterpret_as_int())
()
}
StrokeRect(payload0) => {
mbt_ffi_store8((iter_base) + 0, (1))
mbt_ffi_store32((iter_base) + 4, ((payload0).rect).x)
mbt_ffi_store32((iter_base) + 8, ((payload0).rect).y)
mbt_ffi_store32((iter_base) + 12, (((payload0).rect).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, (((payload0).rect).h).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 20, (((payload0).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload0).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload0).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload0).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload0).width).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 28, ((payload0).radius).reinterpret_as_int())
()
}
Line(payload1) => {
mbt_ffi_store8((iter_base) + 0, (2))
mbt_ffi_store32((iter_base) + 4, ((payload1).start).x)
mbt_ffi_store32((iter_base) + 8, ((payload1).start).y)
mbt_ffi_store32((iter_base) + 12, ((payload1).end).x)
mbt_ffi_store32((iter_base) + 16, ((payload1).end).y)
mbt_ffi_store8((iter_base) + 20, (((payload1).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload1).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload1).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload1).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload1).width).reinterpret_as_int())
()
}
Circle(payload2) => {
mbt_ffi_store8((iter_base) + 0, (3))
mbt_ffi_store32((iter_base) + 4, ((payload2).center).x)
mbt_ffi_store32((iter_base) + 8, ((payload2).center).y)
mbt_ffi_store32((iter_base) + 12, ((payload2).radius).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 16, (((payload2).color).r).to_int())
mbt_ffi_store8((iter_base) + 17, (((payload2).color).g).to_int())
mbt_ffi_store8((iter_base) + 18, (((payload2).color).b).to_int())
mbt_ffi_store8((iter_base) + 19, (((payload2).color).a).to_int())
mbt_ffi_store8((iter_base) + 20, (if (payload2).filled { 1 } else { 0 }))
()
}
Text(payload3) => {
mbt_ffi_store8((iter_base) + 0, (4))
mbt_ffi_store32((iter_base) + 4, ((payload3).origin).x)
mbt_ffi_store32((iter_base) + 8, ((payload3).origin).y)
let ptr = mbt_ffi_str2ptr((payload3).text)
mbt_ffi_store32((iter_base) + 16, (payload3).text.length())
mbt_ffi_store32((iter_base) + 12, ptr)
mbt_ffi_store32((iter_base) + 20, (((payload3).style).size).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 24, ((((payload3).style).color).r).to_int())
mbt_ffi_store8((iter_base) + 25, ((((payload3).style).color).g).to_int())
mbt_ffi_store8((iter_base) + 26, ((((payload3).style).color).b).to_int())
mbt_ffi_store8((iter_base) + 27, ((((payload3).style).color).a).to_int())
mbt_ffi_store8((iter_base) + 28, ((payload3).style).align.ordinal())
mbt_ffi_store8((iter_base) + 29, (if ((payload3).style).bold { 1 } else { 0 }))
()
}
PushClip(payload4) => {
mbt_ffi_store8((iter_base) + 0, (5))
mbt_ffi_store32((iter_base) + 4, (payload4).x)
mbt_ffi_store32((iter_base) + 8, (payload4).y)
mbt_ffi_store32((iter_base) + 12, ((payload4).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, ((payload4).h).reinterpret_as_int())
()
}
PopClip => {
mbt_ffi_store8((iter_base) + 0, (6))
()
}
}
}
mbt_ffi_store32((return_area) + 4, (result).length())
mbt_ffi_store32((return_area) + 0, address)
let ret = return_area
return ret
}
///|
#doc(hidden)
pub fn wasmExportRenderBackgroundPostReturn(p0 : Int) -> Unit {
for index = 0; index < (mbt_ffi_load32((p0) + 4)); index = index + 1 {
let iter_base = (mbt_ffi_load32((p0) + 0)) + (index * 32)
match (mbt_ffi_load8_u((iter_base) + 0)) {
0 => ()
1 => ()
2 => ()
3 => ()
4 => {
mbt_ffi_free(mbt_ffi_load32((iter_base) + 12))
}
5 => ()
6 => ()
_ => panic()
}
}
mbt_ffi_free(mbt_ffi_load32((p0) + 0))
}
///|
extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)
///|
extern "wasm" fn mbt_ffi_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
///|
extern "wasm" fn mbt_ffi_store8(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)
///|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
///|
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
///|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
#|(func (param i32) (result i32) (local i32)
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
#| local.tee 1 i32.const 0 call $moonbit.init_array8
#| local.get 1)
///|
#owned(str)
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
#|(func (param i32) (result i32) local.get 0)
@@ -0,0 +1,7 @@
import {
"moonplasma/desktop/interface/moonplasma/desktop/types" @types,
"moonplasma/desktop/interface/moonplasma/desktop/theme" @theme,
"moonplasma/desktop/lib/shell" @logic,
}
warnings = "-44"
@@ -0,0 +1,17 @@
// Generated using `moon info`, DON'T EDIT IT
package "moonplasma/desktop/components/shell/gen/interface/moonplasma/desktop/desktop-surface"
import {
"moonplasma/desktop/interface/moonplasma/desktop/types",
}
// Values
pub fn render_background(@types.Size) -> Array[@types.DrawOp]
// Errors
// Types and methods
// Type aliases
// Traits
@@ -0,0 +1,6 @@
///| `moonplasma:desktop/desktop-surface` for the reference shell.
///|
pub fn render_background(screen : @types.Size) -> Array[@types.DrawOp] {
@logic.render_background(screen, @theme.get_tokens())
}
@@ -0,0 +1,4 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
declare pub fn render_background(screen : @types.Size) -> Array[@types.DrawOp]
@@ -0,0 +1 @@
Panel layout/chrome contract (the plasmashell "containment" analogue).
@@ -0,0 +1,248 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
#doc(hidden)
pub fn wasmExportComputeLayout(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
let array : Array[Slot] = [];
for index = 0; index < (p3); index = index + 1 {
let iter_base = (p2) + (index * 24)
let result = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4))
array.push(Slot::{id : result, preferred : @types.Size::{w : (mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint()}, min_width : (mbt_ffi_load32((iter_base) + 16)).reinterpret_as_uint(), stretch : (mbt_ffi_load8_u((iter_base) + 20) != 0), align : Edge::from(mbt_ffi_load8_u((iter_base) + 21))})
}
mbt_ffi_free(p2)
let (result0) : (Layout) = compute_layout(@types.Size::{w : (p0).reinterpret_as_uint(), h : (p1).reinterpret_as_uint()}, array);
let return_area = mbt_ffi_malloc(24)
mbt_ffi_store32((return_area) + 0, ((result0).panel).x)
mbt_ffi_store32((return_area) + 4, ((result0).panel).y)
mbt_ffi_store32((return_area) + 8, (((result0).panel).w).reinterpret_as_int())
mbt_ffi_store32((return_area) + 12, (((result0).panel).h).reinterpret_as_int())
let address = mbt_ffi_malloc(((result0).placements).length() * 24);
for index1 = 0; index1 < ((result0).placements).length(); index1 = index1 + 1 {
let iter_elem : Placement = ((result0).placements)[(index1)]
let iter_base = address + (index1 * 24);
let ptr = mbt_ffi_str2ptr((iter_elem).id)
mbt_ffi_store32((iter_base) + 4, (iter_elem).id.length())
mbt_ffi_store32((iter_base) + 0, ptr)
mbt_ffi_store32((iter_base) + 8, ((iter_elem).rect).x)
mbt_ffi_store32((iter_base) + 12, ((iter_elem).rect).y)
mbt_ffi_store32((iter_base) + 16, (((iter_elem).rect).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 20, (((iter_elem).rect).h).reinterpret_as_int())
}
mbt_ffi_store32((return_area) + 20, ((result0).placements).length())
mbt_ffi_store32((return_area) + 16, address)
let ret = return_area
return ret
}
///|
#doc(hidden)
pub fn wasmExportComputeLayoutPostReturn(p0 : Int) -> Unit {
for index = 0; index < (mbt_ffi_load32((p0) + 20)); index = index + 1 {
let iter_base = (mbt_ffi_load32((p0) + 16)) + (index * 24)
mbt_ffi_free(mbt_ffi_load32((iter_base) + 0))
}
mbt_ffi_free(mbt_ffi_load32((p0) + 16))
}
///|
#doc(hidden)
pub fn wasmExportRenderPanel(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int) -> Int {
let (result) : (Array[@types.DrawOp]) = render_panel(@types.Size::{w : (p0).reinterpret_as_uint(), h : (p1).reinterpret_as_uint()}, @types.Rect::{x : p2, y : p3, w : (p4).reinterpret_as_uint(), h : (p5).reinterpret_as_uint()});
let return_area = mbt_ffi_malloc(8)
let address = mbt_ffi_malloc((result).length() * 32);
for index = 0; index < (result).length(); index = index + 1 {
let iter_elem : @types.DrawOp = (result)[(index)]
let iter_base = address + (index * 32);
match iter_elem {
FillRect(payload) => {
mbt_ffi_store8((iter_base) + 0, (0))
mbt_ffi_store32((iter_base) + 4, ((payload).rect).x)
mbt_ffi_store32((iter_base) + 8, ((payload).rect).y)
mbt_ffi_store32((iter_base) + 12, (((payload).rect).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, (((payload).rect).h).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 20, (((payload).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload).radius).reinterpret_as_int())
()
}
StrokeRect(payload0) => {
mbt_ffi_store8((iter_base) + 0, (1))
mbt_ffi_store32((iter_base) + 4, ((payload0).rect).x)
mbt_ffi_store32((iter_base) + 8, ((payload0).rect).y)
mbt_ffi_store32((iter_base) + 12, (((payload0).rect).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, (((payload0).rect).h).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 20, (((payload0).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload0).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload0).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload0).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload0).width).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 28, ((payload0).radius).reinterpret_as_int())
()
}
Line(payload1) => {
mbt_ffi_store8((iter_base) + 0, (2))
mbt_ffi_store32((iter_base) + 4, ((payload1).start).x)
mbt_ffi_store32((iter_base) + 8, ((payload1).start).y)
mbt_ffi_store32((iter_base) + 12, ((payload1).end).x)
mbt_ffi_store32((iter_base) + 16, ((payload1).end).y)
mbt_ffi_store8((iter_base) + 20, (((payload1).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload1).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload1).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload1).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload1).width).reinterpret_as_int())
()
}
Circle(payload2) => {
mbt_ffi_store8((iter_base) + 0, (3))
mbt_ffi_store32((iter_base) + 4, ((payload2).center).x)
mbt_ffi_store32((iter_base) + 8, ((payload2).center).y)
mbt_ffi_store32((iter_base) + 12, ((payload2).radius).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 16, (((payload2).color).r).to_int())
mbt_ffi_store8((iter_base) + 17, (((payload2).color).g).to_int())
mbt_ffi_store8((iter_base) + 18, (((payload2).color).b).to_int())
mbt_ffi_store8((iter_base) + 19, (((payload2).color).a).to_int())
mbt_ffi_store8((iter_base) + 20, (if (payload2).filled { 1 } else { 0 }))
()
}
Text(payload3) => {
mbt_ffi_store8((iter_base) + 0, (4))
mbt_ffi_store32((iter_base) + 4, ((payload3).origin).x)
mbt_ffi_store32((iter_base) + 8, ((payload3).origin).y)
let ptr = mbt_ffi_str2ptr((payload3).text)
mbt_ffi_store32((iter_base) + 16, (payload3).text.length())
mbt_ffi_store32((iter_base) + 12, ptr)
mbt_ffi_store32((iter_base) + 20, (((payload3).style).size).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 24, ((((payload3).style).color).r).to_int())
mbt_ffi_store8((iter_base) + 25, ((((payload3).style).color).g).to_int())
mbt_ffi_store8((iter_base) + 26, ((((payload3).style).color).b).to_int())
mbt_ffi_store8((iter_base) + 27, ((((payload3).style).color).a).to_int())
mbt_ffi_store8((iter_base) + 28, ((payload3).style).align.ordinal())
mbt_ffi_store8((iter_base) + 29, (if ((payload3).style).bold { 1 } else { 0 }))
()
}
PushClip(payload4) => {
mbt_ffi_store8((iter_base) + 0, (5))
mbt_ffi_store32((iter_base) + 4, (payload4).x)
mbt_ffi_store32((iter_base) + 8, (payload4).y)
mbt_ffi_store32((iter_base) + 12, ((payload4).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, ((payload4).h).reinterpret_as_int())
()
}
PopClip => {
mbt_ffi_store8((iter_base) + 0, (6))
()
}
}
}
mbt_ffi_store32((return_area) + 4, (result).length())
mbt_ffi_store32((return_area) + 0, address)
let ret = return_area
return ret
}
///|
#doc(hidden)
pub fn wasmExportRenderPanelPostReturn(p0 : Int) -> Unit {
for index = 0; index < (mbt_ffi_load32((p0) + 4)); index = index + 1 {
let iter_base = (mbt_ffi_load32((p0) + 0)) + (index * 32)
match (mbt_ffi_load8_u((iter_base) + 0)) {
0 => ()
1 => ()
2 => ()
3 => ()
4 => {
mbt_ffi_free(mbt_ffi_load32((iter_base) + 12))
}
5 => ()
6 => ()
_ => panic()
}
}
mbt_ffi_free(mbt_ffi_load32((p0) + 0))
}
///|
#doc(hidden)
pub fn wasmExportPopupPosition(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int, p6 : Int, p7 : Int, p8 : Int, p9 : Int, p10 : Int, p11 : Int) -> Int {
let (result) : (@types.Rect) = popup_position(@types.Size::{w : (p0).reinterpret_as_uint(), h : (p1).reinterpret_as_uint()}, @types.Rect::{x : p2, y : p3, w : (p4).reinterpret_as_uint(), h : (p5).reinterpret_as_uint()}, @types.Rect::{x : p6, y : p7, w : (p8).reinterpret_as_uint(), h : (p9).reinterpret_as_uint()}, @types.Size::{w : (p10).reinterpret_as_uint(), h : (p11).reinterpret_as_uint()});
let return_area = mbt_ffi_malloc(16)
mbt_ffi_store32((return_area) + 0, (result).x)
mbt_ffi_store32((return_area) + 4, (result).y)
mbt_ffi_store32((return_area) + 8, ((result).w).reinterpret_as_int())
mbt_ffi_store32((return_area) + 12, ((result).h).reinterpret_as_int())
let ret = return_area
return ret
}
///|
extern "wasm" fn mbt_ffi_store8(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)
///|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
#|(func (param i32) (result i32) (local i32)
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
#| local.tee 1 i32.const 0 call $moonbit.init_array8
#| local.get 1)
///|
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)
///|
extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)
///|
#owned(str)
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
#|(func (param i32) (result i32) local.get 0)
///|
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
///|
extern "wasm" fn mbt_ffi_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
///|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
@@ -0,0 +1,9 @@
import {
"moonplasma/desktop/interface/moonplasma/desktop/types" @types,
"moonplasma/desktop/interface/moonplasma/desktop/theme" @theme,
"moonplasma/desktop/lib/shell" @shell,
"moonplasma/desktop/lib/panel" @panel,
"moonplasma/desktop/lib/ui" @ui,
}
warnings = "-44"
@@ -0,0 +1,45 @@
// Generated using `moon info`, DON'T EDIT IT
package "moonplasma/desktop/components/shell/gen/interface/moonplasma/desktop/panel-layout"
import {
"moonplasma/desktop/interface/moonplasma/desktop/types",
}
// Values
pub fn compute_layout(@types.Size, Array[Slot]) -> Layout
pub fn popup_position(@types.Size, @types.Rect, @types.Rect, @types.Size) -> @types.Rect
pub fn render_panel(@types.Size, @types.Rect) -> Array[@types.DrawOp]
// Errors
// Types and methods
pub(all) enum Edge {
START
END
}
pub fn Edge::from(Int32) -> Self
pub fn Edge::ordinal(Self) -> Int32
pub(all) struct Layout {
panel : @types.Rect
placements : Array[Placement]
}
pub(all) struct Placement {
id : String
rect : @types.Rect
}
pub(all) struct Slot {
id : String
preferred : @types.Size
min_width : UInt32
stretch : Bool
align : Edge
}
// Type aliases
// Traits
@@ -0,0 +1,57 @@
///| `moonplasma:desktop/panel-layout` for the reference shell. Geometry is in
/// lib/panel (pure, unit-tested); this adapts the WIT records.
///|
pub fn compute_layout(screen : @types.Size, slots : Array[Slot]) -> Layout {
let t = @theme.get_tokens()
let margin = 5
let ins = slots.map(s => @panel.SlotIn::{
id: s.id,
pref_w: s.preferred.w.reinterpret_as_int(),
pref_h: s.preferred.h.reinterpret_as_int(),
min_w: s.min_width.reinterpret_as_int(),
stretch: s.stretch,
end_align: match s.align {
START => false
END => true
},
})
match @panel.layout(
screen.w.reinterpret_as_int(),
screen.h.reinterpret_as_int(),
t.panel_height.reinterpret_as_int(),
margin,
t.spacing.reinterpret_as_int(),
ins,
) {
// Fail loudly: a trap surfaces in the host as a component error.
Err(e) => abort("panel layout failed: " + e)
Ok(l) => {
panel: @ui.rect(l.x, l.y, l.w, l.h),
placements: l.placements.map(p => { id: p.id, rect: @ui.rect(p.x, p.y, p.w, p.h) }),
}
}
}
///|
pub fn render_panel(_screen : @types.Size, panel : @types.Rect) -> Array[@types.DrawOp] {
@shell.render_panel(panel, @theme.get_tokens())
}
///|
pub fn popup_position(
screen : @types.Size,
panel : @types.Rect,
anchor : @types.Rect,
popup : @types.Size,
) -> @types.Rect {
let (x, y) = @panel.popup_position(
screen.w.reinterpret_as_int(),
panel.y,
anchor.x,
popup.w.reinterpret_as_int(),
popup.h.reinterpret_as_int(),
8,
)
@ui.rect(x, y, popup.w.reinterpret_as_int(), popup.h.reinterpret_as_int())
}
@@ -0,0 +1,44 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
pub(all) enum Edge {
START; END
} derive()
///|
pub fn Edge::ordinal(self : Edge) -> Int {
match self {
START => 0
END => 1
}
}
///|
pub fn Edge::from(self : Int) -> Edge {
match self {
0 => START
1 => END
_ => panic()
}
}
///|
pub(all) struct Slot {
id : String; preferred : @types.Size; min_width : UInt; stretch : Bool; align : Edge
}
///|
pub(all) struct Placement {
id : String; rect : @types.Rect
}
///|
pub(all) struct Layout {
panel : @types.Rect; placements : Array[Placement]
}
///|
/// Decide where the panel sits and where each widget goes.
declare pub fn compute_layout(screen : @types.Size, slots : Array[Slot]) -> Layout
///|
/// Panel background/frame (drawn beneath the widgets), in screen coords.
declare pub fn render_panel(screen : @types.Size, panel : @types.Rect) -> Array[@types.DrawOp]
///|
/// Place a popup of `popup` size for the widget at `anchor`.
declare pub fn popup_position(screen : @types.Size, panel : @types.Rect, anchor : @types.Rect, popup : @types.Size) -> @types.Rect
+27
View File
@@ -0,0 +1,27 @@
import {
"moonplasma/desktop/components/shell/gen/interface/moonplasma/desktop/desktop-surface" @desktop-surface,
"moonplasma/desktop/components/shell/gen/interface/moonplasma/desktop/panel-layout" @panel-layout,
}
warnings = "-44"
pkgtype(kind: "foreign_library")
options(
link: {
"wasm": {
"export-memory-name": "memory",
"heap-start-address": 16,
"exports": [
"mbt_ffi_cabi_realloc:cabi_realloc",
"wasmExportComputeLayout:moonplasma:desktop/panel-layout@0.1.0#compute-layout",
"wasmExportComputeLayoutPostReturn:cabi_post_moonplasma:desktop/panel-layout@0.1.0#compute-layout",
"wasmExportPopupPosition:moonplasma:desktop/panel-layout@0.1.0#popup-position",
"wasmExportRenderBackground:moonplasma:desktop/desktop-surface@0.1.0#render-background",
"wasmExportRenderBackgroundPostReturn:cabi_post_moonplasma:desktop/desktop-surface@0.1.0#render-background",
"wasmExportRenderPanel:moonplasma:desktop/panel-layout@0.1.0#render-panel",
"wasmExportRenderPanelPostReturn:cabi_post_moonplasma:desktop/panel-layout@0.1.0#render-panel"
],
},
},
)
+13
View File
@@ -0,0 +1,13 @@
// Generated using `moon info`, DON'T EDIT IT
package "moonplasma/desktop/components/shell/gen"
// Values
pub fn mbt_ffi_cabi_realloc(Int32, Int32, Int32, Int32) -> Int32
// Errors
// Types and methods
// Type aliases
// Traits
+12
View File
@@ -0,0 +1,12 @@
[
{"id": "org.moonplasma.terminal", "name": "Terminal", "comment": "Command-line shell", "category": "System", "glyph": ">_"},
{"id": "org.moonplasma.files", "name": "Files", "comment": "Browse folders and files", "category": "Utilities", "glyph": "F"},
{"id": "org.moonplasma.browser", "name": "Web Browser", "comment": "Browse the web", "category": "Internet", "glyph": "W"},
{"id": "org.moonplasma.settings", "name": "System Settings", "comment": "Configure the desktop", "category": "System", "glyph": "S"},
{"id": "org.moonplasma.editor", "name": "Text Editor", "comment": "Edit plain text files", "category": "Utilities", "glyph": "T"},
{"id": "org.moonplasma.music", "name": "Music Player", "comment": "Play your music library", "category": "Multimedia", "glyph": "M"},
{"id": "org.moonplasma.calc", "name": "Calculator", "comment": "Do quick calculations", "category": "Utilities", "glyph": "="},
{"id": "org.moonplasma.monitor", "name": "System Monitor", "comment": "Processes and resources", "category": "System", "glyph": "%"},
{"id": "org.moonplasma.photos", "name": "Image Viewer", "comment": "View pictures", "category": "Graphics", "glyph": "I"},
{"id": "org.moonplasma.notes", "name": "Notes", "comment": "Sticky notes", "category": "Office", "glyph": "N"}
]
+9
View File
@@ -0,0 +1,9 @@
{
"screen": {"w": 1280, "h": 720},
"theme": "moon-night",
"shell": {"component": "shell", "grants": ["theme"]},
"panel": [
{"id": "launcher", "component": "launcher", "align": "start", "grants": ["theme", "app-catalog", "app-launch"]},
{"id": "clock", "component": "clock-binary", "align": "end", "grants": ["theme", "clock"]}
]
}
+9
View File
@@ -0,0 +1,9 @@
{
"screen": {"w": 1280, "h": 720},
"theme": "moon-night",
"shell": {"component": "shell", "grants": ["theme"]},
"panel": [
{"id": "launcher", "component": "launcher", "align": "start", "grants": ["theme", "app-catalog", "app-launch"]},
{"id": "clock", "component": "clock-digital", "align": "end", "grants": ["theme", "clock"]}
]
}
+19
View File
@@ -0,0 +1,19 @@
{
"name": "Moon Day",
"palette": {
"desktop-top": "#cfe3ff",
"desktop-bottom": "#8fb4e8",
"surface": "#f4f6fbf2",
"surface-hover": "#dde3f0",
"surface-popup": "#fbfcffF5",
"foreground": "#1b2233",
"foreground-muted": "#5b6577",
"accent": "#3b6bff",
"accent-foreground": "#ffffff",
"border": "#b9c3d6"
},
"font-size": 14,
"radius": 6,
"spacing": 6,
"panel-height": 44
}
+19
View File
@@ -0,0 +1,19 @@
{
"name": "Moon Night",
"palette": {
"desktop-top": "#16213e",
"desktop-bottom": "#0b1020",
"surface": "#1f2937f2",
"surface-hover": "#374151",
"surface-popup": "#111827f5",
"foreground": "#f3f4f6",
"foreground-muted": "#9ca3af",
"accent": "#7c9cff",
"accent-foreground": "#0b1020",
"border": "#3b4658"
},
"font-size": 14,
"radius": 6,
"spacing": 6,
"panel-height": 44
}
+3141
View File
File diff suppressed because it is too large. Load diff
+14
View File
@@ -0,0 +1,14 @@
{
"name": "moon-plasma-host",
"private": true,
"version": "0.1.0",
"type": "module",
"description": "Host runtime for moon-plasma (M0: Node/browser host over jco-transpiled components)",
"scripts": {
"test": "node --test test/*.test.mjs"
},
"devDependencies": {
"@bytecodealliance/jco": "1.42.0",
"playwright-core": "^1.50.0"
}
}
+52
View File
@@ -0,0 +1,52 @@
// Terminal rasteriser: a coarse text-mode view of a render list, used for
// headless runs and CI logs. (Real pixels come from the Canvas2D backend.)
const SHADES = ' .:-=+*#%@';
const CW = 8, CH = 16;
export function renderAscii(ops, screen) {
const cols = Math.ceil(screen.w / CW), rows = Math.ceil(screen.h / CH);
const grid = Array.from({ length: rows }, () => Array(cols).fill(' '));
const clips = [{ x: 0, y: 0, w: screen.w, h: screen.h }];
const inClip = (px, py) => { const c = clips[clips.length - 1]; return px >= c.x && py >= c.y && px < c.x + c.w && py < c.y + c.h; };
const lum = (c) => (0.299 * c.r + 0.587 * c.g + 0.114 * c.b) / 255;
const shade = (c) => SHADES[Math.min(SHADES.length - 1, Math.floor(lum(c) * SHADES.length))];
const put = (cx, cy, ch) => { if (cx >= 0 && cy >= 0 && cx < cols && cy < rows && inClip(cx * CW + CW / 2, cy * CH + CH / 2)) grid[cy][cx] = ch; };
for (const op of ops) {
const v = op.val;
switch (op.tag) {
case 'push-clip': {
const c = clips[clips.length - 1];
const x0 = Math.max(c.x, v.x), y0 = Math.max(c.y, v.y);
const x1 = Math.min(c.x + c.w, v.x + v.w), y1 = Math.min(c.y + c.h, v.y + v.h);
clips.push({ x: x0, y: y0, w: Math.max(0, x1 - x0), h: Math.max(0, y1 - y0) });
break;
}
case 'pop-clip': if (clips.length < 2) throw new Error('pop-clip without push-clip'); clips.pop(); break;
case 'fill-rect': {
if (v.color.a < 40) break;
for (let cy = Math.floor(v.rect.y / CH); cy <= Math.floor((v.rect.y + v.rect.h - 1) / CH); cy++)
for (let cx = Math.floor(v.rect.x / CW); cx <= Math.floor((v.rect.x + v.rect.w - 1) / CW); cx++) put(cx, cy, shade(v.color));
break;
}
case 'circle': {
if (!v.filled || v.color.a < 120) break;
for (let cy = 0; cy < rows; cy++) for (let cx = 0; cx < cols; cx++) {
const dx = cx * CW + CW / 2 - v.center.x, dy = cy * CH + CH / 2 - v.center.y;
if (dx * dx + dy * dy <= v.radius * v.radius) put(cx, cy, shade(v.color));
}
break;
}
case 'text': {
const w = v.text.length;
let x0 = v.origin.x;
if (v.style.align === 'center') x0 -= (w * CW) / 2; else if (v.style.align === 'right') x0 -= w * CW;
const cy = Math.floor(v.origin.y / CH);
for (let i = 0; i < w; i++) put(Math.floor(x0 / CW) + i, cy, v.text[i]);
break;
}
default: break; // stroke-rect / line: omitted in text mode
}
}
return grid.map((r) => r.join('').replace(/\s+$/, '')).join('\n');
}
+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/env node
// Headless desktop: boots all components under the Node host and prints the
// composed desktop as text, optionally after a scripted interaction.
// node host/src/cli.mjs [--config file] [--time ISO] [--click-launcher] [--scene out.json]
import { writeFile } from 'node:fs/promises';
import { bootDesktop } from './headless.mjs';
import { renderAscii } from './ascii.mjs';
const args = process.argv.slice(2);
const opt = (n) => { const i = args.indexOf(`--${n}`); return i < 0 ? undefined : args[i + 1]; };
const flag = (n) => args.includes(`--${n}`);
const fixed = opt('time') ? new Date(opt('time')) : undefined;
const { desktop, platform } = await bootDesktop({ configPath: opt('config'), now: fixed ? () => fixed : undefined });
let f = desktop.frame();
if (flag('click-launcher')) {
const e = desktop.hit.widgets.find((w) => w.widget.id === 'launcher');
desktop.pointer('down', e.rect.x + 10, e.rect.y + 10);
f = desktop.frame();
if (flag('type')) { for (const ch of opt('type')) desktop.key(ch); f = desktop.frame(); }
}
console.log(renderAscii(f.ops, f.screen));
console.log(`\n-- ${f.ops.length} draw-ops; widgets: ${desktop.widgets.map((w) => `${w.id}=${w.componentName}`).join(', ')}; theme=${platform.tokens.name}`);
if (opt('scene')) await writeFile(opt('scene'), JSON.stringify(f, null, 1));
if (desktop.faults.length) { console.error(`${desktop.faults.length} component fault(s)`); process.exit(1); }
+201
View File
@@ -0,0 +1,201 @@
// moon-plasma host core (platform-agnostic: runs in Node and the browser).
//
// Responsibilities (the *only* things that are not components):
// * instantiate components and broker capabilities (deny-by-default grants)
// * drive the frame loop: shell layout -> widget render -> render-list
// * route input to the component that owns the surface under the pointer
// * hot-swap a widget's implementation at runtime
// All policy (layout, look, behaviour) lives in components.
import { CAPABILITIES } from './platform.mjs';
import { place, translate } from './scene.mjs';
const PKG = 'moonplasma:desktop';
const PLASMOID = `${PKG}/plasmoid`;
const PANEL = `${PKG}/panel-layout`;
const DESKTOP = `${PKG}/desktop-surface`;
export class PermissionError extends Error {
constructor(msg) { super(msg); this.name = 'PermissionError'; }
}
export class ComponentFault extends Error {
constructor(component, fn, cause) {
super(`component "${component}" faulted in ${fn}: ${cause?.message ?? cause}`);
this.name = 'ComponentFault';
this.component = component;
this.fn = fn;
this.cause = cause;
}
}
/**
* @typedef {{meta: {name:string, world:string, imports:string[], exports:string[]},
* instantiate: (imports: object) => Promise<object>}} LoadedComponent
* @param {{config: any, loader: (name: string) => Promise<LoadedComponent>, platform: any}} opts
*/
export class Desktop {
constructor({ config, loader, platform }) {
this.config = config;
this.loader = loader;
this.platform = platform;
this.screen = { w: config.screen.w, h: config.screen.h };
this.shell = null;
this.widgets = []; // {id, align, componentName, grants, meta, plasmoid}
this.faults = []; // visible, never swallowed: also rendered as error tiles
this.hit = { widgets: [], popup: null };
this.hovered = null;
}
async start() {
this.shell = await this.#instantiate(this.config.shell.component, this.config.shell.grants, 'shell');
for (const w of this.config.panel) {
const inst = await this.#instantiate(w.component, w.grants, 'widget');
this.widgets.push({ id: w.id, align: w.align ?? 'start', grants: w.grants, ...inst });
}
return this;
}
/** Replace the implementation behind panel widget `id` without touching others. */
async swap(id, componentName) {
const i = this.widgets.findIndex((w) => w.id === id);
if (i < 0) throw new Error(`swap: no widget with id "${id}"`);
const old = this.widgets[i];
const inst = await this.#instantiate(componentName, old.grants, 'widget');
this.widgets[i] = { id, align: old.align, grants: old.grants, ...inst };
this.hovered = null;
}
async #instantiate(componentName, grants, role) {
for (const g of grants) {
if (!CAPABILITIES.includes(g)) throw new PermissionError(`config grants unknown capability "${g}" to ${componentName}`);
}
const c = await this.loader(componentName);
const need = c.meta.imports;
const denied = need.filter((n) => !grants.includes(n));
if (denied.length) {
throw new PermissionError(
`component "${componentName}" imports [${denied.join(', ')}] which the desktop config does not grant ` +
`(granted: [${grants.join(', ')}])`);
}
const exp = c.meta.exports;
const wantExports = role === 'shell' ? ['panel-layout', 'desktop-surface'] : ['plasmoid'];
for (const e of wantExports) {
if (!exp.includes(e)) throw new Error(`component "${componentName}" does not export ${e}; cannot act as ${role}`);
}
// Only granted AND imported interfaces are wired; jco fails instantiation
// loudly if anything else is missing.
const imports = {};
for (const n of need) imports[`${PKG}/${n}`] = this.platform.interfaces[n]();
const instance = await c.instantiate(imports);
const get = (iface) => instance[`${iface}@0.1.0`] ?? instance[iface];
return role === 'shell'
? { componentName, meta: c.meta, panel: get(PANEL), desktop: get(DESKTOP) }
: { componentName, meta: c.meta, plasmoid: get(PLASMOID) };
}
#call(owner, fn, thunk) {
try {
return thunk();
} catch (e) {
const f = new ComponentFault(owner.componentName, fn, e);
this.faults.push(f);
console.error(`[host] ${f.message}`);
throw f;
}
}
/** Compose one frame. Returns {ops, layout, screen}. */
frame() {
const screen = this.screen;
const ops = [];
ops.push(...this.#call(this.shell, 'desktop-surface.render-background', () => this.shell.desktop.renderBackground(screen)));
const slots = this.widgets.map((w) => {
const info = this.#call(w, 'plasmoid.info', () => w.plasmoid.info());
w.info = info;
return { id: w.id, preferred: info.preferred, minWidth: info.minWidth, stretch: info.stretch, align: w.align };
});
const layout = this.#call(this.shell, 'panel-layout.compute-layout', () => this.shell.panel.computeLayout(screen, slots));
ops.push(...this.#call(this.shell, 'panel-layout.render-panel', () => this.shell.panel.renderPanel(screen, layout.panel)));
this.hit = { widgets: [], popup: null };
const rects = new Map();
for (const p of layout.placements) rects.set(p.id, p.rect);
for (const w of this.widgets) {
const rect = rects.get(w.id);
if (!rect) throw new Error(`shell returned no placement for widget "${w.id}"`);
this.hit.widgets.push({ widget: w, rect });
let wops;
try {
wops = this.#call(w, 'plasmoid.render', () => w.plasmoid.render({ w: rect.w, h: rect.h }));
} catch {
wops = faultTile(rect, w.componentName);
}
ops.push(...place(wops, rect));
}
// Popup layer (at most one popup open at a time).
for (const entry of this.hit.widgets) {
let pop;
try {
pop = this.#call(entry.widget, 'plasmoid.popup', () => entry.widget.plasmoid.popup());
} catch { continue; }
if (!pop) continue;
const prect = this.#call(this.shell, 'panel-layout.popup-position', () =>
this.shell.panel.popupPosition(screen, layout.panel, entry.rect, pop.size));
this.hit.popup = { widget: entry.widget, anchor: entry.rect, rect: prect };
ops.push(...place(pop.ops, prect));
break;
}
return { ops, layout, screen };
}
#send(widget, target, event) {
return this.#call(widget, 'plasmoid.on-event', () => widget.plasmoid.onEvent(target, event));
}
/** @param {'move'|'down'|'up'} kind Returns true when a redraw is needed. */
pointer(kind, x, y) {
const pt = { x, y };
const inside = (r) => x >= r.x && y >= r.y && x < r.x + r.w && y < r.y + r.h;
const tag = { move: 'pointer-move', down: 'pointer-down', up: 'pointer-up' }[kind];
if (!tag) throw new Error(`unknown pointer kind ${kind}`);
let dirty = false;
const popup = this.hit.popup;
if (popup && inside(popup.rect)) {
return this.#send(popup.widget, 'popup', { tag, val: { x: x - popup.rect.x, y: y - popup.rect.y } });
}
if (popup && kind === 'down' && !inside(popup.anchor)) {
// Click outside the popup: tell its owner it lost focus, then let the
// click fall through to whatever is underneath.
dirty = this.#send(popup.widget, 'widget', { tag: 'focus-lost', val: undefined }) || dirty;
}
const target = this.hit.widgets.find((e) => inside(e.rect));
if (this.hovered && this.hovered !== target?.widget) {
dirty = this.#send(this.hovered, 'widget', { tag: 'pointer-leave', val: undefined }) || dirty;
}
this.hovered = target?.widget ?? null;
if (target) {
dirty = this.#send(target.widget, 'widget', { tag, val: { x: x - target.rect.x, y: y - target.rect.y } }) || dirty;
}
void pt;
return dirty;
}
key(k) {
const popup = this.hit.popup;
if (!popup) return false;
return this.#send(popup.widget, 'popup', { tag: 'key-down', val: k });
}
}
function faultTile(rect, name) {
const red = { r: 200, g: 40, b: 40, a: 255 };
return [
{ tag: 'fill-rect', val: { rect: { x: 0, y: 0, w: rect.w, h: rect.h }, color: red, radius: 4 } },
{ tag: 'text', val: { origin: { x: 6, y: Math.floor(rect.h / 2) }, text: `${name} crashed`,
style: { size: 12, color: { r: 255, g: 255, b: 255, a: 255 }, align: 'left', bold: true } } },
];
}
export { translate };
+19
View File
@@ -0,0 +1,19 @@
// Headless bring-up shared by the CLI and the tests.
import { readFile } from 'node:fs/promises';
import { join, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { Desktop } from './desktop.mjs';
import { createPlatform } from './platform.mjs';
import { tokensFromJson } from './theme.mjs';
import { nodeLoader } from './loader-node.mjs';
export const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..', '..');
export async function bootDesktop({ configPath = join(ROOT, 'config', 'desktop.json'), now, buildDir = join(ROOT, 'build') } = {}) {
const config = JSON.parse(await readFile(configPath, 'utf8'));
const apps = JSON.parse(await readFile(join(ROOT, 'config', 'apps.json'), 'utf8'));
const themeJson = JSON.parse(await readFile(join(ROOT, 'config', 'themes', `${config.theme}.json`), 'utf8'));
const platform = createPlatform({ apps, tokens: tokensFromJson(themeJson), now });
const desktop = await new Desktop({ config, loader: nodeLoader(buildDir), platform }).start();
return { desktop, platform, config };
}
+14
View File
@@ -0,0 +1,14 @@
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';
import { pathToFileURL } from 'node:url';
/** Loader for Node: reads build/ produced by scripts/build.sh. */
export function nodeLoader(buildDir) {
return async (name) => {
const meta = JSON.parse(await readFile(join(buildDir, 'components', `${name}.meta.json`), 'utf8'));
const dir = join(buildDir, 'jco', name);
const mod = await import(pathToFileURL(join(dir, `${name}.js`)).href);
const getCoreModule = async (p) => WebAssembly.compile(await readFile(join(dir, p)));
return { meta, instantiate: (imports) => mod.instantiate(getCoreModule, imports) };
};
}
+39
View File
@@ -0,0 +1,39 @@
// Host-side implementations of the capability interfaces components may import.
// This is where a native host would talk to the OS; here it is in-memory so the
// desktop is deterministic and testable.
/** @param {{now?: () => Date, apps: any[], tokens: any}} opts */
export function createPlatform({ now = () => new Date(), apps, tokens }) {
const p = {
tokens,
apps,
launches: [],
now,
launchable: new Set(apps.map((a) => a.id)),
};
/** Capability name -> WIT interface implementation (jco import shape). */
p.interfaces = {
theme: () => ({ getTokens: () => p.tokens }),
clock: () => ({
now() {
const d = p.now();
return {
year: d.getFullYear(), month: d.getMonth() + 1, day: d.getDate(),
hour: d.getHours(), minute: d.getMinutes(), second: d.getSeconds(), weekday: d.getDay(),
};
},
}),
'app-catalog': () => ({ listApps: () => p.apps }),
'app-launch': () => ({
launch(id) {
if (!p.launchable.has(id)) return { tag: 'err', val: `unknown application: ${id}` };
p.launches.push(id);
console.log(`[host] launch ${id}`);
return { tag: 'ok', val: undefined };
},
}),
};
return p;
}
export const CAPABILITIES = ['theme', 'clock', 'app-catalog', 'app-launch'];
+36
View File
@@ -0,0 +1,36 @@
// Render-list helpers. A draw-op is a jco-lifted WIT variant: {tag, val}.
/** Translate a draw-op list by (dx, dy), returning new ops. */
export function translate(ops, dx, dy) {
return ops.map((op) => {
const v = op.val;
switch (op.tag) {
case 'fill-rect':
case 'stroke-rect':
return { tag: op.tag, val: { ...v, rect: { ...v.rect, x: v.rect.x + dx, y: v.rect.y + dy } } };
case 'line':
return { tag: op.tag, val: { ...v, start: { x: v.start.x + dx, y: v.start.y + dy }, end: { x: v.end.x + dx, y: v.end.y + dy } } };
case 'circle':
return { tag: op.tag, val: { ...v, center: { x: v.center.x + dx, y: v.center.y + dy } } };
case 'text':
return { tag: op.tag, val: { ...v, origin: { x: v.origin.x + dx, y: v.origin.y + dy } } };
case 'push-clip':
return { tag: op.tag, val: { ...v, x: v.x + dx, y: v.y + dy } };
case 'pop-clip':
return op;
default:
throw new Error(`unknown draw-op tag: ${op.tag}`);
}
});
}
/** Place a component's local-space ops at `rect`, clipped to it. */
export function place(ops, rect) {
return [
{ tag: 'push-clip', val: { ...rect } },
...translate(ops, rect.x, rect.y),
{ tag: 'pop-clip', val: undefined },
];
}
export const colorCss = (c) => `rgba(${c.r},${c.g},${c.b},${(c.a / 255).toFixed(3)})`;
+29
View File
@@ -0,0 +1,29 @@
// Theme files use kebab-case keys and #rrggbb[aa] colours; components see the
// WIT `theme.tokens` record (camelCase in jco).
const camel = (k) => k.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
export function parseColor(s) {
const m = /^#([0-9a-fA-F]{6})([0-9a-fA-F]{2})?$/.exec(s);
if (!m) throw new Error(`invalid colour "${s}" (expected #rrggbb or #rrggbbaa)`);
const n = parseInt(m[1], 16);
return { r: (n >> 16) & 255, g: (n >> 8) & 255, b: n & 255, a: m[2] ? parseInt(m[2], 16) : 255 };
}
const PALETTE_KEYS = ['desktop-top', 'desktop-bottom', 'surface', 'surface-hover', 'surface-popup',
'foreground', 'foreground-muted', 'accent', 'accent-foreground', 'border'];
const NUM_KEYS = ['font-size', 'radius', 'spacing', 'panel-height'];
export function tokensFromJson(json) {
const palette = {};
for (const k of PALETTE_KEYS) {
if (!(k in (json.palette ?? {}))) throw new Error(`theme "${json.name}": missing palette.${k}`);
palette[camel(k)] = parseColor(json.palette[k]);
}
const out = { name: json.name, palette };
for (const k of NUM_KEYS) {
if (!Number.isInteger(json[k]) || json[k] < 0) throw new Error(`theme "${json.name}": ${k} must be a non-negative integer`);
out[camel(k)] = json[k];
}
return out;
}
+165
View File
@@ -0,0 +1,165 @@
// Host integration tests: instantiate the real MoonBit components (built by
// scripts/build.sh) under the Node host and exercise the desktop end to end.
import test from 'node:test';
import assert from 'node:assert/strict';
import { readFile, stat, writeFile, mkdtemp } from 'node:fs/promises';
import { join } from 'node:path';
import { tmpdir } from 'node:os';
import { bootDesktop, ROOT } from '../src/headless.mjs';
import { PermissionError } from '../src/desktop.mjs';
import { tokensFromJson } from '../src/theme.mjs';
const NOW = new Date(2026, 10, 24, 14, 7, 37); // Tue 24 Nov 2026, local time
const fixed = () => NOW;
const texts = (ops) => ops.filter((o) => o.tag === 'text').map((o) => o.val.text);
const configWith = async (mutate) => {
const cfg = JSON.parse(await readFile(join(ROOT, 'config', 'desktop.json'), 'utf8'));
mutate(cfg);
const dir = await mkdtemp(join(tmpdir(), 'moonplasma-'));
const p = join(dir, 'desktop.json');
await writeFile(p, JSON.stringify(cfg));
return p;
};
test('boots shell + widgets and composes a frame', async () => {
const { desktop } = await bootDesktop({ now: fixed });
const f = desktop.frame();
assert.deepEqual(f.screen, { w: 1280, h: 720 });
assert.ok(f.ops.length > 50);
const t = texts(f.ops);
assert.ok(t.includes('14:07'), `clock text missing: ${t}`);
assert.ok(t.includes('Tue 24 Nov'));
assert.ok(t.includes('moon-plasma'));
assert.ok(t.includes('Applications'));
assert.equal(desktop.faults.length, 0);
});
test('shell lays the panel out at the bottom, launcher left, clock right', async () => {
const { desktop } = await bootDesktop({ now: fixed });
const { layout } = desktop.frame();
assert.deepEqual(layout.panel, { x: 0, y: 720 - 44, w: 1280, h: 44 });
const byId = Object.fromEntries(layout.placements.map((p) => [p.id, p.rect]));
assert.ok(byId.launcher.x < 20);
assert.equal(byId.clock.x + byId.clock.w, 1280 - 5);
for (const r of Object.values(byId)) {
assert.ok(r.y >= layout.panel.y && r.y + r.h <= 720, 'widget inside the panel');
}
});
test('launcher: click opens popup, row click launches via host capability, popup closes', async () => {
const { desktop, platform } = await bootDesktop({ now: fixed });
desktop.frame();
const l = desktop.hit.widgets.find((w) => w.widget.id === 'launcher').rect;
assert.equal(desktop.hit.popup, null);
assert.equal(desktop.pointer('down', l.x + 5, l.y + 5), true);
const f = desktop.frame();
assert.ok(desktop.hit.popup, 'popup is open');
assert.ok(texts(f.ops).includes('Terminal'));
const pr = desktop.hit.popup.rect;
assert.ok(pr.y + pr.h <= 720 - 44, 'popup sits above the panel');
// second row (52px header + 46px rows)
desktop.pointer('move', pr.x + 20, pr.y + 52 + 46 + 5);
desktop.pointer('down', pr.x + 20, pr.y + 52 + 46 + 5);
assert.deepEqual(platform.launches, ['org.moonplasma.files']);
desktop.frame();
assert.equal(desktop.hit.popup, null, 'popup closed after launch');
});
test('launcher: keyboard search narrows the list and Enter launches the first match', async () => {
const { desktop, platform } = await bootDesktop({ now: fixed });
desktop.frame();
const l = desktop.hit.widgets.find((w) => w.widget.id === 'launcher').rect;
desktop.pointer('down', l.x + 5, l.y + 5);
desktop.frame();
for (const ch of 'calc') desktop.key(ch);
const f = desktop.frame();
const t = texts(f.ops);
assert.ok(t.includes('Calculator') && !t.includes('Terminal'));
desktop.key('Enter');
assert.deepEqual(platform.launches, ['org.moonplasma.calc']);
});
test('clicking outside the popup dismisses it (focus-lost)', async () => {
const { desktop } = await bootDesktop({ now: fixed });
desktop.frame();
const l = desktop.hit.widgets.find((w) => w.widget.id === 'launcher').rect;
desktop.pointer('down', l.x + 5, l.y + 5);
desktop.frame();
assert.ok(desktop.hit.popup);
desktop.pointer('down', 900, 200);
desktop.frame();
assert.equal(desktop.hit.popup, null);
});
test('permissions: a component importing an ungranted capability is refused', async () => {
const cfg = await configWith((c) => { c.panel[1].grants = ['theme']; }); // clock needs "clock"
await assert.rejects(bootDesktop({ configPath: cfg }), (e) => {
assert.ok(e instanceof PermissionError);
assert.match(e.message, /clock-digital.*imports \[clock\]/);
return true;
});
});
test('permissions: unknown capability names in config are rejected', async () => {
const cfg = await configWith((c) => { c.panel[1].grants.push('filesystem'); });
await assert.rejects(bootDesktop({ configPath: cfg }), /unknown capability "filesystem"/);
});
test('a component cannot act in a role it does not export', async () => {
const cfg = await configWith((c) => { c.panel[1].component = 'shell'; c.panel[1].grants = ['theme']; });
await assert.rejects(bootDesktop({ configPath: cfg }), /does not export plasmoid/);
});
test('hot-swap: clock-digital -> clock-binary at runtime, other components untouched', async () => {
const files = ['shell', 'launcher', 'clock-digital', 'clock-binary'].map((n) => join(ROOT, 'build', 'components', `${n}.wasm`));
const before = await Promise.all(files.map(async (f) => (await stat(f)).mtimeMs));
const { desktop } = await bootDesktop({ now: fixed });
const a = desktop.frame();
assert.ok(texts(a.ops).includes('14:07'));
const launcherInstance = desktop.widgets.find((w) => w.id === 'launcher').plasmoid;
await desktop.swap('clock', 'clock-binary');
const b = desktop.frame();
assert.ok(!texts(b.ops).includes('14:07'));
assert.ok(b.ops.filter((o) => o.tag === 'circle').length >= 20, 'binary clock dots drawn');
assert.equal(desktop.widgets.find((w) => w.id === 'launcher').plasmoid, launcherInstance, 'launcher instance reused');
const after = await Promise.all(files.map(async (f) => (await stat(f)).mtimeMs));
assert.deepEqual(after, before, 'no component binary was rebuilt');
});
test('config-level swap (desktop.binary-clock.json) picks the other implementation', async () => {
const { desktop } = await bootDesktop({ configPath: join(ROOT, 'config', 'desktop.binary-clock.json'), now: fixed });
assert.equal(desktop.widgets.find((w) => w.id === 'clock').componentName, 'clock-binary');
assert.ok(desktop.frame().ops.some((o) => o.tag === 'circle' && o.val.filled));
});
test('theme tokens flow through to components (live theme switch)', async () => {
const { desktop, platform } = await bootDesktop({ now: fixed });
const firstFill = (ops) => ops.find((o) => o.tag === 'fill-rect').val.color;
const night = firstFill(desktop.frame().ops);
const day = JSON.parse(await readFile(join(ROOT, 'config', 'themes', 'moon-day.json'), 'utf8'));
platform.tokens = tokensFromJson(day);
const light = firstFill(desktop.frame().ops);
assert.notDeepEqual(night, light);
assert.deepEqual(light, { r: 0xcf, g: 0xe3, b: 0xff, a: 255 }); // desktop-top of moon-day
});
test('component faults are surfaced loudly and isolated to the widget', async () => {
const { desktop, platform } = await bootDesktop({ now: fixed });
platform.now = () => { throw new Error('rtc exploded'); };
const f = desktop.frame(); // does not take the desktop down
assert.equal(desktop.faults.length, 1);
assert.match(desktop.faults[0].message, /clock-digital.*render/);
assert.ok(texts(f.ops).includes('clock-digital crashed'), 'visible error tile');
assert.ok(texts(f.ops).includes('Applications'), 'other widgets still render');
});
test('build manifests match scripts/components.txt', async () => {
const lines = (await readFile(join(ROOT, 'scripts', 'components.txt'), 'utf8')).split('\n')
.filter((l) => l.trim() && !l.startsWith('#'));
for (const l of lines) {
const [name, world] = l.trim().split(/\s+/);
const meta = JSON.parse(await readFile(join(ROOT, 'build', 'components', `${name}.meta.json`), 'utf8'));
assert.equal(meta.world, world);
assert.ok(meta.imports.includes('theme'));
}
});
@@ -0,0 +1,27 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
fn wasmImportListApps(p0 : Int) = "moonplasma:desktop/app-catalog@0.1.0" "list-apps"
///|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
#|(func (param i32) (result i32) (local i32)
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
#| local.tee 1 i32.const 0 call $moonbit.init_array8
#| local.get 1)
///|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
///|
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)
///|
extern "wasm" fn mbt_ffi_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
@@ -0,0 +1,5 @@
import {
"moonplasma/desktop/interface/moonplasma/desktop/types" @types,
}
warnings = "-44"
@@ -0,0 +1,17 @@
// Generated using `moon info`, DON'T EDIT IT
package "moonplasma/desktop/interface/moonplasma/desktop/app-catalog"
import {
"moonplasma/desktop/interface/moonplasma/desktop/types",
}
// Values
pub fn list_apps() -> Array[@types.AppEntry]
// Errors
// Types and methods
// Type aliases
// Traits
@@ -0,0 +1,31 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
/// Installed applications (static list in the PoC; .desktop files later).
pub fn list_apps() -> Array[@types.AppEntry] {
let return_area = mbt_ffi_malloc(8)
wasmImportListApps(return_area);
let array : Array[@types.AppEntry] = [];
for index = 0; index < (mbt_ffi_load32((return_area) + 4)); index = index + 1 {
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index * 40)
let result = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4))
let result0 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12))
let result1 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20))
let result2 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 24), mbt_ffi_load32((iter_base) + 28))
let result3 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 32), mbt_ffi_load32((iter_base) + 36))
array.push(@types.AppEntry::{id : result, name : result0, comment : result1, category : result2, glyph : result3})
}
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
let ret = array
mbt_ffi_free(return_area)
return ret
}
@@ -0,0 +1,36 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
fn wasmImportLaunch(p0 : Int, p1 : Int, p2 : Int) = "moonplasma:desktop/app-launch@0.1.0" "launch"
///|
#owned(str)
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
#|(func (param i32) (result i32) local.get 0)
///|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
///|
extern "wasm" fn mbt_ffi_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
///|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
#|(func (param i32) (result i32) (local i32)
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
#| local.tee 1 i32.const 0 call $moonbit.init_array8
#| local.get 1)
///|
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)
///|
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
@@ -0,0 +1 @@
warnings = "-44"
@@ -0,0 +1,13 @@
// Generated using `moon info`, DON'T EDIT IT
package "moonplasma/desktop/interface/moonplasma/desktop/app-launch"
// Values
pub fn launch(String) -> Result[Unit, String]
// Errors
// Types and methods
// Type aliases
// Traits
@@ -0,0 +1,29 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
/// Ask the host to start an application by catalog id.
pub fn launch(id : String) -> Result[Unit, String] {
let ptr = mbt_ffi_str2ptr(id)
let return_area = mbt_ffi_malloc(12)
wasmImportLaunch(ptr, id.length(), return_area);
let lifted = match (mbt_ffi_load8_u((return_area) + 0)) {
0 => {
Result::Ok(())
}
1 => {
let result = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 4), mbt_ffi_load32((return_area) + 8))
Result::Err(result)
}
_ => panic()
}
let ret = lifted
mbt_ffi_free(ptr)
mbt_ffi_free(return_area)
return ret
}
@@ -0,0 +1,2 @@
Host-brokered capabilities. A component can only call what its world
imports AND what the host grants it in the desktop manifest.
@@ -0,0 +1,24 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
fn wasmImportNow(p0 : Int) = "moonplasma:desktop/clock@0.1.0" "now"
///|
extern "wasm" fn mbt_ffi_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
///|
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
///|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
#|(func (param i32) (result i32) (local i32)
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
#| local.tee 1 i32.const 0 call $moonbit.init_array8
#| local.get 1)
///|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
@@ -0,0 +1,5 @@
import {
"moonplasma/desktop/interface/moonplasma/desktop/types" @types,
}
warnings = "-44"
@@ -0,0 +1,17 @@
// Generated using `moon info`, DON'T EDIT IT
package "moonplasma/desktop/interface/moonplasma/desktop/clock"
import {
"moonplasma/desktop/interface/moonplasma/desktop/types",
}
// Values
pub fn now() -> @types.Datetime
// Errors
// Types and methods
// Type aliases
// Traits
@@ -0,0 +1,13 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
/// Local wall-clock time (the host owns the time zone).
pub fn now() -> @types.Datetime {
let return_area = mbt_ffi_malloc(12)
wasmImportNow(return_area);
let ret = @types.Datetime::{year : (mbt_ffi_load32((return_area) + 0)).reinterpret_as_uint(), month : (mbt_ffi_load8_u((return_area) + 4)).to_byte(), day : (mbt_ffi_load8_u((return_area) + 5)).to_byte(), hour : (mbt_ffi_load8_u((return_area) + 6)).to_byte(), minute : (mbt_ffi_load8_u((return_area) + 7)).to_byte(), second : (mbt_ffi_load8_u((return_area) + 8)).to_byte(), weekday : (mbt_ffi_load8_u((return_area) + 9)).to_byte()}
mbt_ffi_free(return_area)
return ret
}
@@ -0,0 +1 @@
Look-and-feel design tokens (Plasma "Look and Feel"/colour scheme analogue).
@@ -0,0 +1,31 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
fn wasmImportGetTokens(p0 : Int) = "moonplasma:desktop/theme@0.1.0" "get-tokens"
///|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
///|
extern "wasm" fn mbt_ffi_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
///|
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
///|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
#|(func (param i32) (result i32) (local i32)
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
#| local.tee 1 i32.const 0 call $moonbit.init_array8
#| local.get 1)
///|
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,5 @@
import {
"moonplasma/desktop/interface/moonplasma/desktop/types" @types,
}
warnings = "-44"
@@ -0,0 +1,38 @@
// Generated using `moon info`, DON'T EDIT IT
package "moonplasma/desktop/interface/moonplasma/desktop/theme"
import {
"moonplasma/desktop/interface/moonplasma/desktop/types",
}
// Values
pub fn get_tokens() -> Tokens
// Errors
// Types and methods
pub(all) struct Palette {
desktop_top : @types.Color
desktop_bottom : @types.Color
surface : @types.Color
surface_hover : @types.Color
surface_popup : @types.Color
foreground : @types.Color
foreground_muted : @types.Color
accent : @types.Color
accent_foreground : @types.Color
border : @types.Color
}
pub(all) struct Tokens {
name : String
palette : Palette
font_size : UInt32
radius : UInt32
spacing : UInt32
panel_height : UInt32
}
// Type aliases
// Traits
@@ -0,0 +1,23 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
pub(all) struct Palette {
desktop_top : @types.Color; desktop_bottom : @types.Color; surface : @types.Color; surface_hover : @types.Color; surface_popup : @types.Color; foreground : @types.Color; foreground_muted : @types.Color; accent : @types.Color; accent_foreground : @types.Color; border : @types.Color
}
///|
pub(all) struct Tokens {
name : String; palette : Palette; font_size : UInt; radius : UInt; spacing : UInt; panel_height : UInt
}
///|
/// Read on every render so a theme swap shows up on the next frame.
pub fn get_tokens() -> Tokens {
let return_area = mbt_ffi_malloc(64)
wasmImportGetTokens(return_area);
let result = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 0), mbt_ffi_load32((return_area) + 4))
let ret = Tokens::{name : result, palette : Palette::{desktop_top : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 8)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 9)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 10)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 11)).to_byte()}, desktop_bottom : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 12)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 13)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 14)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 15)).to_byte()}, surface : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 16)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 17)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 18)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 19)).to_byte()}, surface_hover : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 20)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 21)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 22)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 23)).to_byte()}, surface_popup : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 24)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 25)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 26)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 27)).to_byte()}, foreground : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 28)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 29)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 30)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 31)).to_byte()}, foreground_muted : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 32)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 33)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 34)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 35)).to_byte()}, accent : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 36)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 37)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 38)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 39)).to_byte()}, accent_foreground : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 40)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 41)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 42)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 43)).to_byte()}, border : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 44)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 45)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 46)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 47)).to_byte()}}, font_size : (mbt_ffi_load32((return_area) + 48)).reinterpret_as_uint(), radius : (mbt_ffi_load32((return_area) + 52)).reinterpret_as_uint(), spacing : (mbt_ffi_load32((return_area) + 56)).reinterpret_as_uint(), panel_height : (mbt_ffi_load32((return_area) + 60)).reinterpret_as_uint()}
mbt_ffi_free(return_area)
return ret
}
@@ -0,0 +1,2 @@
Shared value types. Everything here is plain data (no resources) so that
it can cross any component boundary and any host implementation.
@@ -0,0 +1,2 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
@@ -0,0 +1 @@
warnings = "-44"
@@ -0,0 +1,120 @@
// Generated using `moon info`, DON'T EDIT IT
package "moonplasma/desktop/interface/moonplasma/desktop/types"
// Values
// Errors
// Types and methods
pub(all) struct AppEntry {
id : String
name : String
comment : String
category : String
glyph : String
}
pub(all) struct CircleOp {
center : Point
radius : UInt32
color : Color
filled : Bool
}
pub(all) struct Color {
r : Byte
g : Byte
b : Byte
a : Byte
}
pub(all) struct Datetime {
year : UInt32
month : Byte
day : Byte
hour : Byte
minute : Byte
second : Byte
weekday : Byte
}
pub(all) enum DrawOp {
FillRect(FillRectOp)
StrokeRect(StrokeRectOp)
Line(LineOp)
Circle(CircleOp)
Text(TextOp)
PushClip(Rect)
PopClip
}
pub(all) struct FillRectOp {
rect : Rect
color : Color
radius : UInt32
}
pub(all) enum InputEvent {
PointerMove(Point)
PointerDown(Point)
PointerUp(Point)
PointerLeave
FocusLost
KeyDown(String)
}
pub(all) struct LineOp {
start : Point
end : Point
color : Color
width : UInt32
}
pub(all) struct Point {
x : Int32
y : Int32
}
pub(all) struct Rect {
x : Int32
y : Int32
w : UInt32
h : UInt32
}
pub(all) struct Size {
w : UInt32
h : UInt32
}
pub(all) struct StrokeRectOp {
rect : Rect
color : Color
width : UInt32
radius : UInt32
}
pub(all) enum TextAlign {
LEFT
CENTER
RIGHT
}
pub fn TextAlign::from(Int32) -> Self
pub fn TextAlign::ordinal(Self) -> Int32
pub(all) struct TextOp {
origin : Point
text : String
style : TextStyle
}
pub(all) struct TextStyle {
size : UInt32
color : Color
align : TextAlign
bold : Bool
}
// Type aliases
// Traits
@@ -0,0 +1,98 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
pub(all) struct Size {
w : UInt; h : UInt
}
///|
pub(all) struct Point {
x : Int; y : Int
}
///|
pub(all) struct Rect {
x : Int; y : Int; w : UInt; h : UInt
}
///|
/// Non-premultiplied sRGB, 8 bits per channel.
pub(all) struct Color {
r : Byte; g : Byte; b : Byte; a : Byte
}
///|
pub(all) enum TextAlign {
LEFT; CENTER; RIGHT
} derive()
///|
pub fn TextAlign::ordinal(self : TextAlign) -> Int {
match self {
LEFT => 0
CENTER => 1
RIGHT => 2
}
}
///|
pub fn TextAlign::from(self : Int) -> TextAlign {
match self {
0 => LEFT
1 => CENTER
2 => RIGHT
_ => panic()
}
}
///|
pub(all) struct TextStyle {
size : UInt; color : Color; align : TextAlign; bold : Bool
}
///|
pub(all) struct FillRectOp {
rect : Rect; color : Color; radius : UInt
}
///|
pub(all) struct StrokeRectOp {
rect : Rect; color : Color; width : UInt; radius : UInt
}
///|
pub(all) struct LineOp {
start : Point; end : Point; color : Color; width : UInt
}
///|
pub(all) struct CircleOp {
center : Point; radius : UInt; color : Color; filled : Bool
}
///|
/// `origin` is the left edge (align=left), centre (center) or right edge
/// (right) of the text, at the vertical *middle* of the line box.
pub(all) struct TextOp {
origin : Point; text : String; style : TextStyle
}
///|
/// The render-list vocabulary. Components never touch pixels: they return
/// a list of these in their own local coordinate space (origin top-left),
/// and the host/compositor translates, clips and rasterises them.
pub(all) enum DrawOp {
FillRect(FillRectOp)
StrokeRect(StrokeRectOp)
Line(LineOp)
Circle(CircleOp)
Text(TextOp)
PushClip(Rect)
PopClip
}
///|
pub(all) enum InputEvent {
PointerMove(Point)
PointerDown(Point)
PointerUp(Point)
PointerLeave
FocusLost
KeyDown(String)
}
///|
pub(all) struct Datetime {
year : UInt; month : Byte; day : Byte; hour : Byte; minute : Byte; second : Byte; weekday : Byte
}
///|
pub(all) struct AppEntry {
id : String; name : String; comment : String; category : String; glyph : String
}
+140
View File
@@ -0,0 +1,140 @@
///| Render logic for the clock widgets (pure: tokens + time in, ops out).
///|
pub fn digital_info() -> (String, String, Int, Int, Int) {
// id, name, preferred w, preferred h, min w
("org.moonplasma.clock.digital", "Digital Clock", 120, 36, 80)
}
///|
pub fn render_digital(
size : @types.Size,
t : @theme.Tokens,
now : @types.Datetime,
) -> Array[@types.DrawOp] {
let w = size.w.reinterpret_as_int()
let h = size.h.reinterpret_as_int()
let fs = t.font_size.reinterpret_as_int()
let time = @timefmt.hhmm(now.hour.to_int(), now.minute.to_int())
let date = @timefmt.date_line(
now.weekday.to_int(),
now.day.to_int(),
now.month.to_int(),
)
[
@ui.text(w / 2, h / 2 - fs / 2 + 1, time, fs + 4, t.palette.foreground, align=CENTER, bold=true),
@ui.text(w / 2, h / 2 + fs / 2 + 4, date, fs - 3, t.palette.foreground_muted, align=CENTER),
]
}
///|
pub fn binary_info() -> (String, String, Int, Int, Int) {
("org.moonplasma.clock.binary", "Binary Clock", 96, 36, 96)
}
///| BCD binary clock: six columns (H H M M S S), four rows; lit bits use the
/// accent colour, unused high bits of the tens digits are not drawn.
pub fn render_binary(
size : @types.Size,
t : @theme.Tokens,
now : @types.Datetime,
) -> Array[@types.DrawOp] {
let w = size.w.reinterpret_as_int()
let h = size.h.reinterpret_as_int()
let digits = [
(now.hour.to_int() / 10, 2),
(now.hour.to_int() % 10, 4),
(now.minute.to_int() / 10, 3),
(now.minute.to_int() % 10, 4),
(now.second.to_int() / 10, 3),
(now.second.to_int() % 10, 4),
]
let ops = []
let cols = digits.length()
let step_x = w / cols
let step_y = h / 4
let r = (if step_x < step_y { step_x } else { step_y }) / 2 - 1
for c = 0; c < cols; c = c + 1 {
let (d, nbits) = digits[c]
let bits = @timefmt.bcd_bits(d, nbits)
for i = 0; i < nbits; i = i + 1 {
// Row 3 is the least significant bit.
let row = 4 - nbits + i
let cx = c * step_x + step_x / 2
let cy = row * step_y + step_y / 2
if bits[i] {
ops.push(@ui.circle(cx, cy, r, t.palette.accent))
} else {
ops.push(@ui.circle(cx, cy, r, t.palette.border, filled=false))
}
}
}
ops
}
///|
fn test_tokens() -> @theme.Tokens {
let c = @ui.color(10, 20, 30, 255)
{
name: "t",
palette: {
desktop_top: c,
desktop_bottom: c,
surface: c,
surface_hover: c,
surface_popup: c,
foreground: c,
foreground_muted: c,
accent: c,
accent_foreground: c,
border: c,
},
font_size: 14,
radius: 6,
spacing: 6,
panel_height: 44,
}
}
///|
fn test_time() -> @types.Datetime {
{
year: 2026,
month: b'\x0B',
day: b'\x18',
hour: b'\x0E',
minute: b'\x07',
second: b'\x25',
weekday: b'\x02',
}
}
///|
test "digital clock shows HH:MM and the date" {
let ops = render_digital(@ui.size(120, 36), test_tokens(), test_time())
assert_eq(ops.length(), 2)
match ops[0] {
Text(t) => assert_eq(t.text, "14:07")
_ => fail("expected text")
}
match ops[1] {
Text(t) => assert_eq(t.text, "Tue 24 Nov")
_ => fail("expected text")
}
}
///|
test "binary clock draws one dot per displayed bit" {
let ops = render_binary(@ui.size(96, 36), test_tokens(), test_time())
// 2+4+3+4+3+4 bits
assert_eq(ops.length(), 20)
let mut lit = 0
for op in ops {
match op {
Circle(c) => if c.filled { lit += 1 }
_ => ()
}
}
// 14:07:37 -> 1,4,0,7,3,7 -> popcount 1+1+0+3+2+3
assert_eq(lit, 10)
}
+6
View File
@@ -0,0 +1,6 @@
import {
"moonplasma/desktop/interface/moonplasma/desktop/types" @types,
"moonplasma/desktop/interface/moonplasma/desktop/theme" @theme,
"moonplasma/desktop/lib/ui" @ui,
"moonplasma/desktop/lib/timefmt" @timefmt,
}
+24
View File
@@ -0,0 +1,24 @@
// Generated using `moon info`, DON'T EDIT IT
package "moonplasma/desktop/lib/clock"
import {
"moonplasma/desktop/interface/moonplasma/desktop/theme",
"moonplasma/desktop/interface/moonplasma/desktop/types",
}
// Values
pub fn binary_info() -> (String, String, Int32, Int32, Int32)
pub fn digital_info() -> (String, String, Int32, Int32, Int32)
pub fn render_binary(@types.Size, @theme.Tokens, @types.Datetime) -> Array[@types.DrawOp]
pub fn render_digital(@types.Size, @theme.Tokens, @types.Datetime) -> Array[@types.DrawOp]
// Errors
// Types and methods
// Type aliases
// Traits
+320
View File
@@ -0,0 +1,320 @@
///| Kickoff-style application launcher: state machine + render logic. Pure;
/// host capabilities (app list, launch) are passed in by the component stub.
///| Which surface an event is addressed to (mirrors the WIT `surface` enum).
pub(all) enum Target {
Widget
Popup
}
///|
pub struct State {
mut open : Bool
mut query : String
mut hover : Int
mut error : String
}
///|
pub fn State::new() -> State {
{ open: false, query: "", hover: -1, error: "" }
}
///|
pub let popup_w : Int = 340
///|
let header_h : Int = 52
///|
let row_h : Int = 46
///|
let max_rows : Int = 8
///|
fn ascii_lower(s : String) -> String {
let sb = StringBuilder()
for c in s {
if c >= 'A' && c <= 'Z' {
sb.write_char(Int::unsafe_to_char(c.to_int() + 32))
} else {
sb.write_char(c)
}
}
sb.to_string()
}
///|
fn contains_ci(hay : String, needle : String) -> Bool {
if needle.length() == 0 {
return true
}
ascii_lower(hay).contains(ascii_lower(needle))
}
///| KRunner-ish filter: case-insensitive substring over name, comment and category.
pub fn filter(apps : Array[@types.AppEntry], query : String) -> Array[@types.AppEntry] {
apps.filter(a => {
contains_ci(a.name, query) ||
contains_ci(a.comment, query) ||
contains_ci(a.category, query)
})
}
///|
fn visible_rows(n : Int) -> Int {
if n > max_rows { max_rows } else { n }
}
///|
pub fn popup_size(apps : Array[@types.AppEntry], st : State) -> @types.Size {
let rows = visible_rows(filter(apps, st.query).length())
let rows = if rows == 0 { 1 } else { rows }
@ui.size(popup_w, header_h + rows * row_h + 8)
}
///|
pub fn close(st : State) -> Unit {
st.open = false
st.query = ""
st.hover = -1
}
///| The panel button: a crescent moon plus a label.
pub fn render_button(
size : @types.Size,
t : @theme.Tokens,
st : State,
) -> Array[@types.DrawOp] {
let w = size.w.reinterpret_as_int()
let h = size.h.reinterpret_as_int()
let bg = if st.open { t.palette.accent } else { t.palette.surface_hover }
let fg = if st.open { t.palette.accent_foreground } else { t.palette.foreground }
let r = t.radius.reinterpret_as_int()
let cy = h / 2
[
@ui.fill_rect(@ui.rect(0, 0, w, h), bg, radius=r),
// Crescent: light disc with a button-coloured disc biting into it.
@ui.circle(18, cy, 9, fg),
@ui.circle(22, cy - 3, 8, bg),
@ui.text(36, cy, "Applications", t.font_size.reinterpret_as_int(), fg, bold=true),
]
}
///|
pub fn render_popup(
apps : Array[@types.AppEntry],
t : @theme.Tokens,
st : State,
) -> Array[@types.DrawOp] {
let size = popup_size(apps, st)
let w = size.w.reinterpret_as_int()
let h = size.h.reinterpret_as_int()
let fs = t.font_size.reinterpret_as_int()
let r = t.radius.reinterpret_as_int()
let p = t.palette
let ops = [
@ui.fill_rect(@ui.rect(0, 0, w, h), p.surface_popup, radius=r + 4),
@ui.stroke_rect(@ui.rect(0, 0, w, h), p.border, radius=r + 4),
// search field
@ui.fill_rect(@ui.rect(10, 10, w - 20, 32), p.surface, radius=r),
]
let q = if st.query.length() == 0 {
@ui.text(20, 26, "Type to search applications...", fs - 1, p.foreground_muted)
} else {
@ui.text(20, 26, st.query + "_", fs, p.foreground)
}
ops.push(q)
let shown = filter(apps, st.query)
if shown.length() == 0 {
ops.push(
@ui.text(w / 2, header_h + row_h / 2, "No matching applications", fs, p.foreground_muted, align=CENTER),
)
}
let n = visible_rows(shown.length())
for i = 0; i < n; i = i + 1 {
let a = shown[i]
let y = header_h + i * row_h
if i == st.hover {
ops.push(@ui.fill_rect(@ui.rect(6, y, w - 12, row_h - 2), p.accent, radius=r))
}
let fg = if i == st.hover { p.accent_foreground } else { p.foreground }
let sub = if i == st.hover { p.accent_foreground } else { p.foreground_muted }
ops.push(@ui.circle(30, y + row_h / 2 - 1, 15, p.surface_hover))
ops.push(@ui.text(30, y + row_h / 2 - 1, a.glyph, fs, fg, align=CENTER, bold=true))
ops.push(@ui.text(56, y + 14, a.name, fs, fg, bold=true))
ops.push(@ui.text(56, y + 31, a.comment, fs - 3, sub))
}
if st.error.length() > 0 {
ops.push(@ui.text(14, h - 12, st.error, fs - 3, @ui.color(240, 90, 90, 255)))
}
ops
}
///| Row index under a popup-local point, or -1.
pub fn row_at(apps : Array[@types.AppEntry], st : State, p : @types.Point) -> Int {
if p.x < 6 || p.x >= popup_w - 6 || p.y < header_h {
return -1
}
let i = (p.y - header_h) / row_h
if i < visible_rows(filter(apps, st.query).length()) { i } else { -1 }
}
///| Handle an event. `launch` is the host capability. Returns true on redraw.
pub fn handle_event(
apps : Array[@types.AppEntry],
st : State,
target : Target,
ev : @types.InputEvent,
launch : (String) -> Result[Unit, String],
) -> Bool {
match (target, ev) {
(Widget, PointerDown(_)) => {
if st.open {
close(st)
} else {
st.open = true
st.error = ""
}
true
}
(Popup, PointerMove(p)) => {
let i = row_at(apps, st, p)
if i != st.hover {
st.hover = i
true
} else {
false
}
}
(Popup, PointerLeave) =>
if st.hover != -1 {
st.hover = -1
true
} else {
false
}
(Popup, PointerDown(p)) => {
let i = row_at(apps, st, p)
if i >= 0 {
activate(apps, st, i, launch)
}
true
}
(_, FocusLost) =>
if st.open {
close(st)
true
} else {
false
}
(_, KeyDown(k)) =>
if !st.open {
false
} else if k == "Escape" {
close(st)
true
} else if k == "Backspace" {
if st.query.length() > 0 {
st.query = st.query[:st.query.length() - 1].to_owned()
}
st.hover = -1
true
} else if k == "Enter" {
if filter(apps, st.query).length() > 0 {
activate(apps, st, 0, launch)
}
true
} else if k.length() == 1 {
st.query = st.query + k
st.hover = -1
true
} else {
false
}
_ => false
}
}
///| Launch the i-th filtered app; a failure is shown in the popup (not hidden).
fn activate(
apps : Array[@types.AppEntry],
st : State,
i : Int,
launch : (String) -> Result[Unit, String],
) -> Unit {
let a = filter(apps, st.query)[i]
match launch(a.id) {
Ok(_) => close(st)
Err(e) => st.error = "Launch failed: " + e
}
}
///|
fn sample_apps() -> Array[@types.AppEntry] {
[
{ id: "a", name: "Terminal", comment: "Command line", category: "System", glyph: ">_" },
{ id: "b", name: "Files", comment: "Browse folders", category: "Utilities", glyph: "F" },
{ id: "c", name: "Web Browser", comment: "Browse the web", category: "Internet", glyph: "W" },
]
}
///|
test "filter is case-insensitive over name/comment/category" {
let apps = sample_apps()
assert_eq(filter(apps, "").length(), 3)
assert_eq(filter(apps, "TERM").length(), 1)
assert_eq(filter(apps, "folders")[0].id, "b")
assert_eq(filter(apps, "internet")[0].id, "c")
assert_eq(filter(apps, "zzz").length(), 0)
}
///|
test "open, type, launch via keyboard" {
let apps = sample_apps()
let st = State::new()
let launched : Array[String] = []
let launch = id => {
launched.push(id)
Ok(())
}
assert_true(handle_event(apps, st, Widget, PointerDown({ x: 1, y: 1 }), launch))
assert_true(st.open)
assert_true(handle_event(apps, st, Popup, KeyDown("f"), launch))
assert_true(handle_event(apps, st, Popup, KeyDown("i"), launch))
assert_eq(st.query, "fi")
assert_true(handle_event(apps, st, Popup, KeyDown("Enter"), launch))
assert_eq(launched, ["b"])
assert_false(st.open)
}
///|
test "click on a row launches; failure is surfaced and keeps the menu open" {
let apps = sample_apps()
let st = State::new()
st.open = true
let i = row_at(apps, st, { x: 20, y: 52 + 46 + 5 })
assert_eq(i, 1)
let _ = handle_event(
apps,
st,
Popup,
PointerDown({ x: 20, y: 52 + 46 + 5 }),
_ => Err("boom"),
)
assert_true(st.open)
assert_eq(st.error, "Launch failed: boom")
}
///|
test "focus loss closes and hover tracks the pointer" {
let apps = sample_apps()
let st = State::new()
st.open = true
assert_true(handle_event(apps, st, Popup, PointerMove({ x: 20, y: 60 }), _ => Ok(())))
assert_eq(st.hover, 0)
assert_false(handle_event(apps, st, Popup, PointerMove({ x: 21, y: 61 }), _ => Ok(())))
assert_true(handle_event(apps, st, Widget, FocusLost, _ => Ok(())))
assert_false(st.open)
}
+5
View File
@@ -0,0 +1,5 @@
import {
"moonplasma/desktop/interface/moonplasma/desktop/types" @types,
"moonplasma/desktop/interface/moonplasma/desktop/theme" @theme,
"moonplasma/desktop/lib/ui" @ui,
}
+44
View File
@@ -0,0 +1,44 @@
// Generated using `moon info`, DON'T EDIT IT
package "moonplasma/desktop/lib/launcher"
import {
"moonplasma/desktop/interface/moonplasma/desktop/theme",
"moonplasma/desktop/interface/moonplasma/desktop/types",
}
// Values
pub fn close(State) -> Unit
pub fn filter(Array[@types.AppEntry], String) -> Array[@types.AppEntry]
pub fn handle_event(Array[@types.AppEntry], State, Target, @types.InputEvent, (String) -> Result[Unit, String]) -> Bool
pub fn popup_size(Array[@types.AppEntry], State) -> @types.Size
pub let popup_w : Int32
pub fn render_button(@types.Size, @theme.Tokens, State) -> Array[@types.DrawOp]
pub fn render_popup(Array[@types.AppEntry], @theme.Tokens, State) -> Array[@types.DrawOp]
pub fn row_at(Array[@types.AppEntry], State, @types.Point) -> Int32
// Errors
// Types and methods
pub struct State {
mut open : Bool
mut query : String
mut hover : Int32
mut error : String
}
pub fn State::new() -> Self
pub(all) enum Target {
Widget
Popup
}
// Type aliases
// Traits
View File
Whitespace-only changes.
+218
View File
@@ -0,0 +1,218 @@
///| Panel layout algorithm (pure integer geometry, no WIT types).
///|
pub(all) struct SlotIn {
id : String
pref_w : Int
pref_h : Int
min_w : Int
stretch : Bool
end_align : Bool
}
///|
pub(all) struct Placed {
id : String
x : Int
y : Int
w : Int
h : Int
}
///|
pub(all) struct PanelLayout {
x : Int
y : Int
w : Int
h : Int
placements : Array[Placed]
}
///| Bottom, full-width panel. Widgets pack towards their edge in slot order.
/// Free space goes to `stretch` slots; if even the minimum widths do not fit
/// the call fails (Err) rather than silently dropping widgets.
pub fn layout(
screen_w : Int,
screen_h : Int,
panel_h : Int,
margin : Int,
spacing : Int,
slots : Array[SlotIn],
) -> Result[PanelLayout, String] {
if panel_h <= 0 || panel_h > screen_h {
return Err("panel height \{panel_h} does not fit screen height \{screen_h}")
}
let n = slots.length()
let avail = screen_w - 2 * margin - (if n > 1 { spacing * (n - 1) } else { 0 })
let widths : Array[Int] = slots.map(s => s.pref_w)
let mut total = 0
for w in widths {
total += w
}
if total > avail {
// Shrink towards min_w, taking the deficit from the widest slack first.
let mut deficit = total - avail
let mut guard_iter = 0
while deficit > 0 && guard_iter < 100000 {
guard_iter += 1
let mut best = -1
let mut best_slack = 0
for i = 0; i < n; i = i + 1 {
let slack = widths[i] - slots[i].min_w
if slack > best_slack {
best_slack = slack
best = i
}
}
if best < 0 {
return Err(
"panel overflow: slots need at least \{avail + deficit}px but only \{avail}px available",
)
}
widths[best] = widths[best] - 1
deficit -= 1
}
} else if total < avail {
let mut free = avail - total
let mut stretchers = 0
for s in slots {
if s.stretch {
stretchers += 1
}
}
if stretchers > 0 {
let share = free / stretchers
let mut rem = free - share * stretchers
for i = 0; i < n; i = i + 1 {
if slots[i].stretch {
widths[i] = widths[i] + share + (if rem > 0 { 1 } else { 0 })
if rem > 0 {
rem -= 1
}
}
}
free = 0
}
}
let inner_h = panel_h - 2 * margin
let py = screen_h - panel_h
let placed : Array[Placed?] = Array::make(n, None)
let mut x = margin
for i = 0; i < n; i = i + 1 {
if !slots[i].end_align {
placed[i] = Some(place(slots[i], x, py, margin, inner_h, widths[i]))
x += widths[i] + spacing
}
}
let mut rx = screen_w - margin
for i = n - 1; i >= 0; i = i - 1 {
if slots[i].end_align {
rx -= widths[i]
placed[i] = Some(place(slots[i], rx, py, margin, inner_h, widths[i]))
rx -= spacing
}
}
let out : Array[Placed] = []
for p in placed {
match p {
Some(v) => out.push(v)
None => abort("unreachable: unplaced slot")
}
}
Ok({ x: 0, y: py, w: screen_w, h: panel_h, placements: out })
}
///|
fn place(
s : SlotIn,
x : Int,
py : Int,
margin : Int,
inner_h : Int,
w : Int,
) -> Placed {
let h = if s.pref_h < inner_h { s.pref_h } else { inner_h }
{ id: s.id, x, y: py + margin + (inner_h - h) / 2, w, h }
}
///| Popup rectangle: above the panel, left-aligned with its anchor widget and
/// clamped inside the screen.
pub fn popup_position(
screen_w : Int,
panel_y : Int,
anchor_x : Int,
popup_w : Int,
popup_h : Int,
gap : Int,
) -> (Int, Int) {
let max_x = screen_w - popup_w
let x = if anchor_x > max_x { max_x } else { anchor_x }
let x = if x < 0 { 0 } else { x }
let y = panel_y - popup_h - gap
let y = if y < 0 { 0 } else { y }
(x, y)
}
///|
fn slot(id : String, pref : Int, min : Int, stretch : Bool, end_ : Bool) -> SlotIn {
{ id, pref_w: pref, pref_h: 30, min_w: min, stretch, end_align: end_ }
}
///|
test "start and end packing" {
let r = layout(
1000,
600,
40,
4,
6,
[slot("a", 100, 50, false, false), slot("b", 80, 40, false, true)],
).unwrap()
assert_eq((r.x, r.y, r.w, r.h), (0, 560, 1000, 40))
assert_eq((r.placements[0].x, r.placements[0].w), (4, 100))
assert_eq((r.placements[1].x, r.placements[1].w), (916, 80))
// 30px tall widget centred in 32px inner area.
assert_eq(r.placements[0].y, 565)
}
///|
test "stretch takes the free space" {
let r = layout(
500,
300,
40,
0,
0,
[slot("a", 100, 50, false, false), slot("s", 10, 10, true, false)],
).unwrap()
assert_eq(r.placements[1].w, 400)
}
///|
test "shrinks to minimum then fails loudly" {
let ok = layout(
200,
300,
40,
0,
0,
[slot("a", 150, 80, false, false), slot("b", 150, 80, false, false)],
).unwrap()
assert_eq((ok.placements[0].w, ok.placements[1].w), (100, 100))
let bad = layout(
100,
300,
40,
0,
0,
[slot("a", 150, 80, false, false), slot("b", 150, 80, false, false)],
)
assert_true(bad is Err(_))
}
///|
test "popup clamps to screen" {
assert_eq(popup_position(1000, 560, 4, 300, 200, 6), (4, 354))
assert_eq(popup_position(1000, 560, 900, 300, 200, 6), (700, 354))
assert_eq(popup_position(1000, 100, 4, 300, 200, 6), (4, 0))
}
+39
View File
@@ -0,0 +1,39 @@
// Generated using `moon info`, DON'T EDIT IT
package "moonplasma/desktop/lib/panel"
// Values
pub fn layout(Int32, Int32, Int32, Int32, Int32, Array[SlotIn]) -> Result[PanelLayout, String]
pub fn popup_position(Int32, Int32, Int32, Int32, Int32, Int32) -> (Int32, Int32)
// Errors
// Types and methods
pub(all) struct PanelLayout {
x : Int32
y : Int32
w : Int32
h : Int32
placements : Array[Placed]
}
pub(all) struct Placed {
id : String
x : Int32
y : Int32
w : Int32
h : Int32
}
pub(all) struct SlotIn {
id : String
pref_w : Int32
pref_h : Int32
min_w : Int32
stretch : Bool
end_align : Bool
}
// Type aliases
// Traits
+5
View File
@@ -0,0 +1,5 @@
import {
"moonplasma/desktop/interface/moonplasma/desktop/types" @types,
"moonplasma/desktop/interface/moonplasma/desktop/theme" @theme,
"moonplasma/desktop/lib/ui" @ui,
}
+20
View File
@@ -0,0 +1,20 @@
// Generated using `moon info`, DON'T EDIT IT
package "moonplasma/desktop/lib/shell"
import {
"moonplasma/desktop/interface/moonplasma/desktop/theme",
"moonplasma/desktop/interface/moonplasma/desktop/types",
}
// Values
pub fn render_background(@types.Size, @theme.Tokens) -> Array[@types.DrawOp]
pub fn render_panel(@types.Rect, @theme.Tokens) -> Array[@types.DrawOp]
// Errors
// Types and methods
// Type aliases
// Traits
+104
View File
@@ -0,0 +1,104 @@
///| Desktop background and panel chrome (pure render logic).
///| Vertical gradient built from horizontal bands, a soft "plasma" glow and a
/// wordmark. Everything derives from theme tokens.
pub fn render_background(
screen : @types.Size,
t : @theme.Tokens,
) -> Array[@types.DrawOp] {
let w = screen.w.reinterpret_as_int()
let h = screen.h.reinterpret_as_int()
let p = t.palette
let bands = 48
let ops = []
for i = 0; i < bands; i = i + 1 {
let y0 = h * i / bands
let y1 = h * (i + 1) / bands
ops.push(
@ui.fill_rect(
@ui.rect(0, y0, w, y1 - y0 + 1),
@ui.lerp_color(p.desktop_top, p.desktop_bottom, i, bands - 1),
),
)
}
// Plasma glow: concentric translucent discs.
let gx = w * 3 / 4
let gy = h * 3 / 10
let rings = 8
for i = 0; i < rings; i = i + 1 {
let r = 40 + (rings - i) * 22
ops.push(@ui.circle(gx, gy, r, @ui.with_alpha(p.accent, 14 + i * 4)))
}
ops.push(@ui.circle(gx, gy, 38, @ui.with_alpha(p.accent, 200)))
ops.push(@ui.circle(gx + 14, gy - 10, 34, p.desktop_top))
ops.push(
@ui.text(w / 2, h / 2 - 20, "moon-plasma", 54, @ui.with_alpha(p.foreground, 235), align=CENTER, bold=true),
)
ops.push(
@ui.text(
w / 2,
h / 2 + 24,
"every part is a WebAssembly component",
t.font_size.reinterpret_as_int() + 2,
p.foreground_muted,
align=CENTER,
),
)
ops
}
///|
pub fn render_panel(
panel : @types.Rect,
t : @theme.Tokens,
) -> Array[@types.DrawOp] {
let p = t.palette
[
@ui.fill_rect(panel, p.surface),
@ui.line(panel.x, panel.y, panel.x + @ui.rect_w(panel), panel.y, p.border),
]
}
///|
fn test_tokens() -> @theme.Tokens {
let c = @ui.color(10, 20, 30, 255)
let d = @ui.color(110, 120, 130, 255)
{
name: "t",
palette: {
desktop_top: c,
desktop_bottom: d,
surface: c,
surface_hover: c,
surface_popup: c,
foreground: c,
foreground_muted: c,
accent: c,
accent_foreground: c,
border: c,
},
font_size: 14,
radius: 6,
spacing: 6,
panel_height: 44,
}
}
///|
test "background gradient covers the screen top to bottom" {
let ops = render_background(@ui.size(800, 600), test_tokens())
match ops[0] {
FillRect(f) => {
assert_eq(f.rect.y, 0)
assert_eq(f.color.r.to_int(), 10)
}
_ => fail("expected fill")
}
match ops[47] {
FillRect(f) => {
assert_eq(f.color.r.to_int(), 110)
assert_true(f.rect.y + f.rect.h.reinterpret_as_int() >= 600)
}
_ => fail("expected fill")
}
}
View File
Whitespace-only changes.
+25
View File
@@ -0,0 +1,25 @@
// Generated using `moon info`, DON'T EDIT IT
package "moonplasma/desktop/lib/timefmt"
// Values
pub fn bcd_bits(Int32, Int32) -> Array[Bool]
pub fn date_line(Int32, Int32, Int32) -> String
pub fn hhmm(Int32, Int32) -> String
pub fn hhmmss(Int32, Int32, Int32) -> String
pub fn month_short(Int32) -> String
pub fn pad2(Int32) -> String
pub fn weekday_short(Int32) -> String
// Errors
// Types and methods
// Type aliases
// Traits
+65
View File
@@ -0,0 +1,65 @@
///| Pure time formatting helpers shared by the clock widgets.
///|
pub fn pad2(n : Int) -> String {
if n < 10 && n >= 0 { "0" + n.to_string() } else { n.to_string() }
}
///|
let weekdays : Array[String] = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
///|
let months : Array[String] = [
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
]
///| Weekday 0 = Sunday. Aborts on out-of-range input instead of guessing.
pub fn weekday_short(i : Int) -> String {
guard i >= 0 && i < 7 else { abort("weekday out of range: \{i}") }
weekdays[i]
}
///| Month 1..12.
pub fn month_short(m : Int) -> String {
guard m >= 1 && m <= 12 else { abort("month out of range: \{m}") }
months[m - 1]
}
///|
pub fn hhmm(hour : Int, minute : Int) -> String {
pad2(hour) + ":" + pad2(minute)
}
///|
pub fn hhmmss(hour : Int, minute : Int, second : Int) -> String {
hhmm(hour, minute) + ":" + pad2(second)
}
///| e.g. "Tue 24 Nov"
pub fn date_line(weekday : Int, day : Int, month : Int) -> String {
weekday_short(weekday) + " " + day.to_string() + " " + month_short(month)
}
///| The `bits` low bits of `digit`, most significant first.
pub fn bcd_bits(digit : Int, bits : Int) -> Array[Bool] {
let out = []
let mut i = bits - 1
while i >= 0 {
out.push(((digit >> i) & 1) == 1)
i = i - 1
}
out
}
///|
test "formatting" {
assert_eq(hhmm(9, 5), "09:05")
assert_eq(hhmmss(23, 59, 7), "23:59:07")
assert_eq(date_line(2, 24, 11), "Tue 24 Nov")
}
///|
test "bcd bits" {
assert_eq(bcd_bits(5, 4), [false, true, false, true])
assert_eq(bcd_bits(2, 2), [true, false])
}
+3
View File
@@ -0,0 +1,3 @@
import {
"moonplasma/desktop/interface/moonplasma/desktop/types" @types,
}
+43
View File
@@ -0,0 +1,43 @@
// Generated using `moon info`, DON'T EDIT IT
package "moonplasma/desktop/lib/ui"
import {
"moonplasma/desktop/interface/moonplasma/desktop/types",
}
// Values
pub fn circle(Int32, Int32, Int32, @types.Color, filled? : Bool) -> @types.DrawOp
pub fn color(Int32, Int32, Int32, Int32) -> @types.Color
pub fn contains(@types.Rect, @types.Point) -> Bool
pub fn fill_rect(@types.Rect, @types.Color, radius? : Int32) -> @types.DrawOp
pub fn lerp_color(@types.Color, @types.Color, Int32, Int32) -> @types.Color
pub fn line(Int32, Int32, Int32, Int32, @types.Color, width? : Int32) -> @types.DrawOp
pub fn rect(Int32, Int32, Int32, Int32) -> @types.Rect
pub fn rect_h(@types.Rect) -> Int32
pub fn rect_w(@types.Rect) -> Int32
pub fn size(Int32, Int32) -> @types.Size
pub fn stroke_rect(@types.Rect, @types.Color, width? : Int32, radius? : Int32) -> @types.DrawOp
pub fn text(Int32, Int32, String, Int32, @types.Color, align? : @types.TextAlign, bold? : Bool) -> @types.DrawOp
pub fn text_width(String, Int32) -> Int32
pub fn with_alpha(@types.Color, Int32) -> @types.Color
// Errors
// Types and methods
// Type aliases
// Traits
+171
View File
@@ -0,0 +1,171 @@
///| Shared drawing helpers for components. Pure functions over the WIT types.
///|
pub fn color(r : Int, g : Int, b : Int, a : Int) -> @types.Color {
{ r: r.to_byte(), g: g.to_byte(), b: b.to_byte(), a: a.to_byte() }
}
///|
fn chan(b : Byte) -> Int {
b.to_int()
}
///| Linear interpolation of two colours; `num/den` is the weight of `b`.
pub fn lerp_color(
a : @types.Color,
b : @types.Color,
num : Int,
den : Int,
) -> @types.Color {
guard den > 0 else { abort("lerp_color: den must be positive") }
let n = if num < 0 { 0 } else if num > den { den } else { num }
fn mix(x : Byte, y : Byte, n : Int, den : Int) -> Int {
(chan(x) * (den - n) + chan(y) * n) / den
}
color(
mix(a.r, b.r, n, den),
mix(a.g, b.g, n, den),
mix(a.b, b.b, n, den),
mix(a.a, b.a, n, den),
)
}
///|
pub fn with_alpha(c : @types.Color, a : Int) -> @types.Color {
color(chan(c.r), chan(c.g), chan(c.b), a)
}
///|
pub fn rect(x : Int, y : Int, w : Int, h : Int) -> @types.Rect {
{ x, y, w: w.reinterpret_as_uint(), h: h.reinterpret_as_uint() }
}
///|
pub fn size(w : Int, h : Int) -> @types.Size {
{ w: w.reinterpret_as_uint(), h: h.reinterpret_as_uint() }
}
///|
pub fn rect_w(r : @types.Rect) -> Int {
r.w.reinterpret_as_int()
}
///|
pub fn rect_h(r : @types.Rect) -> Int {
r.h.reinterpret_as_int()
}
///|
pub fn contains(r : @types.Rect, p : @types.Point) -> Bool {
p.x >= r.x &&
p.y >= r.y &&
p.x < r.x + rect_w(r) &&
p.y < r.y + rect_h(r)
}
///|
pub fn fill_rect(
r : @types.Rect,
c : @types.Color,
radius~ : Int = 0,
) -> @types.DrawOp {
@types.DrawOp::FillRect({ rect: r, color: c, radius: radius.reinterpret_as_uint() })
}
///|
pub fn stroke_rect(
r : @types.Rect,
c : @types.Color,
width~ : Int = 1,
radius~ : Int = 0,
) -> @types.DrawOp {
@types.DrawOp::StrokeRect({
rect: r,
color: c,
width: width.reinterpret_as_uint(),
radius: radius.reinterpret_as_uint(),
})
}
///|
pub fn line(
x0 : Int,
y0 : Int,
x1 : Int,
y1 : Int,
c : @types.Color,
width~ : Int = 1,
) -> @types.DrawOp {
@types.DrawOp::Line({
start: { x: x0, y: y0 },
end: { x: x1, y: y1 },
color: c,
width: width.reinterpret_as_uint(),
})
}
///|
pub fn circle(
cx : Int,
cy : Int,
radius : Int,
c : @types.Color,
filled~ : Bool = true,
) -> @types.DrawOp {
@types.DrawOp::Circle({
center: { x: cx, y: cy },
radius: radius.reinterpret_as_uint(),
color: c,
filled,
})
}
///| Draw `s` with `origin` at the vertical middle of the line box.
pub fn text(
x : Int,
y : Int,
s : String,
size : Int,
c : @types.Color,
align~ : @types.TextAlign = LEFT,
bold~ : Bool = false,
) -> @types.DrawOp {
@types.DrawOp::Text({
origin: { x, y },
text: s,
style: { size: size.reinterpret_as_uint(), color: c, align, bold },
})
}
///| The text-metrics contract of the PoC host: every glyph advances by
/// `ceil(0.6 * size)` pixels (monospace). Replaced by a real shaping
/// interface in a later milestone.
pub fn text_width(s : String, size : Int) -> Int {
s.length() * ((size * 6 + 9) / 10)
}
///|
test "lerp_color endpoints and midpoint" {
let a = color(0, 0, 0, 255)
let b = color(200, 100, 50, 255)
assert_eq(lerp_color(a, b, 0, 10).r.to_int(), 0)
assert_eq(lerp_color(a, b, 10, 10).r.to_int(), 200)
assert_eq(lerp_color(a, b, 5, 10).g.to_int(), 50)
assert_eq(lerp_color(a, b, 99, 10).b.to_int(), 50)
}
///|
test "contains is half-open" {
let r = rect(10, 10, 5, 5)
assert_true(contains(r, { x: 10, y: 10 }))
assert_true(contains(r, { x: 14, y: 14 }))
assert_false(contains(r, { x: 15, y: 10 }))
assert_false(contains(r, { x: 9, y: 10 }))
}
///|
test "text_width follows the 0.6em contract" {
assert_eq(text_width("12:30", 20), 60)
assert_eq(text_width("", 20), 0)
}
Loaded 100 of 125 files, more files were not shown because too many files have changed in this diff. Show more