summary refs log tree commit diff stats
path: root/lib/ui/invalidatable.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ui/invalidatable.go')
-rw-r--r--lib/ui/invalidatable.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/ui/invalidatable.go b/lib/ui/invalidatable.go
new file mode 100644
index 0000000..9275712
--- /dev/null
+++ b/lib/ui/invalidatable.go
@@ -0,0 +1,24 @@
+package ui
+
+import (
+	"sync/atomic"
+)
+
+type Invalidatable struct {
+	onInvalidate atomic.Value
+}
+
+func (i *Invalidatable) OnInvalidate(f func(d Drawable)) {
+	i.onInvalidate.Store(f)
+}
+
+func (i *Invalidatable) DoInvalidate(d Drawable) {
+	v := i.onInvalidate.Load()
+	if v == nil {
+		return
+	}
+	f := v.(func(d Drawable))
+	if f != nil {
+		f(d)
+	}
+}
n130'>130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160