Difference between revisions of "Win32MenuStyler"

From Lazarus wiki
(Usage)
(Usage)
Line 17: Line 17:
 
* add win32menustyler to "uses"
 
* add win32menustyler to "uses"
 
* in form's OnShow, call: MenuStyler.ApplyToForm(Self, False)
 
* in form's OnShow, call: MenuStyler.ApplyToForm(Self, False)
* if it's needed to apply different colors later, change them in global var, and call MenuStyler.ApplyForm(Self, True). Second param should be True here, this forces form's resize to repaint the menu bar.
+
* if it's needed to apply different colors later, change them in global var, and call MenuStyler.ApplyToForm(Self, True). Second param should be True here, this forces form's resize to repaint the menu bar.
  
 
Unit gives global var to change all theming details:
 
Unit gives global var to change all theming details:

Revision as of 21:09, 18 September 2020

Windows logo - 2012.svg

This article applies to Windows only.

See also: Multiplatform Programming Guide

About

This is helper unit win32menustyler, which helps to theme TMainMenu for Lazarus Windows apps. Sometimes app has dark theme, so it's needed to make TMainMenu also dark.

About other OS: GitHub repo has cross-platform "lazmenustyler" unit, but it don't give any effect on gtk2 demo app. And it should not work on macOS, macOS has very special theming and menu is located on the screen top.

win32menustyler.png

Author: Alexey Torgashin

License: MPL 2.0 or LGPL

Usage

  • add win32menustyler to "uses"
  • in form's OnShow, call: MenuStyler.ApplyToForm(Self, False)
  • if it's needed to apply different colors later, change them in global var, and call MenuStyler.ApplyToForm(Self, True). Second param should be True here, this forces form's resize to repaint the menu bar.

Unit gives global var to change all theming details:

type
  TWin32MenuStylerTheme = record
    ColorBk: TColor;
    ColorBkSelected: TColor;
    ColorFont: TColor;
    ColorFontDisabled: TColor;
    CharCheckmark: Widechar;
    CharRadiomark: Widechar;
    FontName: string;
    FontSize: integer;
    IndentX: integer;
    IndentX2: integer;
    IndentY: integer;
  end;
var
  MenuStylerTheme: TWin32MenuStylerTheme;

Download

GitHub: https://github.com/Alexey-T/Win32MenuStyler