feat(ui): text-fit, line-height, and ems against the font size an element ends with

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-24 21:51:41 +03:00
parent d163bad406
commit 355201f094
16 changed files with 149 additions and 21 deletions

View file

@ -0,0 +1,23 @@
# 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)}`)
}
}

View file

@ -0,0 +1,10 @@
@import "base.lss";
.page { width: 400px }
.chip { width: 100px; font-size: 16px; text-fit: shrink 10px }
.mid { width: 80px }
.lines { width: 60px; font-size: 16px; line-height: 2 }
.tall { line-height: 30px }
.em { padding: 1em; font-size: 20px }
.em2 { padding: 1em }
.page .em2 { font-size: 24px }
.tie { color: #00ff00 }

View file

@ -0,0 +1,4 @@
# Fit.ludic - chips too narrow for their words, lines spaced by line-height, ems read against the
# font size an element ends with, and a sheet's own rule over an imported one of the same weight
component Fit {
}

View file

@ -0,0 +1,10 @@
<div class="page">
<p class="chip long">Photograph the Bells from the signs</p>
<p class="chip">Short</p>
<p class="chip mid">Medium words</p>
<p class="lines">one two three four five six</p>
<p class="tall">a</p>
<div class="em">x</div>
<div class="em2">y</div>
<p class="tie">t</p>
</div>

View file

@ -0,0 +1 @@
.tie { color: #0000ff }