// examples/34_png_charts_and_flex_widgets.vk
// Demonstrates pure-Veko Light-Mode UI rendering, flex/grid layout, charts, and lossless PNG roundtrip:
// - `ui/layout` & `ui/widgets` (`flex-row`, `flex-col`, `grid`, `stat-card`, `bar-chart`, `line-chart`)
// - `ui/font` proportional mixed-case typography
// - `image/png` RFC 2083 RGBA32 encode & decode roundtrip (zero capabilities required!)
use [
cv = ui/canvas
png = image/png
w = ui/widgets
]
main = fn [] any [
mut c = cv/new-canvas 380 220
mut st = w/new-state
th = w/light-theme
cv/clear mut c th.bg
outer = w/Rect { x = 10, y = 10, w = 360, h = 200 }
rows = w/flex-col outer [(w/px 56) (w/flex 1)] 8
kpis = w/grid rows[0] 1 3 8
w/stat-card mut c kpis[0] 'Requests' '94k/s' '+12%' 'ok' th
w/stat-card mut c kpis[1] 'Binary' '28 KB' 'AOT' 'info' th
w/stat-card mut c kpis[2] 'Latency' '0.4ms' '0 GC' 'ok' th
cols = w/flex-row rows[1] [(w/flex 1) (w/flex 1)] 8
w/panel mut c cols[0] 'Throughput' th
w/bar-chart mut c (w/panel-body cols[0] true 6) ['VM' 'Wasm' 'x64'] [65 130 250] th.accent th
w/panel mut c cols[1] 'P99 Trend' th
series = [
w/ChartSeries { name = 'x64', values = [18 16 15 14 12], color = th.accent }
]
w/line-chart mut c (w/panel-body cols[1] true 6) ['t0' 't1' 't2' 't3' 't4'] series th
_ = st
// Extract 80x56 KPI+chart snapshot region for fast cross-track (VM/Wasm/Native) lossless PNG roundtrip
mut snap = cv/new-canvas 80 56
mut sy = 0
while sy < 56 [
mut sx = 0
while sx < 80 [
cv/set-pixel mut snap sx sy (cv/get-pixel c (10 + sx) (10 + sy))
sx = sx + 1
]
sy = sy + 1
]
raw_png = png/encode snap
dec = png/decode raw_png
if dec.width != 80 or dec.height != 56 [
return (err 'PNG dimension mismatch')
]
p_orig = cv/get-pixel snap 14 14
p_dec = cv/get-pixel dec 14 14
if p_orig.r != p_dec.r or p_orig.g != p_dec.g or p_orig.b != p_dec.b [
return (err 'lossless PNG pixel mismatch')
]
println `[Example 34 OK] canvas=380x220 snap_png={len raw_png}B lossless_verified=true`
.ok
]
res = main
if err? res [
println (str/append 'FAIL: ' (mold res))
os/exit 1
]