Recent

Author Topic: Cross Platform Sizing of Dialog Boxes  (Read 2760 times)

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Cross Platform Sizing of Dialog Boxes
« on: May 06, 2015, 07:59:04 am »
I have several applications that I compile for Windows, Linux, and OS X. For dialog boxes, and Forms in general, I use the Anchor Editor to keep Controls spaced properly on all platforms (as 4 or 6 pixels vertically between Checkboxes).

This works great, but the Form does not resize to accommodate the Controls, the bottom ones are off the Form and hidden, or there is too much space at the bottom. For example, the height of a Linux Checkbox is much greater than an OS X Checkbox, so if I design in OS X the Cancel and OK buttons are hidden in Linux.

I have been setting the dialog heights using IFDEFs for each system, but I am thinking there must be a better way. I must be missing something simple. I'd appreciate any help. Thanks!

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

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Cross Platform Sizing of Dialog Boxes
« Reply #1 on: May 06, 2015, 09:48:06 am »
My current approach is as follows:
Use anchors (like you do) to keep controls in their correct relative positions.
When you show the form, calculate the needed width and height based up the dimensions of the controls that are at the bottom and right hand side of the form.

On Windows this works in FormShow, on Linux it does not, because at that stage the actual dimensions of the controls (as they appear on the screen) are not known yet.
So, for non-windows platform I have a Application.QueueAsyncCall() in FormShow that calls the procedure that calculates the correct dimensions the form has to have.

Theoretically (at least I think) TForm.Autosize should take care of this (?), but it didn't work for me.

Bart

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: Cross Platform Sizing of Dialog Boxes
« Reply #2 on: May 06, 2015, 10:52:21 am »
Bart,

Many thanks. I will try the Autosize, and then probably a calculate the height as you suggest. It would be nice if the anchor editor could anchor the form bottom to a control.

I currently have my dialogs call procedures from a "TDialogState" advanced record that sets and resets the location (Init in Create, GetState in Show, and SetState in Hide). It also checks the controls, sets OS X buttons to 22 height, swaps OK and Cancel positions, and increases the height of Linux StaticText (from 17 to 21 I think) so the bottoms are not cut off, etc.

I could do the calculation there, or maybe better, as you suggest, to do it in a Application.QueueAsyncCall().

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

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: Cross Platform Sizing of Dialog Boxes
« Reply #3 on: May 07, 2015, 08:11:38 am »
Bart,

Thanks again, that worked out well. If it helps anyone, my TDialogState uses:

Code: [Select]
function TDialogState.GetMaxY(dlg: TForm): integer;
var
  c: TControl;
  i, n, max, y: integer;
begin
  max := 0;
  n := dlg.ControlCount;
  for i := 0 to n-1 do begin
    c := dlg.Controls[i];
    if c is TImage then continue; // background
    y := c.Top + c.Height;
    if y > max then
      max := y;
  end;
  result := max;
end;

and then set the dialog height to ymax+12. Setting the height in TForm.FormCreate seems to work in Windows and OS X, and in Linux worked in TForm.FormShow. I did not use QueueAsyncCall.

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

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: Cross Platform Sizing of Dialog Boxes
« Reply #4 on: May 24, 2015, 03:11:12 pm »
I just tried to apply the same method to GroupBoxes and PageControls without luck. Has anyone had success in cross-platform resizing of these?

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

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

 

TinyPortal © 2005-2018