-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlayout.v
More file actions
494 lines (446 loc) · 15.4 KB
/
Copy pathlayout.v
File metadata and controls
494 lines (446 loc) · 15.4 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
module simplegui
// add_heading adds a heading label and separator line to the window layout.
pub fn (win &SimpleWindow) add_heading(title string) &SimpleWindow {
heading_name := 'heading_${win.controls.len}'
win.add_label(heading_name, title)
win.add_separator()
return win
}
// get_spacing returns the layout item spacing in pixels.
pub fn (win &SimpleWindow) get_spacing() int {
return win.spacing
}
// add_group_box adds a group box control to the window layout.
pub fn (win &SimpleWindow) add_group_box(name string, title string) &SimpleWindow {
return win.add_group_box_with_options(name, title, true)
}
// add_group_box_with_options adds a group box control with optional caption (title) and border settings.
pub fn (win &SimpleWindow) add_group_box_with_options(name string, title string, border bool) &SimpleWindow {
mut real_name := name
if real_name == '' {
real_name = win.auto_name('groupbox')
}
unsafe {
mut w := &SimpleWindow(win)
w.upsert_control(real_name, 'groupbox', title, '', false, 0)
}
if win.window_info != unsafe { nil } {
b_val := if border { 1 } else { 0 }
C.window_add_group_box_control_with_options(win.window_info, real_name.str, title.str,
b_val)
}
return win
}
// begin_group_box begins a group box layout container.
pub fn (win &SimpleWindow) begin_group_box(name string, title string) &SimpleWindow {
return win.begin_group_box_with_options(name, title, true)
}
// begin_group_box_with_options begins a group box container with optional caption and border settings.
pub fn (win &SimpleWindow) begin_group_box_with_options(name string, title string, border bool) &SimpleWindow {
mut real_name := name
if real_name == '' {
real_name = win.auto_name('groupbox')
}
unsafe {
mut w := &SimpleWindow(win)
w.upsert_control(real_name, 'groupbox', title, '', false, 0)
}
if win.window_info != unsafe { nil } {
b_val := if border { 1 } else { 0 }
C.window_begin_group_box(win.window_info, real_name.str, title.str, b_val)
}
return win
}
// end_group_box ends the current group box layout container.
pub fn (win &SimpleWindow) end_group_box() &SimpleWindow {
if win.window_info != unsafe { nil } {
C.window_end_group_box(win.window_info)
}
return win
}
// set_group_border enables or disables the border of a group box container.
pub fn (win &SimpleWindow) set_group_border(name string, border bool) &SimpleWindow {
if win.window_info != unsafe { nil } {
b_val := if border { 1 } else { 0 }
C.window_set_group_border(win.window_info, name.str, b_val)
}
return win
}
// set_group_caption updates or sets the caption header title of a group box container.
pub fn (win &SimpleWindow) set_group_caption(name string, caption string) &SimpleWindow {
if win.window_info != unsafe { nil } {
C.window_set_group_caption(win.window_info, name.str, caption.str)
}
return win
}
// add_tabs adds a tabs control to the window layout.
pub fn (win &SimpleWindow) add_tabs(name string, titles []string) &SimpleWindow {
mut real_name := name
if real_name == '' {
real_name = win.auto_name('tabs')
}
mut joined := ''
for i, title in titles {
if i > 0 {
joined += ','
}
joined += title
}
unsafe {
mut w := &SimpleWindow(win)
w.upsert_control(real_name, 'tabs', joined, '', false, 0)
}
if win.window_info != unsafe { nil } {
mut c_titles := []&u8{}
for title in titles {
c_titles << title.str
}
C.window_add_tabs_control(win.window_info, real_name.str, c_titles.data, titles.len)
}
return win
}
// add_scroll_view adds a scroll view control to the window layout.
pub fn (win &SimpleWindow) add_scroll_view(name string, height int) &SimpleWindow {
mut real_name := name
if real_name == '' {
real_name = win.auto_name('scrollview')
}
unsafe {
mut w := &SimpleWindow(win)
w.upsert_control(real_name, 'scrollview', '', '', false, 0)
}
if win.window_info != unsafe { nil } {
C.window_add_scroll_view_control(win.window_info, real_name.str, height)
}
return win
}
// begin_row begins a horizontal row layout container.
pub fn (win &SimpleWindow) begin_row(name string) &SimpleWindow {
if win.window_info != unsafe { nil } {
C.window_begin_row(win.window_info, name.str)
}
return win
}
// end_row ends the current row container layout.
pub fn (win &SimpleWindow) end_row() &SimpleWindow {
if win.window_info != unsafe { nil } {
C.window_end_row(win.window_info)
}
return win
}
// begin_grid begins a multi-column grid layout container with specified column count and item spacing.
pub fn (win &SimpleWindow) begin_grid(name string, columns int, spacing int) &SimpleWindow {
if win.window_info != unsafe { nil } {
C.window_begin_grid(win.window_info, name.str, columns, spacing)
}
return win
}
// end_grid ends the current grid layout container.
pub fn (win &SimpleWindow) end_grid() &SimpleWindow {
if win.window_info != unsafe { nil } {
C.window_end_grid(win.window_info)
}
return win
}
// begin_flex_box begins a flexbox container with direction ('row'|'column'), main-axis justification ('start'|'center'|'end'|'space_between'|'space_around'|'fill'), and cross-axis alignment ('start'|'center'|'end'|'stretch').
pub fn (win &SimpleWindow) begin_flex_box(name string, direction string, justify string, align string) &SimpleWindow {
if win.window_info != unsafe { nil } {
C.window_begin_flex_box(win.window_info, name.str, direction.str, justify.str,
align.str)
}
return win
}
// end_flex_box ends the current flexbox container.
pub fn (win &SimpleWindow) end_flex_box() &SimpleWindow {
if win.window_info != unsafe { nil } {
C.window_end_flex_box(win.window_info)
}
return win
}
// add_vertical_spacer adds a vertical spacer element of specified height to the window layout.
pub fn (win &SimpleWindow) add_vertical_spacer(height int) &SimpleWindow {
if win.window_info != unsafe { nil } {
C.window_add_vertical_spacer(win.window_info, height)
}
return win
}
// add_horizontal_spacer adds a horizontal spacer control to the window layout.
pub fn (win &SimpleWindow) add_horizontal_spacer(width int) &SimpleWindow {
if win.window_info != unsafe { nil } {
C.window_add_horizontal_spacer(win.window_info, width)
}
return win
}
// add_separator adds a separator control to the window layout.
pub fn (win &SimpleWindow) add_separator() &SimpleWindow {
if win.window_info != unsafe { nil } {
C.window_add_separator(win.window_info)
}
return win
}
// add_action_row adds a row of action buttons with associated callbacks.
pub fn (win &SimpleWindow) add_action_row(actions map[string]VoidEventCallback) &SimpleWindow {
row_name := win.auto_name('action_row')
win.begin_row(row_name)
for title, cb in actions {
btn_name := win.auto_name('btn')
win.add_action(btn_name, title, cb)
}
win.end_row()
return win
}
// add_fields_row adds a row of form fields mapped by label and control name.
pub fn (win &SimpleWindow) add_fields_row(fields map[string]string) &SimpleWindow {
row_name := win.auto_name('fields_row')
win.begin_row(row_name)
for label, name in fields {
win.add_form_field(label, name, '')
}
win.end_row()
return win
}
// row creates a horizontal row container and invokes the callback for child elements.
pub fn (win &SimpleWindow) row(name string, callback VoidEventCallback) &SimpleWindow {
win.begin_row(name)
unsafe {
mut w := &SimpleWindow(win)
callback(mut w)
}
win.end_row()
return win
}
// grid creates a grid layout container and invokes the callback for child elements.
pub fn (win &SimpleWindow) grid(name string, columns int, spacing int, callback VoidEventCallback) &SimpleWindow {
win.begin_grid(name, columns, spacing)
unsafe {
mut w := &SimpleWindow(win)
callback(mut w)
}
win.end_grid()
return win
}
// flex_box creates a flexbox layout container and invokes the callback for child elements.
pub fn (win &SimpleWindow) flex_box(name string, direction string, justify string, align string, callback VoidEventCallback) &SimpleWindow {
win.begin_flex_box(name, direction, justify, align)
unsafe {
mut w := &SimpleWindow(win)
callback(mut w)
}
win.end_flex_box()
return win
}
// set_control_alignment sets the alignment of a named control ('left'|'center'|'right'|'top'|'bottom').
pub fn (win &SimpleWindow) set_control_alignment(name string, alignment string) &SimpleWindow {
if win.window_info != unsafe { nil } {
C.window_set_control_alignment_by_name(win.window_info, name.str, alignment.str)
}
for i in 0 .. win.controls.len {
if win.controls[i].name == name {
unsafe {
win.controls[i].alignment = alignment
}
break
}
}
return win
}
// set_control_expand_fill configures whether a named control expands to fill available layout space.
pub fn (win &SimpleWindow) set_control_expand_fill(name string, expand bool) &SimpleWindow {
if win.window_info != unsafe { nil } {
C.window_set_control_expand_fill_by_name(win.window_info, name.str, if expand {
1
} else {
0
})
}
for i in 0 .. win.controls.len {
if win.controls[i].name == name {
unsafe {
win.controls[i].expand_fill = expand
}
break
}
}
return win
}
// align_left aligns the last created control to the left.
pub fn (win &SimpleWindow) align_left() &SimpleWindow {
if win.last_control != '' {
win.set_control_alignment(win.last_control, 'left')
}
return win
}
// align_center aligns the last created control to the center.
pub fn (win &SimpleWindow) align_center() &SimpleWindow {
if win.last_control != '' {
win.set_control_alignment(win.last_control, 'center')
}
return win
}
// align_right aligns the last created control to the right.
pub fn (win &SimpleWindow) align_right() &SimpleWindow {
if win.last_control != '' {
win.set_control_alignment(win.last_control, 'right')
}
return win
}
// align_top aligns the last created control to the top.
pub fn (win &SimpleWindow) align_top() &SimpleWindow {
if win.last_control != '' {
win.set_control_alignment(win.last_control, 'top')
}
return win
}
// align_bottom aligns the last created control to the bottom.
pub fn (win &SimpleWindow) align_bottom() &SimpleWindow {
if win.last_control != '' {
win.set_control_alignment(win.last_control, 'bottom')
}
return win
}
// expand_fill configures the last created control to expand and fill available container space.
pub fn (win &SimpleWindow) expand_fill() &SimpleWindow {
if win.last_control != '' {
win.set_control_expand_fill(win.last_control, true)
}
return win
}
// GroupConfig defines configuration options for a group box container or card.
pub struct GroupConfig {
pub mut:
title string
border bool
border_width f32
border_color string
corner_radius f32
bg_color string
padding int
shadow bool
show_caption bool
caption_color string
caption_alignment string
}
// add_group_box_with_config adds a group box control using a detailed GroupConfig struct.
pub fn (win &SimpleWindow) add_group_box_with_config(name string, cfg GroupConfig) &SimpleWindow {
mut real_name := name
if real_name == '' {
real_name = win.auto_name('groupbox')
}
unsafe {
mut w := &SimpleWindow(win)
w.upsert_control(real_name, 'groupbox', cfg.title, '', false, 0)
}
if win.window_info != unsafe { nil } {
b_val := if cfg.border { 1 } else { 0 }
s_val := if cfg.shadow { 1 } else { 0 }
sc_val := if cfg.show_caption { 1 } else { 0 }
C.window_add_group_box_control_with_config(win.window_info, real_name.str, cfg.title.str,
b_val, cfg.border_width, cfg.border_color.str, cfg.corner_radius, cfg.bg_color.str,
cfg.padding, s_val, sc_val, cfg.caption_color.str, cfg.caption_alignment.str)
}
return win
}
// begin_group_box_with_config begins a group box container layout using a detailed GroupConfig struct.
pub fn (win &SimpleWindow) begin_group_box_with_config(name string, cfg GroupConfig) &SimpleWindow {
mut real_name := name
if real_name == '' {
real_name = win.auto_name('groupbox')
}
unsafe {
mut w := &SimpleWindow(win)
w.upsert_control(real_name, 'groupbox', cfg.title, '', false, 0)
}
if win.window_info != unsafe { nil } {
b_val := if cfg.border { 1 } else { 0 }
s_val := if cfg.shadow { 1 } else { 0 }
sc_val := if cfg.show_caption { 1 } else { 0 }
C.window_begin_group_box_with_config(win.window_info, real_name.str, cfg.title.str,
b_val, cfg.border_width, cfg.border_color.str, cfg.corner_radius, cfg.bg_color.str,
cfg.padding, s_val, sc_val, cfg.caption_color.str, cfg.caption_alignment.str)
}
return win
}
// group creates a group box container and invokes the callback for child elements.
pub fn (win &SimpleWindow) group(name string, title string, callback VoidEventCallback) &SimpleWindow {
return win.group_with_options(name, title, true, callback)
}
// group_with_options creates a group box container with optional caption (title) and border settings.
pub fn (win &SimpleWindow) group_with_options(name string, title string, border bool, callback VoidEventCallback) &SimpleWindow {
return win.group_config(name, GroupConfig{
title: title
border: border
}, callback)
}
// group_config creates a group box container using a GroupConfig struct.
pub fn (win &SimpleWindow) group_config(name string, cfg GroupConfig, callback VoidEventCallback) &SimpleWindow {
win.begin_group_box_with_config(name, cfg)
unsafe {
mut w := &SimpleWindow(win)
callback(mut w)
}
win.end_group_box()
return win
}
// card creates a borderless card container layout with optional shadow and inner padding.
pub fn (win &SimpleWindow) card(name string, callback VoidEventCallback) &SimpleWindow {
return win.group_config(name, GroupConfig{
border: false
show_caption: false
padding: 16
shadow: true
}, callback)
}
// card_with_title creates a styled card container with a header title.
pub fn (win &SimpleWindow) card_with_title(name string, title string, callback VoidEventCallback) &SimpleWindow {
return win.group_config(name, GroupConfig{
title: title
border: true
corner_radius: 12.0
padding: 16
shadow: true
}, callback)
}
// set_group_style updates the visual style of an existing group box container.
pub fn (win &SimpleWindow) set_group_style(name string, cfg GroupConfig) &SimpleWindow {
if win.window_info != unsafe { nil } {
b_val := if cfg.border { 1 } else { 0 }
s_val := if cfg.shadow { 1 } else { 0 }
C.window_set_group_style(win.window_info, name.str, b_val, cfg.border_width, cfg.border_color.str,
cfg.corner_radius, cfg.bg_color.str, s_val)
}
return win
}
// play_sound plays a system sound by name.
pub fn play_sound(sound_name string) {
C.window_play_system_sound(sound_name.str)
}
// begin_split_view begins a split view container in the layout.
pub fn (win &SimpleWindow) begin_split_view(name string, vertical bool) &SimpleWindow {
if win.window_info != unsafe { nil } {
vert := if vertical { 1 } else { 0 }
C.window_begin_split_view(win.window_info, name.str, vert)
}
return win
}
// end_split_view ends the current split view layout container.
pub fn (win &SimpleWindow) end_split_view() &SimpleWindow {
if win.window_info != unsafe { nil } {
C.window_end_split_view(win.window_info)
}
return win
}
// begin_glass_box begins a glassmorphic container layout.
pub fn (win &SimpleWindow) begin_glass_box(name string, material string) &SimpleWindow {
if win.window_info != unsafe { nil } {
C.window_begin_glass_box(win.window_info, name.str, material.str)
}
return win
}
// end_glass_box ends the current glass box container layout.
pub fn (win &SimpleWindow) end_glass_box() &SimpleWindow {
if win.window_info != unsafe { nil } {
C.window_end_glass_box(win.window_info)
}
return win
}
// add_badge adds a badge control to the window layout.