-
Notifications
You must be signed in to change notification settings - Fork 1
/
decoration.go
69 lines (57 loc) · 2.11 KB
/
decoration.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
package goey
import (
"image/color"
"bitbucket.org/rj/goey/base"
)
var (
decorationKind = base.NewKind("bitbucket.org/rj/goey.Decoration")
)
// Decoration describes a widget that provides a border and background, and
// possibly containing a single child widget.
//
// The size of the control will match the size of the child element, although
// padding will be added between the border of the decoration and the child
// element as specified by the field Insets.
type Decoration struct {
Fill color.RGBA // Background colour used to fill interior.
Stroke color.RGBA // Stroke colour used to draw outline.
Insets Insets // Space between border of the decoration and the child element.
Radius base.Length // Radius of the widgets corners.
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 (*Decoration) Kind() *base.Kind {
return &decorationKind
}
// Mount creates a button in the GUI. The newly created widget
// will be a child of the widget specified by parent.
func (w *Decoration) Mount(parent base.Control) (base.Element, error) {
// Forward to the platform-dependant code
return w.mount(parent)
}
func (*decorationElement) Kind() *base.Kind {
return &decorationKind
}
func (w *decorationElement) Layout(bc base.Constraints) base.Size {
hinset := w.insets.Left + w.insets.Right
vinset := w.insets.Top + w.insets.Bottom
innerConstraints := bc.Inset(hinset, vinset)
w.childSize = w.child.Layout(innerConstraints)
return base.Size{
w.childSize.Width + hinset,
w.childSize.Height + vinset,
}
}
func (w *decorationElement) MinIntrinsicHeight(width base.Length) base.Length {
vinset := w.insets.Top + w.insets.Bottom
return w.child.MinIntrinsicHeight(width) + vinset
}
func (w *decorationElement) MinIntrinsicWidth(height base.Length) base.Length {
hinset := w.insets.Left + w.insets.Right
return w.child.MinIntrinsicWidth(height) + hinset
}
func (w *decorationElement) UpdateProps(data base.Widget) error {
// Forward to the platform-dependant code
return w.updateProps(data.(*Decoration))
}