View Issue Details

IDProjectCategoryView StatusLast Update
0008765LazarusWidgetsetpublic2011-12-01 11:22
ReporterGraeme Geldenhuys Assigned ToMattias Gaertner  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformi386OSUbuntu Linux 
Product Version0.9.23 (SVN) 
Target Version0.9.30 
Summary0008765: Text to low in components under GTK2
DescriptionThe exact same forms under Win32 and GTK1 look fine and the text is centred in a button or combobox. Under GTK2 the text is just below centre and gets clipped by the component. See attached images show examples of Button's, ComboBox's and TBitBtn's.
Tagsgtk2
Fixed in Revision23028
LazTarget0.9.30
WidgetsetGTK 2
Attached Files

Relationships

has duplicate 0011120 closedPaul Ishenin Painting bug in GTK2: TButton 
related to 0015367 closedZeljan Rikalo Text too low in comboboxes under GTK2 (reopen of 8765) 

Activities

2007-04-24 16:14

 

button.gtk1.png (406 bytes)   
button.gtk1.png (406 bytes)   

2007-04-24 16:14

 

button.gtk2.png (1,236 bytes)   
button.gtk2.png (1,236 bytes)   

2007-04-24 16:15

 

combobox.gtk1.png (442 bytes)   
combobox.gtk1.png (442 bytes)   

2007-04-24 16:15

 

combobox.gtk2.png (1,229 bytes)   
combobox.gtk2.png (1,229 bytes)   

2007-04-24 16:15

 

login.gtk1.png (1,491 bytes)   
login.gtk1.png (1,491 bytes)   

2007-04-24 16:16

 

login.gtk2.png (2,680 bytes)   
login.gtk2.png (2,680 bytes)   

Henry Vermaak

2009-12-04 11:36

reporter   ~0032713

This doesn't happen for me any more, has it been fixed in the meantime?

Bart Broersma

2009-12-04 15:42

developer   ~0032719

Last edited: 2009-12-04 15:43

Graeme, see note above.
Can you please retest and report back.

Graeme Geldenhuys

2009-12-07 08:42

reporter   ~0032761

Wow, talk about a old bug report! :-)

To my surprise, this issue is still evident. See newly attached screenshot. Droping a default TButton on a form and changing it's caption to "Login" shows the issue - note I did not resize the TButton at all. Also compare the button on the Lazarus Form Designer to the one displayed by Mozilla Firefox for this bug (in Mantis web page). The Firefox button's text is correctly centred vertically and it is exactly the same height as the Lazarus TButton - 25 pixels.

2009-12-07 08:43

 

Screenshot.png (39,235 bytes)   
Screenshot.png (39,235 bytes)   

Graeme Geldenhuys

2009-12-07 08:48

reporter   ~0032762

Problem is reproducible using 0.9.28.3 and 0.9.29. Also note, I am using a totally new PC compared to when I initially reported the bug. So it's not something specific on my PC, otherwise Mozilla Firefox button would also be wrong.

I'm now using Ubuntu 9.04 (64bit).

2009-12-07 11:47

 

hcv_sshot.png (56,427 bytes)   
hcv_sshot.png (56,427 bytes)   

Henry Vermaak

2009-12-07 11:56

reporter   ~0032766

See my screenshot. The close button is 25 height, button1 is 17 height. This may have to do with how the eventbox packs the button widget on your version of gtk2. Does this problem still occur in other widgets like tbitbtn?

Luiz Americo

2009-12-07 12:49

developer   ~0032767

Hi, has been really a long time last time i looked this issue.

Only today i've got some improvement in my tests.

Graeme, try to put the following code in the start of the program file (lpr) :

(Requires gtk2 in uses clause)

  gtk_rc_parse_string(
      'style "lcl-button" {' +
      ' GtkButton::inner-border = {0, 0, 0, 0}' +
      '} ' +
      'class "GtkButton" style "lcl-button"');

Graeme Geldenhuys

2009-12-07 13:04

reporter   ~0032770

@Henry
I don't understand. What is 'how the eventbox packs...' mean?

I simply create a new project, drop a TButton and TBitBtn on the form. Change the Caption of TButton to 'Logout' and you can then see the difference and that the TButton text is clipped. TButton's text is not vertically centre in the button and with the default height of TButton is 25.

Using other themes like BlueCurve or Dust etc., the issue is still there, but not as visible as with the default ClearLooks theme. With the other themes, clipping might not appear, but you can definitely see that the text is to slow (not vertically centred like other Gnome/Gtk2 applications which are not created with Lazarus).

Graeme Geldenhuys

2009-12-07 13:20

reporter   ~0032771

@Luiz
See "Screenshot-1.png". It now looks better - no clipping occurs, but looking at the enlarged version of the button, the text still doesn't seem to be correctly vertical centred. In Lazarus generated GTK2 apps, the TButton text is still to low when I compare it to other non-Lazarus created GTK2 applications like Mozilla Firefox, etc.

2009-12-07 13:20

 

Screenshot-1.png (11,013 bytes)   
Screenshot-1.png (11,013 bytes)   

