ludic/examples/library/ui_text.ludic
2026-09-24 21:51:41 +03:00

23 lines
1.2 KiB
Text

# ui_text.ludic — text: text-fit shrinks a line to its chip down to a least size and then cuts it with
# an ellipsis; line-height as a multiple and in px; an em reads the font size the element ends with
# (set later in the rule, or by a later rule); a sheet's own rule wins a tie with one it imports.
import "ludic.ui"
import "ui_text_parts/Fit.ludic"
program UiText {
numbers float
var said: []string = new []string
function rec_text(x: float, y: float, s: string, size: float, c: int, a: float) -> void { push(said, `{s}@{int(size * 10.0)} y{int(y)}`) }
function w(s: string, size: float) -> float { return float(len(s)) * size * 0.5 }
entry {
let b = new UiBackend
b.text = fn rec_text
b.measure = fn w
ui_backend(b)
ui_show("Fit", null, 0.0, 0.0, 400.0, 600.0)
let root: UiNode = ui_nodes("Fit", null)
ui_place(root, 0.0, 0.0, 400.0, 600.0)
let page = root.children[0]
let lines = page.children[3]
print(`{said[0]} | {said[1]} | {said[2]} | lines {len(lines.lines)} {int(lines.mh)} {said[3]} {said[4]} | tall {int(page.children[4].mh)} | em {int(page.children[5].pt)} {int(page.children[6].pt)} | tie {ui_hex(page.children[7].fg)}`)
}
}