ui icon indicating copy to clipboard operation
ui copied to clipboard

Textbox `on_change` doesn't detect backspaces.

Open Bigjango13 opened this issue 3 years ago • 1 comments

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

Bigjango13 avatar May 03 '22 14:05 Bigjango13

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..

rcqls avatar May 14 '22 13:05 rcqls