forked from fyne-io/fyne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbox.go
107 lines (85 loc) · 2.6 KB
/
box.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
95
96
97
98
99
100
101
102
103
104
105
106
107
package widget
import (
"image/color"
"fyne.io/fyne"
"fyne.io/fyne/canvas"
"fyne.io/fyne/internal/widget"
"fyne.io/fyne/layout"
"fyne.io/fyne/theme"
)
// Box widget is a simple list where the child elements are arranged in a single column
// for vertical or a single row for horizontal arrangement.
// Deprecated: Use container.NewVBox() or container.NewHBox().
type Box struct {
BaseWidget
background color.Color
Horizontal bool
Children []fyne.CanvasObject
}
// Refresh updates this box to match the current theme
func (b *Box) Refresh() {
if b.background != nil {
b.background = theme.BackgroundColor()
}
b.BaseWidget.Refresh()
}
// Prepend inserts a new CanvasObject at the top/left of the box
func (b *Box) Prepend(object fyne.CanvasObject) {
b.Children = append([]fyne.CanvasObject{object}, b.Children...)
b.Refresh()
}
// Append adds a new CanvasObject to the end/right of the box
func (b *Box) Append(object fyne.CanvasObject) {
b.Children = append(b.Children, object)
b.Refresh()
}
// MinSize returns the size that this widget should not shrink below
func (b *Box) MinSize() fyne.Size {
b.ExtendBaseWidget(b)
return b.BaseWidget.MinSize()
}
// CreateRenderer is a private method to Fyne which links this widget to its renderer
func (b *Box) CreateRenderer() fyne.WidgetRenderer {
b.ExtendBaseWidget(b)
var lay fyne.Layout
if b.Horizontal {
lay = layout.NewHBoxLayout()
} else {
lay = layout.NewVBoxLayout()
}
return &boxRenderer{BaseRenderer: widget.NewBaseRenderer(b.Children), layout: lay, box: b}
}
// NewHBox creates a new horizontally aligned box widget with the specified list of child objects.
// Deprecated: Use container.NewHBox() instead.
func NewHBox(children ...fyne.CanvasObject) *Box {
return &Box{BaseWidget: BaseWidget{}, Horizontal: true, Children: children}
}
// NewVBox creates a new vertically aligned box widget with the specified list of child objects.
// Deprecated: Use container.NewVBox() instead.
func NewVBox(children ...fyne.CanvasObject) *Box {
return &Box{BaseWidget: BaseWidget{}, Horizontal: false, Children: children}
}
type boxRenderer struct {
widget.BaseRenderer
layout fyne.Layout
box *Box
}
func (b *boxRenderer) MinSize() fyne.Size {
return b.layout.MinSize(b.Objects())
}
func (b *boxRenderer) Layout(size fyne.Size) {
b.layout.Layout(b.Objects(), size)
}
func (b *boxRenderer) BackgroundColor() color.Color {
if b.box.background == nil {
return theme.BackgroundColor()
}
return b.box.background
}
func (b *boxRenderer) Refresh() {
b.SetObjects(b.box.Children)
for _, child := range b.Objects() {
child.Refresh()
}
canvas.Refresh(b.box)
}