Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-05

AlignTop/AlignBottom issue

7 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Giuliano Colla

AlignTop and AlignBottom do not appear to behave as they should.

When you have several controls contained in another control, you would expect that each AlignTop or AlignBottom would stack the control in the first free position: with AlignBottom on top of the stack of the other bottom aligned components, with AlignTop at the bottom of the stack of the other top aligned components.

On the contrary, it happens that "sometimes", in an unpredictable but reproducible way, the control which should go in one place goes to a different one, either becoming topmost or bottommost, or being inserted between other components.

This occurs both at design time, making it sometimes very difficult to lay out the components as desired, and at runtime, disrupting the desired order of the components.
The only workaround I've found is to set Align to alNone, and to painfully calculate the Top property of each component from the Top and Height properties of the others.

This, besides not being Delphi compatible, is quite annoying.

Should I open an issue in the bugtracker, with the usual small example to demonstrate the issue?

Giuliano

Reply by email

K. P.
to Giuliano Colla

I assume you are speaking of controls being created at run time? If so, then I have seen this behaviour (and I believe I had encountered it in Delphi as well).I deal with it by simply setting the Top property to some value higher than "used", i.e. NewPanel.Top := 10000;
for top aligning controls - there is no need for painful calculations or switching alignments. Just setting top (while control is top aligned) puts it in the proper sequence, i.e. at the bottom of the "stack" Cheers,Kai

Show quoted text 44 lines
Date: Mon, 25 May 2015 19:13:27 +0200 From: To: Subject: [Lazarus] AlignTop/AlignBottom issue AlignTop and AlignBottom do not appear to behave as they should. When you have several controls contained in another control, you would expect that each AlignTop or AlignBottom would stack the control in the first free position: with AlignBottom on top of the stack of the other bottom aligned components, with AlignTop at the bottom of the stack of the other top aligned components. On the contrary, it happens that "sometimes", in an unpredictable but reproducible way, the control which should go in one place goes to a different one, either becoming topmost or bottommost, or being inserted between other components. This occurs both at design time, making it sometimes very difficult to lay out the components as desired, and at runtime, disrupting the desired order of the components. The only workaround I've found is to set Align to alNone, and to painfully calculate the Top property of each component from the Top and Height properties of the others. This, besides not being Delphi compatible, is quite annoying. Should I open an issue in the bugtracker, with the usual small example to demonstrate the issue? Giuliano -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150525/cb9a3189/attachment-0001.html>

Reply by email

Giuliano Colla
to K. P.

Il 25/05/2015 21:33, K. P. ha scritto:

Just setting top (while control is top aligned) puts it in the proper sequence, i.e. at the bottom of the "stack"

It appears to work. I'll make some more tests.
Thanks a lot.

Giuliano

Reply by email

Maxim Ganetsky
to Giuliano Colla: AlignTop and AlignBottom do not appear to behave as they should. When you have several…

25.05.2015 20:13, Giuliano Colla ?????:

Show quoted text 24 lines
AlignTop and AlignBottom do not appear to behave as they should. When you have several controls contained in another control, you would expect that each AlignTop or AlignBottom would stack the control in the first free position: with AlignBottom on top of the stack of the other bottom aligned components, with AlignTop at the bottom of the stack of the other top aligned components. On the contrary, it happens that "sometimes", in an unpredictable but reproducible way, the control which should go in one place goes to a different one, either becoming topmost or bottommost, or being inserted between other components. This occurs both at design time, making it sometimes very difficult to lay out the components as desired, and at runtime, disrupting the desired order of the components. The only workaround I've found is to set Align to alNone, and to painfully calculate the Top property of each component from the Top and Height properties of the others. This, besides not being Delphi compatible, is quite annoying. Should I open an issue in the bugtracker, with the usual small example to demonstrate the issue?

I guess it won't harm.

Best regards, Maxim Ganetsky mailto:

Reply by email

Mattias Gaertner
to Giuliano Colla: AlignTop and AlignBottom do not appear to behave as they should. When you have several…
Show quoted text 7 lines
AlignTop and AlignBottom do not appear to behave as they should. When you have several controls contained in another control, you would expect that each AlignTop or AlignBottom would stack the control in the first free position: with AlignBottom on top of the stack of the other bottom aligned components, with AlignTop at the bottom of the stack of the other top aligned components.

It works like this:
http://wiki.lazarus.freepascal.org/Autosize_/_Layout#Order_of_controls_with_same_Align

When you drop (or move) a control with alTop in the designer, the control is inserted at the current mouse position. It is *not* moved to the free bottom/top position. This is Delphi compatible.

When you add controls at runtime, keep in mind that the initial control's Left/Top is 0,0. Contrary to the VCL the LCL can (and often does) delay updating the layout (DisableAutoSize/EnableAutoSize). For example all changes in FormCreate are delayed and the layout is computed from the final property values. On the other hand ButtonClick has no delay (aka you have to add the
Disable/EnableAutoSize yourself), so inserting alTop controls may have different results.

If you want a specific order, use Disable/EnableAutoSize and set the "Top" properties.

Mattias

Reply by email

Giuliano Colla
to Mattias Gaertner

Il 26/05/2015 14:50, Mattias Gaertner ha scritto:

The reason of my request is that it doesn't appear to work like this. Quoting the #Align paragraph:

First all controls with alTop are put to the top of the client area. If there are several controls with alTop the last added/moved will be put topmost.

....

Then all controls with alBottom are put to the bottom of the client area. Otherwise it works analog to alTop.

This scheme provides a predictable order, although different from Delphi's one which places the last added/moved at the bottom for alTop. It makes it possible to lay out components as desired.

What happens with the sample program I've posted in the bugtracker is that with an order of the commands 1-2-3-4-5-6-7 (executed one by one, with a click event), the resulting order of the components is 4-3-5-2-6-1-7, which appears rather crazy.

The "Order of controls with same Align" should apply when several controls are added/moved simultaneously, not when they're moved one by one.

Giuliano

Reply by email