-
Notifications
You must be signed in to change notification settings - Fork 0
/
extra_size.v
153 lines (133 loc) · 2.52 KB
/
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
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
module ui
import math
pub const (
stretch = -10000.0
compact = 0.0 // from parent
fit = 0.0
z_index_hidden = -10000
)
pub 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
}
// 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
}
}
fn is_children_have_widget(children []Widget) bool {
tmp := children.filter(!(it is Stack || it is Group))
return tmp.len > 0
}
//*********** cache **********
pub enum ChildSize {
compact
fixed
weighted
stretch
weighted_stretch
}
struct CachedSizes {
mut:
width_type []ChildSize
height_type []ChildSize
adj_widths []int
adj_heights []int
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
}
[unsafe]
pub fn (c &CachedSizes) free() {
unsafe {
c.width_type.free()
c.height_type.free()
c.adj_widths.free()
c.adj_heights.free()
c.fixed_widths.free()
c.fixed_heights.free()
c.weight_widths.free()
c.weight_heights.free()
free(c)
}
}
//********** Margin *********
pub enum Side {
top
left
right
bottom
}
// for Stacks
pub struct Margins {
pub mut:
top f32
right f32
bottom f32
left f32
}
// for Config
pub struct Margin {
top f64
right f64
bottom f64
left f64
}
fn margins(m f64, ms Margin) Margins {
mut margin := Margins{f32(m), f32(m), f32(m), f32(m)}
if ms.left != 0 || ms.right != 0 || ms.top != 0 || ms.bottom != 0 {
margin = Margins{f32(ms.top), f32(ms.right), f32(ms.bottom), f32(ms.left)}
}
return margin
}
//******** spacings ***********
fn spacings(sp f64, sps []f64, len int) []f32 {
if len < 0 {
return []f32{}
}
mut spacing := [f32(sp)].repeat(len)
if sps.len == len {
spacing = sps.map(f32(it))
}
return spacing
}
fn relative_size(size f32, w int, h int) f32 {
return if size < 1 { size * f32(math.min(w, h)) } else { size }
}
struct XYPos {
mut:
x int
y int
}