-
Notifications
You must be signed in to change notification settings - Fork 890
/
spacer.go
94 lines (75 loc) · 2.24 KB
/
spacer.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
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
// Copyright 2011 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build windows
package walk
const spacerWindowClass = `\o/ Walk_Spacer_Class \o/`
func init() {
AppendToWalkInit(func() {
MustRegisterWindowClass(spacerWindowClass)
})
}
type Spacer struct {
WidgetBase
sizeHint96dpi Size
layoutFlags LayoutFlags
greedyLocallyOnly bool
}
type SpacerCfg struct {
LayoutFlags LayoutFlags
SizeHint Size // in 1/96" units
GreedyLocallyOnly bool
}
func NewSpacerWithCfg(parent Container, cfg *SpacerCfg) (*Spacer, error) {
return newSpacer(parent, cfg.LayoutFlags, cfg.SizeHint, cfg.GreedyLocallyOnly)
}
func newSpacer(parent Container, layoutFlags LayoutFlags, sizeHint96dpi Size, greedyLocallyOnly bool) (*Spacer, error) {
s := &Spacer{
layoutFlags: layoutFlags,
sizeHint96dpi: sizeHint96dpi,
greedyLocallyOnly: greedyLocallyOnly,
}
if err := InitWidget(
s,
parent,
spacerWindowClass,
0,
0); err != nil {
return nil, err
}
return s, nil
}
func NewHSpacer(parent Container) (*Spacer, error) {
return newSpacer(parent, ShrinkableHorz|ShrinkableVert|GrowableHorz|GreedyHorz, Size{}, false)
}
func NewHSpacerFixed(parent Container, width int) (*Spacer, error) {
return newSpacer(parent, 0, Size{width, 0}, false)
}
func NewVSpacer(parent Container) (*Spacer, error) {
return newSpacer(parent, ShrinkableHorz|ShrinkableVert|GrowableVert|GreedyVert, Size{}, false)
}
func NewVSpacerFixed(parent Container, height int) (*Spacer, error) {
return newSpacer(parent, 0, Size{0, height}, false)
}
func (s *Spacer) CreateLayoutItem(ctx *LayoutContext) LayoutItem {
return &spacerLayoutItem{
idealSize96dpi: s.sizeHint96dpi,
layoutFlags: s.layoutFlags,
greedyLocallyOnly: s.greedyLocallyOnly,
}
}
type spacerLayoutItem struct {
LayoutItemBase
idealSize96dpi Size
layoutFlags LayoutFlags
greedyLocallyOnly bool
}
func (li *spacerLayoutItem) LayoutFlags() LayoutFlags {
return li.layoutFlags
}
func (li *spacerLayoutItem) IdealSize() Size {
return SizeFrom96DPI(li.idealSize96dpi, li.ctx.dpi)
}
func (li *spacerLayoutItem) MinSize() Size {
return SizeFrom96DPI(li.idealSize96dpi, li.ctx.dpi)
}