Name | Modified | Size | Downloads / Week |
---|---|---|---|
Parent folder | |||
ReadMe.md | 2024-04-15 | 3.2 kB | |
Rcs_Dark_Mode.pas | 2024-04-12 | 6.0 kB | |
Totals: 2 Items | 9.2 kB | 0 |
RCS_DarkMode
The purpose of this unit is to provide the possibility to switch from 'normal' mode to 'dark' mode and vice versa for a window.
Usage
Imporant remark: the 'Manifest File' in menu Options -> Application should be set to 'None' to make this unit work well.
The usage is very simple: this is the interface between the using program and the unit:
On every form that needs dark mode, add the following:
- Create a variable of the type 'TMyDarkMode':
MyDarkMode: TMyDarkMode;
- Add in the 'Form.Create' event:
MyDarkMode := TMyDarkMode.Create(Self);
- Add, when needed in the code:
MyDarkMode.SetDarkMode(Self, true/false);
- Add in the 'Form.destroy' event:
MyDarkMode.Free;
The "standard behaviour" is:
The DarkMode unit exchanges the Color and Font.Color properties of a control if in darkmode, or uses the original Color and FontColor in normalmode. The resizing is recursive, e.g. a Panel on the form gets processed and also all components on that panel become processed.
Deviations of standard behaviour
For components that need a deviation on dark/normal switching method there is a callback routine available. This routine is called for every component when it is to be switched.
The signature of this routine is:
TDarkModeCallbackFunction = function(Control: TControl; Color_, FontColor: TColor; DarkMode: boolean): boolean;
The routine parameters: Control: the component about to dark/normal mode; Color_ and FontColor: the original (design) value of both colors; DarkMode: the new dark (true)/normal (false) value to switch to.
This routine has to return a boolean: false: means the callback routine did darkmode processing (this means the standard behaviour will be used); true: means the callback routine DID the darkmode processing (and the standard behaviour is switched off).
The routine itself looks like this (example):
function MyDarkModeCallBack(Control: TControl; Col, FontColor: TColor; DarkMode: boolean): boolean;
begin
Result := false;
if (Control.Name = 'SubSubtitle')
then
Result := true;
if (Control is TSWSeekbar) then
begin
with Control as TSWSeekBar do
begin
if not DarkMode
then BckgrColor := clbtnFace
else BckgrColor := clBlack;
end;
Result := true;
exit;
end;
if (Control is TSWButton) then
begin
with Control as TSWButton do
begin
if not DarkMode
then BckgrColor := clbtnFace
else BckgrColor := clBlack;
end;
Result := true;
exit;
end;
if (Control is TSWTimeCounter) then
begin
with Control as TSWTimeCounter do
begin
if not DarkMode then
begin
BackColor := clbtnFace;
TextColor := clWindowText;
end else
begin
BackColor := clBlack;
TextColor := clWhite;
end;
end;
Result := true;
exit;
end;
end;
The callback routine (if any) is activated in the 'Create' call:
MyDarkMode := TMyDarkMode.Create(Self, MyDarkModeCallBack);
Compiler directives
None.
Have fun!