///| 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") } }