about summary refs log tree commit diff stats
path: root/lib/ui
diff options
context:
space:
mode:
authorJeffas <dev@jeffas.io>2019-07-23 20:03:14 +0100
committerDrew DeVault <sir@cmpwn.com>2019-07-25 18:12:00 -0400
commit1cf90897f74f7f727710a9e61e9c835a040918bf (patch)
tree9615c736daf8596d45d728d37690696681ba2570 /lib/ui
parent2f626ddd18e8472e0ddc2bb9013b7d01c1b5b9a9 (diff)
downloadaerc-1cf90897f74f7f727710a9e61e9c835a040918bf.tar.gz
Fix grid creating too large subcontexts
The grid was not checking there was enough space for the cells so would
just attempt to create subcontexts that don't actually fit.

This attempts to use the remaining space and then if there is no space
then it just skips drawing this cell.
Diffstat (limited to 'lib/ui')
-rw-r--r--lib/ui/grid.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/ui/grid.go b/lib/ui/grid.go
index 96da1cb..7f131bd 100644
--- a/lib/ui/grid.go
+++ b/lib/ui/grid.go
@@ -127,6 +127,15 @@ func (grid *Grid) Draw(ctx *Context) {
 		for _, row := range rows {
 			height += row.Size
 		}
+		if x+width > ctx.Width() {
+			width = ctx.Width() - x
+		}
+		if y+height > ctx.Height() {
+			height = ctx.Height() - y
+		}
+		if width <= 0 || height <= 0 {
+			continue
+		}
 		subctx := ctx.Subcontext(x, y, width, height)
 		cell.Content.Draw(subctx)
 	}