Load the real desktop shell (lib/shell, panel, launcher, clock) into the native compositor
CI / test (push) Successful in 34s
CI / test (push) Successful in 34s
Replaces the hardcoded build_shell_ops with compositor/shell, which drives the same pure lib/* logic the wasm components wrap and adapts it to scene ops. Adds a wall-clock FFI and native stubs for the wasm-only theme bindings. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3cb8417699
commit
769ab829c8
8 files changed
+285
-1
No files matched your search
@@ -0,0 +1,14 @@
|
||||
import {
|
||||
"moonbitlang/core/builtin",
|
||||
"moonplasma/desktop/interface/moonplasma/desktop/types" @types,
|
||||
"moonplasma/desktop/interface/moonplasma/desktop/theme" @theme,
|
||||
"moonplasma/desktop/lib/ui" @ui,
|
||||
"moonplasma/desktop/lib/shell" @libshell,
|
||||
"moonplasma/desktop/lib/panel" @panel,
|
||||
"moonplasma/desktop/lib/clock" @clock,
|
||||
"moonplasma/desktop/lib/launcher" @launcher,
|
||||
"moonplasma/desktop/compositor/scene" @scene,
|
||||
"moonplasma/desktop/compositor/sys" @sys,
|
||||
}
|
||||
|
||||
supported_targets = "-all+native"
|
||||
@@ -0,0 +1,198 @@
|
||||
///| Loads the desktop shell (lib/shell background + panel chrome, lib/panel
|
||||
/// layout, lib/launcher button, lib/clock widget) into the native compositor.
|
||||
/// The shell logic is the same code the wasm components wrap; this package only
|
||||
/// adapts its WIT-shaped types to the compositor's scene types.
|
||||
|
||||
///|
|
||||
fn conv_color(c : @types.Color) -> @scene.Rgba {
|
||||
{ r: c.r, g: c.g, b: c.b, a: c.a }
|
||||
}
|
||||
|
||||
///|
|
||||
fn conv_theme(t : @scene.ThemeTokens) -> @theme.Tokens {
|
||||
let p = t.palette
|
||||
let col = fn(c : @scene.Rgba) -> @types.Color { { r: c.r, g: c.g, b: c.b, a: c.a } }
|
||||
{
|
||||
name: t.name,
|
||||
palette: {
|
||||
desktop_top: col(p.desktop_top),
|
||||
desktop_bottom: col(p.desktop_bottom),
|
||||
surface: col(p.surface),
|
||||
surface_hover: col(p.surface_hover),
|
||||
surface_popup: col(p.surface_popup),
|
||||
foreground: col(p.foreground),
|
||||
foreground_muted: col(p.foreground_muted),
|
||||
accent: col(p.accent),
|
||||
accent_foreground: col(p.accent_foreground),
|
||||
border: col(p.border),
|
||||
},
|
||||
font_size: t.font_size.reinterpret_as_uint(),
|
||||
radius: t.radius.reinterpret_as_uint(),
|
||||
spacing: t.spacing.reinterpret_as_uint(),
|
||||
panel_height: t.panel_height.reinterpret_as_uint(),
|
||||
}
|
||||
}
|
||||
|
||||
///| Translate a widget render-list into scene ops, offset to screen coordinates.
|
||||
fn translate(
|
||||
ops : Array[@types.DrawOp],
|
||||
dx : Int,
|
||||
dy : Int,
|
||||
out : Array[@scene.DrawOp],
|
||||
) -> Unit {
|
||||
let rect = fn(r : @types.Rect) -> @scene.Rect {
|
||||
{
|
||||
x: r.x + dx,
|
||||
y: r.y + dy,
|
||||
w: r.w.reinterpret_as_int(),
|
||||
h: r.h.reinterpret_as_int(),
|
||||
}
|
||||
}
|
||||
for op in ops {
|
||||
match op {
|
||||
FillRect(f) =>
|
||||
out.push(
|
||||
@scene.DrawOp::FillRect(
|
||||
rect(f.rect),
|
||||
conv_color(f.color),
|
||||
f.radius.reinterpret_as_int(),
|
||||
),
|
||||
)
|
||||
StrokeRect(s) =>
|
||||
out.push(
|
||||
@scene.DrawOp::StrokeRect(
|
||||
rect(s.rect),
|
||||
conv_color(s.color),
|
||||
s.width.reinterpret_as_int(),
|
||||
s.radius.reinterpret_as_int(),
|
||||
),
|
||||
)
|
||||
Line(l) =>
|
||||
out.push(
|
||||
@scene.DrawOp::Line(
|
||||
l.start.x + dx,
|
||||
l.start.y + dy,
|
||||
l.end.x + dx,
|
||||
l.end.y + dy,
|
||||
conv_color(l.color),
|
||||
l.width.reinterpret_as_int(),
|
||||
),
|
||||
)
|
||||
Circle(c) =>
|
||||
out.push(
|
||||
@scene.DrawOp::Circle(
|
||||
c.center.x + dx,
|
||||
c.center.y + dy,
|
||||
c.radius.reinterpret_as_int(),
|
||||
conv_color(c.color),
|
||||
c.filled,
|
||||
),
|
||||
)
|
||||
Text(t) => {
|
||||
let align = match t.style.align {
|
||||
LEFT => @scene.TextAlign::Left
|
||||
CENTER => @scene.TextAlign::Center
|
||||
RIGHT => @scene.TextAlign::Right
|
||||
}
|
||||
out.push(
|
||||
@scene.DrawOp::Text(
|
||||
t.origin.x + dx,
|
||||
t.origin.y + dy,
|
||||
t.text,
|
||||
t.style.size.reinterpret_as_int(),
|
||||
conv_color(t.style.color),
|
||||
align,
|
||||
t.style.bold,
|
||||
),
|
||||
)
|
||||
}
|
||||
PushClip(r) => out.push(@scene.DrawOp::PushClip(rect(r)))
|
||||
PopClip => out.push(@scene.DrawOp::PopClip)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///| Current local time in the WIT `datetime` shape.
|
||||
fn now() -> @types.Datetime {
|
||||
{
|
||||
year: @sys.wall_time_field(0).reinterpret_as_uint(),
|
||||
month: @sys.wall_time_field(1).to_byte(),
|
||||
day: @sys.wall_time_field(2).to_byte(),
|
||||
hour: @sys.wall_time_field(3).to_byte(),
|
||||
minute: @sys.wall_time_field(4).to_byte(),
|
||||
second: @sys.wall_time_field(5).to_byte(),
|
||||
weekday: @sys.wall_time_field(6).to_byte(),
|
||||
}
|
||||
}
|
||||
|
||||
///| The desktop shell: wallpaper + bottom panel with launcher, task list and clock.
|
||||
pub(all) struct DesktopShell {
|
||||
launcher_state : @launcher.State
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn DesktopShell::new() -> DesktopShell {
|
||||
{ launcher_state: @launcher.State::new() }
|
||||
}
|
||||
|
||||
///| Build the (background, panel) render-lists for the current frame.
|
||||
pub fn DesktopShell::render(
|
||||
self : DesktopShell,
|
||||
w : Int,
|
||||
h : Int,
|
||||
theme : @scene.ThemeTokens,
|
||||
layout_label : String,
|
||||
window_titles : Array[String],
|
||||
) -> (Array[@scene.DrawOp], Array[@scene.DrawOp]) {
|
||||
let tokens = conv_theme(theme)
|
||||
let bg : Array[@scene.DrawOp] = []
|
||||
translate(@libshell.render_background(@ui.size(w, h), tokens), 0, 0, bg)
|
||||
|
||||
let (_, _, clock_w, clock_h, clock_min) = @clock.digital_info()
|
||||
let slots : Array[@panel.SlotIn] = [
|
||||
{ id: "launcher", pref_w: 190, pref_h: 36, min_w: 170, stretch: false, end_align: false },
|
||||
{ id: "layout", pref_w: 96, pref_h: 36, min_w: 80, stretch: false, end_align: false },
|
||||
{ id: "tasks", pref_w: 100, pref_h: 36, min_w: 0, stretch: true, end_align: false },
|
||||
{ id: "clock", pref_w: clock_w, pref_h: clock_h, min_w: clock_min, stretch: false, end_align: true },
|
||||
]
|
||||
let panel_ops : Array[@scene.DrawOp] = []
|
||||
match @panel.layout(w, h, theme.panel_height, 4, tokens.spacing.reinterpret_as_int(), slots) {
|
||||
Err(_) => ()
|
||||
Ok(pl) => {
|
||||
let pr = @ui.rect(pl.x, pl.y, pl.w, pl.h)
|
||||
translate(@libshell.render_panel(pr, tokens), 0, 0, panel_ops)
|
||||
for p in pl.placements {
|
||||
let size = @ui.size(p.w, p.h)
|
||||
let local : Array[@types.DrawOp] = match p.id {
|
||||
"launcher" => @launcher.render_button(size, tokens, self.launcher_state)
|
||||
"clock" => @clock.render_digital(size, tokens, now())
|
||||
"layout" => [
|
||||
@ui.fill_rect(@ui.rect(0, 0, p.w, p.h), tokens.palette.surface_hover, radius=tokens.radius.reinterpret_as_int()),
|
||||
@ui.text(p.w / 2, p.h / 2, layout_label, tokens.font_size.reinterpret_as_int() - 2, tokens.palette.foreground, align=CENTER),
|
||||
]
|
||||
_ => []
|
||||
}
|
||||
translate(local, p.x, p.y, panel_ops)
|
||||
if p.id == "tasks" {
|
||||
let mut tx = 0
|
||||
for title in window_titles {
|
||||
let pill_w = 140
|
||||
if tx + pill_w <= p.w {
|
||||
translate(
|
||||
[
|
||||
@ui.fill_rect(@ui.rect(tx, 0, pill_w, p.h), tokens.palette.surface_hover, radius=tokens.radius.reinterpret_as_int()),
|
||||
@ui.text(tx + 10, p.h / 2, title, tokens.font_size.reinterpret_as_int() - 2, tokens.palette.foreground),
|
||||
],
|
||||
p.x,
|
||||
p.y,
|
||||
panel_ops,
|
||||
)
|
||||
tx = tx + pill_w + 6
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
(bg, panel_ops)
|
||||
}
|
||||
Reference in new issue
Block a user