ludic.ui: ui_override(path, text), ui_override_clear(path | "") and ui_overridden(path) - a template's or a stylesheet's text given from outside, its component shown again with its state kept and its own text brought back when let go; lib_text answers a copy of the override, and the dev poll leaves an overridden component alone; examples/library/ui_override
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9f07fc8a62
commit
aad3f8ca27
8 changed files with 144 additions and 0 deletions
36
examples/library/ui_override.ludic
Normal file
36
examples/library/ui_override.ludic
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
# ui_override.ludic - a template's text given from outside in place of its file (a studio editing a
|
||||
# running game's interface): the component is shown again with the new template and its state kept,
|
||||
# and letting go brings the file back, the state still kept. Prints three lines: the counters as the
|
||||
# files have them, as the override has them, and as the files have them again.
|
||||
import "ludic.ui"
|
||||
import "ui_component_parts/Counter.ludic"
|
||||
import "ui_component_parts/App.ludic"
|
||||
program UiOverride {
|
||||
numbers float
|
||||
function texts(n: UiNode, out: []string) -> void {
|
||||
if n.text != "" { push(out, n.text) }
|
||||
for i in 0 .. len(n.children) { texts(n.children[i], out) }
|
||||
}
|
||||
function frame(ui_st: mut UiState) -> UiNode {
|
||||
let root: UiNode = ui_nodes(ui_st, "App", null)
|
||||
ui_place(ui_st, root, 0.0, 0.0, 400.0, 400.0)
|
||||
return root
|
||||
}
|
||||
function said(ui_st: mut UiState) -> string {
|
||||
let out = new []string
|
||||
texts(frame(ui_st), out)
|
||||
var joined = ""
|
||||
for i in 0 .. len(out) { joined = joined + out[i] + "|" }
|
||||
return joined
|
||||
}
|
||||
entry (ui_st: mut UiState) {
|
||||
let root = frame(ui_st)
|
||||
ui_press(ui_st, root.children[0].children[1].children[1]) # counter a: + once
|
||||
print(said(ui_st))
|
||||
let xml = "examples/library/ui_component_parts/Counter.xml"
|
||||
ui_override(ui_st, xml, "<div class=\"counter\"><p>[{label}={count}]</p><button on-click=\"bump()\">+</button></div>")
|
||||
print(`{said(ui_st)} {ui_overridden(ui_st, xml)}`)
|
||||
ui_override_clear(ui_st, "")
|
||||
print(`{said(ui_st)} {ui_overridden(ui_st, xml)}`)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue