mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
ui/examples: users: fix button click
This commit is contained in:
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 )
|
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 )
|
||||||
}
|
}
|
||||||
|
@ -52,15 +52,15 @@ struct Window {
|
|||||||
onclick: btn_click
|
onclick: btn_click
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Improved V
|
// Improved V
|
||||||
struct Window {
|
struct Window {
|
||||||
width: 500
|
width: 500
|
||||||
height: 300
|
height: 300
|
||||||
title: 'Users'
|
title: 'Users'
|
||||||
|
|
||||||
Layout {
|
Layout {
|
||||||
[
|
[
|
||||||
TextBox {
|
TextBox {
|
||||||
@ -77,8 +77,8 @@ struct Window {
|
|||||||
onclick: btn_click
|
onclick: btn_click
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
@ -100,10 +100,10 @@ Window {
|
|||||||
title: 'Add user'
|
title: 'Add user'
|
||||||
onclick: btn_click
|
onclick: btn_click
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
draw: draw_fn
|
draw: draw_fn
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user