libgimpwidgets: Fix GUI twitching due to bold label sizing

Resolves #10026

Selecting a checkbutton makes the label bold. This increases the
width of its label, and if it's the longest item in a box, this
causes minor "twitching" and resizing of the dialogue.
This patch calculates the size of the label when bold and then
requests the label width be set accordingly to resolve the issue.
This commit is contained in:
Mark Sweeney 2024-05-18 21:33:51 +00:00 committed by Alx Sa
parent e51a128acd
commit 8adcc0cdcb
5 changed files with 32 additions and 0 deletions

View File

@ -472,6 +472,7 @@ check_button_with_icon_new (const gchar *label,
GtkWidget *hbox;
GtkWidget *button;
GtkWidget *image;
GtkWidget *label_widget;
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_box_pack_start (vbox, hbox, FALSE, FALSE, 0);
@ -485,5 +486,9 @@ check_button_with_icon_new (const gchar *label,
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
gtk_widget_show (button);
/* size the label to its bold size, avoiding a GUI twitch */
label_widget = gtk_bin_get_child (GTK_BIN (button));
gtk_widget_set_size_request (label_widget, gimp_get_bold_label_width (label), -1);
return button;
}

View File

@ -122,6 +122,7 @@ gimp_prop_check_button_new (GObject *config,
GParamSpec *param_spec;
GtkWidget *button;
const gchar *blurb;
GtkWidget *label_widget;
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
g_return_val_if_fail (property_name != NULL, NULL);
@ -137,6 +138,10 @@ gimp_prop_check_button_new (GObject *config,
button = gtk_check_button_new_with_mnemonic (label);
gtk_widget_show (button);
/* size the label to its bold size, avoiding a GUI twitch */
label_widget = gtk_bin_get_child (GTK_BIN (button));
gtk_widget_set_size_request (label_widget, gimp_get_bold_label_width (label), -1);
blurb = g_param_spec_get_blurb (param_spec);
if (blurb)
gimp_help_set_help_data (button, blurb, NULL);

View File

@ -201,6 +201,7 @@ EXPORTS
gimp_float_adjustment_update
gimp_frame_get_type
gimp_frame_new
gimp_get_bold_label_width
gimp_get_monitor_at_pointer
gimp_grid_attach_aligned
gimp_help_connect

View File

@ -1279,3 +1279,23 @@ gimp_widget_set_handle_on_mapped (GtkWidget *widget,
return FALSE;
}
/* get the width of the label when it is bold */
gint
gimp_get_bold_label_width (const gchar *text)
{
GtkWidget *temp_label = gtk_label_new (NULL);
GtkRequisition natural_size;
gtk_label_set_text (GTK_LABEL (temp_label), text);
gtk_widget_set_visible (temp_label, TRUE);
gimp_label_set_attributes (GTK_LABEL (temp_label),
PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD,
-1);
gtk_widget_get_preferred_size (temp_label, NULL, &natural_size);
gtk_widget_destroy (temp_label);
return natural_size.width;
}

View File

@ -70,6 +70,7 @@ const Babl * gimp_widget_get_render_space (GtkWidget *widget,
void gimp_widget_set_native_handle (GtkWidget *widget,
GBytes **handle);
gint gimp_get_bold_label_width (const gchar *text);
/* Internal use */