Recent

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

iteh

  • New Member
  • *
  • Posts: 33
Re: TCustomLabel constraints in design and runtime
« Reply #15 on: September 21, 2019, 10:43:25 pm »
I always specify the control. Please do that yourself and see what happens...


maybe your parent control isn't what you think it is ?

or am I doing something wrong or if we explicitly indicate the anchor component (for example, the form) and the left and right anchors, then the anchor goes initially to the edges of the form. then we can set the distance to the edge in the anchor editor, right?

but if we made such a setting (indicate not only the presence of the anchor, but also what it is attached to), then we lose the ability (if you set only akLeft / akRight in the OI, without the anchor editor, then we had such an opportunity) to resize and position component on the form just with the mouse, right?

but again - if I do not indicate what to bind to, then this always works correctly for all components except tlabel and then for tlabel it also works correctly if wordwrap = false even if there are anchors.

I’m trying to understand why everything works correctly if there is wordwrap but no anchor or if there is an anchor but no wordwrap, but the combination of “both anchors + wordwrap” gives the wrong behavior but only for tlabel.

what's wrong with tcustomlabel ..

jamie

  • Hero Member
  • *****
  • Posts: 3250
Re: TCustomLabel constraints in design and runtime
« Reply #16 on: September 21, 2019, 10:48:43 pm »
Look, if there is another control sitting on the form left of your label, it will slide under it if you don't specify that control that is left to it for example.

 Without specifying the attached controls, it uses the parent which could be in your case the form, so it's limited only to the form, it does not care what controls are between it and the edge of the form. It will simply expand under a control etc.

 if you do have other controls sitting around the label you need to attached to them instead and not the parent .

 I've never seen the behavior you are showing..
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 3250
Re: TCustomLabel constraints in design and runtime
« Reply #17 on: September 21, 2019, 10:54:39 pm »
change your check point code to this..

 Abs(Label1.Width-OldW)>1
The only true wisdom is knowing you know nothing

iteh

  • New Member
  • *
  • Posts: 33
Re: TCustomLabel constraints in design and runtime
« Reply #18 on: September 21, 2019, 11:02:43 pm »
change your check point code to this..

 Abs(Label1.Width-OldW)>1

no, it does not work.
I can even simply set color for label’s background and visually verify that the label’s dimensions do not change as the width increases .... until I do wordwrap := false

here it’s not a calculation error, it’s some kind of architectural “bug” - because under the indicated conditions we can’t even specify a new width in designtime although no constraints are specified.
it is not clear who forbids resizing even in designtime and only when wordwrap = true


I therefore previously attached the archive with the project. everything is there by default, only 3-4 properties are set for the components ... but I can’t understand why the "stupid" tlabel behaves this way when all the others behave normally.

I need the ability to simultaneously set the binding to the left/right edges of the form (or rather, to the edges of the parent component on which I "put" the label) so that the dimensions of the label change automatically when the dimensions of the parent component change (in the attached example, the form) but also so that I can in designtime use the mouse to move the component within the parent and resize it with the mouse as well, so that wordwrap is true.

I can do this with tmemo and any other components (including those that do not have wordwrap), but I can’t understand how I can achieve the same for tlabel / tdbtext :(

iteh

  • New Member
  • *
  • Posts: 33
Re: TCustomLabel constraints in design and runtime
« Reply #19 on: September 21, 2019, 11:07:12 pm »
probably for now the best solution is not to use components inherited from tcustomlabel simultaneously with left-right anchors and wordwrap in situations where I need to programmatically change the width of this particular component or often need to manually resize them with the mouse in designtime .. maybe someday developers correct this behavior.
« Last Edit: September 21, 2019, 11:08:58 pm by iteh »

jamie

  • Hero Member
  • *****
  • Posts: 3250
Re: TCustomLabel constraints in design and runtime
« Reply #20 on: September 21, 2019, 11:18:16 pm »
I have absolutely no idea why you keep attaching WORDWRAP on this problem?

 The example you posted I have down loaded and tested it, its only off by 1 Pixel when you attempt to reset the size? I showed you how to make your example work which seems to have nothing to do with the problem you are claiming..

 I have played endlessly over here with WORWRAP on/off, different combinations, loaded the Label with a long statement etc... other than it adding one pixel to the size of the label, there is no ill effects..

  I think you better look deeper in your code because this isn't where it's at.

 I am always interested in finding solutions of there is a real problem because I like you use the LCL and need it to work so when I see an issue posted I want to investigate it to ensure it is a real issue and not the posters code causing it.

 From what I've found here, you have something else going on in your code that is causing the issue because the example project you posted does not prove anything that supports your theory about the word wrap being on or off...

 With that, good luck finding your bug, I am now happy that knowing there isn't any real issue here.


The only true wisdom is knowing you know nothing

iteh

  • New Member
  • *
  • Posts: 33
Re: TCustomLabel constraints in design and runtime
« Reply #21 on: September 21, 2019, 11:23:06 pm »
you tried the archive I posted and without any changes it opened and you were able to resize the label in designtime ??
if so, then the problem is not in the project, but in some settings in my IDE.

You can take my project from the archive and just in designtime (OI) set width for label1 to any (for example, 100) value - will the sizes of label1 increase?

jamie

  • Hero Member
  • *****
  • Posts: 3250
Re: TCustomLabel constraints in design and runtime
« Reply #22 on: September 21, 2019, 11:28:10 pm »
The only way the LABEL is going to give you an issue in the OI is if you have AUTOSIZE
on or anchored the right side to something..
The only true wisdom is knowing you know nothing

iteh

  • New Member
  • *
  • Posts: 33
Re: TCustomLabel constraints in design and runtime
« Reply #23 on: September 21, 2019, 11:30:35 pm »
can do the following:
1) open the project from my archive and without changing anything try to stretch the length of label1 to the right in designtime with the mouse. will it work out?
2) in the OI for label1 set wordwrap to false and try again to stretch the length of label1 to the right with the mouse.

