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.
This commit is contained in:
Jeffas 2019-07-23 20:03:14 +01:00 committed by Drew DeVault
parent 2f626ddd18
commit 1cf90897f7

View file

@ -127,6 +127,15 @@ func (grid *Grid) Draw(ctx *Context) {
for _, row := range rows { for _, row := range rows {
height += row.Size 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) subctx := ctx.Subcontext(x, y, width, height)
cell.Content.Draw(subctx) cell.Content.Draw(subctx)
} }