Recent

Author Topic: Mac Lazarus Compile: How to stop the shifting of Graphics/GUI ?  (Read 4758 times)

Boleeman

  • Hero Member
  • *****
  • Posts: 833
Mac Lazarus Compile: How to stop the shifting of Graphics/GUI ?
« on: January 05, 2025, 02:09:00 am »
Spent yesterday installing Lazarus on a Mac Book Pro i5 x86_x64 with Sierra (with Cocoa used in XCode) and finally got it to compile.
Noticed that the graphics on the Mac compiled programs and the controls have shifted positions from the Windows 10 compiled versions. When not compiled (in design mode) the forms appear identical to the windows versions, but when compiling the scaling and positioning is changing.

How do I keep the scaling the same ?
The positioning on the Mac compiled programs are somehow changing in erratic ways

I have set High Dpi in the settings.

As shown in the attached png pictures:

Sometimes the rendered image on the TPaintbox becomes too big, yet everything on the TPanel is OK (NFlakes program)
Sometimes the rendered picture on the Paintbox is shifted by the width of the TPanel when a TPanel is on the side (Overlapping flake)
Sometimes the TForm is a bit lower in height by the size of the titlebar (curly tree).

On Windows 10 all of those are well scaled, but after compiling on a Mac, bits and pieces change in size or position.

I have been manually resizing things on the Mac, but surely there is a better (programmatic) way of adjusting things to make the GUI consistent, regardless of whether it is run on a Windows 10 or a Mac computer ?

I read here https://forum.lazarus.freepascal.org/index.php/topic,49159.0.html that HighDPI Mode LCL automatically resize form Width and Height based on form PixelsPerInch property. They also suggested to scale to ScaleScreenTo96 (Not sure why/)

grpbReservations.Width := ScaleScreenTo96( grpbReservations.Width );
pnlSettledGuest.Width := ScaleScreenTo96( pnlSettledGuest.Width );




« Last Edit: January 05, 2025, 02:27:52 am by Boleeman »

zeljko

  • Hero Member
  • *****
  • Posts: 1719
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Mac Lazarus Compile: How to stop the shifting of Graphics/GUI ?
« Reply #1 on: January 05, 2025, 02:39:08 am »
Afaik, forms designed on windows with dpi > 96 writes into lfm DesignTimePPI, when such form is loaded eg on mac then it's size and font should be automatically recalculated to 96 dpi (which is default on mac cocoa afair). If your forms aren't scaled well then something is wrong with HighDpi recalculations on lazarus. eg Qt5 (from Qt5 5.14 up) and Qt6 just leaved DPI away on all platforms and uses only scaling factors. Eg windows dpi 192 becomes scaling factor 2 with mentioned qt versions, and inside app dpi is always 96.
If you have example project attach it here, I'll take a look.

Boleeman

  • Hero Member
  • *****
  • Posts: 833
Re: Mac Lazarus Compile: How to stop the shifting of Graphics/GUI ?
« Reply #2 on: January 05, 2025, 06:21:28 am »
Thanks zeljko for your reply.

Attached is the NFlakes program as a test program written on a Windows 10 computer.

In the Windows 10 environment it appears well scaled, but in Mac it renders as a bigger size on the TPaintbox.

It almost appears that the TForm of the Mac version takes on the width of the TPanel (as the controls seem to be spaced out similarly in both cases on the TPanel) but adjusts the height of the TForm to a shorter height.

Or is it that the curve on the TPaintbox is being drawn behind the TPanel (at the top) , with a larger radius size (so perhaps the radius distance TSpinedit needs to be somehow adjusted for the scaling of the Mac screen dpi) ?

I also noticed on the Mac that the form was at it's largest size (it could not be resized any more).

Do we perhaps need to find the PPI for the Windows form/TPainbox and then set the same for the Mac form/Paintbox ?

Looking at the png images, what appears as an almost square form in WIndows 10 looks quite rectangular in the Mac environment.

The last png sort of shows what I mean:
The TPaintbox on the Mac version is being cropped in the height and the width by the amount of the TPanel width.
« Last Edit: January 05, 2025, 07:15:12 am by Boleeman »

