ludic/examples/library/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

59 lines
1.9 KiB
Text

# ui_popover.ludic — HTML's popover and progress in ludic.ui: a button opens a popover of verbs, the
# keyboard stays inside it, a press outside or Esc closes it, and a progress bar fills to its value.
import "ludic.ui"
import "ui_popover_parts/Verbs.ludic"
program UiPopover {
numbers float
function frame(ui_st: mut UiState, i: UiInput) -> UiNode {
ui_input(ui_st, i)
ui_show(ui_st, "Verbs", null, 0.0, 0.0, 400.0, 400.0)
let root: UiNode = ui_nodes(ui_st, "Verbs", null)
ui_place(ui_st, root, 0.0, 0.0, 400.0, 400.0)
return root
}
function click(ui_st: mut UiState, x: float, y: float) -> void {
let d = new UiInput
d.x = x
d.y = y
d.down = true
frame(ui_st, d)
let u = new UiInput
u.x = x
u.y = y
frame(ui_st, u)
}
function said(root: UiNode) -> string {
let page = root.children[0]
return page.children[len(page.children) - 1].text
}
entry (ui_st: mut UiState) {
ui_backend(ui_st, new UiBackend)
var root = frame(ui_st, new UiInput)
let cell = root.children[0].children[0]
click(ui_st, cell.x + 2.0, cell.y + 2.0)
root = frame(ui_st, new UiInput)
let tab = new UiInput
tab.tab = true
frame(ui_st, tab)
frame(ui_st, tab)
root = frame(ui_st, tab)
let enter = new UiInput
enter.enter = true
root = frame(ui_st, enter)
root = frame(ui_st, new UiInput)
let first = said(root)
click(ui_st, cell.x + 2.0, cell.y + 2.0)
root = frame(ui_st, new UiInput)
let opened = said(root)
click(ui_st, 390.0, 390.0)
root = frame(ui_st, new UiInput)
let outside = said(root)
click(ui_st, cell.x + 2.0, cell.y + 2.0)
let esc = new UiInput
esc.escape = true
frame(ui_st, esc)
root = frame(ui_st, new UiInput)
let bar = root.children[0].children[1]
print(`{first} | {opened} | {outside} | {said(root)} | fill {int(bar.children[0].cw)} of {int(bar.cw)}`)
}
}