-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathtool_align.v
More file actions
67 lines (59 loc) · 1.47 KB
/
tool_align.v
File metadata and controls
67 lines (59 loc) · 1.47 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
// Copyright (c) 2020-2022 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by a MIT license
// that can be found in the LICENSE file.
module ui
import math
pub enum VerticalAlignment {
top = 0
center
bottom
}
pub enum HorizontalAlignment {
left = 0
center
right
}
pub struct HorizontalAlignments {
pub:
left []int
center []int
right []int
}
pub struct VerticalAlignments {
pub:
top []int
center []int
bottom []int
}
// Anticipating replacement of VerticalAlignments
pub struct Alignments {
pub:
center []int
left_top []int
top []int
right_top []int
right []int
right_bottom []int
bottom []int
left_bottom []int
left []int
}
pub fn get_align_offset_from_parent(mut w Widget, aw f64, ah f64) (int, int) {
width, height := w.size()
parent := w.parent
parent_width, parent_height := if parent is Stack { parent.free_size() } else { parent.size() }
dw := math.max(parent_width - width, 0)
dh := math.max(parent_height - height, 0)
$if get_align ? {
if w.id in env('UI_IDS').split(',') {
println('align: ${w.id} int(${aw} * ${dw}), int(${ah} * ${dh})')
println('${width}, ${height} ${parent_width}, ${parent_height}')
}
}
return int(aw * dw), int(ah * dh)
}
pub fn get_align_offset_from_size(width int, height int, pwidth int, pheight int, aw f64, ah f64) (int, int) {
dw := math.max(pwidth - width, 0)
dh := math.max(pheight - height, 0)
return int(aw * dw), int(ah * dh)
}