libgimpwidgets: Fix formatting from 8adcc0cd

Some minor code style issues remained 
that I missed in 8adcc0cd.
After further reflection, I also converted
the code to be a private/internal function.
gimp_prop_check_button_new () should
cover the majority of GtkCheckButtons,
and the function is currently only used
to fix the size of those widgets. We could
revisit it as a public function in the
future if more use cases are found.
This commit is contained in:
Alx Sa 2024-05-19 02:10:23 +00:00
parent 5a4afd39eb
commit 47dde0580a
5 changed files with 50 additions and 36 deletions

View File

@ -67,13 +67,14 @@ struct _ItemOptionsDialog
/* local function prototypes */
static void item_options_dialog_free (ItemOptionsDialog *private);
static void item_options_dialog_response (GtkWidget *dialog,
gint response_id,
ItemOptionsDialog *private);
static GtkWidget * check_button_with_icon_new (const gchar *label,
const gchar *icon_name,
GtkBox *vbox);
static void item_options_dialog_free (ItemOptionsDialog *private);
static void item_options_dialog_response (GtkWidget *dialog,
gint response_id,
ItemOptionsDialog *private);
static GtkWidget * check_button_with_icon_new (const gchar *label,
const gchar *icon_name,
GtkBox *vbox);
static gint check_button_get_bold_label_width (const gchar *text);
/* public functions */
@ -484,11 +485,32 @@ check_button_with_icon_new (const gchar *label,
button = gtk_check_button_new_with_mnemonic (label);
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
gtk_widget_show (button);
gtk_widget_set_visible (button, TRUE);
/* size the label to its bold size, avoiding a GUI twitch */
/* Resize the label to its bold size to avoid 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);
gtk_widget_set_size_request (label_widget,
check_button_get_bold_label_width (label),
-1);
return button;
}
static gint
check_button_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

@ -136,11 +136,26 @@ gimp_prop_check_button_new (GObject *config,
label = g_param_spec_get_nick (param_spec);
button = gtk_check_button_new_with_mnemonic (label);
gtk_widget_show (button);
gtk_widget_set_visible (button, TRUE);
/* size the label to its bold size, avoiding a GUI twitch */
/* Resize the label to its bold size to avoid 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);
if (label_widget)
{
GtkWidget *temp_label = gtk_label_new (label);
GtkRequisition natural_size;
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);
gtk_widget_set_size_request (label_widget, natural_size.width, -1);
}
blurb = g_param_spec_get_blurb (param_spec);
if (blurb)

View File

@ -201,7 +201,6 @@ 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,23 +1279,3 @@ 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,8 +70,6 @@ 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 */
G_GNUC_INTERNAL void _gimp_widget_get_profiles (GtkWidget *widget,