RRUZ / vcl-styles-utils

Extend and improve the Delphi VCL Styles
https://theroadtodelphi.wordpress.com/
329 stars 115 forks source link

Menus DPI #195

Open justapps opened 7 years ago

justapps commented 7 years ago

Hi

I use Delphi Berlin and use the High DPI setting in my applications. To overcome the Delphi issue of not showing the top level menu with the right font size when switching between displays with different resolutions, I use a TToolBar and assign my menu to that. Today I included your units so I could using styles. It works but the font size isn't right when moving the forms between different dpi displays. I added this line below. That fixes the font but the MenuItem but I cannot figure out how to extend the menuitem width to accommodate the new size.

procedure TSysPopupStyleHook.MNSELECTITEM(var Message: TMessage); .. if Assigned(Font) then begin Canvas.Font := Font; Canvas.Font.Size := MulDiv(9, Application.ActiveForm.PixelsPerInch , 96); // here end;

justapps commented 7 years ago

I also did this in Vcl.Menus but others may not need to because I'm using the ImageList components from AlphaSkins to scale based on DPI:

function TMenuItem.GetDevicePPI: Integer;
begin
  Result := Screen.ActiveForm.PixelsPerInch;
end;
 procedure MeasureThemedMenuItem;
  const
    CheckMarkStates: array[Boolean {Enabled}, Boolean {RadioItem}] of TThemedMenu =
      ((tmPopupCheckDisabled, tmPopupBulletDisabled), (tmPopupCheckNormal, tmPopupBulletNormal));
    CAlignments: array[TPopupAlignment] of TTextFormats = (tfLeft, tfRight, tfCenter);
  var
    LMargins: TElementMargins;
    LSize, GlyphSize: TSize;
    LDrawStyle: TTextFormat;
  begin
    Height := 0;
    //Width := 0; //brent commented out

    // brent
    if (Screen.ActiveForm.PixelsPerInch = 96) then
      Width := 0
    else
      Width := MulDiv(30, LPPI, 96);
    // end brent
pyscripter commented 6 years ago

You can try the fix in #205