From a439faf60504c06aa15529d0876d2e4406f8f726 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 24 May 2019 01:12:07 +0200 Subject: [PATCH] examples/users_gui: V 0.0.8 fixes --- examples/users_gui/users.v | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/examples/users_gui/users.v b/examples/users_gui/users.v index e9faeebf04..d839d8e548 100644 --- a/examples/users_gui/users.v +++ b/examples/users_gui/users.v @@ -2,10 +2,10 @@ import ui import gx const ( - NR_COLS = 3 - CELL_HEIGHT = 25 - CELL_WIDTH = 100 - TABLE_WIDTH = CELL_WIDTH * NR_COLS + NrCols = 3 + CellHeight = 25 + CellWidth = 100 + TableWidth = CellWidth * NrCols ) struct User { @@ -38,15 +38,14 @@ 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.widget.set_pos(TABLE_WIDTH + 50, ctx.txt_pos) + btn.widget.set_pos(TableWidth + 50, ctx.txt_pos) for { ui.wait_events() } } // TODO replace with `fn (ctx mut Context) btn_click() {` -fn btn_click(_ctx *Context) { - mut ctx = _ctx// TODO hack +fn btn_click(btn voidptr, ctx mut Context) { ctx.users << User { first_name: ctx.first_name.text() last_name: ctx.last_name.text() @@ -59,23 +58,23 @@ fn btn_click(_ctx *Context) { fn draw(ctx *Context) { for i, user in ctx.users { x := 10 - y := 10 + i * CELL_HEIGHT + y := 10 + i * CellHeight // Outer border - gx.draw_empty_rect(x, y, TABLE_WIDTH, CELL_HEIGHT, gx.GRAY) + ui.draw_empty_rect(x, y, TableWidth, CellHeight, 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 + CellWidth, y, x + CellWidth, y + CellHeight) + ui.draw_line(x + CellWidth * 2, y, x + CellWidth * 2, y + CellHeight) // 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 + CellWidth, y + 5, user.last_name) + ui.draw_text_def(x + 5 + CellWidth * 2, y + 5, user.age.str()) } } 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) + txt_box.widget.set_pos(TableWidth + 50, ctx.txt_pos) ctx.txt_pos += 30 return txt_box }