write to me what happens.

for me - it all depends on wordwrap and with wordwrap=true it is NOT stretched, with wordwrap=false ("2" above) it is stretched.

if it’s different with you, write, I don’t understand why this is not visible, I have it repeated in 100% of cases.

let's try my simplest project from the archive. if your copy of the IDE has a different behavior - problems with the settings of my IDE, if the same - then it all depends on wordwrap as I wrote above.

jamie

  • Hero Member
  • *****
  • Posts: 3250
Re: TCustomLabel constraints in design and runtime
« Reply #24 on: September 21, 2019, 11:44:12 pm »
It's your test app that is off.

You didn't correctly code it to show the real problem.

I'll recode the block for you ..
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   oldW: Integer;
  4. begin
  5.   oldW := Label1.Width;
  6.   Label1.AutoSize := false;
  7.   Label1.WordWrap := true;
  8.   Label1.Width := oldW * 2;
  9.   if  Abs(Label1.Width-OldW)< 2 then
  10.     ShowMessage('label: anchors with wordwrap - failed')
  11.   else
  12.     ShowMessage('label: anchors with wordwrap - ok');
  13.   Label1.Width := oldW;
  14.  
  15.   Label1.WordWrap := false;
  16.   Label1.Width := oldW * 2;
  17.   if Label1.Width = oldW then
  18.     ShowMessage('label: anchors wo wordwrap - failed')
  19.   else
  20.     ShowMessage('label: anchors wo wordwrap - ok');
  21. end;                                        
  22.  

Put a long line in the Label caption
« Last Edit: September 21, 2019, 11:48:28 pm by jamie »
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 7347
Re: TCustomLabel constraints in design and runtime
« Reply #25 on: September 21, 2019, 11:52:17 pm »
I confirm iteh's observation. Debugged into the LCL and found that the new Label width is set correctly by DoSetBounds, but down the short procedure, if WidthChanged and WordWrap both are true, the width is reset back to its old value by AdjustSize. When I comment AdjustSize for a test then iteh's test program behaves correctly.

Unfortunately, the SetBounds routines in TControl and its descendants are extremely complicated (for my understanding) and I don't know a quick solution:

Code: Pascal  [Select][+][-]
  1. procedure TCustomLabel.DoSetBounds(ALeft, ATop, AWidth, AHeight: integer);
  2. var
  3.   WidthChanged: Boolean;
  4. begin
  5.   WidthChanged:=AWidth<>Width;
  6.   inherited DoSetBounds(ALeft, ATop, AWidth, AHeight);
  7.   if OptimalFill and (not AutoSize) then
  8.     AdjustFontForOptimalFill;
  9.   if WidthChanged and WordWrap then begin
  10.     InvalidatePreferredSize;
  11.     AdjustSize;     // <----------- here the width is reset back to the old value
  12.   end;
  13. end;
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

jamie

  • Hero Member
  • *****
  • Posts: 3250
Re: TCustomLabel constraints in design and runtime
« Reply #26 on: September 21, 2019, 11:57:44 pm »
Well that is wrong, there is no reason to be checking for WordWrap there.
it should be checking for AutoSize instead.
The only true wisdom is knowing you know nothing

iteh

  • New Member
  • *
  • Posts: 33
Re: TCustomLabel constraints in design and runtime
« Reply #27 on: September 22, 2019, 12:08:21 am »
I confirm iteh's observation. Debugged into the LCL and found that the new Label width is set correctly by DoSetBounds, but down the short procedure, if WidthChanged and WordWrap both are true, the width is reset back to its old value by AdjustSize. When I comment AdjustSize for a test then iteh's test program behaves correctly.

Unfortunately, the SetBounds routines in TControl and its descendants are extremely complicated (for my understanding) and I don't know a quick solution:
Thank you very much for the detailed analysis of the reason!

I commented out the line you specified in \lazarus\lcl\include\customlabel.inc (checked under windows), recompiled and the problem disappeared in both designtime and runtime.

can I ask you to issue a request in the bug track for lazarus, so that the developers correct this in the next release?

jamie

  • Hero Member
  • *****
  • Posts: 3250
Re: TCustomLabel constraints in design and runtime
« Reply #28 on: September 22, 2019, 12:23:03 am »
there is something strange because I made a local attempt to override that and turn off the WordWrap but it seem to ignore that. Humm..
 
 Oh well.

 This is my solution..
Code: Pascal  [Select][+][-]
  1. TLabel = Class(StdCtrls.TLabel)
  2.     procedure AdjustSize override;
  3.   end;                                        
  4. procedure TLabel.AdjustSize;
  5. begin
  6.   if Not AutoSize Then exit;
  7.   Inherited AdjustSize;
  8. end;                                      
  9.  
I override the AdjustSize and that works because commented out the Adjustsize won't adjust the box if autoSize is true..
« Last Edit: September 22, 2019, 12:45:50 am by jamie »
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 3250
Re: [SOLVED] TCustomLabel constraints in design and runtime
« Reply #29 on: September 22, 2019, 12:57:04 am »
I hope that the deleted line you did does not make it into the release because that is wrong, if needs to test for AutoSize before it can ignore it, otherwise you just made another bug
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018