-
Notifications
You must be signed in to change notification settings - Fork 1
/
expand.go
88 lines (73 loc) · 2.21 KB
/
expand.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
package goey
import (
"bitbucket.org/rj/goey/base"
)
var (
expandKind = base.NewKind("bitbucket.org/rj/goey.Expand")
)
// Expand wraps another widget to indicate that the widget should expand to
// occupy any available space in a HBox or VBox. When used in any other
// context, the widget will be ignored, and behaviour delegated to the child
// widget.
//
// In an HBox or VBox, the widget will be positioned according to the rules
// of its child. However, any excess space along the main axis will be added
// based on the ratio of the widget's factor to the sum of factors for all
// widgets in the box. Note that
type Expand struct {
Factor int // Fraction (minus one) of available space used by this widget
Child base.Widget // Child widget.
}
// Kind returns the concrete type for use in the Widget interface.
// Users should not need to use this method directly.
func (*Expand) Kind() *base.Kind {
return &expandKind
}
// Mount creates a button in the GUI. The newly created widget
// will be a child of the widget specified by parent.
func (w *Expand) Mount(parent base.Control) (base.Element, error) {
// Mount the child
child, err := base.Mount(parent, w.Child)
if err != nil {
return nil, err
}
return &expandElement{
parent: parent,
child: child,
factor: w.Factor,
}, nil
}
type expandElement struct {
parent base.Control
child base.Element
factor int
}
func (w *expandElement) Close() {
if w.child != nil {
w.child.Close()
w.child = nil
}
}
func (*expandElement) Kind() *base.Kind {
return &expandKind
}
func (w *expandElement) Layout(bc base.Constraints) base.Size {
return w.child.Layout(bc)
}
func (w *expandElement) MinIntrinsicHeight(width base.Length) base.Length {
return w.child.MinIntrinsicHeight(width)
}
func (w *expandElement) MinIntrinsicWidth(height base.Length) base.Length {
return w.child.MinIntrinsicWidth(height)
}
func (w *expandElement) SetBounds(bounds base.Rectangle) {
w.child.SetBounds(bounds)
}
func (w *expandElement) updateProps(data *Expand) (err error) {
w.child, err = base.DiffChild(w.parent, w.child, data.Child)
w.factor = data.Factor
return err
}
func (w *expandElement) UpdateProps(data base.Widget) error {
return w.updateProps(data.(*Expand))
}