From 569a64068aa0b6ae31cf9df2aa8e9229baac5d4b Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 12 Dec 2019 23:42:51 +0300 Subject: [PATCH] ui/examples: users: fix button click --- vlib/compiler/fn.v | 3 ++- vlib/ui/examples/users_gui/users.v | 24 ++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/vlib/compiler/fn.v b/vlib/compiler/fn.v index e5d06f4a02..75c89c02a1 100644 --- a/vlib/compiler/fn.v +++ b/vlib/compiler/fn.v @@ -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 ) } diff --git a/vlib/ui/examples/users_gui/users.v b/vlib/ui/examples/users_gui/users.v index 3106ef9fc2..d1891240d2 100644 --- a/vlib/ui/examples/users_gui/users.v +++ b/vlib/ui/examples/users_gui/users.v @@ -52,15 +52,15 @@ struct Window { onclick: btn_click }, ] - } -} + } +} // Improved V struct Window { width: 500 height: 300 title: 'Users' - + Layout { [ TextBox { @@ -77,8 +77,8 @@ struct Window { onclick: btn_click } ] - } -} + } +} /* @@ -100,10 +100,10 @@ Window { title: 'Add user' onclick: btn_click } - } - + } + draw: draw_fn -} +} */ */ @@ -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)