Recent

Author Topic: [SOLVED] Adjust form height to the position of the inner control  (Read 1756 times)

furious programming

  • Hero Member
  • *****
  • Posts: 858
On the form is standard TPageControl with one sheet, and inside this sheet is the label and the button. The label size is depend of its content (words are wrapped), and the offset between label and button is fixed thanks to the AnchorSide.


My question is — how to adjust the size of the form, to keep 16px height offset between bottom od the button and the bottom of the sheet, and keep 12px between the bottom of the TPageControl and the bottom of the form? In the attachment is the expected result.

Is there a way to set some properties or must I do it in the code? I checked the Anchor Editor, but it does not allow to do it. I tried to calculate the absolute position of the button and then set the size of the form, but everytime I got wrong form height.


To visualize what I need and shorten the problem to the minimum, I created a simple project — see the second attachment. To change the caption of the label, just append the value of the edit field (because the form size originally is fixed and the user can't change it).

Thanks in advance for help.
« Last Edit: July 11, 2019, 12:22:08 am by furious programming »
Lazarus 3.2 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on an acrade, action/adventure game in retro style (pixelart), programming the engine and shell from scratch, using Free Pascal and SDL. Release planned in 2026.

wp

  • Hero Member
  • *****
  • Posts: 11916
Auto-Size the form (but do this only at the end of the following steps).
  • Anchor the PageControl to the form, but leave the right side unanchored. Otherwise the AutoSize would squeeze the the pagecontrol to minimum constraints.
  • Anchor left, top and right sides of the label to the TabSheet. Provide adequate margins.
  • Anchor left, top and right sides of the edit to the label
  • Anchor top and right sides of the button to the edit
  • Specify the distance between button and lower tabsheet edge as bottom margin of the button
  • Set the form's AutoSize to true - you will the effect later at runtime.

furious programming

  • Hero Member
  • *****
  • Posts: 858
Thank you very much @wp — it works perfectly.

I had to skip something while setting up AnchorSide, because I tried to do it in many ways and every time something did not work. I need to learn more about this functionality — sometimes I can't understand how this damn thing works. 8)


But I have one question — the label should have a 16px offset on the left and right, but 24px on top. You set the 24px offset for each side. Is this mandatory? If yes, I can fix this by setting fixed width in the Constraints property, but I'm just curious.
« Last Edit: July 11, 2019, 12:27:42 am by furious programming »
Lazarus 3.2 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on an acrade, action/adventure game in retro style (pixelart), programming the engine and shell from scratch, using Free Pascal and SDL. Release planned in 2026.

wp

  • Hero Member
  • *****
  • Posts: 11916
I need to learn more about this functionality — sometimes I can't understand how this damn thing works. 8)
Me too, but the more I use and know it the more I like it. In fact, the Anchor Editor is one of the best design tools within the Lazarus environment.

Quote
the label should have a 16px offset on the left and right, but 24px on top. You set the 24px offset for each side. Is this mandatory?
No, you can select any values. Test them and see what happens. For example I added the left margin of the button because without it AutoSize would move the button to the very edge of the tabsheet when the edit text is changed.

The only problem is that with the circular anchor conditions which sometimes are not very clear and difficult to resolve. Try to work from left to right and top to bottom whenever possible.
« Last Edit: July 11, 2019, 01:02:25 am by wp »

furious programming

  • Hero Member
  • *****
  • Posts: 858
Re: [SOLVED] Adjust form height to the position of the inner control
« Reply #4 on: July 11, 2019, 01:05:19 am »
In fact, the Anchor Editor is one of the best design tools within the Lazarus environment.

Yep, this is a great tool, for me too. I remember my old projects made in Delphi 7 — every time I had to design the form, add some controls and change the layout, I had to relocate controls manually in design time and write a code to made an automatic mechanism to set offsets between component at runtime. And with AnchorSide, just few clicks is needed and all controls behave as I want — both at design time and runtime.

But I would like to have one function in this tool — component picker. Instead of choosing the control from combobox, I could just turn on the picker and click on the control in the form. This would speed up and simplify the configuration of components, especially when the form have a lot of components.

Quote
No, you can select any values. Test them and see what happens.

Ok, I will play with it. Thank you again for your help.
« Last Edit: July 13, 2019, 03:56:02 am by furious programming »
Lazarus 3.2 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on an acrade, action/adventure game in retro style (pixelart), programming the engine and shell from scratch, using Free Pascal and SDL. Release planned in 2026.

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: [SOLVED] Adjust form height to the position of the inner control
« Reply #5 on: July 11, 2019, 01:09:47 am »
But I would like to have one function in this tool — component picker. Instead of choosing the control from combobox, I could just turn on the picker and click on the control in the form. This would speed up and simplify the configuration of components, especially when the form have a lot of components.
You mean: a picker instead of (or: in addition to) the comboboxes? Yes, sounds interesting. Why don't you write a feature request on bugtracker? Maybe somebody picks up this idea.

furious programming

  • Hero Member
  • *****
  • Posts: 858
Re: [SOLVED] Adjust form height to the position of the inner control
« Reply #6 on: July 11, 2019, 01:12:48 am »
You mean: a picker instead of (or: in addition to) the comboboxes?

Yes, picker in addition to the comboboxes.

Quote
Why don't you write a feature request on bugtracker? Maybe somebody picks up this idea.

Because I came up with this idea during writing previous posts and testing your demo. 8)
Lazarus 3.2 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on an acrade, action/adventure game in retro style (pixelart), programming the engine and shell from scratch, using Free Pascal and SDL. Release planned in 2026.

 

TinyPortal © 2005-2018