-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathtool_message_dialog.v
More file actions
111 lines (90 loc) · 2.03 KB
/
Copy pathtool_message_dialog.v
File metadata and controls
111 lines (90 loc) · 2.03 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
module ui
import gg
//=== Basic Message Dialog ===/
// Before sokol deals with multiple window (soon)
fn (mut win Window) add_message_dialog() {
mut dlg := column(
id: '_msg_dlg_col'
alignment: .center
widths: compact
heights: compact
spacing: 10
margin: Margin{5, 5, 5, 5}
bg_color: gg.Color{140, 210, 240, 100}
bg_radius: .3
children: [
label(id: '_msg_dlg_lab', text: ' Hello World'),
button(
id: '_msg_dlg_btn'
text: 'OK'
width: 100
radius: .3
z_index: 1000
on_click: message_dialog_click
),
]
)
dlg.is_root_layout = false
win.children << dlg
dlg.set_visible(false)
}
fn message_dialog_click(b &Button) {
mut dlg := b.ui.window.get_or_panic[Stack]('_msg_dlg_col')
dlg.set_visible(false)
}
pub fn (win &Window) message(s string) {
if win.native_message {
message_box(s)
} else {
mut dlg := win.get_or_panic[Stack]('_msg_dlg_col')
mut msg := win.get_or_panic[Label]('_msg_dlg_lab')
msg.set_text(s)
mut tw, mut th := text_lines_size(s.split('\n'), win.ui)
msg.propose_size(tw, th)
if tw < 200 {
tw = 200
}
th += 50
// println("msg: ($tw, $th) $s")
dlg.propose_size(tw, th)
ww, wh := win.size()
dlg.set_pos(ww / 2 - tw / 2, wh / 2 - th / 2)
dlg.set_visible(true)
dlg.update_layout()
}
}
/*
// Playing with Styled Text
struct TextChunk {
text string
start int
stop int
cfg gg.TextCfg
}
pub struct TextContext {
chunks []TextChunk
colors map[string]gg.Color
styles map[string]gg.TextCfg
}
struct TextView {
x int
y int
width int
height int
context &TextContext = unsafe { nil }
}
* default: {style: "", size: 10, color: black}
* start:
- style: normal "", italic {i], bold {b], underline {u]
- size: uint8 (ex: {12])
- color: r,g,b,a or hexa (0x00000000) string lowercase (ex: {red])
- font-family: string capitalized
- combined: {...|...|...]
end:
- idem with closing [...} or [...|...|...}
- empty [} means last opened
current:
custom style: blurr
stack of style operations:
{b] {t] [b} [t}
*/