Luiz Americo

2009-12-07 13:53

developer   ~0032773

@Graeme:
Try
gtk_rc_parse_string(
      'style "lcl-button" {' +
      ' GtkButton::inner-border = {0, 0, 0, 0}' +
      ' xthickness = 0' +
      ' ythickness = 0' +
      '} ' +
      'class "GtkButton" style "lcl-button"');

With that i got an extra border around the button. Not sure how to avoid that.

I did not tried to add those line:

GtkButton::default-outside-border = {0, 0, 0, 0}
GtkButton::default-border = {0, 0, 0, 0}
GtkWidget::draw-border = {0, 0, 0, 0}

I also did not try GtkContainer property "border-width"

Graeme Geldenhuys

2009-12-07 14:27

reporter   ~0032775

I don't know GTK2 or those settings you mentioned. The extra border is obviously not correct, so I would still go with your first example even though the text is not 100% vertically centred. :-)

Henry Vermaak

2009-12-07 14:48

reporter   ~0032776

@Graeme:

The button is constructed by the lcl by putting a button widget into an eventbox. The LCL needs the eventbox for certain things. The way the button is added is very unsophisticated, since there are no settings for alignment or scaling, but gtk should centre it by default. The fact that this works fine for me with any theme led me to believe that maybe it's a bug in some gtk version. We may be able to remedy this by adding an alignment widget between the even box and the button. I'm just speculating, though, and it's hard since I can't reproduce here.

Luiz Americo

2009-12-07 15:27

developer   ~0032782

@Graeme

Please try:

  gtk_rc_parse_string(
      'style "lcl-button" {' +
      ' GtkButton::inner-border = {0, 0, 0, 0}' +
      ' xthickness = 0' +
      ' ythickness = 0' +
      ' GtkWidget::focus-line-width = 0' +
      '} ' +
      'class "GtkButton" style "lcl-button"');

Graeme Geldenhuys

2009-12-07 16:15

reporter   ~0032787

@Luiz
Your last idea looks perfect in the ClearLooks (my default) theme, but then when I change to themes like BlueCurve or eXperience, then the buttons are drawn completely flat and looks totally different to the non-Lazarus application buttons.

So still I think your first option is the best option. Playing with the Button Caption and various themes a bit more I definitely say your first option is the best. I also think I know why the text isn't 100% vertical centred when I had the caption "Logout". See screenshot-2 and screenshot-3. If you have capital letters with accents, then the total text height (including the accent) is actually centred (as far as I can see).

2009-12-07 16:16

 

Screenshot-2.png (5,427 bytes)   
Screenshot-2.png (5,427 bytes)   

2009-12-07 16:16

 

Screenshot-3.png (5,700 bytes)   
Screenshot-3.png (5,700 bytes)   

Luiz Americo

2009-12-07 17:21

developer   ~0032790

@Graeme:
It can be better than the first option

The problem is that GtkButton takes into account to position the child label three variables: innerborder, borderwidth and *thickness

Changing InnerBorder and BorderWidth to 0 has no collateral effects unlike *thickness that is used also to draw the focus etc.

The definite solution is to subclass GtkButton size_allocate and set the child position as we want.

A possible solution is to intercept when the button child (a label) is about to being positioned (on gtk semantic size allocated) and subtract *thickness from the left and top. not sure if this is possible using size-allocate signal or if it will be necessary subclassing

2009-12-08 02:07

 

button_size.diff (1,988 bytes)   
Index: lcl/interfaces/gtk2/gtk2wsstdctrls.pp
===================================================================
--- lcl/interfaces/gtk2/gtk2wsstdctrls.pp	(revision 23018)
+++ lcl/interfaces/gtk2/gtk2wsstdctrls.pp	(working copy)
@@ -1886,6 +1886,42 @@
   Result := DeliverMessage(AInfo^.LCLObject, Msg) = 0;
 end;
 
+procedure Gtk2WSButton_SizeAllocate(widget: PGtkWidget; allocation: PGtkAllocation; user_data: gpointer); cdecl;
+var
+  xthickness, ythickness: gint;
+  inner_border: PGtkBorder;
+begin
+  //the default GtkButton size_allocate handler takes into account
+  //*thickness and inner_border properties to position the child (label)
+  //see gtk_button_size_allocate in gtkbutton.c
+  //here this is reverted so the child is not padded
+  xthickness := widget^.style^.xthickness;
+  ythickness := widget^.style^.ythickness;
+  with PGtkBin(widget)^.child^.allocation do
+  begin
+    y := y - ythickness;
+    height := height + 2 * ythickness;
+    x := x - xthickness;
+    width := width + 2 * xthickness;
+    gtk_widget_style_get (widget, 'inner-border', @inner_border, nil);
+    if inner_border <> nil then
+    begin
+       x := x - inner_border^.left;
+       width := width + inner_border^.left + inner_border^.right;
+       y := y - inner_border^.top;
+       height := height + inner_border^.top + inner_border^.bottom;
+    end
+    else
+    begin
+      //if no inner-border is set, GtkButton uses a default border = (1,1,1,1)
+      dec(x);
+      dec(y);
+      inc(width, 2);
+      inc(height, 2);
+    end;
+  end;
+end;
+
 { TGtk2WSButton }
 
 class function TGtk2WSButton.GetButtonWidget(AEventBox: PGtkEventBox): PGtkButton;
