Recent

Author Topic: TLabel autosize crops descenders [fixed]  (Read 2603 times)

andyH

  • Jr. Member
  • **
  • Posts: 99
TLabel autosize crops descenders [fixed]
« on: March 02, 2021, 02:42:28 pm »
Suspect this might be OS specific so posting here. Running linux (LM20.1) with Lazarus 2.0.10.

With the property autosize:= true (the default) on a TLabel it is chopping the descenders, e.g. g, j, y, on the caption - see attached.

Setting autosize:= false fixes the problem but that then means that I have to manage the TLabel height and width. My captions in TLabels will change  :(

Am I missing something, looked for a property to set vertical alignment of text in a TLabel, couldn't find one?
« Last Edit: March 03, 2021, 02:27:09 pm by andyH »

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: TLabel autosize
« Reply #1 on: March 02, 2021, 03:10:50 pm »
Already reported in the bugtracker (too lazy to look it up for you right now).

Bart
« Last Edit: March 02, 2021, 03:34:33 pm by Bart »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: TLabel autosize
« Reply #2 on: March 02, 2021, 03:12:27 pm »
I think the autosize descenders truncation is a gtk-related bug which may have been fixed in more recent Lazarus versions.
TLabel has a Layout property which gives you three options for vertical alignment: tlTop, tlCenter, tlBottom.
If you want more finely-grained control than that, you have to draw the text yourself, not rely on a label.

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1111
  • Professional amateur ;-P
Re: TLabel autosize
« Reply #3 on: March 02, 2021, 03:26:25 pm »
The problem is definitely a gtk related issue.

I had to change fonts on my Geany(Ubuntu 20.10) because all the underscores disappeared from the default monospace font.

And it's not only on a TLabel, all the node text on a VirtualStringTree will have truncated descenders.

Not to mention the fact that the min height for a TEdit is way bigger on my Ubuntu than it is on Windows!!
Lazarus 3.99(main) FPC 3.3.1(main) Ubuntu 23.10 64b Dark Theme
Lazarus 3.0.0(stable) FPC 3.2.2(stable) Ubuntu 23.10 64b Dark Theme
http://github.com/gcarreno

andyH

  • Jr. Member
  • **
  • Posts: 99
Re: TLabel autosize
« Reply #4 on: March 02, 2021, 04:24:40 pm »
Already reported in the bugtracker (too lazy to look it up for you right now).
I could have looked it up myself, so not the only lazy one!

@howardpc - I'll have a play with tlTop, tlCenter, tlBottom and see if it makes any difference, otherwise I'll have to do it by code - get text height and width and then set the tlabel as appropriate.

Quote
I had to change fonts on my Geany(Ubuntu 20.10) because all the underscores disappeared from the default monospace font. And it's not only on a TLabel, all the node text on a VirtualStringTree will have truncated descenders.
Funnily, the captions on the form headings and titles on Ttabsheets are okay, just the TLabels, but I'll look more closely.

Thanks to all.

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: TLabel autosize
« Reply #5 on: March 02, 2021, 04:26:26 pm »
I've noticed this bug. A quick check is not showing it now though, maybe it got fixed. I'll have another look when I have time.

The large size of the TEdit box on Linux is annoying when trying to design cross-platform forms. I run some code on each dialog to calculate the total required height to contain the controls, and resize the form to contain them. It works most of the time, but it would be nice to be able to anchor the bottom of the form to the lowest control. If that is possible, I have not figured it out.
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: TLabel autosize
« Reply #6 on: March 02, 2021, 04:29:32 pm »
Hi!

This problem is ancient. And yes: a gtk2 problem.

Nobody cared for years.

I wrote it to the bugtracker last December: https://bugs.freepascal.org/view.php?id=38211

assigned to: [nobody]

So nobody cares.

Winni
« Last Edit: March 02, 2021, 04:53:12 pm by winni »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: TLabel autosize
« Reply #7 on: March 02, 2021, 05:07:29 pm »
assigned to: [nobody]

So nobody cares.
That is one conclusion among many possibilities.
Perhaps no one who understands gtk well enough to address the problem is aware of it.
Or perhaps there is such a person but s/he has other priorities, or only checks the bug list very occasionally.
Or perhaps it is a fundamental widgetset flaw for which no Lazarus person yet has a reliable workaround that will circumvent it.
etc., etc.



andyH

  • Jr. Member
  • **
  • Posts: 99
Re: TLabel autosize
« Reply #8 on: March 03, 2021, 02:26:18 pm »
A fix, an 'autosizing' TLabel that won't chop the descenders. I won't pretend it is elegant  :)
Code: Pascal  [Select][+][-]
  1. unit GTKlabel;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, StdCtrls, Graphics;
  9.  
  10. type
  11.   TLabelGTK = class(TLabel)
  12.     const
  13.       hAdd = 2; //add to text height of caption
  14.       wAdd = 10; //add to text width of caption
  15.     private
  16.       procedure setWidth;
  17.       procedure setHeight;
  18.     public
  19.       constructor Create(TheOwner: TComponent);  override;
  20.       procedure setCaption(CaptionStr : string);
  21.   end;
  22.  
  23. implementation
  24. constructor TLabelGTK.Create(TheOwner: TComponent);
  25. begin
  26.   inherited Create(TheOwner);
  27.   AutoSize:= false;
  28.   layout:= tlCenter;
  29.   Caption:= 'xxx';
  30.   setWidth;
  31.   setHeight;
  32. end;
  33. procedure TLabelGTK.setWidth;
  34. var
  35.   bmp: TBitmap;
  36. begin
  37.   bmp := TBitmap.Create;
  38.   writeln('caption in setwidth=',caption);
  39.   try
  40.     bmp.Canvas.Font.Assign(Font);
  41.     Width:= bmp.Canvas.TextWidth(Caption) + wAdd;
  42.     writeln('width in caption=',width);
  43.   finally
  44.     bmp.Free;
  45.   end;
  46. end;
  47. procedure TLabelGTK.setHeight;
  48. var
  49.   bmp: TBitmap;
  50. begin
  51.   bmp := TBitmap.Create;
  52.   try
  53.     bmp.Canvas.Font.Assign(Font);
  54.     Height:= bmp.Canvas.TextHeight(Caption) + hAdd;
  55.   finally
  56.     bmp.Free;
  57.   end;
  58. end;
  59. procedure TLabelGTK.setCaption(CaptionStr : string);
  60. begin
  61.   Caption:= CaptionStr;
  62.   writeln('GTK width before=',width);
  63.   setWidth;
  64.   writeln('GTK width after=',width);
  65.   setHeight;
  66. end;
  67.  
  68. end.
  69.  
Change hAdd and wAdd to suit and strip out the writelns.

Replace all TLabels with TLabelGTK and in normal use, use setCaption to change the caption:
Code: Pascal  [Select][+][-]
  1. var
  2.   mylabel : TLabelGTK;
  3. begin
  4.   mylabel:= TLabelGTK.create;
  5.   mylabel.setCaption('whatever you want');
  6. end;
  7.  

Screenshots, left label = TLabel, right label = TLabelGTK, before click = caption in TLabelGTK assigned as normal in a TLabel, after = caption set with setCaption.
« Last Edit: March 03, 2021, 02:44:41 pm by andyH »

 

TinyPortal © 2005-2018