Boleeman

  • Hero Member
  • *****
  • Posts: 833
Re: Mac Lazarus Compile: How to stop the shifting of Graphics/GUI ?
« Reply #3 on: January 05, 2025, 07:23:43 am »
And here is the Overlapping Snow Flake with WIndows 10 screenshot and the source.

A possible solution for the Mac version of the Overlapping flake fractal seems to be to reduce the height and the width of the TPaintbox on the Mac form by the value of the width of the TPanel. Then adjust the radius value of the curve by some sort of scaled reduction coefficient.
« Last Edit: January 05, 2025, 07:46:07 am by Boleeman »

zeljko

  • Hero Member
  • *****
  • Posts: 1719
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Mac Lazarus Compile: How to stop the shifting of Graphics/GUI ?
« Reply #4 on: January 05, 2025, 10:29:34 am »
Here is screenshoot of your project on linux-qt5, system with 96dpi. Seem that it's same problem like on mac when scaling from DesignTimePPI = 120dpi (as it is in your unit1.lfm) to 96 dpi.

zeljko

  • Hero Member
  • *****
  • Posts: 1719
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Mac Lazarus Compile: How to stop the shifting of Graphics/GUI ?
« Reply #5 on: January 05, 2025, 10:48:27 am »
According to form's width/height written into lfm it is perfectly scaled to 96 dpi, also TPaintBox is also scaled ok. That part is just fine. When you change flake size from 420 to 336 which is exactly (420/120) * 96 from 120 to 96 then everything works ok as I can see. According to that, see in form create if you can catch old DesignTimePPI and if it's so calc that value to current screen.pixelsperinch (mac).

zeljko

  • Hero Member
  • *****
  • Posts: 1719
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Mac Lazarus Compile: How to stop the shifting of Graphics/GUI ?
« Reply #6 on: January 05, 2025, 11:01:25 am »
Here is solution for you (first attach FormCreate to OnCreate of form), then look into attached image for possible solution.

Boleeman

  • Hero Member
  • *****
  • Posts: 833
Re: Mac Lazarus Compile: How to stop the shifting of Graphics/GUI ?
« Reply #7 on: January 05, 2025, 01:27:07 pm »
zeljko, thanks for working things out.
I tried putting in form OnCreate SpinEditSize.Value := ScaleX(420, 120); but it was not setting that value in the TSpinedit.
Also tried SpinEditSize.Value := 336; in form OnCreate but the spinedit value still remained at the 420 value.

In the end I manually put the value 336 in the properties of SpinEditSize but the height of the form was still too big for the screen. The width was OK but the Form height needed was too big for the Mac screen.

I ended up reducing the width of the form and the paintbox to 700 pixels and setting SpinEditSize.Value := 296; which gave a reasonable view of the whole form on the Mac Book Pro screen (as shown in the attached png)
« Last Edit: January 05, 2025, 01:31:24 pm by Boleeman »

zeljko

  • Hero Member
  • *****
  • Posts: 1719
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Mac Lazarus Compile: How to stop the shifting of Graphics/GUI ?
« Reply #8 on: January 05, 2025, 11:47:50 pm »
Your FormCreate() event isn't attached to form, that's why it does not work. Select form, in Object inspector press tab Events, goto OnCreate, click combo arrow and choose FormCreate, now save and build your app. Now code in FormCreate() will be executed.

Boleeman

  • Hero Member
  • *****
  • Posts: 833
Re: Mac Lazarus Compile: How to stop the shifting of Graphics/GUI ?
« Reply #9 on: January 06, 2025, 03:02:36 am »
Thanks again zeljko.

You were correct. The FormCreate procedure was there but for some reason the event was not created in Object Inspector. Also I did not realize on a Mac that the image goes behind the TPanel when the height of the form is resized (diffferent behavior to a Windows form).

On Mac Lazarus, does anyone know how to align the tops of selected controls?
(I know how to do it in Windows Laz. but in Mac Laz. I could not find where it was).
« Last Edit: January 06, 2025, 03:05:11 am by Boleeman »

 

TinyPortal © 2005-2018