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

67 lines
3.6 KiB
Text

# ui_look.ludic — what ludic.ui draws, through a backend that writes each call down: a component
# whose root is another component, styled by every sheet above it by specificity; text-shadow under
# text; a native reading the opacity it is drawn at (ui_opacity); border-image as painted, tinted by
# a background colour, and gone under `transparent`; a picture drawn as it is and an atlas cell in
# the text's colour; a tooltip of two lines; and popovers placed beside their anchors, one flipped.
import "ludic.ui"
import "ui_look_parts/Look.ludic"
import "ui_look_parts/Middle.ludic"
import "ui_look_parts/Inner.ludic"
import "ui_look_parts/Menu.ludic"
program UiLook {
numbers float
state UiLookState {
said: []string = new []string
seen: float = 0.0
}
function rec_rect(x: float, y: float, w: float, h: float, c: int, a: float) -> void { }
function rec_text(ui_look_st: mut UiLookState, x: float, y: float, s: string, size: float, c: int, a: float) -> void { push(ui_look_st.said, `text {s} {int(x)},{int(y)} {ui_hex(c)}`) }
function rec_image(ui_look_st: mut UiLookState, src: string, x: float, y: float, w: float, h: float, c: int, a: float) -> void { push(ui_look_st.said, `image {src} {ui_hex(c)}`) }
function rec_nine(ui_look_st: mut UiLookState, src: string, slice: float, x: float, y: float, w: float, h: float, dst: float, c: int, a: float) -> void { push(ui_look_st.said, `nine {int(w)} {ui_hex(c)}`) }
function gauge_measure(n: UiNode, avail: float) -> void { }
function gauge_draw(ui_look_st: mut UiLookState, ui_st: UiState, n: UiNode) -> void { ui_look_st.seen = ui_opacity(ui_st) }
function count(ui_look_st: UiLookState, s: string) -> int {
var n = 0
for i in 0 .. len(ui_look_st.said) {
if Text.starts_with(ui_look_st.said[i], s) { n += 1 }
}
return n
}
function has(ui_look_st: UiLookState, s: string) -> string {
for i in 0 .. len(ui_look_st.said) {
if Text.starts_with(ui_look_st.said[i], s) { return ui_look_st.said[i] }
}
return "-"
}
function show(ui_look_st: mut UiLookState, ui_st: mut UiState, name: string, i: UiInput) -> UiNode {
ui_input(ui_st, i)
ui_look_st.said = new []string
ui_show(ui_st, name, null, 0.0, 0.0, 400.0, 300.0)
let root: UiNode = ui_nodes(ui_st, name, null)
ui_place(ui_st, root, 0.0, 0.0, 400.0, 300.0)
return root.children[0]
}
entry (ui_look_st: mut UiLookState, ui_st: mut UiState) {
let b = new UiBackend
b.rect = fn rec_rect
b.text = fn rec_text
b.image = fn rec_image
b.nine = fn rec_nine
ui_backend(ui_st, b)
ui_native(ui_st, "gauge", fn gauge_measure, fn gauge_draw)
var page = show(ui_look_st, ui_st, "Look", new UiInput)
let inner = page.children[0]
let tip = page.children[7]
let rest = new UiInput
rest.x = tip.x + 2.0
rest.y = tip.y + 2.0
for f in 0 .. 40 { page = show(ui_look_st, ui_st, "Look", rest) }
print(`root {inner.tag}.{inner.classes[0]}.{inner.classes[1]}.{inner.classes[2]} pad {int(inner.pt)} margin {int(inner.mt)} color {ui_hex(inner.fg)}`)
print(`{has(ui_look_st, "text Hi")} | {has(ui_look_st, "text Hi 0")} | opacity {ui_look_st.seen} | {has(ui_look_st, "nine 40 #ffffff")} {has(ui_look_st, "nine 40 #ff0000")} of {count(ui_look_st, "nine")}`)
print(`{has(ui_look_st, "image photo")} | {has(ui_look_st, "image icon")} | {has(ui_look_st, "text first")} | {has(ui_look_st, "text second")}`)
let menu = show(ui_look_st, ui_st, "Menu", new UiInput)
let a = menu.children[1]
let c = menu.children[3]
print(`by id at {int(a.x)},{int(a.y)} | flipped at {int(c.x)},{int(c.y)} {int(c.cw)}x{int(c.ch)}`)
}
}