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 357950 - Style property to control arrow size
Style property to control arrow size
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkComboBox
unspecified
Other All
: Normal enhancement
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2006-09-27 11:18 UTC by Kristian Rietveld
Modified: 2006-11-01 19:16 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch (1.41 KB, patch)
2006-09-27 11:20 UTC, Kristian Rietveld
none Details | Review
updated patch (1.89 KB, patch)
2006-10-18 12:17 UTC, Kristian Rietveld
none Details | Review
patch as committed (2.24 KB, patch)
2006-11-01 19:12 UTC, Kristian Rietveld
accepted-commit_now Details | Review

Description Kristian Rietveld 2006-09-27 11:18:28 UTC
Maemo adds properties to control the arrow width/height of the arrow in the combo box.  Based on this idea I wrote a small patch which adds a style property to set the arrow size.

Currently the size of the arrow is determined by size requisition/allocation of the other widgets in the combo box -- choosing a nice default here is difficult.  For now I've choosen a default of 18, which looks nice here.

Also, this property actually sets a guaranteed minimum size for the arrow.  If much more space is allocated the the combo box, the arrow will be bigger than arrow-size.
Comment 1 Kristian Rietveld 2006-09-27 11:20:24 UTC
Created attachment 73485 [details] [review]
patch
Comment 2 Matthias Clasen 2006-10-02 02:55:12 UTC
Looks fine to me. Maybe the docs should say "minimum size" then.
And there should be a doc comment with a "Since: 2.12" in it
Comment 3 Tim Janik 2006-10-02 11:50:25 UTC
doesn't this mean that comboboxes will suddenly have really big arrows for people who currently use pretty small fonts?
why does there need to be a minimum size of 18 at all? can't we simply default to 0 and have the arrow fill the actual allocation like it currently works?
Comment 4 Kristian Rietveld 2006-10-04 13:21:07 UTC
After some more testing it looks like I was wrong in my original comment.

