ui/examples: users: fix button click

pull/3073/head
Alexander Medvednikov 2019-12-12 23:42:51 +03:00
parent cddfbf7395
commit 569a64068a
2 changed files with 18 additions and 9 deletions

View File

@ -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 ) 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 && 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 ) p.error_with_token_index('`$var.name` is declared as mutable, but it was never changed', var.token_idx )
} }

View File

@ -111,6 +111,11 @@ fn main() {
mut ctx := &Context { mut ctx := &Context {
txt_pos: 10 txt_pos: 10
} }
ctx.users << User {
first_name: 'Sam'
last_name: 'Johnson'
age: 29
}
ctx.window = ui.new_window(ui.WinCfg { ctx.window = ui.new_window(ui.WinCfg {
width: 500 width: 500
height: 300 height: 300
@ -122,7 +127,9 @@ fn main() {
ctx.last_name = ctx.add_textbox('Last name') ctx.last_name = ctx.add_textbox('Last name')
ctx.age = ctx.add_textbox('Age') ctx.age = ctx.add_textbox('Age')
mut btn := ui.new_button('Add user', ctx.window, btn_click) 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) btn.widget.set_pos(TABLE_WIDTH + 50, ctx.txt_pos)
for { for {
ui.wait_events() ui.wait_events()
} }
@ -158,6 +165,7 @@ fn draw(ctx &Context) {
} }
fn (ctx mut Context) add_textbox(placeholder string) ui.TextBox { fn (ctx mut Context) add_textbox(placeholder string) ui.TextBox {
mut txt_box := ui.new_textbox(ctx.window, false) mut txt_box := ui.new_textbox(ctx.window, false)
txt_box.set_placeholder(placeholder) txt_box.set_placeholder(placeholder)
txt_box.widget.set_pos(TABLE_WIDTH + 50, ctx.txt_pos) txt_box.widget.set_pos(TABLE_WIDTH + 50, ctx.txt_pos)