aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ui/grid.go
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2022-10-07 11:00:31 -0500
committerRobin Jarry <robin@jarry.cc>2022-10-12 22:16:40 +0200
commitba24e92062f1a9b38065d503fd1dde749c27a56c (patch)
treed1a2981f8f9bda50a070b50c688388fe2130f770 /lib/ui/grid.go
parent34014d3ceeebe8a9c131213fa56d1977fbc26b4a (diff)
downloadaerc-ba24e92062f1a9b38065d503fd1dde749c27a56c.tar.gz
invalidatable: cleanup dead code
Remove invalidatable type and all associated calls. All items can directly invalidate the UI. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/ui/grid.go')
-rw-r--r--lib/ui/grid.go59
1 files changed, 5 insertions, 54 deletions
diff --git a/lib/ui/grid.go b/lib/ui/grid.go
index fe1d03e8..76eba000 100644
--- a/lib/ui/grid.go
+++ b/lib/ui/grid.go
@@ -1,21 +1,17 @@
package ui
import (
- "fmt"
"math"
"sync"
- "sync/atomic"
"github.com/gdamore/tcell/v2"
)
type Grid struct {
- Invalidatable
rows []GridSpec
rowLayout []gridLayout
columns []GridSpec
columnLayout []gridLayout
- invalid bool
// Protected by mutex
cells []*GridCell
@@ -51,11 +47,10 @@ type GridCell struct {
RowSpan int
ColSpan int
Content Drawable
- invalid atomic.Value // bool
}
func NewGrid() *Grid {
- return &Grid{invalid: true}
+ return &Grid{}
}
// MakeGrid creates a grid with the specified number of columns and rows. Each
@@ -95,19 +90,12 @@ func (grid *Grid) Columns(spec []GridSpec) *Grid {
}
func (grid *Grid) Draw(ctx *Context) {
- invalid := grid.invalid
- if invalid {
- grid.reflow(ctx)
- }
+ grid.reflow(ctx)
grid.mutex.RLock()
defer grid.mutex.RUnlock()
for _, cell := range grid.cells {
- cellInvalid := cell.invalid.Load().(bool)
- if !cellInvalid && !invalid {
- continue
- }
rows := grid.rowLayout[cell.Row : cell.Row+cell.RowSpan]
cols := grid.columnLayout[cell.Column : cell.Column+cell.ColSpan]
x := cols[0].Offset
@@ -142,16 +130,11 @@ func (grid *Grid) Draw(ctx *Context) {
func (grid *Grid) MouseEvent(localX int, localY int, event tcell.Event) {
if event, ok := event.(*tcell.EventMouse); ok {
- invalid := grid.invalid
grid.mutex.RLock()
defer grid.mutex.RUnlock()
for _, cell := range grid.cells {
- cellInvalid := cell.invalid.Load().(bool)
- if !cellInvalid && !invalid {
- continue
- }
rows := grid.rowLayout[cell.Row : cell.Row+cell.RowSpan]
cols := grid.columnLayout[cell.Column : cell.Column+cell.ColSpan]
x := cols[0].Offset
@@ -220,23 +203,10 @@ func (grid *Grid) reflow(ctx *Context) {
}
flow(&grid.rows, &grid.rowLayout, ctx.Height())
flow(&grid.columns, &grid.columnLayout, ctx.Width())
- grid.invalid = false
-}
-
-func (grid *Grid) invalidateLayout() {
- grid.invalid = true
- grid.DoInvalidate(grid)
}
func (grid *Grid) Invalidate() {
- grid.invalidateLayout()
- grid.mutex.RLock()
- for _, cell := range grid.cells {
- if cell.Content != nil {
- cell.Content.Invalidate()
- }
- }
- grid.mutex.RUnlock()
+ Invalidate()
}
func (grid *Grid) AddChild(content Drawable) *GridCell {
@@ -248,9 +218,7 @@ func (grid *Grid) AddChild(content Drawable) *GridCell {
grid.mutex.Lock()
grid.cells = append(grid.cells, cell)
grid.mutex.Unlock()
- cell.Content.OnInvalidate(grid.cellInvalidated)
- cell.invalid.Store(true)
- grid.invalidateLayout()
+ grid.Invalidate()
return cell
}
@@ -263,24 +231,7 @@ func (grid *Grid) RemoveChild(content Drawable) {
}
}
grid.mutex.Unlock()
- grid.invalidateLayout()
-}
-
-func (grid *Grid) cellInvalidated(drawable Drawable) {
- var cell *GridCell
- grid.mutex.RLock()
- for _, cell = range grid.cells {
- if cell.Content == drawable {
- break
- }
- cell = nil
- }
- grid.mutex.RUnlock()
- if cell == nil {
- panic(fmt.Errorf("Attempted to invalidate unknown cell"))
- }
- cell.invalid.Store(true)
- grid.DoInvalidate(grid)
+ grid.Invalidate()
}
func Const(i int) func() int {