Recent

Author Topic: problem with label alignment in pagecontrol  (Read 2140 times)

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: problem with label alignment in pagecontrol
« Reply #15 on: November 27, 2022, 12:01:25 am »
I see. I must confess that I had never realized that a label which has an anchor akLeft but Alignment taRightJustify keeps its right edge fixed when the Caption is changed. Almost sounds like a bug, but I checked with Delphi, and it shows that same unlogical behaviour.

Seems logical to me. It's like inflating a balloon... it expands and contracts on the end that is not being held in place.
But this is just what I am saying: The anchor akLeft holds it fixed at the left, thus the balloon should grow to the right. This behaviour also contradicts other controls: A TStaticText with Alignment=taRightJustify, AutoSize=true and akLeft in Anchors grows to the right with the Caption. Or TCheckbox/TRadioButton always grows to the right, too - its default Alignment is taRightJustify.

But maybe all this is a misunderstanding of the Anchors. They probably only are used when the size of the parent changes. And in case of TCheckbox/TRadiobox the Alignment property probably is simply poorly named and means the position of the text in relation to the button.

This is a very confusing situation... Therefore it is even more important to use anchoring with the Anchor Editor for clarification.

calebs

  • Full Member
  • ***
  • Posts: 190
Re: problem with label alignment in pagecontrol
« Reply #16 on: November 27, 2022, 12:17:34 am »
I see. I must confess that I had never realized that a label which has an anchor akLeft but Alignment taRightJustify keeps its right edge fixed when the Caption is changed. Almost sounds like a bug, but I checked with Delphi, and it shows that same unlogical behaviour.

Anyway, if you want a label to be right-aligned and keep its right edge fixed then you should set its akRight anchor, as dsiders already said. And I would even go a step further an use the anchor editor to anchor the right edge of the label to a fixed point, e.g. the right edge of the parent.

I am attaching a modified version of your first project in which the left labels are anchored to the left side of the tabsheet, the center labels are anchored to the center of the tabsheet, and the right labels are anchored to the right sides of the tabsheet. I also painted the background in yellow to exactly see the position of the labels.

thanks! it sound logical to me that if i put a label and i chose right alignment it would align to the rightest side of the label but then again, is confusing. The very rare thing is that when it happens inside a ttab, in the active tab when i compile it and run, appears ok and on the other tabs don't. That is what puzzles me. Then again, stop program, set index to tab 2 and compile again, the tab two aligns as expected but the one is left aligned. That's why i think its a bug
I never used anchors and border spacing but in the example you gave me is working as expected so i will implement it that way next time.
Thank you all!

dsiders

  • Hero Member
  • *****
  • Posts: 1052
Re: problem with label alignment in pagecontrol
« Reply #17 on: November 27, 2022, 12:33:38 am »
I see. I must confess that I had never realized that a label which has an anchor akLeft but Alignment taRightJustify keeps its right edge fixed when the Caption is changed. Almost sounds like a bug, but I checked with Delphi, and it shows that same unlogical behaviour.

Anyway, if you want a label to be right-aligned and keep its right edge fixed then you should set its akRight anchor, as dsiders already said. And I would even go a step further an use the anchor editor to anchor the right edge of the label to a fixed point, e.g. the right edge of the parent.

I am attaching a modified version of your first project in which the left labels are anchored to the left side of the tabsheet, the center labels are anchored to the center of the tabsheet, and the right labels are anchored to the right sides of the tabsheet. I also painted the background in yellow to exactly see the position of the labels.

thanks! it sound logical to me that if i put a label and i chose right alignment it would align to the rightest side of the label but then again, is confusing. The very rare thing is that when it happens inside a ttab, in the active tab when i compile it and run, appears ok and on the other tabs don't. That is what puzzles me. Then again, stop program, set index to tab 2 and compile again, the tab two aligns as expected but the one is left aligned. That's why i think its a bug
I never used anchors and border spacing but in the example you gave me is working as expected so i will implement it that way next time.
Thank you all!

Then you did not learn anything from this discussion. It has nothing to do with TPageControl... and everything to do with a random number of digits being stuffed into an auto-sized label. But never mind... you have your solution. Copy and paste.  We can all move on now.
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

calebs

  • Full Member
  • ***
  • Posts: 190
