Recent

Author Topic: Cross Platform Form Height  (Read 2489 times)

VTwin

  • Hero Member
  • *****
  • Posts: 1037
  • Former Turbo Pascal 3 user
Cross Platform Form Height
« on: May 24, 2021, 09:05:30 pm »
I develop on Windows, Mac, and Linux. The Anchor Editor is very helpful in placing controls. However, selecting a Form height that works on all platforms is challenging, as the Form bottom can not be anchored to a contained control.

Currently I use a class that determines the bottom of the lowest control, typically an OK button, and then set the Form Height to that plus a margin. This is done in the OnShow handler and works pretty well, but seems a bit of a kludge.

I wonder if I am missing something obvious.



“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.0
macOS 10.13.6: Lazarus 2.0.12 (64 bit Cocoa)
Ubuntu 18.04.3: Lazarus 2.0.12 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.12 (64 bit on VBox)

winni

  • Hero Member
  • *****
  • Posts: 2507
Re: Cross Platform Form Height
« Reply #1 on: May 24, 2021, 09:38:49 pm »
Hi!

No, you dont overlook something obvious.

For this item I am not up to date, but there were times when in Linux Form.Height was the same as client.height.  So you needed the height of the TitleBar. That could be retrieved with this hack:

Code: Pascal  [Select][+][-]
  1. function TitleBarHeight (Form: TForm) : Integer;
  2. var ws : TWindowState;
  3.     oldheight : integer;
  4.     count : integer = 0;
  5. begin
  6. ws := Form.WindowState;
  7. if ws <> wsMaximized then
  8.   begin
  9.    oldHeight := Form.Height;
  10.    Form.WindowState := wsMaximized;
  11.    repeat
  12.    Application.ProcessMessages; // let Form expand
  13.    // but one ProcessMessages may be not enough!
  14.    inc (Count);
  15.    until (Form.Height<>oldHeight) or (count >= 10);
  16.    end;
  17. result := Form.Monitor.WorkAreaRect.Height -Form.Height;
  18. if ws <> wsMaximized then
  19.   begin
  20.   Form.WindowState := ws; // and back again
  21.   Application.ProcessMessages;
  22.   end;
  23. end;

Winni

VTwin

  • Hero Member
  • *****
  • Posts: 1037
  • Former Turbo Pascal 3 user
Re: Cross Platform Form Height
« Reply #2 on: May 24, 2021, 10:06:51 pm »
I don't currently have a problem with the TitleBar height, possibly a few years back if I recall.

It is even more difficult dealing with WinControls, such as PageControls. I wrote a procedure to get the maximum control bottom, looping through all the TabSheets, but it is not working well. Currently I'm just checking them on all platforms and calling it "good enough" if all the controls are visible. Linux usually requires the most space.

It would be nice to have a general solution that could adjust a WinControl height to enclose all controls, but perhaps that does not exist.
« Last Edit: May 24, 2021, 10:09:06 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.0
macOS 10.13.6: Lazarus 2.0.12 (64 bit Cocoa)
Ubuntu 18.04.3: Lazarus 2.0.12 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.12 (64 bit on VBox)

winni

  • Hero Member
  • *****
  • Posts: 2507
Re: Cross Platform Form Height
« Reply #3 on: May 24, 2021, 10:14:29 pm »
Hi!

Hack around the world:

Leave a space of let's say 10 Pixel to the borders. That must be enogh.
You can make a nice decoration for this border.

Or for testing reasons a pixel meter: a short line at every second pixel and a long one at 10 pixel from the border.

Winni

PS.: With a PageControl and some Tabsheets there are at least with Linux some Pixels in the Nirvana.
« Last Edit: May 24, 2021, 10:16:54 pm by winni »

VTwin

  • Hero Member
  • *****
  • Posts: 1037
  • Former Turbo Pascal 3 user
Re: Cross Platform Form Height
« Reply #4 on: May 24, 2021, 11:30:22 pm »
For a PageControl, you have to account for ShowTabs, if true this adds additional pixels... :(
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.0
macOS 10.13.6: Lazarus 2.0.12 (64 bit Cocoa)
Ubuntu 18.04.3: Lazarus 2.0.12 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.12 (64 bit on VBox)

winni

  • Hero Member
  • *****
  • Posts: 2507
Re: Cross Platform Form Height
« Reply #5 on: May 24, 2021, 11:56:10 pm »
For a PageControl, you have to account for ShowTabs, if true this adds additional pixels... :(

Hi!

Yes I know.

But you should not have brought me to the crazy idea to use a PageConrol without tabs. Never did that before.
Suddenly appears a mini bug:

Exact at the x-position where before the now disabled Tab should appear, the image on the tabsheet is erased. Only on startrup.  Not a big problem because a invalidate does the job, but ....

Proof in attachment.

I return quick back to enable the tabs before more bugs appear ....

Winni


 

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1509
  • Former Delphi 1-7, 10.2 user
Re: Cross Platform Form Height
« Reply #6 on: May 25, 2021, 01:02:43 am »
I've been compiling an application for macOS, Linux, Windows and FreeBSD and just use an IFDEF for form height for each OS. Simples :)
Lazarus 2.1 r65061 FPC 3.3.1 r49223 macOS 10.14.6 Xcode 11.3.1
Lazarus 2.3 r65500 FPC 3.3.1 r49634 macOS 11.5 aarch64 Xcode 12.5.1
Lazarus 2.1 r61574 FPC 3.3.1 r42318 FreeBSD 12.1 amd64 VMware VM
Lazarus 2.1 r61574 FPC 3.0.4 Ubuntu 20.04 Parallels VM
Lazarus 2.0.10 FPC 3.2.0 Win10 Parallels VM

VTwin

  • Hero Member
  • *****
  • Posts: 1037
  • Former Turbo Pascal 3 user
Re: Cross Platform Form Height
« Reply #7 on: May 25, 2021, 03:21:58 am »
I've been compiling an application for macOS, Linux, Windows and FreeBSD and just use an IFDEF for form height for each OS. Simples :)

Thanks. That works, if not elegant. I've got dozens of dialogs, so it is cumbersome.

For dialogs without PageControls, my solution works ok, so perhaps I can limit this to the few that contain PageControls.
« Last Edit: May 25, 2021, 03:27:51 am by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.0
macOS 10.13.6: Lazarus 2.0.12 (64 bit Cocoa)
Ubuntu 18.04.3: Lazarus 2.0.12 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.12 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 1037
  • Former Turbo Pascal 3 user
Re: Cross Platform Form Height
« Reply #8 on: May 27, 2021, 04:16:57 pm »
@Winni

I have a PageControl with about 25 TabSheets. They are selected using a TreeView instead of tabs, like the Lazarus IDE Options dialog, so I hide the tabs.
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.0
macOS 10.13.6: Lazarus 2.0.12 (64 bit Cocoa)
Ubuntu 18.04.3: Lazarus 2.0.12 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.12 (64 bit on VBox)

 

TinyPortal © 2005-2018