From 1cf90897f74f7f727710a9e61e9c835a040918bf Mon Sep 17 00:00:00 2001 From: Jeffas Date: Tue, 23 Jul 2019 20:03:14 +0100 Subject: 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. --- lib/ui/grid.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib/ui/grid.go') 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) } -- cgit 1.4.1-2-gfad0