libgimp: new gimp_procedure_dialog_get_scale_entry() function.

Though a GimpScaleEntry could already be created with
gimp_procedure_dialog_get_widget(), this specific function allows to add
a factor to the property range.
This commit is contained in:
Jehan 2020-11-25 12:25:59 +01:00
parent f678aeba77
commit 87062e22ec
2 changed files with 68 additions and 0 deletions

View File

@ -600,6 +600,71 @@ gimp_procedure_dialog_get_int_combo (GimpProcedureDialog *dialog,
return widget;
}
/**
* gimp_procedure_dialog_get_scale_entry:
* @dialog: the associated #GimpProcedureDialog.
* @property: name of the int property to build a combo for. It must be
* a property of the #GimpProcedure @dialog has been created
* for.
* @factor: a display factor for the range shown by the widget.
*
* Creates a new #GimpScaleEntry for @property which must necessarily be
* an integer or double property.
* This can be used instead of gimp_procedure_dialog_get_widget() in
* particular if you want to tweak the display factor. A typical example
* is showing a [0.0, 1.0] range as [0.0, 100.0] instead (@factor = 100.0).
*
* If a widget has already been created for this procedure, it will be
* returned instead (whatever its actual widget type).
*
* Returns: (transfer none): the #GtkWidget representing @property. The
* object belongs to @dialog and must not be
* freed.
*/
GtkWidget *
gimp_procedure_dialog_get_scale_entry (GimpProcedureDialog *dialog,
const gchar *property,
gdouble factor)
{
GtkWidget *widget = NULL;
GParamSpec *pspec;
g_return_val_if_fail (GIMP_IS_PROCEDURE_DIALOG (dialog), NULL);
g_return_val_if_fail (property != NULL, NULL);
pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (dialog->priv->config),
property);
if (! pspec)
{
g_warning ("%s: parameter %s does not exist.",
G_STRFUNC, property);
return NULL;
}
g_return_val_if_fail (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_INT ||
G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_DOUBLE, NULL);
/* First check if it already exists. */
widget = g_hash_table_lookup (dialog->priv->widgets, property);
if (widget)
return widget;
widget = gimp_prop_scale_entry_new (G_OBJECT (dialog->priv->config),
property,
_(g_param_spec_get_nick (pspec)),
factor, FALSE, 0.0, 0.0);
gtk_size_group_add_widget (dialog->priv->label_group,
gimp_labeled_get_label (GIMP_LABELED (widget)));
gimp_procedure_dialog_check_mnemonic (dialog, widget, property, NULL);
g_hash_table_insert (dialog->priv->widgets, g_strdup (property), widget);
return widget;
}
/**
* gimp_procedure_dialog_get_label:
* @dialog: the #GimpProcedureDialog.

View File

@ -81,6 +81,9 @@ GtkWidget * gimp_procedure_dialog_get_widget (GimpProcedureDialog *dialog
GtkWidget * gimp_procedure_dialog_get_int_combo (GimpProcedureDialog *dialog,
const gchar *property,
GimpIntStore *store);
GtkWidget * gimp_procedure_dialog_get_scale_entry (GimpProcedureDialog *dialog,
const gchar *property,
gdouble factor);
GtkWidget * gimp_procedure_dialog_get_label (GimpProcedureDialog *dialog,
const gchar *label_id,
const gchar *text);