forked from fyne-io/fyne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase.go
112 lines (86 loc) · 2.69 KB
/
base.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
108
109
110
111
112
// Package canvas contains all of the primitive CanvasObjects that make up a Fyne GUI
//
// The types implemented in this package are used as building blocks in order
// to build higher order functionality. These types are designed to be
// non-interactive, by design. If additional functonality is required,
// it's usually a sign that this type should be used as part of a custom
// Widget.
package canvas // import "fyne.io/fyne/v2/canvas"
import (
"sync"
"fyne.io/fyne/v2"
)
type baseObject struct {
size fyne.Size // The current size of the canvas object
position fyne.Position // The current position of the object
Hidden bool // Is this object currently hidden
min fyne.Size // The minimum size this object can be
propertyLock sync.RWMutex
}
// CurrentSize returns the current size of this canvas object.
func (r *baseObject) Size() fyne.Size {
r.propertyLock.RLock()
defer r.propertyLock.RUnlock()
return r.size
}
// Resize sets a new size for the canvas object.
func (r *baseObject) Resize(size fyne.Size) {
r.propertyLock.Lock()
defer r.propertyLock.Unlock()
r.size = size
}
// CurrentPosition gets the current position of this canvas object, relative to its parent.
func (r *baseObject) Position() fyne.Position {
r.propertyLock.RLock()
defer r.propertyLock.RUnlock()
return r.position
}
// Move the object to a new position, relative to its parent.
func (r *baseObject) Move(pos fyne.Position) {
r.propertyLock.Lock()
defer r.propertyLock.Unlock()
r.position = pos
}
// MinSize returns the specified minimum size, if set, or {1, 1} otherwise.
func (r *baseObject) MinSize() fyne.Size {
r.propertyLock.RLock()
defer r.propertyLock.RUnlock()
if r.min.Width == 0 && r.min.Height == 0 {
return fyne.NewSize(1, 1)
}
return r.min
}
// SetMinSize specifies the smallest size this object should be.
func (r *baseObject) SetMinSize(size fyne.Size) {
r.propertyLock.Lock()
defer r.propertyLock.Unlock()
r.min = size
}
// IsVisible returns true if this object is visible, false otherwise.
func (r *baseObject) Visible() bool {
r.propertyLock.RLock()
defer r.propertyLock.RUnlock()
return !r.Hidden
}
// Show will set this object to be visible.
func (r *baseObject) Show() {
r.propertyLock.Lock()
defer r.propertyLock.Unlock()
r.Hidden = false
}
// Hide will set this object to not be visible.
func (r *baseObject) Hide() {
r.propertyLock.Lock()
defer r.propertyLock.Unlock()
r.Hidden = true
}
// Refresh instructs the containing canvas to refresh the specified obj.
func Refresh(obj fyne.CanvasObject) {
if fyne.CurrentApp() == nil || fyne.CurrentApp().Driver() == nil {
return
}
c := fyne.CurrentApp().Driver().CanvasForObject(obj)
if c != nil {
c.Refresh(obj)
}
}