Recent

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

calebs

  • Full Member
  • ***
  • Posts: 173
problem with label alignment in pagecontrol
« on: November 25, 2022, 09:33:42 pm »
Hi everyone i have spotted this problem long ago and i think i've reported here also
It's been happening since a several versions before last (2.2.4).
tested on lazarus fixes (2.2.5) on windows 11 but it happens with previous stable versions also in windows 10 (i recall). WIll try on linux after
Test like this:

new application
drop pagecontrol
create two tabs
create 3 labels on each tab
set alignment to the first (in the two tabs) to left
set alignment to the sencond (ijn the two tabs) to center
set alignment to the third  (in the two tabs) to right.
on formshow write a number (or any text) on each label and this happens:
when i compile and run (f9) and focusing on the first tab when application runs the labels on the first tab are well aligned but in the sencond all are left aligned.
close and return to lazarus
focus on second tab and run again (f9) and labels on second tab are well aligned but in the first all appear left aligned.
it puzzles me so the only solution i found is use string functions to align labels and fixed font size for numbers appear well aligned.
Hope i was clear with the procedure.
Thanks to all!

wp

  • Hero Member
  • *****
  • Posts: 10462
Re: problem with label alignment in pagecontrol
« Reply #1 on: November 25, 2022, 10:27:22 pm »
Something is missing here: Are the labels autosized? And where are they? When AutoSize=true, how can you tell whether the text is left-aligned/centered/right-aligned?

When I place three labels on each tab, set their Align to alTop so that they extend over the full width of the tab and set the Alignment to taLeftJustify, taCenter and taRightJustify everything is fine. The same observation when I turn AutoSize off and grow the width of the labels so that they extend over the tab width.

calebs

  • Full Member
  • ***
  • Posts: 173
Re: problem with label alignment in pagecontrol
« Reply #2 on: November 26, 2022, 12:33:38 am »
all other options are default ones.
they are put in the ttab one behind the other
its easy to know if they are rigth aligned, when i load numbers with 2 decimals if the align is right its easy to notice. (ej 12.23 and 4832.33)
Change the align to right only and you will see it
im not usign align only aligment

wp

  • Hero Member
  • *****
  • Posts: 10462
Re: problem with label alignment in pagecontrol
« Reply #3 on: November 26, 2022, 12:48:18 am »
Please post a project for clarification.

WooBean

  • Full Member
  • ***
  • Posts: 170
Re: problem with label alignment in pagecontrol
« Reply #4 on: November 26, 2022, 09:13:03 am »
Well, there is something indeed - when the code for setting captions of labels is put in FormCreate event (as I/we usually do) all seems OK but when it is written inside  FormShow the strange behaviour (described by TS) occurs. Tested on Lazarus 2.2.0 (rev lazarus_2_2_0) FPC 3.2.2 x86_64-win64-win32/win64, IDE set as docked. See below:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormShow(Sender: TObject);
  2. begin
  3.   label1.caption:='111.11';
  4.   label2.caption:='222.22';
  5.   label3.caption:='333.33';
  6.   //label2.left:=label1.Left; //needed to keep position unchanged
  7.   //label3.left:=label1.Left; //needed to keep position unchanged
  8.  
  9.   label4.caption:='444.44';
  10.   label5.caption:='555.55';
  11.   label6.caption:='666.66';
  12.  
  13. end;
  14.  

 

« Last Edit: November 26, 2022, 04:16:13 pm by WooBean »
Platforms: Win7/64, Linux Mint Ulyssa/64

jamie

  • Hero Member
  • *****
  • Posts: 5052
Re: problem with label alignment in pagecontrol
« Reply #5 on: November 26, 2022, 07:26:57 pm »
I can tell you that any GUI changes that effects the appearance should not be done in the Show event because it can cause retriggers.

 The OnShow event is to show what you have and what changes you make there should not directly affect the GUI layout in anyway.
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 10462
Re: problem with label alignment in pagecontrol
« Reply #6 on: November 26, 2022, 07:43:06 pm »
all other options are default ones.
So, the labels have AutoSize=true? Then there is no way to distinguish left-aligned, centered and right-aligned single-line labels because the size of the label is adjusted such that it tightly encloses the text. I don't understand...
« Last Edit: November 26, 2022, 07:58:20 pm by wp »

