View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0008765 | Lazarus | Widgetset | public | 2007-04-24 16:14 | 2011-12-01 11:22 |
Reporter | Graeme Geldenhuys | Assigned To | Mattias Gaertner | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | closed | Resolution | fixed | ||
Platform | i386 | OS | Ubuntu Linux | ||
Product Version | 0.9.23 (SVN) | ||||
Target Version | 0.9.30 | ||||
Summary | 0008765: Text to low in components under GTK2 | ||||
Description | The 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. | ||||
Tags | gtk2 | ||||
Fixed in Revision | 23028 | ||||
LazTarget | 0.9.30 | ||||
Widgetset | GTK 2 | ||||
Attached Files |
|
has duplicate | 0011120 | closed | Paul Ishenin | Painting bug in GTK2: TButton |
related to | 0015367 | closed | Zeljan Rikalo | Text too low in comboboxes under GTK2 (reopen of 8765) |
2007-04-24 16:14
|
|
2007-04-24 16:14
|
|
2007-04-24 16:15
|
|
2007-04-24 16:15
|
|
2007-04-24 16:15
|
|
2007-04-24 16:16
|
|
|
This doesn't happen for me any more, has it been fixed in the meantime? |
|
Graeme, see note above. Can you please retest and report back. |
|
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
|
|
|
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
|
|
|
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? |
|
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"'); |
|
@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). |
|
@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
|
|
|
@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" |
|
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. :-) |
|
@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. |
|
@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"'); |
|
@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
|
|
2009-12-07 16:16
|
|
|
@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; { |
|
@Graeme Please test the attached patch. No call to gtk_rc_parse_string is required Luiz |
|
@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. |
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 |