Forum > Win32/64

Saving Form sizes using Windows DPI aware

<< < (2/4) > >>

wp:
I can't say much about Mac, I only remember a discussion on the mailing list where it was mentioned that its default resolution is 72 dpi but LCL assumes 96 dpi. This would make a factor 96/72 = 1.33. But the discrepancy that you observe is larger, isn't it?

But without seeing what you are doing exactly it is not possible to tell whether this really is an issue of LCL scaling.

VTwin:
I think I figured it out this morning, it was making me crazy. The weird behavior started after I switched on LCL scaling, everything worked fine before.

I have methods to set and get preferences, which include the Form position, size, column widths, etc.

I was calling GetPrefs in FormHide, which saved the settings perfectly in display coordinates. But I was calling SetPrefs in FormCreate, this read the preferences fine, but interpreted them as design coordinates, which were rescaled before showing the form. %)

The solution, probably obvious in retrospect, was to move SetPrefs from FormCreate to FormShow, after the Form has been rescaled to display coordinates. It seems to be working.

I think you (wp) may be right about the 96 vs 72 on the Mac, and maybe that is why the (shrinking) scaling was occurring. However, the form design scaling is the same on Mac and Linux (e.g., anchor spacings are the same), but is rescaled on Windows. Actually, I may have found an answer to that (my second question). There is a "Force DPI scaling in design time" option, I'll try turning that off to see if I can design in 96 DPI on all platforms.


EDIT: This means I do not need to call:

sw := Self.ScaleFormTo96(Self.Width);
Self.Width := Self.Scale96ToForm(sw);

that was a red herring.

VTwin:

--- Quote from: PascalDragon on July 24, 2019, 09:36:29 am ---I've reported a similar issue with the SQLDBRest demos provided with Lazarus.

--- End quote ---

Is it possible to check if they are setting form size in FormCreate?

winni:
Yes, they do. If you follow the Tform.create you'll reach the class TCustomDesignControl:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- constructor TCustomDesignControl.Create(TheOwner: TComponent);begin  inherited Create(TheOwner);   FScaled := True;  FDesignTimePPI := 96;  FPixelsPerInch := FDesignTimePPI;  if Application.Scaled then    Font.PixelsPerInch := FDesignTimePPI;  end; 
There are always problems with DPI aware.

Winni

wp:

--- Quote from: winni on July 24, 2019, 05:54:52 pm ---There are always problems with DPI aware.

--- End quote ---
Unfortunately, many third-party components were written long before Lazarus came up with LCL scaling, and since many of them are no longer maintened there is almost no chance that this will change. But don't blame LCL scaling for this.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version