ludic/packages/ludic.ui/popover_within.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

35 lines
1.2 KiB
Text

# popover_within.ludic - what an anchored popover is kept inside: the element named by within="id",
# else the nearest scroll box (or overflow box) around it, else the screen; it flips against the same
function pp_bounds(ui_st: mut UiState, p: UiNode) -> void {
ui_st.pp_bx = ui_st.ly_vp_x
ui_st.pp_by = ui_st.ly_vp_y
ui_st.pp_bw = ui_st.ly_vp_w
ui_st.pp_bh = ui_st.ly_vp_h
var box: UiNode = null
let id = ui_attr_text(p, "within")
if id != "" {
var at = p.parent
while at != null and box == null {
box = pp_by_id(at, id, p)
at = at.parent
}
if box == null { ui_err(ui_st, `within="{id}": no element has that id`) }
} else {
var at = p.parent
while at != null and box == null {
if at.kind == UI_SCROLL { box = at }
at = at.parent
}
}
if box == null { return }
ui_st.pp_bx = box.x
ui_st.pp_by = box.y
ui_st.pp_bw = box.cw
ui_st.pp_bh = box.ch
}
# where a popover of `size` starts along its anchor's side: level with its start, centred, or its end
function pp_along(align: string, at: float, span: float, size: float) -> float {
if align == "center" { return at + (span - size) / 2.0 }
if align == "end" { return at + span - size }
return at
}