Skip to content

Commit 82a30f8

Browse files
fix: TStringGrid dark theme
The dark theme for Linux and macOS cannot use AlternateColor. Even rows are visible, uneven rows are invisible. [skip ci]
1 parent 24b6714 commit 82a30f8

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

source/code/controler_trackerlist_online.pas

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface
1313

1414
type
1515

16-
TDefaultChecked = function(const TrackerURL: UTF8String): boolean of object;
16+
TDefaultChecked = function(const TrackerURL: utf8string): boolean of object;
1717

1818
{ TControlerTrackerListOnline }
1919

@@ -35,7 +35,7 @@ TControlerTrackerListOnline = class
3535
procedure SetChecked(index: integer; AValue: boolean);
3636
procedure ShowTrackerStatus(Visible: boolean);
3737
procedure AppendRow(Checked: boolean; Status: TTrackerListOnlineStatus;
38-
const TrackerURL: UTF8String);
38+
const TrackerURL: utf8string);
3939
public
4040
property Checked[index: integer]: boolean read GetChecked write SetChecked;
4141
function TrackerURL(index: integer): string;
@@ -65,6 +65,17 @@ implementation
6565
{ TControlerTrackerListOnline }
6666

6767

68+
function IsDarkTheme: boolean;
69+
// by "Hansaplast" & "Alextp" from Lazarus forum
70+
function _Level(C: TColor): double;
71+
begin
72+
Result := Red(C) * 0.3 + Green(C) * 0.59 + Blue(C) * 0.11;
73+
end;
74+
75+
begin
76+
Result := _Level(ColorToRGB(clWindow)) < _Level(ColorToRGB(clWindowText));
77+
end;
78+
6879
function TControlerTrackerListOnline.DownloadTrackers_All_Live_Stable: boolean;
6980
begin
7081
Result := FNewTrackon.Download_All_Live_Stable;
@@ -88,7 +99,11 @@ constructor TControlerTrackerListOnline.Create(StringGridTorrentURL: TStringGrid
8899
FStringGridTorrentURL := StringGridTorrentURL;
89100
FStringGridTorrentURL.RowCount := 1;
90101
FStringGridTorrentURL.FixedRows := 1;
91-
FStringGridTorrentURL.AlternateColor := clCream;
102+
103+
if not IsDarkTheme then
104+
begin // The dark theme for Linux and macOS cannot use AlternateColor. Text will be invisible.
105+
FStringGridTorrentURL.AlternateColor := clCream;
106+
end;
92107

93108
FSelect := FStringGridTorrentURL.Columns.Add;
94109
FSelect.Title.Caption := 'Keep';
@@ -144,7 +159,7 @@ procedure TControlerTrackerListOnline.SetChecked(index: integer; AValue: boolean
144159

145160

146161
procedure TControlerTrackerListOnline.AppendRow(Checked: boolean;
147-
Status: TTrackerListOnlineStatus; const TrackerURL: UTF8String);
162+
Status: TTrackerListOnlineStatus; const TrackerURL: utf8string);
148163
var
149164
CheckedStr, StatusStr: string;
150165
begin

source/code/main.lfm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ object FormTrackerModify: TFormTrackerModify
7878
Top = 0
7979
Width = 1165
8080
Align = alClient
81-
AlternateColor = clWhite
8281
ColCount = 0
8382
FixedCols = 0
8483
FixedRows = 0

0 commit comments

Comments
 (0)