libgimp: different widget default for GimpChoice in GimpProcedureDialog…

… depending on the number of choices.

Enforcing a UX decision into code from GIMP/Design/gimp-ux#323.
Note that this is not a perfect automatization, since the right default
widget may still be a combo box even for limited choices arguments, when
the dialog is crowded.
It still improves the defaults, and it is still possible to override the
widget on case by case (just as of now).

(cherry picked from commit bcb736db61)
This commit is contained in:
Jehan 2025-05-05 15:12:02 +02:00
parent 38b5a53783
commit 972206d08c

View file

@ -647,8 +647,8 @@ gimp_procedure_dialog_set_ok_label (GimpProcedureDialog *dialog,
* * %GIMP_TYPE_LABEL_ENTRY (default): an entry with a label.
* * %GTK_TYPE_ENTRY: an entry with no label.
* * %GTK_TYPE_TEXT_VIEW: a text view with no label.
* - %GIMP_TYPE_CHOICE:
* * %GTK_TYPE_COMBO_BOX (default): a combo box displaying every
* - %GIMP_TYPE_CHOICE (default will depend on the number of choices):
* * %GTK_TYPE_COMBO_BOX: a combo box displaying every
* choice.
* * %GIMP_TYPE_INT_RADIO_FRAME: a frame with radio buttons.
* - %GEGL_TYPE_COLOR:
@ -857,14 +857,28 @@ gimp_procedure_dialog_get_widget (GimpProcedureDialog *dialog,
}
else if (G_PARAM_SPEC_TYPE (pspec) == GIMP_TYPE_PARAM_CHOICE)
{
if (widget_type == G_TYPE_NONE || widget_type == GTK_TYPE_COMBO_BOX)
GType real_widget_type = widget_type;
if (real_widget_type == G_TYPE_NONE)
{
GimpChoice *choice = gimp_param_spec_choice_get_choice (pspec);
gint n_choices;
n_choices = g_list_length (gimp_choice_list_nicks (choice));
if (n_choices > 3)
real_widget_type = GTK_TYPE_COMBO_BOX;
else
real_widget_type = GIMP_TYPE_INT_RADIO_FRAME;
}
if (real_widget_type == GTK_TYPE_COMBO_BOX)
{
widget = gimp_prop_choice_combo_box_new (G_OBJECT (priv->config), property);
gtk_widget_set_vexpand (widget, FALSE);
gtk_widget_set_hexpand (widget, TRUE);
widget = gimp_label_string_widget_new (g_param_spec_get_nick (pspec), widget);
}
else if (widget_type == GIMP_TYPE_INT_RADIO_FRAME)
else if (real_widget_type == GIMP_TYPE_INT_RADIO_FRAME)
{
widget = gimp_prop_choice_radio_frame_new (G_OBJECT (priv->config), property);
gtk_widget_set_vexpand (widget, FALSE);