Lazarus

Programming => LCL => Topic started by: VTwin on May 24, 2021, 09:05:30 pm

Title: Cross Platform Form Height
Post by: VTwin 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.



Title: Re: Cross Platform Form Height
Post by: winni 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
Title: Re: Cross Platform Form Height
Post by: VTwin 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.
Title: Re: Cross Platform Form Height
Post by: winni 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.
Title: Re: Cross Platform Form Height
Post by: VTwin on May 24, 2021, 11:30:22 pm
For a PageControl, you have to account for ShowTabs, if true this adds additional pixels... :(
Title: Re: Cross Platform Form Height
Post by: winni 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


 
Title: Re: Cross Platform Form Height
Post by: trev 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 :)
Title: Re: Cross Platform Form Height
Post by: VTwin 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.
Title: Re: Cross Platform Form Height
Post by: VTwin 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.
TinyPortal © 2005-2018