Sign in Join

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

Mailing lists / lazarus / 2012-02

Anchoring buttons (or other graphical elements)

11 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

Jürgen Hestermann

I am trying to understand the logic of the anchors of graphic elements like buttons etc., especially the meaning of the margin values. Assume two buttons A and B:

----- -----
| A | | B |
----- -----

With the object inspector I can align the top of button B to the top of button A. Then the top of B is always the top of A plus the (top) margin of B. The margin values of A are irrelevant for the relation between the two borders. The same applies to the bottom alignment.

But if I now align the left border of B to the right border of A it behaves different: The left margin of B is no longer the only value that defines the position of B relativ to (the right of) A. The right margin of A is also considered. It seems that the maximum of both values is used for the distance. This is very confusing. Is that by design?

Reply by email

Mattias Gaertner
to Jürgen Hestermann

"J?rgen Hestermann" hat am 12. Februar 2012 um
12:16 geschrieben:

Show quoted text 18 lines
I am trying to understand the logic of the anchors of graphic elements like buttons etc., especially the meaning of the margin values. Assume two buttons A and B: ----- ----- | A | | B | ----- ----- With the object inspector I can align the top of button B to the top of button A. Then the top of B is always the top of A plus the (top) margin of B. The margin values of A are irrelevant for the relation between the two borders. The same applies to the bottom alignment. But if I now align the left border of B to the right border of A it behaves different: The left margin of B is no longer the only value that defines the position of B relativ to (the right of) A. The right margin of A is also considered. It seems that the maximum of both values is used for the distance. This is very confusing. Is that by design?

Maybe you want read the documentation:
http://wiki.lazarus.freepascal.org/Autosize_/_Layout#BorderSpacing

Mattias

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120212/2c82ace3/attachment.html>

Reply by email

Jürgen Hestermann
to Mattias Gaertner
Show quoted text 6 lines
> I am trying to understand the logic of the anchors of graphic elements > like buttons etc., especially the meaning of the margin values. Maybe you want read the documentation: http://wiki.lazarus.freepascal.org/Autosize_/_Layout#BorderSpacing

