ui
ui copied to clipboard
Textbox `on_change` doesn't detect backspaces.
V version: V 0.2.4 506259a.6da3004 UI version: 0.0.4 OS: Linux, Ubuntu 18.04.5 LTS (VM) What did you do?
module main
import ui
struct App {
mut:
window &ui.Window = 0
}
fn print_change(text string) {
println(text)
}
fn main() {
mut app := &App{}
app.window = ui.window(
children: [
ui.textbox(
placeholder: 'Enter a some text'
on_change: print_change
),
]
)
ui.run(app.window)
}
I ran it, and typed "Hello" and then hit Backspace until it was gone.
What did you expect to see?
H
He
Hel
Hell
Hello
Hell
Hel
He
H
What did you see instead?
H
He
Hel
Hell
Hello
Because of some doubt about compatibility with volt, I did not want to change on_change but preferred introduce on_changed like in the modified code.
module main
import ui
struct App {
mut:
window &ui.Window = 0
}
fn print_change(tb &ui.TextBox, a voidptr) {
println(*(tb.text))
}
fn main() {
mut app := &App{}
app.window = ui.window(
children: [
ui.column(children: [
ui.textbox(
placeholder: 'Enter a some text'
on_changed: print_change
),
])
]
)
ui.run(app.window)
}
Also notice the ui.column layout to fit automatically textbox..