-
Notifications
You must be signed in to change notification settings - Fork 1
/
layout.go
61 lines (54 loc) · 2.02 KB
/
layout.go
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
package goey
import (
"bitbucket.org/rj/goey/base"
)
func calculateHGap(previous base.Element, current base.Element) base.Length {
// The vertical gap between most controls is 11 relative pixels. However,
// there are different rules for between a label and its associated control,
// or between related controls. These relationship do not appear in the
// model provided by this package, so these relationships need to be
// inferred from the order and type of controls.
//
// https://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
if _, ok := previous.(*buttonElement); ok {
if _, ok := current.(*buttonElement); ok {
// Any pair of successive buttons will be assumed to be in a
// related group.
return 7 * DIP
}
}
// The spacing between unrelated controls.
return 11 * DIP
}
func calculateVGap(previous base.Element, current base.Element) base.Length {
// The vertical gap between most controls is 11 relative pixels. However,
// there are different rules for between a label and its associated control,
// or between related controls. These relationship do not appear in the
// model provided by this package, so these relationships need to be
// inferred from the order and type of controls.
//
// https://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
// Unwrap and Expand widgets.
if expand, ok := previous.(*expandElement); ok {
previous = expand.child
}
if expand, ok := current.(*expandElement); ok {
current = expand.child
}
// Apply layout rules.
if _, ok := previous.(*labelElement); ok {
// Any label immediately preceding any other control will be assumed to
// be 'associated'.
return 5 * DIP
}
if _, ok := previous.(*checkboxElement); ok {
if _, ok := current.(*checkboxElement); ok {
// Any pair of successive checkboxes will be assumed to be in a
// related group.
return 7 * DIP
}
}
// The spacing between unrelated controls. This is also the default space
// between paragraphs of text.
return 11 * DIP
}