@@ -1903,6 +1939,7 @@
 begin
   TGtkWSWinControl.SetCallbacks(PGtkObject(AGtkWidget), TComponent(AWidgetInfo^.LCLObject));
   SignalConnect(AWidgetInfo^.CoreWidget, 'clicked', @Gtk2WSButton_Clicked, AWidgetInfo);
+  SignalConnect(AWidgetInfo^.CoreWidget, 'size-allocate', @Gtk2WSButton_SizeAllocate, AWidgetInfo);
 end;
 
 {
button_size.diff (1,988 bytes)   

Luiz Americo

2009-12-08 02:08

developer   ~0032799

@Graeme

Please test the attached patch. No call to gtk_rc_parse_string is required

Luiz

Graeme Geldenhuys

2009-12-08 10:25

reporter   ~0032805

@Luiz
Congrats!! :-) Your patch file works perfectly on all themes (including those with focus rectangle on buttons). Using xmag (screen magnifier app) I can confirm that the text is now perfectly vertical centred.

If that patch is committed, this bug report can finally be closed.

Issue History

Date Modified Username Field Change
2007-04-24 16:14 Graeme Geldenhuys New Issue
2007-04-24 16:14 Graeme Geldenhuys File Added: button.gtk1.png
2007-04-24 16:14 Graeme Geldenhuys Widgetset => GTK 2
2007-04-24 16:14 Graeme Geldenhuys File Added: button.gtk2.png
2007-04-24 16:15 Graeme Geldenhuys File Added: combobox.gtk1.png
2007-04-24 16:15 Graeme Geldenhuys File Added: combobox.gtk2.png
2007-04-24 16:15 Graeme Geldenhuys File Added: login.gtk1.png
2007-04-24 16:16 Graeme Geldenhuys File Added: login.gtk2.png
2007-04-24 16:17 Vincent Snijders LazTarget => 1.2
2007-04-24 16:17 Vincent Snijders Status new => acknowledged
2008-04-12 12:26 Felipe Monteiro de Carvalho Tag Attached: gtk2
2008-04-16 02:54 Felipe Monteiro de Carvalho Relationship added has duplicate 0011120
2009-12-04 11:36 Henry Vermaak Note Added: 0032713
2009-12-04 15:42 Bart Broersma Note Added: 0032719
2009-12-04 15:42 Bart Broersma Status acknowledged => feedback
2009-12-04 15:43 Bart Broersma Note Edited: 0032719
2009-12-07 08:42 Graeme Geldenhuys Note Added: 0032761
2009-12-07 08:43 Graeme Geldenhuys File Added: Screenshot.png
2009-12-07 08:48 Graeme Geldenhuys Note Added: 0032762
2009-12-07 11:47 Henry Vermaak File Added: hcv_sshot.png
2009-12-07 11:56 Henry Vermaak Note Added: 0032766
2009-12-07 12:49 Luiz Americo Note Added: 0032767
2009-12-07 13:04 Graeme Geldenhuys Note Added: 0032770
2009-12-07 13:20 Graeme Geldenhuys Note Added: 0032771
2009-12-07 13:20 Graeme Geldenhuys File Added: Screenshot-1.png
2009-12-07 13:53 Luiz Americo Note Added: 0032773
2009-12-07 14:27 Graeme Geldenhuys Note Added: 0032775
2009-12-07 14:48 Henry Vermaak Note Added: 0032776
2009-12-07 15:27 Luiz Americo Note Added: 0032782
2009-12-07 16:15 Graeme Geldenhuys Note Added: 0032787
2009-12-07 16:16 Graeme Geldenhuys File Added: Screenshot-2.png
2009-12-07 16:16 Graeme Geldenhuys File Added: Screenshot-3.png
2009-12-07 17:21 Luiz Americo Note Added: 0032790
2009-12-08 02:07 Luiz Americo File Added: button_size.diff
2009-12-08 02:08 Luiz Americo Note Added: 0032799
2009-12-08 10:25 Graeme Geldenhuys Note Added: 0032805
2009-12-08 13:13 Vincent Snijders LazTarget 1.2 => 0.9.30
2009-12-08 13:13 Vincent Snijders Target Version => 0.9.30
2009-12-08 13:13 Vincent Snijders Status feedback => assigned
2009-12-08 13:13 Vincent Snijders Assigned To => Mattias Gaertner
2009-12-08 13:39 Mattias Gaertner Fixed in Revision => 23028
2009-12-08 13:39 Mattias Gaertner Status assigned => resolved
2009-12-08 13:39 Mattias Gaertner Resolution open => fixed
2009-12-17 12:44 Vincent Snijders Relationship added related to 0015367
2011-12-01 11:22 Marc Weustink Status resolved => closed