(In reply to comment #0)
> Currently the size of the arrow is determined by size requisition/allocation of
> the other widgets in the combo box -- choosing a nice default here is
> difficult.  For now I've choosen a default of 18, which looks nice here.

It appears GtkArrow has a default arrow size of 15, with a default requistion of arrow_size + {x,y}pad.

> Also, this property actually sets a guaranteed minimum size for the arrow.  If
> much more space is allocated the the combo box, the arrow will be bigger than
> arrow-size.

When setting a much bigger font, the button scales up but the arrow doesn't.

I guess 15 is a nicer default, seen that xpad/ypad are zero by default.


Comment 5 Kristian Rietveld 2006-10-18 12:17:06 UTC
Created attachment 74941 [details] [review]
updated patch

To reply again to Tim; for people with really small fonts, the size of the arrow will stay at 15.  To me it makes sense to introduce this minimum size to keep the minimum size of the arrow the same as it was before.  Also, if we don't do this, the arrow is barely visible for font size 6, for example.

The arrow size is also a minimum size now, as it will scale up together with the font size.
Comment 6 Tim Janik 2006-10-23 11:57:00 UTC
Comment on attachment 74941 [details] [review]
updated patch

(In reply to comment #5)
> To reply again to Tim; for people with really small fonts, the size of the
> arrow will stay at 15.  To me it makes sense to introduce this minimum size to
> keep the minimum size of the arrow the same as it was before.  Also, if we
> don't do this, the arrow is barely visible for font size 6, for example.

sounds good.

>Index: gtkcombobox.c
>===================================================================
>RCS file: /cvs/gnome/gtk+/gtk/gtkcombobox.c,v
>retrieving revision 1.185
>diff -u -p -r1.185 gtkcombobox.c
>--- gtkcombobox.c	12 Oct 2006 13:48:07 -0000	1.185
>+++ gtkcombobox.c	18 Oct 2006 12:07:43 -0000
>@@ -756,6 +756,25 @@ gtk_combo_box_class_init (GtkComboBoxCla
>                                                                  FALSE,
>                                                                  GTK_PARAM_READABLE));
> 
>+  /**
>+   * GtkComboBox:arrow-size:
>+   *
>+   * Sets the minimum size of the arrow in the combo box.  Note
>+   * that the arrow size is coupled to the font size, so in case
>+   * a larger font is used, the arrow will be larger than set
>+   * by arrow size.
>+   *
>+   * Since: 2.12
>+   */
>+  gtk_widget_class_install_style_property (widget_class,
>+					   g_param_spec_int ("arrow-size",
>+							     P_("Arrow Size"),
>+							     P_("The minimum size of the arrow in the combo box"),
>+							     0,
>+							     G_MAXINT,
>+							     15,
>+							     GTK_PARAM_READABLE));
>+
>   g_type_class_add_private (object_class, sizeof (GtkComboBoxPrivate));
> }
> 
>@@ -1897,6 +1916,8 @@ gtk_combo_box_size_request (GtkWidget   
> {
>   gint width, height;
>   gint focus_width, focus_pad;
>+  gint font_size;

if font_size is an int...

>+  gint arrow_size;
>   GtkRequisition bin_req;
> 
>   GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
>@@ -1910,7 +1931,14 @@ gtk_combo_box_size_request (GtkWidget   
>   gtk_widget_style_get (GTK_WIDGET (widget),
> 			"focus-line-width", &focus_width,
> 			"focus-padding", &focus_pad,
>+			"arrow-size", &arrow_size,
> 			NULL);
>+
>+  font_size = (double)pango_font_description_get_size (GTK_BIN (widget)->child->style->font_desc) / (double)PANGO_SCALE;

the double casts here are pretty useless. (and needless casts are generally bad, they blinden the compiler.)

in any case, i think your use of pango_font_description_get_size() needs to be fixed to special case absolute size settings, as indicated by the docs:
  http://developer.gnome.org/doc/API/2.0/pango/pango-Fonts.html#pango-font-description-get-size
or, it might be easier to use pango_font_metrics_get_ascent() / pango_font_metrics_get_descent() to figure the arrow size.

>+
>+  arrow_size = MAX (arrow_size, font_size);
>+
>+  gtk_widget_set_size_request (combo_box->priv->arrow, arrow_size, arrow_size);
> 
>   if (!combo_box->priv->tree_view)
>     {

one thing that escapes me here is:

> The arrow size is also a minimum size now, as it will scale up together with
> the font size.

how's that evident from the current code? i.e. what's currently causing the arrow to be 15 pixels?
Comment 7 Kristian Rietveld 2006-10-23 18:14:02 UTC
(In reply to comment #6)
> in any case, i think your use of pango_font_description_get_size() needs to be
> fixed to special case absolute size settings, as indicated by the docs:
>  
> http://developer.gnome.org/doc/API/2.0/pango/pango-Fonts.html#pango-font-description-get-size
> or, it might be easier to use pango_font_metrics_get_ascent() /
> pango_font_metrics_get_descent() to figure the arrow size.

I saw that and then looked in the gtk+ source for an example, but it appeared that nothing in gtk+ is taking this special case into account.  So that means that many more cases need to be fixed ...

> > The arrow size is also a minimum size now, as it will scale up together with
> > the font size.
> 
> how's that evident from the current code? i.e. what's currently causing the
> arrow to be 15 pixels?

See comment #4, the arrow has a default (hard coded) size of 15 and it requests that plus xpad/ypad.
Comment 8 Kristian Rietveld 2006-11-01 19:12:21 UTC
Created attachment 75789 [details] [review]
patch as committed

I ended up using font metrics anyway ...
Comment 9 Kristian Rietveld 2006-11-01 19:16:15 UTC
2006-11-01  Kristian Rietveld  <kris@imendio.com>

        * gtk/gtkcombobox.c (gtk_combo_box_class_init),
        (gtk_combo_box_size_request): add arrow-size property to control
        the minimum size of the arrow, have the arrow scale up with the
        font by default. (#357950).