ludic/packages/ludic.ui/build_more.ludic
Orkuncakilkaya 1dad96102a 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>
2026-09-24 17:26:09 +03:00

41 lines
1.4 KiB
Text

# build_more.ludic - <let name="{value}"/> names a value for the siblings after it, and
# <provide name="{value}"> gives it to everything inside, components included (React's context)
function bd_let(k: UiTpl, e: UiEnv) -> UiEnv {
let le = env_new(e)
for i in 0 .. len(k.keys) { env_bind(le, k.keys[i], ui_eval(k.vals[i], e)) }
return le
}
function bd_provide(k: UiTpl, e: UiEnv, key: string, out: []UiNode) -> void {
let cx = env_new(e.ctx)
for i in 0 .. len(k.keys) { env_bind(cx, k.keys[i], ui_eval(k.vals[i], e)) }
let pe = env_new(e)
pe.ctx = cx
bd_kids(k.kids, pe, key, out)
}
# a fragment's (or a template's) content: its elements, or its words as a text of their own
function bd_group(k: UiTpl, e: UiEnv, key: string, out: []UiNode) -> void {
if k.text == null {
bd_kids(k.kids, e, key, out)
return
}
let t = new UiNode
t.kind = UI_TEXT
t.key = key
t.text = ui_tr(ui_eval_text(k.text, e))
t.env = e
t.children = new []UiNode
push(out, t)
}
# text inside text - <p>Hi <b>there</b></p>, <h3><slot/></h3> - reads as one line of it
function el_inline(n: UiNode) -> void {
if n.kind != UI_TEXT or len(n.children) == 0 { return }
var s = n.text
for i in 0 .. len(n.children) {
let c = n.children[i]
el_inline(c)
if len(s) > 0 and len(c.text) > 0 { s = s + " " }
s = s + c.text
}
n.text = s
n.children = new []UiNode
}