[gnome-shell] StIcon: pass in the StThemeNode to get colorized symbolic icons
- From: Owen Taylor <otaylor src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] StIcon: pass in the StThemeNode to get colorized symbolic icons
- Date: Fri, 12 Nov 2010 22:38:17 +0000 (UTC)
commit af7ba00e97d97fab8516d6f7b8bb3bc16567a243
Author: Owen W. Taylor <otaylor fishsoup net>
Date: Tue Nov 2 16:15:53 2010 -0400
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
src/st/st-icon.c | 38 ++++++++++++++++++++++--------------
tests/interactive/icons.js | 46 ++++++++++++++++++++++++++++++++++++++-----
2 files changed, 63 insertions(+), 21 deletions(-)
---
diff --git a/src/st/st-icon.c b/src/st/st-icon.c
index 1716986..bd7e9eb 100644
--- a/src/st/st-icon.c
+++ b/src/st/st-icon.c
@@ -56,8 +56,8 @@ struct _StIconPrivate
gint icon_size; /* icon size we are using */
};
-static void st_icon_update (StIcon *icon);
-static void st_icon_update_icon_size (StIcon *icon);
+static void st_icon_update (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,19 +319,24 @@ st_icon_update (StIcon *icon)
/* Try to lookup the new one */
if (priv->icon_name)
{
- StTextureCache *cache = st_texture_cache_get_default ();
-
- priv->icon_texture = st_texture_cache_load_icon_name (cache,
- priv->icon_name,
- priv->icon_type,
- priv->icon_size);
-
- if (priv->icon_texture)
- clutter_actor_set_parent (priv->icon_texture, CLUTTER_ACTOR (icon));
+ StThemeNode *theme_node = st_widget_peek_theme_node (ST_WIDGET (icon));
+
+ 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);
+
+ if (priv->icon_texture)
+ 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");
}
}
diff --git a/tests/interactive/icons.js b/tests/interactive/icons.js
index 0c5a879..829516d 100644
--- a/tests/interactive/icons.js
+++ b/tests/interactive/icons.js
@@ -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();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]