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>
52 lines
1.8 KiB
Text
52 lines
1.8 KiB
Text
# ui_popover_mouse.ludic — a popover takes the mouse: its own button, at the same pixels as the grid
|
|
# cell under it, is the one a click presses; a click outside it (on that cell, or on nothing) closes
|
|
# it and presses nothing else.
|
|
import "ludic.ui"
|
|
import "ui_popover_mouse_parts/Grid.ludic"
|
|
program UiPopoverMouse {
|
|
numbers float
|
|
function frame(ui_st: mut UiState, i: UiInput) -> UiNode {
|
|
ui_input(ui_st, i)
|
|
ui_show(ui_st, "Grid", null, 0.0, 0.0, 400.0, 400.0)
|
|
let root: UiNode = ui_nodes(ui_st, "Grid", 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) -> string {
|
|
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)
|
|
let root = frame(ui_st, new UiInput)
|
|
let page = root.children[0]
|
|
return page.children[len(page.children) - 1].text
|
|
}
|
|
function find(n: UiNode, id: string) -> UiNode {
|
|
if n.id == id { return n }
|
|
for i in 0 .. len(n.children) {
|
|
let f = find(n.children[i], id)
|
|
if f != null { return f }
|
|
}
|
|
return null
|
|
}
|
|
entry (ui_st: mut UiState) {
|
|
ui_backend(ui_st, new UiBackend)
|
|
frame(ui_st, new UiInput)
|
|
let opened = click(ui_st, 20.0, 20.0)
|
|
let root = frame(ui_st, new UiInput)
|
|
let drop = find(root, "drop")
|
|
let cell = find(root, "cell")
|
|
let over = drop.x >= cell.x and drop.y >= cell.y and drop.x + drop.cw <= cell.x + cell.cw
|
|
let dropped = click(ui_st, drop.x + drop.cw / 2.0, drop.y + drop.ch / 2.0)
|
|
click(ui_st, 20.0, 20.0)
|
|
let on_cell = click(ui_st, 180.0, 90.0)
|
|
click(ui_st, 20.0, 20.0)
|
|
let on_nothing = click(ui_st, 390.0, 390.0)
|
|
print(`over the cell {over} | {opened} | {dropped} | {on_cell} | {on_nothing}`)
|
|
}
|
|
}
|