Recent

Author Topic: [SOLVED] TCustomLabel constraints in design and runtime  (Read 961 times)

iteh

  • New Member
  • *
  • Posts: 31
Re: [SOLVED] TCustomLabel constraints in design and runtime
« Reply #30 on: September 22, 2019, 01:12:26 am »
But is it correct to do autosize with wordwrap ?

you can get ambiguity: if the line is long, then do you need to expand the width in autosize and put everything in one line or do you need to reduce the width, but increase the height and make a word break ?

In rad studio delphi the whole text is analyzed there and the TLabel width is set according to the longest word, and then wordwrap works and the height is adjusted to fit the whole text.

Is a similar algorithm implemented in AdjustSize so that both AutoSize and WordWrap work simultaneously ?

jamie

  • Hero Member
  • *****
  • Posts: 1980
Re: [SOLVED] TCustomLabel constraints in design and runtime
« Reply #31 on: September 22, 2019, 01:30:26 am »
I am just saying that removing it all together introduces another problem where those that want auto size to work with word wrap on will not have it..

 the process can be ignored if in designer mode, it does not need to be there but other than that, if should be this in the code..

 if AutoSize then AdjustSize. instead of removing it all together.

 You still get your fix and others still have a working autosize with wordWrap.

iteh

  • New Member
  • *
  • Posts: 31
Re: [SOLVED] TCustomLabel constraints in design and runtime
« Reply #32 on: September 22, 2019, 02:09:01 am »
Please, try your solution - it doesn’t work for me, but the wp solution just works correctly:
1) akLeft, akRight, wordwrap = true, autosize = false - word wrap is done based on the width set by the user, but the height is not adjusted
2) akLeft, akRight, wordwrap = true, autosize = true - word wrap is done based on the width set by the user and the height is adjusted to fit the entire text
3) akLeft, akRight, wordwrap = false, autosize = true - the text is in one line and the width is adjusted
4) akLeft only, wordwrap = true, autosize = true - the text is in one line and the width is adjusted

and that’s all in the solution from wp.

but if I write “if autosize then adjustsize;” instead of the commented line, then the above rule 2 ("2" above) do not work and rule 4 works the same as in the solution from wp.

« Last Edit: September 22, 2019, 02:13:31 am by iteh »

jamie

  • Hero Member
  • *****
  • Posts: 1980
Re: [SOLVED] TCustomLabel constraints in design and runtime
« Reply #33 on: September 22, 2019, 02:15:00 am »
For you, you can't use AutoSize. In your code you would need to turn that off of course.

 For the IDE operation you also need to test for the Designer state so if AutoSize is on the IDE designer will ignore it and allow you to move it with word wrap.
Code: Pascal  [Select]
  1. if (csDesignInteractive in ControlStyle) or (Not AutoSize) Then exit;
  2.   Inherited AdjustSize;                                                  
  3.  

This is the concept of the code.
 This allows others to use the AutoSize if they wish..
what you are doing is removing that wish from those that may still want it as it is and it seems apparent that you don't have your AutoSize on anyways so this should work for you.

P.S.
 I may have the wrong Flag in use for Designer state, I need to check into that more

« Last Edit: September 22, 2019, 02:18:34 am by jamie »

iteh

  • New Member
  • *
  • Posts: 31
Re: [SOLVED] TCustomLabel constraints in design and runtime
« Reply #34 on: September 22, 2019, 02:27:07 am »
you are mistaken, I can use autosize and it works successfully - which I indicated by listing 4 combinations above and how they work out.

also note that analyzing only designtime and "not autosize" is incorrect - you need not only to be able to increase the width in designtime by mouse, but also give the user the ability to manually set the width for different conditions.

but this feature is blocked by your patch - it does not allow to assign a new value to width if wordwrap=true and autosize=true, for this case you code will apply the old bug (which wp fixed) and call the function that will return the previous width: the user will call width := nn, and your code will simply cancel it.

(added)

if you think I'm wrong and your patch does not have all these shortcomings that I indicated about it - let's not discuss it here, but publish your patch in the Lazarus bugtrack branch, let the developers confirm the correctness of your code there and add it to the next release and that’s it.

here the initial problem is already clear, then everyone will make a private patch for himself, but we still need to solve the issue of editing the error in the general branch.
« Last Edit: September 22, 2019, 02:34:56 am by iteh »

iteh

  • New Member
  • *
  • Posts: 31
Re: [SOLVED] TCustomLabel constraints in design and runtime
« Reply #35 on: September 22, 2019, 02:47:08 am »
wp code prevents canceling width changes.

