ludic/examples/library/ui_emit_click.ludic
Orkuncakilkaya e476a9d975 ludic.ui: emit click reaches on-click, and a select's < steps back
From the user's play: clicking an item in the pack opened nothing, and the wardrobe's picks did
not respond - both are a component whose button says `emit click` (ItemCell, LookCell, ListRow),
answered by its user's on-click. An on-* attribute's name is kept as a browser would have it, so
on-click is on-press (tpl_event), and the emit looked for "click" and found nothing. An emitted
name now goes through the same tpl_event.

And a settings cycler's left arrow did the right one's job: any press let go on a select stepped it
forward. ct_activate_at steps back when it is let go over the select's .ui-prev; Enter and the rest
of the select still step forward.

Goldens ui_emit_click (the mouse and a press both reach on-click; with the toolchain before this,
neither does) and ui_select_arrows (1 -> 0 on <, then 2 on > >; before this, 1 -> 2 on <). The 33
ui examples pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 12:32:45 +03:00

40 lines
1.5 KiB
Text

# ui_emit_click.ludic - a component whose button says `emit click` is answered by its user's
# on-click, by the mouse or a press: on-click is kept as on-press, and the emit once looked for
# "click" and found nothing (the pack's items and the wardrobe's picks did not respond)
import "ludic.ui"
import "ui_emit_click_parts/Cell.ludic"
import "ui_emit_click_parts/Pick.ludic"
program UiEmitClick {
numbers float
function frame(ui_st: mut UiState, x: float, y: float, down: bool) -> UiNode {
let i = new UiInput
i.x = x
i.y = y
i.down = down
ui_input(ui_st, i)
ui_show(ui_st, "Pick", null, 0.0, 0.0, 400.0, 400.0)
let root: UiNode = ui_nodes(ui_st, "Pick", null)
ui_place(ui_st, root, 0.0, 0.0, 400.0, 400.0)
return root
}
function first_text(n: UiNode) -> string {
if n.text != "" { return n.text }
for i in 0 .. len(n.children) { let t = first_text(n.children[i]); if t != "" { return t } }
return ""
}
entry (ui_st: mut UiState) {
var root = frame(ui_st, -1.0, -1.0, false)
root = frame(ui_st, -1.0, -1.0, false)
let b = root.children[0].children[2].children[0]
let x = b.x + b.cw / 2.0
let y = b.y + b.ch / 2.0
root = frame(ui_st, x, y, false)
root = frame(ui_st, x, y, true)
root = frame(ui_st, x, y, false)
root = frame(ui_st, x, y, false)
let clicked = first_text(root)
ui_press(ui_st, root.children[0].children[1].children[0])
root = frame(ui_st, x, y, false)
print(`{clicked} | pressed: {first_text(root)}`)
}
}