# ui_fill.ludic — linear-gradient backgrounds (a direction or an angle, stops placed or spread) drawn
# as whole-pixel bands; object-fit contain and cover for a picture of its own size; aspect-ratio
# making a height from a width, and a native's width from its height.
import "ludic.ui"
program UiFill {
numbers float
state UiFillState {
rects: []string = new []string
pics: []string = new []string
clips: int = 0
}
const STYLE: string = ""
const BODY: string = "

"
function rec_rect(ui_fill_st: mut UiFillState, x: float, y: float, w: float, h: float, c: int, a: float) -> void { push(ui_fill_st.rects, `{int(x)},{int(y)} {int(w)}x{int(h)} {ui_hex(c)}`) }
function rec_image(ui_fill_st: mut UiFillState, src: string, x: float, y: float, w: float, h: float, c: int, a: float) -> void { push(ui_fill_st.pics, `{int(x)},{int(y)} {int(w)}x{int(h)}`) }
function rec_clip(ui_fill_st: mut UiFillState, x: float, y: float, w: float, h: float) -> void { ui_fill_st.clips += 1 }
function no_clip() -> void { }
function no_text(x: float, y: float, s: string, size: float, c: int, a: float) -> void { }
function nat_w(src: string) -> float { return 200.0 }
function nat_h(src: string) -> float { return 100.0 }
function knob_measure(n: UiNode, avail: float) -> void { }
function knob_draw(n: UiNode) -> void { }
entry (ui_fill_st: UiFillState, ui_st: mut UiState) {
let b = new UiBackend
b.rect = fn rec_rect
b.text = fn no_text
b.image = fn rec_image
b.image_w = fn nat_w
b.image_h = fn nat_h
b.clip = fn rec_clip
b.unclip = fn no_clip
ui_backend(ui_st, b)
ui_native(ui_st, "knob", fn knob_measure, fn knob_draw)
ui_load_text(ui_st, "" + STYLE + BODY + "", "f.xml")
ui_show(ui_st, "f", null, 0.0, 0.0, 400.0, 600.0)
let r: UiNode = ui_nodes(ui_st, "f", null)
ui_place(ui_st, r, 0.0, 0.0, 400.0, 600.0)
let n = len(ui_fill_st.rects)
print(`{ui_fill_st.rects[0]} .. {ui_fill_st.rects[49]} | {ui_fill_st.rects[50]} .. {ui_fill_st.rects[59]} .. {ui_fill_st.rects[69]} of {n} | {ui_fill_st.pics[0]} | {ui_fill_st.pics[1]} clipped {ui_fill_st.clips} | ratio {int(r.children[4].ch)} knob {int(r.children[5].children[0].cw)}`)
}
}