45 lines
1.6 KiB
Text
45 lines
1.6 KiB
Text
# ui_submit.ludic — on-submit on a text field: Enter (or the pad's A) while it has the focus sends what
|
|
# it holds with event.value; the focus stays, and so does the text, unless clear-on-submit empties it.
|
|
import "ludic.ui"
|
|
program UiSubmit {
|
|
numbers float
|
|
var said: string = ""
|
|
var chat: string = ""
|
|
var name: string = ""
|
|
view Chat {
|
|
chat = chat
|
|
name = name
|
|
on set_chat(v: string) { chat = v }
|
|
on set_name(v: string) { name = v }
|
|
on send(v: string) { said = said + "[" + v + "]" }
|
|
}
|
|
const PAGE: string = "<ui><screen name='c'><input type='text' label='Say' value='{chat}' clear-on-submit on-change='set_chat(event.value)' on-submit='send(event.value)'/><input type='text' label='Name' value='{name}' on-change='set_name(event.value)' on-submit='send(event.value)'/></screen></ui>"
|
|
function frame(i: UiInput) -> void {
|
|
ui_input(i)
|
|
ui_show("c", view_chat(), 0.0, 0.0, 400.0, 400.0)
|
|
}
|
|
function press(tab: bool, enter: bool, pad: bool, typed: string) -> void {
|
|
let i = new UiInput
|
|
i.tab = tab
|
|
i.enter = enter
|
|
i.pad_a = pad
|
|
i.typed = typed
|
|
frame(i)
|
|
frame(new UiInput)
|
|
}
|
|
entry {
|
|
ui_backend(new UiBackend)
|
|
ui_load_text(PAGE, "c.xml")
|
|
frame(new UiInput)
|
|
press(true, false, false, "")
|
|
press(false, false, false, "hi")
|
|
press(false, true, false, "")
|
|
let after = `{said} chat '{chat}'`
|
|
press(false, false, false, "yo")
|
|
press(false, false, true, "")
|
|
press(true, false, false, "")
|
|
press(false, false, false, "Ada")
|
|
press(false, true, false, "")
|
|
print(`{after} | {said} chat '{chat}' name '{name}'`)
|
|
}
|
|
}
|