Re: problem with label alignment in pagecontrol
« Reply #18 on: November 27, 2022, 01:14:15 am »
Im always learning and i will study these options i never used to solve the problem that i had.
Now you can get down a little from your pedestal and explain to me (and appearantly to all) why this happen in this project and why it is not a bug?
I'll try to express very clear the procedures so you can test and dignify me (and us) with your enlightment so i (or we) can keep learning from you.
Open lazarus project.
Focus on first tab
f9 (run if you dont know)
look at labels on screen
press the (only button)
watch all the numbers appear correctly RIGHT ALIGNED
change to tab 2
whach all the numbers NOT RIGHT ALIGNED.
Close running program (the one you are debuggin in lazarus, not the web browser)
click on second tab (tabsheet2)
press f9 again
look at the labels on screen
press again the only button
watch all the numbers IN TAB TWO corectly right aligned
now switch to tabsheet 1
watch the numbers NOT RIGHT ALIGNED.
so if you can explain why this happens and its not a bug or why it dependes on what tab is focused at compiling time i will be very very glad and (maybe) make an idol on my porch to venerate such high priest on the forum.
if not, well i thank you  for the only useful answer you give me about the anchors and take notice and investigate myself.
Thank you all for your time!

I see. I must confess that I had never realized that a label which has an anchor akLeft but Alignment taRightJustify keeps its right edge fixed when the Caption is changed. Almost sounds like a bug, but I checked with Delphi, and it shows that same unlogical behaviour.

Anyway, if you want a label to be right-aligned and keep its right edge fixed then you should set its akRight anchor, as dsiders already said. And I would even go a step further an use the anchor editor to anchor the right edge of the label to a fixed point, e.g. the right edge of the parent.

I am attaching a modified version of your first project in which the left labels are anchored to the left side of the tabsheet, the center labels are anchored to the center of the tabsheet, and the right labels are anchored to the right sides of the tabsheet. I also painted the background in yellow to exactly see the position of the labels.

thanks! it sound logical to me that if i put a label and i chose right alignment it would align to the rightest side of the label but then again, is confusing. The very rare thing is that when it happens inside a ttab, in the active tab when i compile it and run, appears ok and on the other tabs don't. That is what puzzles me. Then again, stop program, set index to tab 2 and compile again, the tab two aligns as expected but the one is left aligned. That's why i think its a bug
I never used anchors and border spacing but in the example you gave me is working as expected so i will implement it that way next time.
Thank you all!

Then you did not learn anything from this discussion. It has nothing to do with TPageControl... and everything to do with a random number of digits being stuffed into an auto-sized label. But never mind... you have your solution. Copy and paste.  We can all move on now.

dsiders

  • Hero Member
  • *****
  • Posts: 1052
Re: problem with label alignment in pagecontrol
« Reply #19 on: November 27, 2022, 01:27:56 am »
You can lead a horse to water, but you cannot make it drink. I'm done.
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: problem with label alignment in pagecontrol
« Reply #20 on: November 27, 2022, 02:51:45 am »
I wouldn't give up so quicky, I just ran that last test app and yes, there is a bug.

All labels are being process the same way and this is what I've found.

if the label is not showing, in this case the tab sheet that it lives on is not showing, then changing the contents of the text which forces the label to adjust itself for right justify, should move the left position of the label over, and it does not.

The page that is visible does adjust the label over to the left as much as it needs to make it show proper.

 Now you can do this in any combination, and it seems that the initial page that isn't visible does not move the label to the left.

 But after switching back and forth, it seems it never corrects itself, so this is an initial one time for the labels that are not visible and need to adjust the label to the left so that they can right justify the to the border.

 There is definitely a problem, and the last test app makes it easy to work with.
 
  I think @WP could look at this since he has a lot of time on the TLabel  ;D
have a good day.

EDIT:
  A little more detail.

   If seems it has nothing to do with the first time around, it's all to do about not being visible when the label is adjusted. So once it is sized to fit, it will never correct itself afterwards because the label is already long enough to fit the content.
 
  So, while not visible the right justify fails and simply does a left justify.

« Last Edit: November 27, 2022, 03:38:17 am by jamie »
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: problem with label alignment in pagecontrol
« Reply #21 on: November 27, 2022, 11:51:47 am »
Let me assume first that the behaviour of a label with Anchors = [akLeft, akTop], Alignment = taRightJustify and AutoSize = true growing to the left when its caption is changed, is correct although it is not logical. I want to simplify the test project in order to understand what's going on - 18 labes is way too much...

