grid: protect calls to cell.Content
Many panics occur from calling Draw on a nil widget, stemming from the grid ui element. Protect the calls to Draw from within grid to prevent this method of panic. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
parent
a31606db0d
commit
a91009edf7
1 changed files with 6 additions and 2 deletions
|
@ -134,9 +134,11 @@ func (grid *Grid) Draw(ctx *Context) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
subctx := ctx.Subcontext(x, y, width, height)
|
subctx := ctx.Subcontext(x, y, width, height)
|
||||||
|
if cell.Content != nil {
|
||||||
cell.Content.Draw(subctx)
|
cell.Content.Draw(subctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (grid *Grid) MouseEvent(localX int, localY int, event tcell.Event) {
|
func (grid *Grid) MouseEvent(localX int, localY int, event tcell.Event) {
|
||||||
if event, ok := event.(*tcell.EventMouse); ok {
|
if event, ok := event.(*tcell.EventMouse); ok {
|
||||||
|
@ -230,8 +232,10 @@ func (grid *Grid) Invalidate() {
|
||||||
grid.invalidateLayout()
|
grid.invalidateLayout()
|
||||||
grid.mutex.RLock()
|
grid.mutex.RLock()
|
||||||
for _, cell := range grid.cells {
|
for _, cell := range grid.cells {
|
||||||
|
if cell.Content != nil {
|
||||||
cell.Content.Invalidate()
|
cell.Content.Invalidate()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
grid.mutex.RUnlock()
|
grid.mutex.RUnlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue