feat(ui): ludic.ui is a UI framework - input, controls, render3d backend, the CSS a game needs

A game no longer writes a host:
- The runtime reads Input itself: focus and keyboard navigation (Tab, arrows, Enter/Space,
  autofocus), the pointer (hover, :active, click on release, drag), and scroll boxes with the
  wheel, a draggable scrollbar, clipping and scroll-into-view.
- HTML's controls are built in (button, checkbox, radio, range, select, text, key capture), made
  of plain parts a stylesheet styles, each reporting with on-change and event.value.
- ludic.ui/render3d.ludic draws with render3d's overlay: textures, named atlases (icon:NAME),
  nine-slice border-image, rounded rects and rings, clipping, and a scale.
- Hooks for the program's language, sounds and clock (ui_translator, ui_sounds, ui_clock).
- ui_dev: hot reload, errors on screen, LUDIC_UI_DUMP.
- CSS:
  - colours as #rgb / #rrggbbaa / rgb() / rgba() / names;
  - border-radius and outline (following the radius), box-shadow, background-image and a tinted
    border-image;
  - group opacity, @keyframes / animation, transition;
  - :focus, :focus-visible and :focus-within.
- HTML mixed content, and boolean attributes.
- render3d gains tex_width / tex_height, and the XML reader keeps text runs in order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-24 17:26:09 +03:00
parent 20d011f8e9
commit 1dad96102a
45 changed files with 1386 additions and 218 deletions

View file

@ -22,6 +22,7 @@ property Xml {
avals: []pointer # attribute values (entity-decoded)
kids: []Xml # child elements, in document order
at: int = 0 # where its '<' is in the text, for an error that names a line
mixed: []Xml # its elements and its runs of text ("#text"), in document order
}
function xml_new(tag: pointer) -> Xml {
@ -31,6 +32,7 @@ function xml_new(tag: pointer) -> Xml {
n.akeys = new []pointer
n.avals = new []pointer
n.kids = new []Xml
n.mixed = new []Xml
return n
}
@ -276,18 +278,39 @@ function xp_element(p: XP) -> Xml {
p.i += 3 # past "]]>"
} else {
if xp_skip_misc(p) { } # comment / PI inside content
else { push(node.kids, xp_element(p)) }
else {
let kid = xp_element(p)
push(node.kids, kid)
push(node.mixed, kid)
}
}
} else {
# character data run up to the next '<'
let start = p.i
while p.i < p.n and p.s[p.i] != '<' { p.i += 1 }
node.text += xml_unescape(p.s[start..p.i])
let run = xml_unescape(p.s[start..p.i])
node.text += run
xp_text_run(node, run)
}
}
return node
}
# a run of text among an element's children, kept in order unless it is only white space
function xp_text_run(node: Xml, run: string) -> void {
var blank = true
var i = 0
while i < len(run) {
let c = run[i]
if not (c == ' ' or c == '\t' or c == '\n' or c == '\r') { blank = false }
i += 1
}
if blank { return }
let t = xml_new("#text")
t.text = run
push(node.mixed, t)
}
# parse a whole document -> its root element (or the synthetic empty node).
function xml_parse(s: pointer) -> Xml {
let p = new XP