From 213f13fcc4368ea3d3efa3b8fab13e5bd439da9e Mon Sep 17 00:00:00 2001 From: Oliver <480930+rivo@users.noreply.github.com> Date: Sun, 14 Jan 2018 15:11:37 +0100 Subject: [PATCH] Added individual cell background colors. Resolves #20 --- table.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/table.go b/table.go index 6388b8c..f58df9d 100644 --- a/table.go +++ b/table.go @@ -628,12 +628,14 @@ ColumnLoop: continue } - // Determine colors. + // Determine cell colors. bgColor := t.backgroundColor textColor := cell.Color + if cell.BackgroundColor != tcell.ColorDefault { + bgColor = cell.BackgroundColor + } if cellSelected && !cell.NotSelectable { - bgColor = cell.Color - textColor = t.backgroundColor + textColor, bgColor = bgColor, textColor } // Draw cell background. @@ -647,6 +649,18 @@ ColumnLoop: } cell.x, cell.y, cell.width = x+columnX+1, y+rowY, finalWidth + // We may want continuous background colors in rows so change + // border/separator background colors, too. + if column > 0 { + leftCell := getCell(row, column-1) + if leftCell != nil { + if cell.BackgroundColor == leftCell.BackgroundColor { + ch, _, style, _ := screen.GetContent(x+columnX, y+rowY) + screen.SetContent(x+columnX, y+rowY, ch, nil, style.Background(bgColor)) + } + } + } + // Draw text. text := cell.Text textWidth := runewidth.StringWidth(text)