TLabel autosize crops descenders [fixed] lazarus / 32-Linux ---------------------------------------------------------------------- andyH · 2021-03-02 13:42 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? ---------------------------------------------------------------------- Bart · 2021-03-02 14:10 Already reported in the bugtracker (too lazy to look it up for you right now). Bart ---------------------------------------------------------------------- howardpc · 2021-03-02 14:12 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 · 2021-03-02 14:26 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!! ---------------------------------------------------------------------- andyH · 2021-03-02 15:24 Quote from: Bart on March 02, 2021, 03:10:50 pmAlready 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. QuoteI 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 · 2021-03-02 15:26 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. ---------------------------------------------------------------------- winni · 2021-03-02 15:29 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 ---------------------------------------------------------------------- howardpc · 2021-03-02 16:07 Quote from: winni on March 02, 2021, 04:29:32 pmassigned 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 · 2021-03-03 13:26 A fix, an 'autosizing' TLabel that won't chop the descenders. I won't pretend it is elegant  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit GTKlabel; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, StdCtrls, Graphics; type  TLabelGTK = class(TLabel)    const      hAdd = 2; //add to text height of caption      wAdd = 10; //add to text width of caption    private      procedure setWidth;      procedure setHeight;    public      constructor Create(TheOwner: TComponent);  override;      procedure setCaption(CaptionStr : string);  end; implementationconstructor TLabelGTK.Create(TheOwner: TComponent);begin  inherited Create(TheOwner);  AutoSize:= false;  layout:= tlCenter;  Caption:= 'xxx';  setWidth;  setHeight;end;procedure TLabelGTK.setWidth;var  bmp: TBitmap;begin  bmp := TBitmap.Create;  writeln('caption in setwidth=',caption);  try    bmp.Canvas.Font.Assign(Font);    Width:= bmp.Canvas.TextWidth(Caption) + wAdd;    writeln('width in caption=',width);  finally    bmp.Free;  end;end;procedure TLabelGTK.setHeight;var  bmp: TBitmap;begin  bmp := TBitmap.Create;  try    bmp.Canvas.Font.Assign(Font);    Height:= bmp.Canvas.TextHeight(Caption) + hAdd;  finally    bmp.Free;  end;end;procedure TLabelGTK.setCaption(CaptionStr : string);begin  Caption:= CaptionStr;  writeln('GTK width before=',width);  setWidth;  writeln('GTK width after=',width);  setHeight;end; end. 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  mylabel : TLabelGTK;begin  mylabel:= TLabelGTK.create;  mylabel.setCaption('whatever you want');end;  Screenshots, left label = TLabel, right label = TLabelGTK, before click = caption in TLabelGTK assigned as normal in a TLabel, after = caption set with setCaption.