ludic/packages/ludic.ui/draw_nine.ludic
Orkuncakilkaya 49b5e80af5 ludic ui-preview: ludic.ui components previewed for a studio over stdio (R5)
A prebuilt tool, bin/ludic-ui-preview (built by ludic-dev build, shipped beside ludic-lsp, run as
`ludic ui-preview [--font DIR]`): ludic.ui with a backend that records every draw call as a line,
and mock component classes the studio describes (load / model / calls). frame t runs ui_show at
interface time t; text is measured on the CPU with the game's font.json metrics; locale goes
through ludic.i18n; tree / box / rules inspect the frame. No game code, no GPU, no network. The wire
protocol is frozen as tools/ui-preview/protocol-v1.md; smoke.txt is a transcript to run.

ludic.ui gains, all additive: UiClass.make_of, UiBackend.said / emitted, UiRule.text / at (with
comment line breaks kept so rule lines count true, and a class's styles read under its .lss path),
and ui_root, ui_find, ui_rules_of, ui_rule_value, ui_building, ui_class, ui_class_load,
ui_file_forget, ui_errors_clear; ui_nine_cuts_into exported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 19:53:26 +03:00

21 lines
1.1 KiB
Text

# draw_nine.ludic - where a nine-slice is cut: its corners as wide as border-image says, but never
# more than half the box across or half of it down (each direction on its own, so a small key cap
# keeps its round ends and has no seam), on whole pixels so the nine pieces meet exactly
# x0 x1 x2 x3 then y0 y1 y2 y3: the columns' and the rows' edges
export function ui_nine_cuts(x: float, y: float, w: float, h: float, dst: float) -> []float { return ui_nine_cuts_into(new []float, x, y, w, h, dst) }
# the same into a list the caller keeps, emptied first
export function ui_nine_cuts_into(out: []float, x: float, y: float, w: float, h: float, dst: float) -> []float {
let dx = Math.max(Math.min(dst, w / 2.0), 0.0)
let dy = Math.max(Math.min(dst, h / 2.0), 0.0)
List.clear(out)
push(out, nn_px(x))
push(out, nn_px(x + dx))
push(out, nn_px(x + w - dx))
push(out, nn_px(x + w))
push(out, nn_px(y))
push(out, nn_px(y + dy))
push(out, nn_px(y + h - dy))
push(out, nn_px(y + h))
return out
}
function nn_px(v: float) -> float { return Math.floor(v + 0.5) }