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

@ -0,0 +1,59 @@
# focus.ludic - the keyboard's place: focus moves through the controls in document order (Tab and
# Shift+Tab, or the arrows), Enter and Space activate what has it, and a pointer press focuses what
# it presses. A key that is gone from the screen leaves nothing focused.
var fc_key: string = ""
var fc_visible: bool = false # focus came from the keyboard: :focus-visible, and the ring
var fc_list: []UiNode = new []UiNode
function fc_collect(n: UiNode) -> void {
if n.focusable and n.enabled { push(fc_list, n) }
for i in 0 .. len(n.children) { fc_collect(n.children[i]) }
}
function fc_find() -> int {
for i in 0 .. len(fc_list) {
if fc_list[i].key == fc_key { return i }
}
return -1
}
function fc_move(step: int) -> void {
if len(fc_list) == 0 { return }
var at = fc_find()
if at < 0 {
at = 0
if step < 0 { at = len(fc_list) - 1 }
} else { at = (at + step + len(fc_list)) % len(fc_list) }
fc_key = fc_list[at].key
fc_visible = true
}
# the keys, after the tree is laid out: moving, then acting on what has the focus
function fc_keys(root: UiNode) -> void {
fc_list = new []UiNode
fc_collect(root)
let i = in_now
if fc_find() < 0 { fc_autofocus() }
let at = fc_find()
var n: UiNode = null
if at >= 0 { n = fc_list[at] }
if i.tab and i.shift { fc_move(-1) } else if i.tab { fc_move(1) }
let horizontal = n != null and ct_takes_arrows(n)
if i.up or (i.left and not horizontal) { fc_move(-1) }
if i.down_key or (i.right and not horizontal) { fc_move(1) }
if n == null { return }
if i.enter or (i.space and not ct_takes_space(n)) { ct_activate(n) }
if horizontal and i.left { ct_step(n, -1) }
if horizontal and i.right { ct_step(n, 1) }
ct_typed(n)
}
export function ui_focus(key: string) -> void {
fc_key = key
fc_visible = false
}
# nothing focused (a screen just opened): the control that says autofocus, as HTML's does
function fc_autofocus() -> void {
for i in 0 .. len(fc_list) {
if ui_attr_on(fc_list[i], "autofocus") {
fc_key = fc_list[i].key
fc_visible = false
return
}
}
}