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

47 lines
1.8 KiB
Text

# draw_order.ludic - painting order, and clipping that nests
function fr_clip_push(ui_st: mut UiState, x: float, y: float, w: float, h: float) -> void {
var x0 = x
var y0 = y
var x1 = x + w
var y1 = y + h
let n = len(ui_st.fr_clips)
if n >= 4 {
x0 = Math.max(x0, ui_st.fr_clips[n - 4])
y0 = Math.max(y0, ui_st.fr_clips[n - 3])
x1 = Math.min(x1, ui_st.fr_clips[n - 2])
y1 = Math.min(y1, ui_st.fr_clips[n - 1])
}
push(ui_st.fr_clips, x0)
push(ui_st.fr_clips, y0)
push(ui_st.fr_clips, x1)
push(ui_st.fr_clips, y1)
ui_st.ui_be.clip(x0, y0, Math.max(x1 - x0, 0.0), Math.max(y1 - y0, 0.0))
}
function fr_clip_pop(ui_st: mut UiState) -> void {
var keep = new []float
for i in 0 .. len(ui_st.fr_clips) - 4 { push(keep, ui_st.fr_clips[i]) }
ui_st.fr_clips = keep
let n = len(ui_st.fr_clips)
if n >= 4 { ui_st.ui_be.clip(ui_st.fr_clips[n - 4], ui_st.fr_clips[n - 3], ui_st.fr_clips[n - 2] - ui_st.fr_clips[n - 4], ui_st.fr_clips[n - 1] - ui_st.fr_clips[n - 3]) } else if ui_st.ui_be.unclip != null { ui_st.ui_be.unclip() }
}
# the children in painting order: those in the flow first, then positioned ones by z-index
function fr_children(ui_st: mut UiState, n: UiNode) -> void {
var positioned = 0
for i in 0 .. len(n.children) {
if n.children[i].popover { push(ui_st.pop_list, n.children[i]) } else if n.children[i].pos == 0 { fr_draw(ui_st, n.children[i]) } else { positioned += 1 }
}
if positioned == 0 { return }
var lo = 1000000
var hi = -1000000
for i in 0 .. len(n.children) {
if n.children[i].pos != 0 and not n.children[i].popover {
lo = Math.min(lo, n.children[i].z)
hi = Math.max(hi, n.children[i].z)
}
}
for z in lo .. hi + 1 {
for i in 0 .. len(n.children) {
if n.children[i].pos != 0 and not n.children[i].popover and n.children[i].z == z { fr_draw(ui_st, n.children[i]) }
}
}
}