The attached project contains a label with Anchors = [akLeft, akTop], Alignment = taRightJustify and AutoSize = true. I had dragged it to the very right of the form such that its right side aligns approximately with the right side of the form. While typing some text into the Caption property it can be seen that the right side of the label is held fixed and the label grows to the left. For the test I chose a rather narrow text for the label, e.g. '1'. And most of all, the label's Visible property has been set to false. In order to get around the mysteries happending during the OnShow/OnActivate events, I added a button which sets the label's Caption to a long text in the OnClick event and then sets Visible to true in order to show the label.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   Label1.Caption := 'This is a long, long, long text.';
  4.   Label1.Visible := true;
  5. end;

Running this and clicking the button, you see that the text changes, but it stays at its original starting position. Due to the special treatment of Alignment = taRightJustify it should have moved to the left so that it ends at the right edge of the form.

I think this is the problem reported.

I compiled with Laz/main and with Laz 1.4.4 (the oldest Lazarus that I still have), and both show the same behaviour. Therefore, it is not a recently introduced regression, and probably exists since the beginning. I also converted the project to Delphi, and here the behaviour is "correct" in the sense that the text ends at the right side of the form.

One other experiment with the Laz/version: Exchange the two instructions in the ButtonClick handler so that the label is visible when its Caption is changed. - Now the behaviour is like in Delphi. It seems to be essential that the label is visible.

Following the debugger shows that the issue occurs in TControl.AdjustSize which executes the autosizing operation (due to the changed caption text) only when the control and all its parents are visible.

Please file a bug report. Maybe a developer picks it up and attempts to fix it (but I hope that this will not happen because the autosizing code is very complex, and in my experience it is very probably that something else will break...)

Even if this is not fixed, you always have the possibility to set the label Anchors to [akRight, akTop] (rather than [akLeft, akTop]), and the right alignment will always work. Of course, now the label will move when the size of the container changes. If you don't want this you can put the labels into a panel without akRight (or use the anchor editor to anchor them to other controls).

calebs

  • Full Member
  • ***
  • Posts: 190
Re: problem with label alignment in pagecontrol
« Reply #22 on: November 27, 2022, 02:53:26 pm »
Thanks jamie and wp.
Correct, this i have noticed a long a go and tryed to explain this because i have an application that shows balances on several tabs with a lot of labels and i wasn't aware of the problem until a client note it (the great beta-testers) and then discovered what wp explains. It seems to me there was a bug because the behaviour is not normal netiher expected with alignment.
But there is always an elevated guru like <you know who> that trolls in the road of knowledge and never could arrive to an explanation or if i was missing something.
I will look up to the solutions you gave me wp, for now i solved it with fixed font and filling zeros or spaces to the left of the number to correct the column items because i think left alignment always worked thanks to the anchors (i guess) like high priest shared with a simple mortal like me (or us), but using anchors is maybe a little less work.
I don't know how to fil a bug, never done it before but it's not a critical problem, only a  cosmethical one that can be fixed so many other ways so it's no hurry.
Many thanks to everyone and special one to the gods in the limbo that came down from time to time to help the feral horses of the world.

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: problem with label alignment in pagecontrol
« Reply #23 on: November 27, 2022, 03:03:36 pm »
There is an old bug report about taRightJustify labels not working in the Delphi way. This has been fixed in 2016, but not for the case that the labels are invisible. I now assigned the report to Ondrej who had fixed the main incompatibility. Maybe he looks at it again.

There is no need for you to file another bug report.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: problem with label alignment in pagecontrol
« Reply #24 on: November 27, 2022, 08:23:51 pm »
I see Ondrej put something in the trunk to check the left of the label but whatever he did it didn't solve anything from what I can see, it still fails.

 Maybe he is working on it still.
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: problem with label alignment in pagecontrol
« Reply #25 on: November 27, 2022, 10:45:58 pm »
whatever he did it didn't solve anything from what I can see, it still fails.
No, he fixed the first level of visibility (Label.Visible = false).

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: problem with label alignment in pagecontrol
« Reply #26 on: November 30, 2022, 01:24:42 pm »
whatever he did it didn't solve anything from what I can see, it still fails.
No, he fixed the first level of visibility (Label.Visible = false).
... but he met serious difficulties when extending the fix into the LCL (all parents of the label must be visible!), and in the end the changes would be too massive and risky so that he decided to revert the related changes and document them as Delphi-incompatibility issues:
- https://wiki.freepascal.org/Lazarus_2.4.0_release_notes#LCL
- https://wiki.freepascal.org/TLabel#Delphi_incompatibility_for_right-aligned_labels

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: problem with label alignment in pagecontrol
« Reply #27 on: November 30, 2022, 03:09:19 pm »
why not simply post pone the update of the label after a Text change has been issued until it becomes visible?

 So basically, don't to any of the calculations until visible. make a fPostPoneAlign etc.
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018