It's a bit frustrating that I *thought* I had found the documentation ( http://wiki.lazarus.freepascal.org/Anchor_Sides )
but then you point me to yet another documentation about the same topic. Spreading documentation all over the place is not a good idea. ;-(

I read a bit more (I did not understand this fully yet because it seems a very complicated algorithm
with lots of variables involved) but what strikes me is that horizontal and vertical borders seem
to be treated differently. Is there a reason for this?

Reply by email

Mattias Gaertner
to Jürgen Hestermann
Show quoted text 13 lines
Mattias Gaertner schrieb: > > I am trying to understand the logic of the anchors of graphic elements > > like buttons etc., especially the meaning of the margin values. > Maybe you want read the documentation: > http://wiki.lazarus.freepascal.org/Autosize_/_Layout#BorderSpacing It's a bit frustrating that I *thought* I had found the documentation ( http://wiki.lazarus.freepascal.org/Anchor_Sides ) but then you point me to yet another documentation about the same topic. Spreading documentation all over the place is not a good idea. ;-(

Putting everything on one page is not a good idea either. That's why the www uses links. Both pages are linked.
I also got complains that the page is too big. Golden rule: The layout of documentation is always wrong.

I read a bit more (I did not understand this fully yet because it seems a very complicated algorithm with lots of variables involved)

It's more powerful than the VCL.
It's small compared to other layout engines e.g. for html and css.

but what strikes me is that horizontal and vertical borders seem to be treated differently. Is there a reason for this?

Why do you think so?

Mattias

Reply by email

Jürgen Hestermann
to Mattias Gaertner
> but what strikes me is that horizontal > and vertical borders seem > to be treated differently. Is there a reason for this? Why do you think so?

Well, at first the documentation only mentions horizontal borders to be the maximum of both elements but nothing that this also applies to vertical borders. It says:
-------------------------------
The horizontal space between two controls (LeftControl, RightControl on Parent) is the maximum of ...
-------------------------------
But no words about the vertical alignment.

And second that was my experience too. But I just tried it again on a fresh project and now suddenly vertical alignment behave the same! This "eratic" (unpredictable, at least to me) behaviour was the reason I wanted to look into the documentation but it did not make it clearer but more obscure. It seems I have to invest much more time into this than I wanted...

Reply by email

Mattias Gaertner
to Jürgen Hestermann
Show quoted text 14 lines
Mattias Gaertner schrieb: >> but what strikes me is that horizontal >> and vertical borders seem >> to be treated differently. Is there a reason for this? > Why do you think so? Well, at first the documentation only mentions horizontal borders to be the maximum of both elements but nothing that this also applies to vertical borders. It says: ------------------------------- The horizontal space between two controls (LeftControl, RightControl on Parent) is the maximum of ... ------------------------------- But no words about the vertical alignment.

I added it analog.

Show quoted text 6 lines
And second that was my experience too. But I just tried it again on a fresh project and now suddenly vertical alignment behave the same! This "eratic" (unpredictable, at least to me) behaviour was the reason I wanted to look into the documentation but it did not make it clearer but more obscure. It seems I have to invest much more time into this than I wanted...

There is only one difference between vertical and horizontal and that is Delphi compatible: Align applies alTop and alBottom before alLeft and alRight.

Some widgets may override default rules.

Mattias

Reply by email

Hans-Peter Diettrich
to Jürgen Hestermann: Well, at first the documentation only mentions horizontal borders to be the maximum of…
Show quoted text 6 lines
And second that was my experience too. But I just tried it again on a fresh project and now suddenly vertical alignment behave the same! This "eratic" (unpredictable, at least to me) behaviour was the reason I wanted to look into the documentation but it did not make it clearer but more obscure. It seems I have to invest much more time into this than I wanted...

Anchoring and child-sizing IMO doesn't fit together nicely. Anchoring is a critical feature by itself, because it can end up in loops or other unwanted effects, if not repaired properly by the property setters.

I really don't wonder about inconsistent behaviour of these features, after an attempt to remove these features from the controls, and putting them into an separate layout manager. In this attempt I found out *in how many places* these features deserve special handling, so that the risk for broken code is high, in both the existing implementation and in every later update. The interdependencies never have been researched, and consequently also the documentation is complicated and incomplete. Some parts of the described features look nice, but only for themselves. In their entirety they opened up a can of worms, that is near unmanagable now.

So I'd prefer a general layout manager interface instead a bunch of built-in layout features, but I know that this never will come. But in contrast I'm sure that I'll be flamed for that extravagant opinion ;-)

DoDi

Reply by email

Jürgen Hestermann
to Mattias Gaertner: On Thu, 16 Feb 2012 07:23:15 +0100 I added it analog. There is only one difference…
> And second that was my experience too. But I just tried it again on a > fresh project and now suddenly vertical alignment behave the same! This > "eratic" (unpredictable, at least to me) behaviour was the reason I > wanted to look into the documentation but it did not make it clearer

but

Show quoted text 5 lines
> more obscure. It seems I have to invest much more time into this than I > wanted... There is only one difference between vertical and horizontal and that is Delphi compatible: Align applies alTop and alBottom before alLeft and alRight.

I just remember the situation that made me wonder about the alignment algorithm:

If I align the *top* of an element B to the *top* of another element A then any margin defined in A is ignored. Only the margin values for B are valid. This looks quite inconsistent to me. To what will B be aligned? To the border of the element or to the border plus margin? When I change the alignment so that the top of B is aligned to the *bottom* of A then suddenly the (bottom) margins of A are take into account. That drove me nuts the first time because the alignment editor only shows me the margin values of the element I wanted to align but I never thought that margins of the other element play any role here. And it seems that for *some* cases this is true but for others it is not.

Reply by email

Hans-Peter Diettrich
to Jürgen Hestermann
Show quoted text 6 lines
I just remember the situation that made me wonder about the alignment algorithm: If I align the *top* of an element B to the *top* of another element A then any margin defined in A is ignored. Only the margin values for B are valid. This looks quite inconsistent to me.

IMO that's due to the specification. When a user wants to align the sides of controls, then he wants the *visible* edges aligned. The additional spacing instead is based on the idea of *cells*, which exceed the visual parts of the controls. Now tell whether the alignment is based on the control sides with or without border spacing? :-(

DoDi

Reply by email

Mattias Gaertner
to Jürgen Hestermann: but I just remember the situation that made me wonder about the alignment algorithm: If I…
Show quoted text 19 lines
Mattias Gaertner schrieb: >> And second that was my experience too. But I just tried it again on a >> fresh project and now suddenly vertical alignment behave the same! This >> "eratic" (unpredictable, at least to me) behaviour was the reason I >> wanted to look into the documentation but it did not make it clearer but >> more obscure. It seems I have to invest much more time into this than I >> wanted... > There is only one difference between vertical and horizontal and that > is Delphi compatible: Align applies alTop and alBottom before alLeft > and alRight. I just remember the situation that made me wonder about the alignment algorithm: If I align the *top* of an element B to the *top* of another element A then any margin defined in A is ignored. Only the margin values for B are valid. This looks quite inconsistent to me.

At the beginning both borderspacings of A and B were used for for the distance of "same sides" anchoring (e.g. left/left). It was confusing and no one needed it. So it was changed and each of the three modi "same sides", "opposite sides" and "center" have their own rules.
I have to draw more pictures to explain it better in the docs.

Show quoted text 7 lines
To what will B be aligned? To the border of the element or to the border plus margin? When I change the alignment so that the top of B is aligned to the *bottom* of A then suddenly the (bottom) margins of A are take into account. That drove me nuts the first time because the alignment editor only shows me the margin values of the element I wanted to align but I never thought that margins of the other element play any role here. And it seems that for *some* cases this is true but for others it is not.

Anchoring "opposite sides": borderspacing of both controls are used. Anchoring "same sides" A to B: borderspacing of the anchoring control A is used.
Anchoring "center": no borderspacing is used.

Mattias

Reply by email

Jürgen Hestermann
to Mattias Gaertner
Show quoted text 5 lines
Anchoring "opposite sides": borderspacing of both controls are used. Anchoring "same sides" A to B: borderspacing of the anchoring control A is used. Anchoring "center": no borderspacing is used.

Aha! Yes, that's a simple and clear explanation which was missing in the documentation. Thanks.

Reply by email