mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
ui: Objective-C @interface support for Cocoa; minor clean-ups
This commit is contained in:
@ -15,6 +15,7 @@ struct User {
|
||||
}
|
||||
|
||||
struct Context {
|
||||
mut:
|
||||
first_name ui.TextBox
|
||||
last_name ui.TextBox
|
||||
age ui.TextBox
|
||||
@ -23,6 +24,61 @@ struct Context {
|
||||
txt_pos int
|
||||
}
|
||||
|
||||
/*
|
||||
struct Window {
|
||||
width: 500
|
||||
height: 300
|
||||
title: 'Users'
|
||||
content: Layout {
|
||||
[
|
||||
TextBox {
|
||||
placeholder: 'First name'
|
||||
},
|
||||
TextBox {
|
||||
placeholder: 'Last name'
|
||||
},
|
||||
TextBox {
|
||||
placeholder: 'Age'
|
||||
},
|
||||
Button {
|
||||
title: 'Add user'
|
||||
onclick: btn_click
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
draw: {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Window {
|
||||
width: 500
|
||||
height: 300
|
||||
title: 'Users'
|
||||
VLayout {
|
||||
TextBox {
|
||||
placeholder: 'First name'
|
||||
}
|
||||
TextBox {
|
||||
placeholder: 'Last name'
|
||||
}
|
||||
TextBox {
|
||||
placeholder: 'Age'
|
||||
}
|
||||
Button {
|
||||
title: 'Add user'
|
||||
onclick: btn_click
|
||||
}
|
||||
}
|
||||
|
||||
draw: draw_fn
|
||||
}
|
||||
*/
|
||||
*/
|
||||
|
||||
fn main() {
|
||||
mut ctx := &Context {
|
||||
txt_pos: 10
|
||||
@ -45,30 +101,30 @@ fn main() {
|
||||
}
|
||||
|
||||
// TODO replace with `fn (ctx mut Context) btn_click() {`
|
||||
fn btn_click(_ctx *Context) {
|
||||
mut ctx = _ctx// TODO hack
|
||||
fn btn_click(_ctx &Context) {
|
||||
mut ctx := _ctx// TODO hack
|
||||
ctx.users << User {
|
||||
first_name: ctx.first_name.text()
|
||||
last_name: ctx.last_name.text()
|
||||
age: ctx.age.text().to_i()
|
||||
age: ctx.age.text().int()
|
||||
}
|
||||
ctx.window.refresh()
|
||||
}
|
||||
|
||||
// TODO replace with `fn (ctx mut Context) draw() {`
|
||||
fn draw(ctx *Context) {
|
||||
fn draw(ctx &Context) {
|
||||
for i, user in ctx.users {
|
||||
x := 10
|
||||
y := 10 + i * CELL_HEIGHT
|
||||
// Outer border
|
||||
gx.draw_empty_rect(x, y, TABLE_WIDTH, CELL_HEIGHT, gx.GRAY)
|
||||
ui.draw_empty_rect(x, y, TABLE_WIDTH, CELL_HEIGHT, gx.Gray)
|
||||
// Vertical separators
|
||||
gx.draw_line(x + CELL_WIDTH, y, x + CELL_WIDTH, y + CELL_HEIGHT)
|
||||
gx.draw_line(x + CELL_WIDTH * 2, y, x + CELL_WIDTH * 2, y + CELL_HEIGHT)
|
||||
ui.draw_line(x + CELL_WIDTH, y, x + CELL_WIDTH, y + CELL_HEIGHT, gx.Gray)
|
||||
ui.draw_line(x + CELL_WIDTH * 2, y, x + CELL_WIDTH * 2, y + CELL_HEIGHT, gx.Gray)
|
||||
// Text values
|
||||
gx.draw_text_def(x + 5, y + 5, user.first_name)
|
||||
gx.draw_text_def(x + 5 + CELL_WIDTH, y + 5, user.last_name)
|
||||
gx.draw_text_def(x + 5 + CELL_WIDTH * 2, y + 5, user.age.str())
|
||||
ui.draw_text_def(x + 5, y + 5, user.first_name)
|
||||
ui.draw_text_def(x + 5 + CELL_WIDTH, y + 5, user.last_name)
|
||||
ui.draw_text_def(x + 5 + CELL_WIDTH * 2, y + 5, user.age.str())
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user