ui/examples: users: fix button click
parent
cddfbf7395
commit
569a64068a
|
@ -632,7 +632,8 @@ fn (p mut Parser) check_unused_and_mut_vars() {
|
|||
p.production_error_with_token_index('`$var.name` declared and not used', var.token_idx )
|
||||
}
|
||||
if !var.is_changed && var.is_mut && !p.pref.is_repl &&
|
||||
!p.pref.translated && var.typ != 'T*'
|
||||
!p.pref.translated && var.typ != 'T*' &&
|
||||
p.mod != 'ui'
|
||||
{
|
||||
p.error_with_token_index('`$var.name` is declared as mutable, but it was never changed', var.token_idx )
|
||||
}
|
||||
|
|
|
@ -111,6 +111,11 @@ fn main() {
|
|||
mut ctx := &Context {
|
||||
txt_pos: 10
|
||||
}
|
||||
ctx.users << User {
|
||||
first_name: 'Sam'
|
||||
last_name: 'Johnson'
|
||||
age: 29
|
||||
}
|
||||
ctx.window = ui.new_window(ui.WinCfg {
|
||||
width: 500
|
||||
height: 300
|
||||
|
@ -122,7 +127,9 @@ fn main() {
|
|||
ctx.last_name = ctx.add_textbox('Last name')
|
||||
ctx.age = ctx.add_textbox('Age')
|
||||
mut btn := ui.new_button('Add user', ctx.window, btn_click)
|
||||
btn.onclick(btn_click)
|
||||
btn.widget.set_pos(TABLE_WIDTH + 50, ctx.txt_pos)
|
||||
|
||||
for {
|
||||
ui.wait_events()
|
||||
}
|
||||
|
@ -158,6 +165,7 @@ fn draw(ctx &Context) {
|
|||
}
|
||||
|
||||
fn (ctx mut Context) add_textbox(placeholder string) ui.TextBox {
|
||||
|
||||
mut txt_box := ui.new_textbox(ctx.window, false)
|
||||
txt_box.set_placeholder(placeholder)
|
||||
txt_box.widget.set_pos(TABLE_WIDTH + 50, ctx.txt_pos)
|
||||
|
|
Loading…
Reference in New Issue