@@ -4,16 +4,18 @@ import (
4
4
"image"
5
5
"image/draw"
6
6
"sort"
7
- )
8
7
9
- type BoxProps struct {
10
- }
8
+ "candy/ui/ptr"
9
+ )
11
10
12
11
var _ Component = (* Box )(nil )
13
12
14
13
type Box struct {
15
14
SharedComponent
16
- props BoxProps
15
+ }
16
+
17
+ func (b Box ) GetName () string {
18
+ return "Box"
17
19
}
18
20
19
21
func (b Box ) Paint (painter * Painter , destLayer draw.Image , offset Offset ) {
@@ -23,6 +25,9 @@ func (b Box) Paint(painter *Painter, destLayer draw.Image, offset Offset) {
23
25
Y : b .size .height ,
24
26
},
25
27
})
28
+ if b .style .Background != nil {
29
+ b .style .Background .Paint (painter , contentLayer )
30
+ }
26
31
27
32
sortedChildren := Children {
28
33
children : b .children ,
@@ -45,33 +50,36 @@ func (b Box) Paint(painter *Painter, destLayer draw.Image, offset Offset) {
45
50
}
46
51
47
52
func (b Box ) ComputeLeafSize (_ Constraints ) Size {
53
+ padding := b .style .GetPadding ()
54
+
48
55
width := 0
49
56
if b .style .Width != nil {
50
57
width = * b .style .Width
51
58
}
59
+ width += padding .GetLeft () + padding .GetRight ()
52
60
height := 0
53
61
if b .style .Height != nil {
54
62
height = * b .style .Height
55
63
}
64
+ height += padding .GetTop () + padding .GetBottom ()
56
65
return Size {width : width , height : height }
57
66
}
58
67
59
- func NewBox (props * BoxProps , children []Component , style * Style ) * Box {
60
- if props == nil {
61
- props = & BoxProps {}
62
- }
68
+ func NewBox (children []Component , style * Style ) * Box {
63
69
if style == nil {
64
70
style = & Style {
65
- LayoutType : BoxLayoutType ,
71
+ LayoutType : ( * LayoutType )( ptr . Int ( int ( BoxLayoutType ))) ,
66
72
}
67
73
}
74
+ if style .LayoutType == nil {
75
+ style .LayoutType = (* LayoutType )(ptr .Int (int (BoxLayoutType )))
76
+ }
68
77
if children == nil {
69
78
children = make ([]Component , 0 )
70
79
}
71
80
return & Box {
72
- props : * props ,
73
81
SharedComponent : SharedComponent {
74
- layout : newLayout (style .LayoutType ),
82
+ layout : newLayout (* style .LayoutType ),
75
83
style : * style ,
76
84
children : children ,
77
85
childrenOffset : []Offset {},
0 commit comments