WIT package, MoonBit components, Node host and tests (WIP)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e5548fc067
commit
e0bde1d150
125 files changed
+8681
No files matched your search
@@ -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
|
||||
|
||||
Reference in new issue
Block a user