-
Notifications
You must be signed in to change notification settings - Fork 153
/
Copy pathbox_layout_with_textbox.v
71 lines (66 loc) · 1.29 KB
/
box_layout_with_textbox.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import ui
import gx
const win_width = 400
const win_height = 300
struct App {
mut:
text string
btn_cb map[string]fn (&ui.Button)
}
fn make_tb(mut app App, has_row bool) ui.Widget {
tb := ui.textbox(
mode: .multiline
bg_color: gx.yellow
text: &app.text
)
return if has_row {
ui.Widget(ui.row(
widths: ui.stretch
children: [
tb,
]
))
} else {
ui.Widget(tb)
}
}
fn (mut app App) make_btn() ui.Widget {
app.btn_cb['btn_click'] = fn (_ &ui.Button) {
ui.message_box('coucou toto!')
}
return ui.button(
text: 'toto'
on_click: app.btn_cb['btn_click']
)
}
fn main() {
mut with_row := false
$if with_row ? {
with_row = true
}
mut app := App{
text: 'blah blah blah\n'.repeat(10)
}
ui.run(ui.window(
width: win_width
height: win_height
title: 'V UI: Rectangles inside BoxLayout'
mode: .resizable
layout: ui.box_layout(
id: 'bl'
children: {
'id1: (0,0) ++ (30,30)': ui.rectangle(
color: gx.rgb(255, 100, 100)
)
'id2: (30,30) -> (-30.5,-30.5)': ui.rectangle(
color: gx.rgb(100, 255, 100)
)
'id3: (50%,50%) -> (100%,100%)': make_tb(mut app, with_row)
'id4: (-30.5, -30.5) ++ (30,30)': ui.rectangle(
color: gx.white
)
'id5: (70%,20%) ++ (50,20)': app.make_btn()
}
)
))
}