After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 104679 - misaligned icons/text in GtkToolbar buttons
misaligned icons/text in GtkToolbar buttons
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: Other
2.2.x
Other All
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
: 106337 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2003-01-28 22:14 UTC by Daniel Elstner
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gtktoolbar_alignment_fix.diff (10.18 KB, patch)
2003-01-28 22:15 UTC, Daniel Elstner
none Details | Review
gtktoolbar_alignment_fix_uw.diff (4.27 KB, patch)
2003-01-29 21:48 UTC, Daniel Elstner
none Details | Review
gtktoolbar_alignment_fix_proper.diff (7.70 KB, patch)
2003-01-30 18:36 UTC, Daniel Elstner
none Details | Review

Description Daniel Elstner 2003-01-28 22:14:19 UTC
The label/image inside a toolbar button is not properly centered if the
GtkToolbar style is icons-only or text-only.  Even worse, the exact
alignment depends on the style that was set previously.

This happens because the image/label is packed into a GtkBox with the
expand and fill flags set to either FALSE or the value used by the previous
style.  The packing options are always the same only for the 'both' and
'both_horiz' styles.

The attached patch fixes the problem by setting expand = TRUE, fill = TRUE
if there's only a single widget in the GtkBox.
Comment 1 Daniel Elstner 2003-01-28 22:15:34 UTC
Created attachment 13895 [details] [review]
gtktoolbar_alignment_fix.diff
Comment 2 Owen Taylor 2003-01-29 20:03:06 UTC
Could you regenerate the patch with cvs diff -uw? It's
a little hard to see what changed in the version above.
Thanks.
Comment 3 Daniel Elstner 2003-01-29 21:48:26 UTC
Created attachment 13932 [details] [review]
gtktoolbar_alignment_fix_uw.diff
Comment 4 Daniel Elstner 2003-01-29 21:49:14 UTC
Oh cool.  Didn't know about -uw ;-)
Comment 5 Owen Taylor 2003-01-29 22:43:14 UTC
A) Isn't the only time you want anything other than TRUE/TRUE
   the icon for BOTH_HORIZONTAL and maybe the text for 
   BOTH?

B) Really, I'm think this patch needs to clean up the
   code not make things worse :-)

   The logic for deciding the packing options needs to
   be in only one place. I think it might be best to
   just pack them in an arbitrary fashion to begin with
   and have a function to set_child_packing() that is called 
   as necessary.
Comment 6 Daniel Elstner 2003-01-30 18:36:23 UTC
Created attachment 13964 [details] [review]
gtktoolbar_alignment_fix_proper.diff
Comment 7 Daniel Elstner 2003-01-30 18:39:20 UTC
This one is easier to read without -w :)

Was there any reason not to use gtk_bin_get_child()?  I couldn't think
of any and thus deliberately removed the get_first_child() helper
function.
Comment 8 Owen Taylor 2003-01-30 20:29:28 UTC
I think the code didn't use gtk_bin_get_child()
because it predated it.

Hmm, you seem to be setting the magic object 
data on items  of type CHILD_WIDGET now. What's
the reason for this.

-      if (type != GTK_TOOLBAR_CHILD_WIDGET)
-        {
-          /* Mark child as ours */
-          g_object_set_data (G_OBJECT (child->widget),
-                             "gtk-toolbar-is-child",
-                             GINT_TO_POINTER (TRUE));
-        }
+      set_child_packing_and_visibility (toolbar, child);
+

Other than that it looks good. Reading over the code, 
I see that both the old code and your code has:

+                  gtk_container_remove (GTK_CONTAINER
(child->widget), hbox)

The remove the old hbox or vbox and get rid of it.
I would recommend:

 gtk_widget_destroy (hbox);

instead ... less chance of a memory leak from a left
over weak reference, and simpler as well.




Comment 9 Daniel Elstner 2003-01-30 20:41:58 UTC
The if (type != GTK_TOOLBAR_CHILD_WIDGET) is superfluous because it's
always true.  The switch() branch is:

    case GTK_TOOLBAR_CHILD_BUTTON:
    case GTK_TOOLBAR_CHILD_TOGGLEBUTTON:
    case GTK_TOOLBAR_CHILD_RADIOBUTTON:

GTK_TOOLBAR_CHILD_WIDGET is handled before that, and there's no
fallthrough.
Comment 10 Owen Taylor 2003-01-30 20:53:54 UTC
Ah, makes sense.
Comment 11 Daniel Elstner 2003-01-30 21:48:01 UTC
Committed to gtk-2-2 and HEAD.
Comment 12 Owen Taylor 2003-02-17 20:22:14 UTC
*** Bug 106337 has been marked as a duplicate of this bug. ***