Programming => Packages and Libraries => RichMemo => Topic started by: rossh_lz on July 25, 2020, 09:30:51 pm

Title: clDefault and text in darktheme
Post by: rossh_lz on July 25, 2020, 09:30:51 pm
Having trouble making rich text pick up the default color, when the OS theme is darkmode, or high contrast (Win and Mac), where the text has to be white.

If I set the richmemo.font.color to initialize with clDefault, then it draws with system white text.
But any and all changes to the richmemo.font, such as size, or manipulating richtext, then the component uses black text.   When writing anything new to the Font property, causes a new Font object to be created, but it comes out black text every time.  Any attempt to have the component adopt the systems clDefault color is not accepted.  I don't think the richmemo native objects is even capable of accepting clDefault.

How to read the actual color value of clDefault, so I can hard code the text color into rich text edits?

Title: Re: clDefault and text in darktheme
Post by: Blaazen on July 25, 2020, 09:54:54 pm
RichMemo is not a native widget so I agree it probably does not understand clDefault..
clDefault is defined as
Code: Pascal  [Select][+][-]
  1. clDefault = TColor($20000000);
so it is therefore interpreted as a black color.
You can do something (function) like
Code: Pascal  [Select][+][-]
  1. if AColor=clDefault
  2.   then richmemo.font.color:=clBtnText // or clWindowText etc.
  3.   else richmemo.font.color:=AColor;
I use this a lot in EC-Controls, so they know clDefault even if they are not native widgets.
Title: Re: clDefault and text in darktheme
Post by: skalogryz on July 26, 2020, 07:52:40 pm
It's actually quite an interesting subject you brought up.

As of right now, RichMemo only expects the color to be specified as RGB color.
There's no handling of specially named colors (i.e. clDefault) in the background.
It only happens that clDefault code is the same as black color.
Title: Re: clDefault and text in darktheme
Post by: rossh_lz on July 27, 2020, 08:48:20 am
The TRichMemo descends from a TCustomMemo, and that parent and branch is able to stay with the OS defaults, even after making font size, style changes.  But even using TRichmemo as a plain TMemo, it looses sync with the OS theme font color.   So some inheritance is missing for the TRichMemo.   I'm still looking for the missing piece.

In the meantime, I'm using this handy cheat to discover clDefault; scrape the canvas of a TPanel to get its color.

Code: Pascal  [Select][+][-]
  1.   PanelRichMemoResult.Update;
  2.   ThemeCanvasColor := PanelRichMemoResult.Canvas.Pixels[4,4];
  3.   ThemeFontColor := ContrastColor(ThemeCanvasColor);
  4.   RichMemoResult.Font.Color := ThemeFontColor;

TinyPortal © 2005-2018