diff options
Diffstat (limited to 'lib/ui/invalidatable.go')
-rw-r--r-- | lib/ui/invalidatable.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/ui/invalidatable.go b/lib/ui/invalidatable.go new file mode 100644 index 00000000..92757121 --- /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) + } +} |