calebs

  • Full Member
  • ***
  • Posts: 173
Re: problem with label alignment in pagecontrol
« Reply #7 on: November 26, 2022, 08:01:24 pm »
open, focus on first tab, run and watch alignment of labels... first column is left, center is center, right is right.
then change tab and watch missaligned.
Then click on the button below and change tab and do it several tabs...
now i find that labels moves far from their design position.
if you stop, focus on second tab and run.
second tab is as should be with alignment but first not...
play again with button and changin tabs and you will see

howardpc

  • Hero Member
  • *****
  • Posts: 4098
Re: problem with label alignment in pagecontrol
« Reply #8 on: November 26, 2022, 08:30:09 pm »
Not quite sure what you are after, but the attached adapted project uses childsizing for TabSheet1, with a number of other properties also changed, and TabSheet2 left as in your project1.
You can play with the various childsizing sub-properties to get the effect you want (whatever it is). Confusingly, I failed to rename the altered project, sorry.

dsiders

  • Hero Member
  • *****
  • Posts: 748
Re: problem with label alignment in pagecontrol
« Reply #9 on: November 26, 2022, 09:52:08 pm »
open, focus on first tab, run and watch alignment of labels... first column is left, center is center, right is right.
then change tab and watch missaligned.
Then click on the button below and change tab and do it several tabs...
now i find that labels moves far from their design position.
if you stop, focus on second tab and run.
second tab is as should be with alignment but first not...
play again with button and changin tabs and you will see

So, rather than playing 20 questions... post a project or some code that demonstrates the error.
Preview Lazarus 2.3.0 documentation at: https://dsiders.gitlab.io/lazdocsnext

calebs

  • Full Member
  • ***
  • Posts: 173
Re: problem with label alignment in pagecontrol
« Reply #10 on: November 26, 2022, 09:53:35 pm »
i've noticed in another program i have several labels on several tabs.
I fill them all with decimal numbers (xxx.xx) and i want to all to be right aligned (with right alignment)
The problem is when i run the project only the focused tab when i run the project is well aligned... all othar labels on other tab are aligned to left.
If i stop the program and recompile it or run it with other tab focused, this tab is aligned to right but others to the left.
But the property of the labels are ALL right alignment.

in the project above other problems arise

calebs

  • Full Member
  • ***
  • Posts: 173
Re: problem with label alignment in pagecontrol
« Reply #11 on: November 26, 2022, 10:02:52 pm »
New version of the project.
i've added checks to use as guide for the alignment
you can see that right alignment is not working as expected (or at least i think they should be)
the numbers NOT align to the right (encolumned (dont know if its the right term))
in runtime If you change the tabs and press the button and change the tab again they move more!!

dsiders

  • Hero Member
  • *****
  • Posts: 748
Re: problem with label alignment in pagecontrol
« Reply #12 on: November 26, 2022, 10:30:44 pm »
New version of the project.
i've added checks to use as guide for the alignment
you can see that right alignment is not working as expected (or at least i think they should be)
the numbers NOT align to the right (encolumned (dont know if its the right term))
in runtime If you change the tabs and press the button and change the tab again they move more!!


For any Label that is right-aligned, change the Anchors to Top, Right instead of Top, Left.
Preview Lazarus 2.3.0 documentation at: https://dsiders.gitlab.io/lazdocsnext

wp

  • Hero Member
  • *****
  • Posts: 10462
Re: problem with label alignment in pagecontrol
« Reply #13 on: November 26, 2022, 11:23:15 pm »
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.

dsiders

  • Hero Member
  • *****
  • Posts: 748
Re: problem with label alignment in pagecontrol
« Reply #14 on: November 26, 2022, 11:34:31 pm »
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.
Preview Lazarus 2.3.0 documentation at: https://dsiders.gitlab.io/lazdocsnext

 

TinyPortal © 2005-2018