[St] add st_describe_actor, for debugging

This can be used when adding debug printfs, to get clear descriptions of
actors.

Also update the Looking Glass inspector to use it

https://bugzilla.gnome.org/show_bug.cgi?id=621668
This commit is contained in:
Dan Winship 2010-06-11 13:45:43 -04:00
parent 9baf8e19ea
commit 792dc489ee
3 changed files with 105 additions and 8 deletions

View File

@ -402,14 +402,10 @@ Inspector.prototype = {
let target = global.stage.get_actor_at_pos(Clutter.PickMode.ALL, let target = global.stage.get_actor_at_pos(Clutter.PickMode.ALL,
stageX, stageX,
stageY); stageY);
let id, style_class; let position = '[inspect x: ' + stageX + ' y: ' + stageY + ']';
if (target instanceof St.Widget) { displayText.text = '';
id = target.get_theme_node().get_element_id(); let description = St.describe_actor(target);
style_class = target.get_theme_node().get_element_class(); displayText.text = position + ' ' + description;
}
let position = '<inspect x: ' + stageX + ' y: ' + stageY + '>';
let style = '<style id: ' + id + ' class: ' + style_class + '>';
displayText.text = position + ' ' + style + ' ' + target;
if (borderPaintTarget != null) if (borderPaintTarget != null)
borderPaintTarget.disconnect(borderPaintId); borderPaintTarget.disconnect(borderPaintId);
borderPaintTarget = target; borderPaintTarget = target;

View File

@ -36,6 +36,7 @@
#include "st-widget.h" #include "st-widget.h"
#include "st-label.h"
#include "st-marshal.h" #include "st-marshal.h"
#include "st-private.h" #include "st-private.h"
#include "st-texture-cache.h" #include "st-texture-cache.h"
@ -1605,3 +1606,101 @@ st_widget_get_hover (StWidget *widget)
return widget->priv->hover; return widget->priv->hover;
} }
static gboolean
append_actor_text (GString *desc,
ClutterActor *actor)
{
if (CLUTTER_IS_TEXT (actor))
{
g_string_append_printf (desc, " (\"%s\")",
clutter_text_get_text (CLUTTER_TEXT (actor)));
return TRUE;
}
else if (ST_IS_LABEL (actor))
{
g_string_append_printf (desc, " (\"%s\")",
st_label_get_text (ST_LABEL (actor)));
return TRUE;
}
else
return FALSE;
}
/**
* st_describe_actor:
* @actor: a #ClutterActor
*
* Creates a string describing @actor, for use in debugging. This
* includes the class name and actor name (if any), plus if @actor
* is an #StWidget, its style class and pseudo class names.
*
* Return value: the debug name.
*/
char *
st_describe_actor (ClutterActor *actor)
{
GString *desc;
const char *name;
int i;
if (!actor)
return g_strdup ("[null]");
desc = g_string_new (NULL);
g_string_append_printf (desc, "[%p %s", actor,
G_OBJECT_TYPE_NAME (actor));
if (ST_IS_WIDGET (actor))
{
const char *style_class = st_widget_get_style_class_name (ST_WIDGET (actor));
const char *pseudo_class = st_widget_get_style_pseudo_class (ST_WIDGET (actor));
char **classes;
if (style_class)
{
classes = g_strsplit (style_class, ",", -1);
for (i = 0; classes[i]; i++)
{
g_strchug (classes[i]);
g_string_append_printf (desc, ".%s", classes[i]);
}
g_strfreev (classes);
}
if (pseudo_class)
{
classes = g_strsplit (pseudo_class, ",", -1);
for (i = 0; classes[i]; i++)
{
g_strchug (classes[i]);
g_string_append_printf (desc, ":%s", classes[i]);
}
g_strfreev (classes);
}
}
name = clutter_actor_get_name (actor);
if (name)
g_string_append_printf (desc, " \"%s\"", name);
if (!append_actor_text (desc, actor) && CLUTTER_IS_CONTAINER (actor))
{
GList *children, *l;
/* Do a limited search of @actor's children looking for a label */
children = clutter_container_get_children (CLUTTER_CONTAINER (actor));
for (l = children, i = 0; l && i < 20; l = l->next, i++)
{
if (append_actor_text (desc, l->data))
break;
else if (CLUTTER_IS_CONTAINER (l->data))
children = g_list_concat (children, clutter_container_get_children (l->data));
}
g_list_free (children);
}
g_string_append_c (desc, ']');
return g_string_free (desc, FALSE);
}

View File

@ -141,6 +141,8 @@ void st_widget_set_direction (StWidget *self
void st_widget_style_changed (StWidget *widget); void st_widget_style_changed (StWidget *widget);
StThemeNode * st_widget_get_theme_node (StWidget *widget); StThemeNode * st_widget_get_theme_node (StWidget *widget);
/* debug method */
char *st_describe_actor (ClutterActor *actor);
G_END_DECLS G_END_DECLS