Commit 0ca014af authored by Christian Hergert's avatar Christian Hergert

stackswitcher: add GtkStackSwitcher:icon-size property

Set the GtkStackSwitcher:icon-size property to change the size of icons
used in the linked GtkRadioButton children.

https://bugzilla.gnome.org/show_bug.cgi?id=758208
parent c6592929
......@@ -58,11 +58,13 @@ struct _GtkStackSwitcherPrivate
{
GtkStack *stack;
GHashTable *buttons;
gint icon_size;
gboolean in_child_changed;
};
enum {
PROP_0,
PROP_ICON_SIZE,
PROP_STACK
};
......@@ -76,6 +78,7 @@ gtk_stack_switcher_init (GtkStackSwitcher *switcher)
priv = gtk_stack_switcher_get_instance_private (switcher);
priv->icon_size = GTK_ICON_SIZE_MENU;
priv->stack = NULL;
priv->buttons = g_hash_table_new (g_direct_hash, g_direct_equal);
......@@ -105,7 +108,8 @@ on_button_clicked (GtkWidget *widget,
static void
rebuild_child (GtkWidget *self,
const gchar *icon_name,
const gchar *title)
const gchar *title,
gint icon_size)
{
GtkStyleContext *context;
GtkWidget *button_child;
......@@ -119,7 +123,7 @@ rebuild_child (GtkWidget *self,
if (icon_name != NULL)
{
button_child = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
button_child = gtk_image_new_from_icon_name (icon_name, icon_size);
if (title != NULL)
gtk_widget_set_tooltip_text (GTK_WIDGET (self), title);
......@@ -179,7 +183,7 @@ update_button (GtkStackSwitcher *self,
"icon-name", &icon_name,
NULL);
rebuild_child (button, icon_name, title);
rebuild_child (button, icon_name, title, priv->icon_size);
gtk_widget_set_visible (button, gtk_widget_get_visible (widget) && (title != NULL || icon_name != NULL));
......@@ -452,6 +456,29 @@ gtk_stack_switcher_get_stack (GtkStackSwitcher *switcher)
return priv->stack;
}
static void
gtk_stack_switcher_set_icon_size (GtkStackSwitcher *switcher,
gint icon_size)
{
GtkStackSwitcherPrivate *priv;
g_return_if_fail (GTK_IS_STACK_SWITCHER (switcher));
priv = gtk_stack_switcher_get_instance_private (switcher);
if (icon_size != priv->icon_size)
{
priv->icon_size = icon_size;
if (priv->stack != NULL)
{
clear_switcher (switcher);
populate_switcher (switcher);
g_object_notify (G_OBJECT (switcher), "icon-size");
}
}
}
static void
gtk_stack_switcher_get_property (GObject *object,
guint prop_id,
......@@ -464,6 +491,10 @@ gtk_stack_switcher_get_property (GObject *object,
priv = gtk_stack_switcher_get_instance_private (switcher);
switch (prop_id)
{
case PROP_ICON_SIZE:
g_value_set_int (value, priv->icon_size);
break;
case PROP_STACK:
g_value_set_object (value, priv->stack);
break;
......@@ -484,6 +515,10 @@ gtk_stack_switcher_set_property (GObject *object,
switch (prop_id)
{
case PROP_ICON_SIZE:
gtk_stack_switcher_set_icon_size (switcher, g_value_get_int (value));
break;
case PROP_STACK:
gtk_stack_switcher_set_stack (switcher, g_value_get_object (value));
break;
......@@ -528,6 +563,23 @@ gtk_stack_switcher_class_init (GtkStackSwitcherClass *class)
object_class->dispose = gtk_stack_switcher_dispose;
object_class->finalize = gtk_stack_switcher_finalize;
/**
* GtkStackSwitcher:icon-size:
*
* Use the "icon-size" property to change the size of the image displayed
* when a #GtkStackSwitcher is displaying icons.
*
* Since: 3.20
*/
g_object_class_install_property (object_class,
PROP_ICON_SIZE,
g_param_spec_int ("icon-size",
P_("Icon Size"),
P_("Symbolic size to use for named icon"),
0, G_MAXINT,
GTK_ICON_SIZE_MENU,
G_PARAM_EXPLICIT_NOTIFY | GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_STACK,
g_param_spec_object ("stack",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment