Alternating row background colors in table columns list, if activated by user. Closes #139

This commit is contained in:
Ansgar Becker
2024-04-29 09:24:47 +02:00
parent 7647fa19c0
commit f49804afbe

View File

@ -1092,11 +1092,30 @@ end;
procedure TfrmTableEditor.listColumnsBeforeCellPaint(Sender: TBaseVirtualTree;
TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);
var
clEven, clOdd, BgColor: TColor;
isEven: Boolean;
begin
BgColor := clNone;
// Alternating row background. See issue #139
clEven := AppSettings.ReadInt(asRowBackgroundEven);
clOdd := AppSettings.ReadInt(asRowBackgroundOdd);
isEven := Node.Index mod 2 = 0;
if IsEven and (clEven <> clNone) then
BgColor := AppSettings.ReadInt(asRowBackgroundEven)
else if (not IsEven) and (clOdd <> clNone) then
BgColor := AppSettings.ReadInt(asRowBackgroundOdd);
// Darken cell background to signalize it doesn't allow length/set
// Exclude non editable checkbox columns - grey looks ugly there.
if (not CellEditingAllowed(Node, Column)) and (not (Column in [4, 5, 6])) then begin
TargetCanvas.Brush.Color := GetThemeColor(clBtnFace);
BgColor := clBtnFace;
end;
// Apply color
if BgColor <> clNone then begin
TargetCanvas.Brush.Color := BgColor;
TargetCanvas.FillRect(CellRect);
end;
end;