# 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 state UiSubmitState { said: string = "" chat: string = "" name: string = "" } view Chat (ui_submit_st: mut UiSubmitState) { chat = ui_submit_st.chat name = ui_submit_st.name on set_chat(v: string) { ui_submit_st.chat = v } on set_name(v: string) { ui_submit_st.name = v } on send(v: string) { ui_submit_st.said = ui_submit_st.said + "[" + v + "]" } } const PAGE: string = "" function frame(ui_st: mut UiState, i: UiInput) -> void { ui_input(ui_st, i) ui_show(ui_st, "c", view_chat(), 0.0, 0.0, 400.0, 400.0) } function press(ui_st: mut UiState, 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(ui_st, i) frame(ui_st, new UiInput) } entry (ui_st: mut UiState, ui_submit_st: UiSubmitState) { ui_backend(ui_st, new UiBackend) ui_load_text(ui_st, PAGE, "c.xml") frame(ui_st, new UiInput) press(ui_st, true, false, false, "") press(ui_st, false, false, false, "hi") press(ui_st, false, true, false, "") let after = `{ui_submit_st.said} chat '{ui_submit_st.chat}'` press(ui_st, false, false, false, "yo") press(ui_st, false, false, true, "") press(ui_st, true, false, false, "") press(ui_st, false, false, false, "Ada") press(ui_st, false, true, false, "") print(`{after} | {ui_submit_st.said} chat '{ui_submit_st.chat}' name '{ui_submit_st.name}'`) } }