Recent

Author Topic: Aligning two buttons (etc.) relative to the middle of a form  (Read 1423 times)

MarkMLl

  • Hero Member
  • *****
  • Posts: 3235
Aligning two buttons (etc.) relative to the middle of a form
« on: August 28, 2021, 09:04:40 am »
When a form has "Cancel" and "OK" buttons, it's easy enough to align them to the bottom using the anchor editor.

How does one align them horizontally, particularly if the form can be resized? Is there some datum running up the middle of the form to which the anchor editor can refer, or is the best way to put e.g. a zero-width bevel in the middle of the form as a dummy control relative to which others can be anchored?

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

MarkMLl

  • Hero Member
  • *****
  • Posts: 3235
Re: Aligning two buttons (etc.) relative to the middle of a form
« Reply #1 on: September 20, 2021, 10:44:01 am »
I ended up using a zero-width bevel running up the middle of the form as a construction line. Not sure whether there's a better way using some combination of anchors etc.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

howardpc

  • Hero Member
  • *****
  • Posts: 3783
Re: Aligning two buttons (etc.) relative to the middle of a form
« Reply #2 on: September 20, 2021, 11:37:37 am »
Code: Pascal  [Select][+][-]
  1. okButton.AnchorsideLeft.Control := theForm;
  2. okButton.AnchorsideLeft.Side := asrCenter;
  3. okButton.BorderSpacing.Left{or .Right as needed} := distanceFromCenter;
ought to do it.

You could also use the AnchorsideRight property, of course, but by default a control's Anchors already includes akLeft.

MarkMLl

  • Hero Member
  • *****
  • Posts: 3235
Re: Aligning two buttons (etc.) relative to the middle of a form
« Reply #3 on: September 20, 2021, 12:05:25 pm »
Thanks, I'll check that.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

wp

  • Hero Member
  • *****
  • Posts: 8885
Re: Aligning two buttons (etc.) relative to the middle of a form
« Reply #4 on: September 20, 2021, 01:10:06 pm »
Code: Pascal  [Select][+][-]
  1. okButton.AnchorsideLeft.Control := theForm;
  2. okButton.AnchorsideLeft.Side := asrCenter;
  3. okButton.BorderSpacing.Left{or .Right as needed} := distanceFromCenter;
ought to do it.

You could also use the AnchorsideRight property, of course, but by default a control's Anchors already includes akLeft.
In my experience this is not working. "Centered is centered" and there is no way to move the centered control, neither with the left nor with the right BorderSpacing,

I always follow the ideas already proposed by MarkMLI: add a TBevel to the container, set its Shape to bsSpacer to make it invisible and set its width to the distance that the two buttons on each side should have. Anchor the right side of the left button to the left side of the bevel, and anchor the left side of the right button to the right side of the bevel.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

howardpc

  • Hero Member
  • *****
  • Posts: 3783
Re: Aligning two buttons (etc.) relative to the middle of a form
« Reply #5 on: September 20, 2021, 02:29:06 pm »
Yes, wp, you are quite correct.
I should have tried out my thought in practice before suggesting something that does not work.

MarkMLl

  • Hero Member
  • *****
  • Posts: 3235
Re: Aligning two buttons (etc.) relative to the middle of a form
« Reply #6 on: September 20, 2021, 02:43:19 pm »
And I should have checked before agreeing with you :-)

Actually, I think that the IDE actively warns that border control is inoperative with certain combinations.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Leledumbo

  • Hero Member
  • *****
  • Posts: 8386
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Aligning two buttons (etc.) relative to the middle of a form
« Reply #7 on: September 21, 2021, 07:25:22 am »
Not sure if the attached project is what you expected, but basically just play around with ChildSizing.

MarkMLl

  • Hero Member
  • *****
  • Posts: 3235
Re: Aligning two buttons (etc.) relative to the middle of a form
« Reply #8 on: September 21, 2021, 06:49:54 pm »
Not sure if the attached project is what you expected, but basically just play around with ChildSizing.

OK, I think I see what you've done... ChildSizing on the form/panel/groupbox etc. which then tells the children where to stand, rather than giving each child an anchor. I note that this is described at https://wiki.lazarus.freepascal.org/Autosize_/_Layout#Precedence_rules, which has been on my screen pending time to read it for the last couple of days.

I note the discussion at https://wiki.lazarus.freepascal.org/LCL_AutoSizing, which makes it sound pleasantly deterministic. In the past people have looked at things like https://constraints.cs.washington.edu/deltablue/ for UI layout, but the always appeared to come with health warnings.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018