ludic/packages/ludic.ui/popover.ludic
Orkuncakilkaya 19fcf60599 wip(0.S3): packages and examples migrated again from their pre-0.S sources in one run
ludic migrate state packages <every example program> packages/ludic.lab/example/plate.ludic
  1804 vars into 126 states, 64 into lets; 23498 edits in 460 files

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 15:31:34 +03:00

32 lines
1.3 KiB
Text

# popover.ludic - HTML's popover: `<div popover on-close="...">` sits where its position puts it
# (absolutely, in its parent) and is drawn on the top layer, over everything. While one is up the
# pointer and the keyboard are its: a press outside it, or Esc, closes it (on-close), and Tab
# walks only its own controls.
function pp_find(n: UiNode, out: []UiNode) -> void {
if n.popover {
push(out, n)
return
}
for i in 0 .. len(n.children) { pp_find(n.children[i], out) }
}
# the topmost popover open in this tree, or null
function pp_top(root: UiNode) -> UiNode {
let all = new []UiNode
pp_find(root, all)
if len(all) == 0 { return null }
return all[len(all) - 1]
}
# the pointer against the popover: inside it is as usual; a press outside closes it and is spent
function pp_pointer(ui_st: mut UiState, top: UiNode) -> bool {
let i = ui_st.in_now
if not (i.down and not ui_st.in_was_down) { return false }
if i.x >= top.x and i.y >= top.y and i.x < top.x + top.cw and i.y < top.y + top.ch { return false }
ui_st.fr_press_key = ""
ui_fire(ui_st, top, "close", Value.null())
return true
}
function pp_draw_top(ui_st: mut UiState) -> void {
let list = ui_st.pop_list
ui_st.pop_list = new []UiNode
for i in 0 .. len(list) { fr_draw(ui_st, list[i]) }
}