HiDPI Issue/Misunderstanding lazarus / 31-LCL ---------------------------------------------------------------------- Pascal · 2020-08-24 05:02 I recently changed my developent pc to use a 32"-4K-Monitor (144 PPI) with 150% scaling (Windows 10 2004). App is using LCL-Scaling. Now my app looks uggly/distorted on a machine with 24" FHD-Monitor (96 PPI) with 100% scaling. What am i doing wrong? My understanding is that LCL-scaling should handle this. BTW: If i use a multi monitor dev setup with these monitors and settings with the 4K display (144 PPI, 150%) beeing the main monitor, every form gets design time PPI of 144 even when i design/change it on the FHD monitor (96 PPI, 100%). Pascal ---------------------------------------------------------------------- wp · 2020-08-24 08:31 Is the "LCL Scaling" box checked in the project options? Is the "DPI awarness" combobox selected to a non-"off" value? Both options should be correct by default in Laz-trunk (your signature) and any Laz2.0+. ---------------------------------------------------------------------- Pascal · 2020-08-24 09:51 Yes, they are. ---------------------------------------------------------------------- jamie · 2020-08-24 14:44 designing in anything other than 96 has never worked for me.. ---------------------------------------------------------------------- Pascal · 2020-08-25 05:51 Quote from: jamie on August 24, 2020, 04:44:11 pmdesigning in anything other than 96 has never worked for me.. Well, then there is definitely something going wrong! This should work. Otherwise there is no need to store the DesignPPI in the form. ---------------------------------------------------------------------- trev · 2020-08-25 10:40 Quote from: Pascal on August 24, 2020, 07:02:44 amNow my app looks uggly/distorted on a machine with 24" FHD-Monitor (96 PPI) with 100% scaling. What am i doing wrong? My understanding is that LCL-scaling should handle this Did you: * Use anchors? * Enable the autosize property of the form's controls? See the Wiki Autosize/Layout. ---------------------------------------------------------------------- wp · 2020-08-25 12:27 I changed the display settings of my Win10 to 150% (144ppi) and designed the attached project. Everything at default settings, i.e. LCLScaling is checked, "Use manifest resource" is checked, "DPI awareness" is "On (True)", "Force DPI Scaling at design-time" is checked (in Form Editor settings).  There is also a compatibility setting somewhere in the file properties in Windows which activates some automatic scaling and this results in a blurry display - I do not use this. Running this project at 144ppi I see screenshot "design144ppi- run144ppi.png". After reverting back to 96 ppi I get screenshot "Design144ppi-run96ppi.png". Everything scales perfectly. Quote from: Pascal on August 25, 2020, 07:51:39 amWell, then there is definitely something going wrong! This should work. Otherwise there is no need to store the DesignPPI in the form. Dropping the unit of a dimensioned value results in non-sense. When you say "the distance is 1000" it is not clear whether this value is meters or light-years or milli-inches. The same is true with the pixels on the screen in the form designer. The DesignTimePPI is the unit of these numbers. Quote from: trev on August 25, 2020, 12:40:13 pmDid you: * Use anchors? * Enable the autosize property of the form's controls? This does not have to do anything with LCLScaling. LCL scaling is needed to take care of different screen resolutions. AutoSize is needed to take care of different font metrics. Switching resolution on the same OS is a case for LCL scaling, but switching between Windows at 96ppi to Linux/gtk2 at 96ppi is a case for AutoSize. ---------------------------------------------------------------------- Pascal · 2020-08-25 13:45 You project works well here, too. In the meantime i did some further tests and it mainly seems to be a problem with Laz.VirtulTreeView not working like expected (toVariableNodeHeight). I'll provide a demo when i find some time to investigate this further. Many thanks for your efforts so far! ---------------------------------------------------------------------- wp · 2020-08-25 15:15 Quote from: Pascal on August 25, 2020, 03:45:51 pmYou project works well here, too. In the meantime i did some further tests and it mainly seems to be a problem with Laz.VirtulTreeView not working like expected (toVariableNodeHeight). I'll provide a demo when i find some time to investigate this further. This sounds reasonable. This individual node height is specified in an event, OnMeasureItem, probably. When you specify a constant value here there is no way how Lazarus should know that the value needs to be scaled. In such a case you must do the scaling yourself, e.g. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.LazVirtualStringTree1MeasureItem(Sender: TBaseVirtualTree;  TargetCanvas: TCanvas; Node: PVirtualNode; var NodeHeight: Integer);var  h: Integer;  // Value which is correct for 96ppibegin  h := 25;  ANodeHeight := Scale96ToForm(h);  // scale the "25" to the current resolutionend; Or, better, specifiy the nodeheight in terms of text height because the font heights are automatically scaled and in fact, they are the basis of the entire LCL scaling thing: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.LazVirtualStringTree1MeasureItem(Sender: TBaseVirtualTree;  TargetCanvas: TCanvas; Node: PVirtualNode; var NodeHeight: Integer);const  margin = 4;  // pixels margin at top and bottom, seen at 96ppibegin  ANodeHeight := TargetCanvas.TextHeight('Tg') * 3 + Scale96ToForm(margin*2);  // 3 lines high, plus a scaled margin at top and at bottomend; ---------------------------------------------------------------------- Pascal · 2020-08-25 17:25 I use Scale96To.. in on MeasureItem. But the font height/size does not seem to adapt. ---------------------------------------------------------------------- wp · 2020-08-25 19:54 What exactly are you doing? Font.Size and Font.Height are different things. Font.Size is measured in typographic points and is the same in all resolutions (1pt = 1/72 inch). Font.Height is in pixels and increases with PPI because at higher PPI more pixels are required to arrive at the same height. (BTW. Font.Height is negative, you must use the abs value). ---------------------------------------------------------------------- Pascal · 2020-08-26 06:59 Sorry, didn't want to confuse you  These things do not work when changing dpi: - VTV: the header height changes accordingly but not the font height - VTV: the variable node height changes accordingly but not the font height - The font height of the main menu also does not change accordingly BTW: I am using anchor docking. ---------------------------------------------------------------------- wp · 2020-08-26 07:46 Did you change these fonts from default? I mean: is Font.Name <> default or is Font.Size <> 0? For this case a fix was added to trunk LCL scaling maybe half a year ago, and I see that the needed new method "FixDesignFontsPPI" is missing in VTV. I just uploaded a fix for it to Lazarus trunk. Of course, if you use another version from somewhere else the fix will not be contained, and you have to revert your fonts to default to fix the issue. ---------------------------------------------------------------------- Pascal · 2020-08-26 08:42 Just update lazarus trunk. With no luck. I use default fonts and size. I have placed a writeln in TVirtualTreeColumns.PaintHeader:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   with PaintInfo, TargetCanvas do  begin    // Use shortcuts for the images and the font.    Images := FHeader.FImages;    Font := FHeader.FFont;    if Font.Color = clDefault then      Font.Color := FHeader.Treeview.GetDefaultColor(dctFont);    writeln('paintheader: ', Font.PixelsPerInch);    .    .    .    DrawButtonText(TargetCanvas.Handle, String(ColCaptionText), TextRectangle, IsEnabled, DrawHot, DrawFormat, WrapCaption);    .    .    . Output is always 144. Even after changing monitor back to 96! So maybe FHeader.FFont has to get changed in TVTHeader.AutoAdjustLayout. ---------------------------------------------------------------------- wp · 2020-08-26 09:09 OK, before I start diving into details, another question: When you open Online Package Manager (menu "Package") does it scale correctly? I am asking because it uses the VTV which comes with Lazarus. ---------------------------------------------------------------------- Pascal · 2020-08-26 09:36 I've installed package OPM and it crashes lazarus when opening! ---------------------------------------------------------------------- Pascal · 2020-08-26 09:45 Did a full rebuild with -WC and doesn't crash now. OPM seems to scale okay. ---------------------------------------------------------------------- wp · 2020-08-26 09:51 Then I'd say that VTV is basically correct. Can you try to set up a simple project (just a VTV with some dummy nodes) which shows the scaling issue? Pack the .pas, llfm, lpi and lpr files into a common zip which you can upload here under "Attachement and other options". ---------------------------------------------------------------------- Pascal · 2020-08-26 10:05 Found the Problem: ---------------------------------------------------------------------- Pascal · 2020-08-26 10:07 If i use "on (True)" it works as expected. But what is the difference and shouldn't all of the "on" options work? ---------------------------------------------------------------------- Pascal · 2020-08-26 10:13 Quote from: wp on August 26, 2020, 09:46:55 amI just uploaded a fix for it to Lazarus trunk. Shouldn't FixDesignFontsPPI be "override" and be in the public section? See attached patch. ---------------------------------------------------------------------- wp · 2020-08-26 10:25 Correct. Can you try? But I think the header's FixDesignFontsPPI should not be called from TVTHeader.AutoAdjustLayout because it is already called from the tree's FixDesignFontsPPI. [EDIT] To be more specific: TVTHeader.FixDesignFontsPPI cannot be "override" because TVTHeader inherits from TPersistent, but FixDesignFontsPPI is introduced for TControl. TVTBaseVirtualTree.FixDesignFontsPPI is inherited from TControl and thus must be "override". It should be "public" (I put it into "protected" because I copied from TCustomGrid in grids.pas where it is in "protected" which seems to be wrong). ---------------------------------------------------------------------- Pascal · 2020-08-26 12:40 Quote from: wp on August 26, 2020, 12:25:19 pmCan you try?What exactly? Quote from: wp on August 26, 2020, 12:25:19 pmBut I think the header's FixDesignFontsPPI should not be called from TVTHeader.AutoAdjustLayout because it is already called from the tree's FixDesignFontsPPI.Yes, as the DPI awareness mode caused the problem. Quote from: wp on August 26, 2020, 12:25:19 pmTo be more specific: TVTHeader.FixDesignFontsPPI cannot be "override" because TVTHeader inherits from TPersistent, but FixDesignFontsPPI is introduced for TControl. TVTBaseVirtualTree.FixDesignFontsPPI is inherited from TControl and thus must be "override". It should be "public" (I put it into "protected" because I copied from TCustomGrid in grids.pas where it is in "protected" which seems to be wrong). Yes sure, see attachment of previous post. ---------------------------------------------------------------------- Pascal · 2020-08-26 13:43 corrected patch. ---------------------------------------------------------------------- wp · 2020-08-26 14:53 Quote from: Pascal on August 26, 2020, 02:40:09 pmQuote from: wp on August 26, 2020, 12:25:19 pmCan you try?What exactly? Sorry I did not notice that you had solved the issue by selecting "on" in the "DPI Awareness". The other "on" settings are meant for multi-monitor set-up, like in your situation: when you have several monitors, each of them with different resolution, then a form will be scaled when it is dragged onto another monitor. Since I only have a single monitor I could never test this feature (BTW - I am not the author of LCL scaling, so I am not sure whether I am not talking nonsense here...); I also don't know whether this features works correctly in the form designer of Lazarus. If you want to check it yourself you should first write a simple demo with a single form and simple standard components (or use my demo of reply #6, but adjust the "DPI awareness"); at runtime, drag the form on the other monitor. Write a bug report if the form does not scale. As for the form designer, open the project lazarus.lpi (in folder "ide" of your lazarus installation - make a backup copy of lazarus.exe), set its "DPI awareness" to "Vista-8: on, 8.1+: per monitor" or "Vista-8:on; 8.1-10+: per monitor/V2" (in fact, I don't even know what V2 is...) and recompile the IDE (it is built by default with the "on" setting, i.e. the "per monitor" feature should be off. In the new IDE, drag a form in design mode onto the other monitor. Does it rescale and update the DesigntimePPI accordingly? If not report as an error of the IDE. ---------------------------------------------------------------------- Pascal · 2020-08-26 19:15 Quote from: wp on August 26, 2020, 04:53:47 pmin fact, I don't even know what V2 is...https://docs.microsoft.com/en- us/windows/win32/hidpi/high-dpi-desktop-application-development-on- windows ---------------------------------------------------------------------- Pascal · 2020-08-27 08:21 Quote from: wp on August 26, 2020, 04:53:47 pmIf you want to check it yourself you should first write a simple demo with a single form and simple standard components (or use my demo of reply #6, but adjust the "DPI awareness"); at runtime, drag the form on the other monitor. Write a bug report if the form does not scale With the simple "on (True)" everything works as expected when i move the form to a monitor with other PPI! So why do we need that many options? And: V2 does not work as expected! ---------------------------------------------------------------------- PascalDragon · 2020-08-27 11:59 Quote from: Pascal on August 27, 2020, 10:21:45 amWith the simple "on (True)" everything works as expected when i move the form to a monitor with other PPI! So why do we need that many options? And: V2 does not work as expected! Because Windows provides them. And if I want my application to work on older Windows I can't select e.g. the V2 setting, but must instead use e.g. Vista and enable the per-monitor one in code. Also it could be that the user creates an application without the LCL, then all settings need to be available as well, because the user's code might not handle per-monitor DPI changes. ---------------------------------------------------------------------- Pascal · 2020-08-27 13:22 Quote from: PascalDragon on August 27, 2020, 01:59:30 pmQuote from: Pascal on August 27, 2020, 10:21:45 amWith the simple "on (True)" everything works as expected when i move the form to a monitor with other PPI! So why do we need that many options? And: V2 does not work as expected! Because Windows provides them. And if I want my application to work on older Windows I can't select e.g. the V2 setting, but must instead use e.g. Vista and enable the per-monitor one in code. Also it could be that the user creates an application without the LCL, then all settings need to be available as well, because the user's code might not handle per-monitor DPI changes. Okay, but then we need to make scaling work with those settings enabled. Which is not the case if PM_V2 is enabled atm. See https://bugs.freepascal.org/view.php?id=32017 ---------------------------------------------------------------------- BrunoK · 2023-06-11 15:53 Where are we on this topic. WIN10, Lazarus trunk, FPC 3.2.2 System - laptop 13.3", resolution 2560x1600.  Size of text scaled  by 225% as main screen 216 DPI. - secondary 15", resolution 1280x1024.  Size of text scaled  by 100% as main screen 96 DPI. There are similar troubles as those described by Pascal on lazarus for AllCompilerOptions.pas with line overlapping.  So I thougt, OK, look thru it and found a very reasonable way to dimension the lines, using the Edit in the top panel as sizing reference. That worked very well, on both screens. l was happy except that it messed up the design time sizing of both the top panel and the bottom button frame, so I could not get a stable design time form, and, as may be expected on the resulting lazarus.exe Is something being done to solve this problem ?