-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui_extra_size.v
104 lines (92 loc) · 2 KB
/
ui_extra_size.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
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
module ui
pub const (
stretch = -100.
compact = 0. // from parent
)
enum WindowSizeType {
normal_size
resizable
max_size
fullscreen
}
pub type Size = []f64 | f64
fn (size Size) as_f32_array(len int) []f32 {
mut res := []f32{}
match size {
[]f64 {
for _, v in size {
res << f32(v)
}
}
f64 {
res = [f32(size)].repeat(len)
}
}
return res
}
// Tool to convert width and height from f32 to int
pub fn size_f32_to_int(size f32) int {
// Convert c.width and c.height from f32 to int used as a trick to deal with relative size with respect to parent
mut s := int(size)
// println("f32_int: start $size -> $s")
if 0 < size && size <= 1 {
s = -int(size * 100) // to be converted in percentage of parent size inside init call
// println("f32_int: size $size $w ${typeof(size).name} ${typeof(s).name}")
}
return s
}
pub fn sizes_f32_to_int(width f32, height f32) (int, int) {
return size_f32_to_int(width), size_f32_to_int(height)
}
// if size is negative, it is relative in percentage of the parent
pub fn relative_size_from_parent(size int, parent_free_size int) int {
return if size == -100 {
parent_free_size
} else if size < 0 {
percent := f32(-size) / 100
new_size := int(percent * parent_free_size)
println('relative size: $size $new_size -> $percent * $parent_free_size) ')
new_size
} else {
size
}
}
// Spacing
pub type Spacing = []int | int
fn (i Spacing) as_int_array(len int) []int {
return match i {
[]int {
i.clone()
}
int {
[i].repeat(len)
}
}
}
fn is_children_have_widget(children []Widget) bool {
tmp := children.filter(!(it is Stack || it is Group))
return tmp.len > 0
}
pub enum ChildSize {
fixed
weighted
weighted_minsize
stretch
compact
propose
}
struct CachedSizes {
mut:
width_type []ChildSize
height_type []ChildSize
fixed_widths []int
fixed_heights []int
fixed_width int
fixed_height int
min_width int
min_height int
weight_widths []f64
width_mass f64
weight_heights []f64
height_mass f64
}