Recent

Author Topic: Menu Colors  (Read 515 times)

dbannon

  • Hero Member
  • *****
  • Posts: 690
    • tomboy-ng, a rewrite of the classic Tomboy
Menu Colors
« on: June 22, 2019, 05:50:23 am »
I need to set the background and text color of menu items. But don't seem to be able to do so.

This is specifically needed for Windows where the various colors are not inherited from the OS theme. On Linux, if I have a dark theme, all components recognise that and follow suit but Windows has only just caught up with this (yucky) trend to have dark themes and LCL does not adjust itself.

So, for Windows only I am manually adjusting the colors. Easy for forms and buttons etc but not for menus. The menu's parent is set to the form, the compiler won't let me manually set MenuItems Parent and there is no Color or Font property.

And, yet, a menu's colors do change depending on the OS theme so its not hard coded into the binary.

Any ideas anyone ?

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

dbannon

  • Hero Member
  • *****
  • Posts: 690
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Menu Colors
« Reply #1 on: June 22, 2019, 10:01:13 am »
....

I should have mentioned when saying the "the menu's colors do change" that I mean they change under linux, perhaps its not possible to change them at all under Windows ?

David
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

wp

  • Hero Member
  • *****
  • Posts: 6231
Re: Menu Colors
« Reply #2 on: June 22, 2019, 11:10:25 am »
There is an OnDrawItem event for TMainMenu and its items. Does not look perfect, but maybe you can investigate further
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

dbannon

  • Hero Member
  • *****
  • Posts: 690
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Menu Colors
« Reply #3 on: June 22, 2019, 12:17:17 pm »
Hmm, thats a challenge !

I just had a look at it, I get a chance to change  canvas [Font, Pen, Brush] colors but the event does not seem to be called. With OwnerDraw true or false.  Tried to find where its setup during create and it does not 'seem' (to my uneducated gaze) to be involved at all. I am, currently, using Linux, maybe its only used in (eg) Windows ?

Is it possible that its a unimplemented hook ?

Davo

Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

wp

  • Hero Member
  • *****
  • Posts: 6231
Re: Menu Colors
« Reply #4 on: June 22, 2019, 01:28:56 pm »
I only tested on Windows where the OnDrawItem is called, but the results were not convincing to me (background not painted over the entire width of the menu bar, bright margin around the area painted, requirement to paint "everything" including icons, checkboxes etc)

Normally I'd recommend to use a third-party menu bar, such as TB2_TBX (https://github.com/edivando-fpc/TB2_TBX). But I cannot run their demo program because of a debugger error.

JVCL has a TJvMainMenu - it has not yet been ported to Lazarus, and, most of all, inherits from TMainMenu and thus will have the same issues as the LCL MainMenu.

Or use TSpkToolbar (disbibuted by Online-Package-Manager) which imitates the new ribbon interface and can be freely modified; there is even a dark theme. But it's not a TMainmenu...
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

dbannon

  • Hero Member
  • *****
  • Posts: 690
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Menu Colors
« Reply #5 on: June 22, 2019, 01:43:01 pm »
Thanks wp, you have actually given me a big hint there. I prefer (almost universally) to work under Linux but the issue I am trying to solve is a windows one.  If that onDraw event is fired in Windows, I need to swallow my pride and reboot !

-- but ---

The app is cross platform and I am not all that sure I want to add a whole set of new components just to get dark theme working on windows, it works fine 'out of the box' on linux but thats because Linux has been doing dark themes for years. Windows has only just dipped their toe in the water.

Honestly, rather than hacking away, maybe I'd be better to wait until 'someone' makes LCL comply with an emerging theme standard on windows ?  Cheeky !   Maybe thats me ....

Anyway, the menus are (mostly) just text, I'll reboot into windows and see how things work....

Thanks wp, good advice indeed !

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

wp

  • Hero Member
  • *****
  • Posts: 6231
Re: Menu Colors
« Reply #6 on: June 22, 2019, 02:22:28 pm »
maybe I'd be better to wait until 'someone' makes LCL comply with an emerging theme standard on windows ? 
I don't think that this is a fault of the LCL. I just switched my Win 10 to "dark mode" - yes, the system settings form became dark, the explorer too - but that's it, everything else remained bright, Delphi 10.2, Excel, Libre Office, even their NotePad is bright. The Windows dark mode is not complete, it applies only to the new tablet apps but not to standard desktop applications. Wait until Microsoft passes the dark mode settings to the ThemeServices, then the LCL will have it as well automatically.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

dbannon

  • Hero Member
  • *****
  • Posts: 690
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Menu Colors
« Reply #7 on: June 23, 2019, 02:34:03 am »
Yes, I see your reasoning there wp.  But I wonder if its a chicken and egg situation ?

When the windows (.inc) sections of LCL was written, there was no 'theme' available. Nor could they look for the registry entry that indicates you have set the dark theme, it was not, then, defined.

I wonder if System Settings and Explorer look to the registry setting rather than ThemeServices and perhaps Microsoft think thats "job done" ?

I have code in my app that looks at GetRGBColorResolvingParent() color because I do need to manually set some colors, particularly in KControls. Works fine in Linux but under windows that function does not work because, presumably, Windows returns the desktop color ?  and it has not changed. But checking the registry entry is easy -
Code: Pascal  [Select]
  1.    {$ifdef WINDOWS}  function WinDarkTheme : boolean;
  2.    var
  3.      RegValue : string='';
  4.      Registry : TRegistry;
  5.    begin
  6.      Registry := TRegistry.Create;
  7.      try
  8.        Registry.RootKey := HKEY_CURRENT_USER;
  9.        if Registry.OpenKeyReadOnly('\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize') then
  10.            exit(Registry.ReadInteger('AppsUseLightTheme') = 0)
  11.        else exit(false);
  12.      finally
  13.        Registry.Free;
  14.      end;
  15.    end; {$endif}
         

So, my thoughts are that LCL needs to do that during initialization and adjust its colors then. That assumes Microsoft is content to have one dark theme switch and one dark theme.

Something I have noted is that the only thing uglier than a dark theme is a dark theme done badly, and that what I am doing !     :-)

Thanks wp.

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng