StIcon: pass in the StThemeNode to get colorized symbolic icons

Use st_texture_cache_load_icon_name_for_theme() so that we get the
right colors for symbolic icons. The code refactoring to achieve this
also avoids constantly starting a new icon load each time we set
a property on initialization ... the icon is loaded only after we
have a #StThemeNode assigned.

https://bugzilla.gnome.org/show_bug.cgi?id=633865
This commit is contained in:
Owen W. Taylor 2010-11-02 16:15:53 -04:00
parent 8d6ab6fe84
commit af7ba00e97
2 changed files with 61 additions and 19 deletions

View File

@ -57,7 +57,7 @@ struct _StIconPrivate
};
static void st_icon_update (StIcon *icon);
static void st_icon_update_icon_size (StIcon *icon);
static gboolean st_icon_update_icon_size (StIcon *icon);
#define DEFAULT_ICON_SIZE 48
#define DEFAULT_ICON_TYPE ST_ICON_SYMBOLIC
@ -245,6 +245,7 @@ st_icon_style_changed (StWidget *widget)
priv->theme_icon_size = st_theme_node_get_length (theme_node, "icon-size");
st_icon_update_icon_size (self);
st_icon_update (self);
}
static void
@ -318,9 +319,13 @@ st_icon_update (StIcon *icon)
/* Try to lookup the new one */
if (priv->icon_name)
{
StTextureCache *cache = st_texture_cache_get_default ();
StThemeNode *theme_node = st_widget_peek_theme_node (ST_WIDGET (icon));
priv->icon_texture = st_texture_cache_load_icon_name (cache,
if (theme_node)
{
StTextureCache *cache = st_texture_cache_get_default ();
priv->icon_texture = st_texture_cache_load_icon_name_for_theme (cache,
theme_node,
priv->icon_name,
priv->icon_type,
priv->icon_size);
@ -329,8 +334,9 @@ st_icon_update (StIcon *icon)
clutter_actor_set_parent (priv->icon_texture, CLUTTER_ACTOR (icon));
}
}
}
static void
static gboolean
st_icon_update_icon_size (StIcon *icon)
{
StIconPrivate *priv = icon->priv;
@ -347,8 +353,10 @@ st_icon_update_icon_size (StIcon *icon)
{
clutter_actor_queue_relayout (CLUTTER_ACTOR (icon));
priv->icon_size = new_size;
st_icon_update (icon);
return TRUE;
}
else
return FALSE;
}
/**
@ -477,8 +485,8 @@ st_icon_set_icon_size (StIcon *icon,
if (priv->prop_icon_size != size)
{
priv->prop_icon_size = size;
st_icon_update_icon_size (icon);
if (st_icon_update_icon_size (icon))
st_icon_update (icon);
g_object_notify (G_OBJECT (icon), "icon-size");
}
}

View File

@ -8,6 +8,9 @@ const UI = imports.testcommon.ui;
UI.init();
let stage = Clutter.Stage.get_default();
stage.width = 400;
stage.height = 700;
let b = new St.BoxLayout({ vertical: true,
width: stage.width,
height: stage.height });
@ -26,28 +29,59 @@ function addTest(label, icon_props) {
}
addTest("Symbolic",
{ icon_name: 'zoom-in',
{ icon_name: 'battery-full',
icon_type: St.IconType.SYMBOLIC,
icon_size: 48 });
addTest("Full color",
{ icon_name: 'zoom-in',
{ icon_name: 'battery-full',
icon_type: St.IconType.FULLCOLOR,
icon_size: 48 });
addTest("Default size",
{ icon_name: 'zoom-in',
{ icon_name: 'battery-full',
icon_type: St.IconType.SYMBOLIC });
addTest("Size set by property",
{ icon_name: 'zoom-in',
{ icon_name: 'battery-full',
icon_type: St.IconType.SYMBOLIC,
icon_size: 32 });
addTest("Size set by style",
{ icon_name: 'zoom-in',
{ icon_name: 'battery-full',
icon_type: St.IconType.SYMBOLIC,
style: 'icon-size: 1em;' });
addTest("16px icon in 48px icon widget",
{ icon_name: 'zoom-in',
{ icon_name: 'battery-full',
icon_type: St.IconType.SYMBOLIC,
style: 'icon-size: 16px; width: 48px; height: 48px;' });
function iconRow(icons, box_style) {
let hb = new St.BoxLayout({ vertical: false, style: box_style });
for each (let iconName in icons) {
hb.add(new St.Icon({ icon_name: iconName,
icon_type: St.IconType.SYMBOLIC,
icon_size: 48 }));
}
b.add(hb);
}
let normalCss = 'background: white; color: black; padding: 10px 10px;';
let reversedCss = 'background: black; color: white; warning-color: #ffcc00; error-color: #ff0000; padding: 10px 10px;';
let batteryIcons = ['battery-full-charging',
'battery-full',
'battery-good',
'battery-low',
'battery-caution' ];
let volumeIcons = ['audio-volume-high',
'audio-volume-medium',
'audio-volume-low',
'audio-volume-muted' ];
iconRow(batteryIcons, normalCss);
iconRow(batteryIcons, reversedCss);
iconRow(volumeIcons, normalCss);
iconRow(volumeIcons, reversedCss);
stage.show();
Clutter.main();