Recent

Author Topic: Label properties  (Read 10759 times)

douglas.cast

  • Guest
Label properties
« on: March 11, 2017, 08:51:24 pm »
Hello everyone.

I have two forms in my application, form1 sending a long string (more than 300 characters) or short string (less than 50 characthers) to a label on form2 with a click of a button

Code: Pascal  [Select][+][-]
  1. Some label properties
  2. Align == alClient
  3. Alignment = taCenter
  4. Layout = tlCenter
  5. WordWrap = True
  6. AutoSize = True
  7. OptimalFill = True

The idea is to adjust the height of the text with OptimalFill, but when I send a long string to the label, the font size, goes all wrong, sometimes the label fills right (when I repeat a long string after a short string for example).

IF I change the Caption, the text height goes bad (still the font size of the first string that I've used), it only changes when I send a small string, things just go strange.

Already tried:

Code: Pascal  [Select][+][-]
  1. Caption: = ''; // to 'reset' the font size
  2.  
  3. Legend: = # 0;
  4.  
  5. Caption: = '';
  6.  
  7. Caption: = '-'; // to 'delete' and refresh the font height, after it, I assinged the right string
  8.  
  9. Label.Update; // to update the 'math'
  10.  
  11. Label.Refresh; // to update the 'math'
  12.  
  13. Label.AdjustSize
  14.  
  15. Application.ProcessMessages
  16.  
  17. Form2.Update
  18.  
  19. Label.UpdateBaseBound
  20.  
  21. Labe.AdjustFontForOptimalFill;

I tried after and before the 'on click sent string to'

Code: Pascal  [Select][+][-]
  1. label.Caption: = stringGrid.Cells [0, stringGrid.Row];

Also tried enable and disable the label to 'reset' everything.

Nothing works right, things have a strange value so the font size depends on the length of the sequence.

How can I make it work right and create the right source calculation each time Legend changes?

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1186
    • Burdjia
Re: Label properties
« Reply #1 on: March 12, 2017, 08:24:00 pm »
Is that the actual code?  It looks really messy.  Anyway, I think you don't need to assign Caption so much times.
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

douglas.cast

  • Guest
Re: Label properties
« Reply #2 on: March 13, 2017, 03:13:10 am »
That's not the code, I've used the
Code: [Select]
tag to set what I've already tried, but I've tried one by one, like:

[code=pascal]
    label.Caption: = stringGrid.Cells [0, stringGrid.Row];
    label.Update //one command at time

After Update I've tried Refresh

Code: Pascal  [Select][+][-]
  1.     label.Caption: = stringGrid.Cells [0, stringGrid.Row];
  2.     label.Refresh
  3.  

After Refres I've tried 'clean up' the OptimalFill

Code: Pascal  [Select][+][-]
  1.     label.Caption:= ' ';
  2.     label.Caption: = stringGrid.Cells [0, stringGrid.Row];
  3.  

And so on...

But nothing works rigth.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Label properties
« Reply #3 on: March 13, 2017, 10:10:36 am »
Code snippets are mostly useless to help others understanding problems in code, since often they do not show the 'real' problem (or it may only appear in combination with unshown code).
If you want help show a (possibly cut-down, perhaps with dummy data) compilable project which demonstrates the feature you don't want.
BTW your code snippet appears to use the keyword "label" as an identifier.

douglas.cast

  • Guest
Re: Label properties
« Reply #4 on: March 13, 2017, 04:21:43 pm »
I think I was clear enough, but english still 'pretty bad' (somewhere).

The example (to copy and paste and try)

form1
4 Buttons, 3 to send the strings and one to call form2

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, Unit2;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Button2: TButton;
  17.     Button3: TButton;
  18.     Button4: TButton;
  19.     procedure Button1Click(Sender: TObject);
  20.     procedure Button2Click(Sender: TObject);
  21.     procedure Button3Click(Sender: TObject);
  22.     procedure Button4Click(Sender: TObject);
  23.   private
  24.     { private declarations }
  25.   public
  26.     { public declarations }
  27.   end;
  28.  
  29. var
  30.   Form1: TForm1;
  31.  
  32. implementation
  33.  
  34. {$R *.lfm}
  35.  
  36. { TForm1 }
  37.  
  38. procedure TForm1.Button4Click(Sender: TObject);
  39. begin
  40.   with Form2 do begin
  41.     Show;
  42.   end;
  43. end;
  44.  
  45. procedure TForm1.Button1Click(Sender: TObject);
  46. begin
  47.   Form2.lDisplay.Caption:='Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
  48. end;
  49.  
  50. procedure TForm1.Button2Click(Sender: TObject);
  51. begin
  52.   Form2.lDisplay.Caption:='Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.';
  53. end;
  54.  
  55. procedure TForm1.Button3Click(Sender: TObject);
  56. begin
  57.   Form2.lDisplay.Caption:='Just a string';
  58. end;
  59.  
  60. end.
  61.  

Form2

Just a label called lDisplay,
align = alClient
AutoSize = True
BorderSpacing.Around = 15
OptimalFill = True
WordWrap = True

Code: Pascal  [Select][+][-]
  1. unit Unit2;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm2 }
  13.  
  14.   TForm2 = class(TForm)
  15.     lDisplay: TLabel;
  16.   private
  17.     { private declarations }
  18.   public
  19.     { public declarations }
  20.   end;
  21.  
  22. var
  23.   Form2: TForm2;
  24.  
  25. implementation
  26.  
  27. {$R *.lfm}
  28.  
  29. end.
  30.  

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Label properties
« Reply #5 on: March 13, 2017, 07:06:05 pm »
TBH I've never used TLabel's OptimalFill property before.
It seems a bit unreliable in my testing, or perhaps it's just that changes in Autosize, Wordwrap, Anchors, Align etc. can complicate the label environment completely.
Anyway, the attached project allows you to play with all a label's published properties using a RTTIGrid, and if AutoSize is False and WordWrap is True and Align is alNone it seems to work as one would expect (at least with the gtk2 widgetset).

ASerge

  • Hero Member
  • *****
  • Posts: 2222
Re: Label properties
« Reply #6 on: March 14, 2017, 03:37:19 pm »
Looks like a bug in the method TLabel.CalcFittingFontHeight, which used by OptimalFill
Added issue http://bugs.freepascal.org/view.php?id=31538

douglas.cast

  • Guest
Re: Label properties
« Reply #7 on: March 22, 2017, 02:55:33 pm »
TBH I've never used TLabel's OptimalFill property before.
It seems a bit unreliable in my testing, or perhaps it's just that changes in Autosize, Wordwrap, Anchors, Align etc. can complicate the label environment completely.
Anyway, the attached project allows you to play with all a label's published properties using a RTTIGrid, and if AutoSize is False and WordWrap is True and Align is alNone it seems to work as one would expect (at least with the gtk2 widgetset).

Sorry for the time I've picked to  awser, but I'm literally runnning out of time in hier  = /

Sorry for the time I've picked to  answer, but I'm literally runnning out of time in hier  = /

I've tryied your attachment but I got a error: Can't open resource file "path/published/LabelPropertiesExample.res"

Can't find a way to create it, sadly I'm not that smart with programming yet.

Looks like a bug in the method TLabel.CalcFittingFontHeight, which used by OptimalFill
Added issue http://bugs.freepascal.org/view.php?id=31538

Do you know how many 12 months they need to fix it?

Let's say I need to figure out a way to display the text, but Canvas property it's out of my plans, considering the math and code that is used.

Thanks for the support until now.

ASerge

  • Hero Member
  • *****
  • Posts: 2222
Re: Label properties
« Reply #8 on: March 22, 2017, 08:04:34 pm »
Do you know how many 12 months they need to fix it?
The bug shows the fix, use it in you code without waiting 12 months.

GAN

  • Sr. Member
  • ****
  • Posts: 370
Re: Label properties
« Reply #9 on: March 23, 2017, 05:21:24 am »
Please, try this code:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   form2.lDisplay.Align:=alClient;
  4.   form2.lDisplay.Alignment:=taCenter;
  5.   form2.lDisplay.Layout:=tlCenter;
  6.   form2.lDisplay.WordWrap:=True;
  7.   form2.lDisplay.AutoSize:=True;
  8.   form2.lDisplay.OptimalFill:=True;
  9.   //form2.lDisplay.Font.Height:=20;
  10.   Form2.lDisplay.Caption:='Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
  11. end;  

Regards.
Lazarus 2.0.8 FPC 3.0.4 Linux Mint Mate 19.3
Zeos 7̶.̶2̶.̶6̶ 7.1.3a-stable - Sqlite 3.32.3 - LazReport

ASerge

  • Hero Member
  • *****
  • Posts: 2222
Re: Label properties
« Reply #10 on: March 23, 2017, 05:57:28 pm »
Please, try this code:
In Windows it does not work: the text doesn't fit, but the font does not change.
The hotfix that is listed in the buglist, changes the font correctly.

bytebites

  • Hero Member
  • *****
  • Posts: 632
Re: Label properties
« Reply #11 on: March 23, 2017, 07:24:05 pm »
Please, try this code:
In Windows it does not work: the text doesn't fit, but the font does not change.
The hotfix that is listed in the buglist, changes the font correctly.

Could you please create proper diff-file about the fix.

ASerge

  • Hero Member
  • *****
  • Posts: 2222
Re: Label properties
« Reply #12 on: March 25, 2017, 06:52:46 am »
Could you please create proper diff-file about the fix.
Is there a link to the utility for this purpose?

douglas.cast

  • Guest
Re: Label properties
« Reply #13 on: March 30, 2017, 09:49:08 pm »
Do you know how many 12 months they need to fix it?
The bug shows the fix, use it in you code without waiting 12 months.

It was a joke, just wondering how much time to a fix be turned into a final fix, I'll try the code.

Please, try this code:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   form2.lDisplay.Align:=alClient;
  4.   form2.lDisplay.Alignment:=taCenter;
  5.   form2.lDisplay.Layout:=tlCenter;
  6.   form2.lDisplay.WordWrap:=True;
  7.   form2.lDisplay.AutoSize:=True;
  8.   form2.lDisplay.OptimalFill:=True;
  9.   //form2.lDisplay.Font.Height:=20;
  10.   Form2.lDisplay.Caption:='Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
  11. end;  

Regards.

That was my default configuration, I've tried this way, but nothing seems to work.

douglas.cast

  • Guest
Re: Label properties
« Reply #14 on: April 18, 2017, 06:38:03 pm »
Before some long time off with programing, I'm just wondering how can I use the "solution code" from bug tracker on Linux (Windows its not in there) and by some reason I can't login into bug tracker to ask for it in there.

Any suggestions?

 

TinyPortal © 2005-2018