in my opinion, even autosize should not block the width - the width should always be changed by the user, but autosize (with wordwrap=true) is responsible for adjusting only the height.

based on this concept - the patch from wp is correct.

if you want autosize to block manual changes to the width, then (only in my opinion!) the meaning of wordwrap + autosize is completely lost: after all, we will not be able to set the fixed width we need for wordwrap, and all the text will always be in one line (autosize will still fit the width of the entire text).

but this is just my vision of how autosize should work :)

jamie

  • Hero Member
  • *****
  • Posts: 1980
Re: [SOLVED] TCustomLabel constraints in design and runtime
« Reply #36 on: September 22, 2019, 02:55:01 am »
did you notice I was trying to test if the control was in Design mode?

Have it your way, I don't care.. I've never had an issue with that to be honest, I just
set word wrap when I get the control where I want it and it stays in place..
   
 So more testing with others need to be done, that wasn't put there for no reason and I am sure someone will complain.

 Mean while I got bigger fish to fry...

 Have a good day.

wp

  • Hero Member
  • *****
  • Posts: 6224
Re: [SOLVED] TCustomLabel constraints in design and runtime
« Reply #37 on: September 22, 2019, 12:27:27 pm »
I am attaching a test program which checks several conditions for a TLabel. Each button click toggles the label width between 100 and 200 pixels. The label background is drawn in yellow to show whether the command was obeyed. The only situation which is not correct is the combination "left- and right-anchored" AND "WordWrap" (Button "(4)...") - here the width does not change. Left+right anchoring without WordWrap is correct (Button "(2)..."), as well as Wordwrap with left-anchoring only (Button "(3)..."). (Maybe this already has been found above, I did not read everything).

Removing the "AdjustSize" line in "TCustomLabel.DoSetbounds" (or the entire "if" block containing it) seems to fix the issue without introducing other issues. But maybe my test is not complete... This code was originally introduced by Mattias in r24917 (April 25, 2010: "LCL: TCustomLabel: AdjustSize if WordWrap and Width changed") - too long gone to ask why.

The final button "(6)..." tests the AutoSize behavior which has been annoying me for some time because it ignores WordWrap and expands an already wrapped text to a single line. It should behave like Delphi which applies the AutoSize to the height only and keeps the preset width of the multi-line label.


« Last Edit: September 22, 2019, 02:36:18 pm by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

iteh

  • New Member
  • *
  • Posts: 31
Re: [SOLVED] TCustomLabel constraints in design and runtime
« Reply #38 on: September 22, 2019, 05:14:31 pm »
The final button "(6)..." tests the AutoSize behavior which has been annoying me for some time because it ignores WordWrap and expands an already wrapped text to a single line. It should behave like Delphi which applies the AutoSize to the height only and keeps the preset width of the multi-line label.

in Delphi (tested on Delphi 10.1 “Berlin”), everything is not going smoothly with the “button 6” test:

the second (autosize=false wordwrap=true) looks the same as in lazarus (after the first "click" - everything is on one line and remains so, after disabling autosize - the width does not come back).

but the first one (autosize=false wordwrap=false) is drawn once "as it should" (there is an auto-fit of the width, in a larger direction, based on the maximum length of the word in the line, and then the auto-fit of the height is already done using word wrapping), and with subsequent "clicks "is already similar to lazarus - the maximum line length without any wordwrap.

Only if we add the same "smart" algorithm to Lazarus: if both autosize and wordwrap are enabled at the same time, then adjust the width (or just to the side an increase in length, as in delphi now, or to either side) to the maximum word length, and then adjust the height so that the whole line fits through wordwrap. And repeat this algorithm both when autosize and wordwrap are turned on at the same time and when the contents of the string change.


jamie

  • Hero Member
  • *****
  • Posts: 1980
Re: [SOLVED] TCustomLabel constraints in design and runtime
« Reply #39 on: September 23, 2019, 12:58:30 am »
I Checked my old Delphi and it behaves a little different than Lazarus..

If I don't use AutoSize the WordWrap feature does not effect the sizing at design time or runtime. I can turn it on/off etc..

 if I enable autosize, then the first time it does this it will resize the box but only the first time.

 With AutoSize still on, if I enable WordWrap it will then Resize the label again but only once.

 Basically, if AutoSize is on, it only resizes the label for the initial state of that or turning the WordWRap on.

 Putting that all together, with any combination of those I am able to size the label in the designer via the mouse or OI with no issues, the size will remain where I set it until I play with those AutoSize setting etc.. So it seems the sizing methods are only getting called when playing with the properties while in the designer.

 In Lazarus it seems once you turn on the AutoSize it's locked.