[clutter] Use ClutterActorIter inside layout managers
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [clutter] Use ClutterActorIter inside layout managers
- Date: Tue, 31 Jan 2012 09:49:10 +0000 (UTC)
commit 986307f5e4abc5c1c86207bcdb6bb998e67b5364
Author: Emmanuele Bassi <ebassi linux intel com>
Date: Mon Jan 30 10:55:30 2012 +0000
Use ClutterActorIter inside layout managers
Whenever it is possible, or convenient.
clutter/clutter-bin-layout.c | 42 ++++------
clutter/clutter-box-layout.c | 179 +++++++++++++++++++++--------------------
clutter/clutter-flow-layout.c | 18 ++--
3 files changed, 119 insertions(+), 120 deletions(-)
---
diff --git a/clutter/clutter-bin-layout.c b/clutter/clutter-bin-layout.c
index 09dd897..d09da6b 100644
--- a/clutter/clutter-bin-layout.c
+++ b/clutter/clutter-bin-layout.c
@@ -339,14 +339,14 @@ clutter_bin_layout_get_preferred_width (ClutterLayoutManager *manager,
gfloat *nat_width_p)
{
ClutterActor *actor = CLUTTER_ACTOR (container);
+ ClutterActorIter iter;
ClutterActor *child;
gfloat min_width, nat_width;
min_width = nat_width = 0.0;
- for (child = clutter_actor_get_first_child (actor);
- child != NULL;
- child = clutter_actor_get_next_sibling (child))
+ clutter_actor_iter_init (&iter, actor);
+ while (clutter_actor_iter_next (&iter, &child))
{
gfloat minimum, natural;
@@ -373,14 +373,14 @@ clutter_bin_layout_get_preferred_height (ClutterLayoutManager *manager,
gfloat *nat_height_p)
{
ClutterActor *actor = CLUTTER_ACTOR (container);
+ ClutterActorIter iter;
ClutterActor *child;
gfloat min_height, nat_height;
min_height = nat_height = 0.0;
- for (child = clutter_actor_get_first_child (actor);
- child != NULL;
- child = clutter_actor_get_next_sibling (child))
+ clutter_actor_iter_init (&iter, actor);
+ while (clutter_actor_iter_next (&iter, &child))
{
gfloat minimum, natural;
@@ -430,15 +430,15 @@ clutter_bin_layout_allocate (ClutterLayoutManager *manager,
gfloat allocation_x, allocation_y;
gfloat available_w, available_h;
ClutterActor *actor, *child;
+ ClutterActorIter iter;
clutter_actor_box_get_origin (allocation, &allocation_x, &allocation_y);
clutter_actor_box_get_size (allocation, &available_w, &available_h);
actor = CLUTTER_ACTOR (container);
- for (child = clutter_actor_get_first_child (actor);
- child != NULL;
- child = clutter_actor_get_next_sibling (child))
+ clutter_actor_iter_init (&iter, actor);
+ while (clutter_actor_iter_next (&iter, &child))
{
ClutterLayoutMeta *meta;
ClutterBinLayer *layer;
@@ -609,22 +609,14 @@ clutter_bin_layout_class_init (ClutterBinLayoutClass *klass)
gobject_class->set_property = clutter_bin_layout_set_property;
gobject_class->get_property = clutter_bin_layout_get_property;
- g_object_class_install_properties (gobject_class,
- PROP_LAST,
- bin_props);
-
- layout_class->get_preferred_width =
- clutter_bin_layout_get_preferred_width;
- layout_class->get_preferred_height =
- clutter_bin_layout_get_preferred_height;
- layout_class->allocate =
- clutter_bin_layout_allocate;
- layout_class->create_child_meta =
- clutter_bin_layout_create_child_meta;
- layout_class->get_child_meta_type =
- clutter_bin_layout_get_child_meta_type;
- layout_class->set_container =
- clutter_bin_layout_set_container;
+ g_object_class_install_properties (gobject_class, PROP_LAST, bin_props);
+
+ layout_class->get_preferred_width = clutter_bin_layout_get_preferred_width;
+ layout_class->get_preferred_height = clutter_bin_layout_get_preferred_height;
+ layout_class->allocate = clutter_bin_layout_allocate;
+ layout_class->create_child_meta = clutter_bin_layout_create_child_meta;
+ layout_class->get_child_meta_type = clutter_bin_layout_get_child_meta_type;
+ layout_class->set_container = clutter_bin_layout_set_container;
}
static void
diff --git a/clutter/clutter-box-layout.c b/clutter/clutter-box-layout.c
index c7055ba..f8c11cc 100644
--- a/clutter/clutter-box-layout.c
+++ b/clutter/clutter-box-layout.c
@@ -79,6 +79,8 @@
#include "deprecated/clutter-container.h"
#include "clutter-box-layout.h"
+
+#include "clutter-actor-private.h"
#include "clutter-debug.h"
#include "clutter-enum-types.h"
#include "clutter-layout-meta.h"
@@ -133,7 +135,9 @@ enum
PROP_CHILD_Y_ALIGN,
PROP_CHILD_X_FILL,
PROP_CHILD_Y_FILL,
- PROP_CHILD_EXPAND
+ PROP_CHILD_EXPAND,
+
+ PROP_CHILD_LAST
};
enum
@@ -146,9 +150,13 @@ enum
PROP_PACK_START,
PROP_USE_ANIMATIONS,
PROP_EASING_MODE,
- PROP_EASING_DURATION
+ PROP_EASING_DURATION,
+
+ PROP_LAST
};
+static GParamSpec *obj_props[PROP_LAST] = { NULL, };
+
G_DEFINE_TYPE (ClutterBoxChild,
clutter_box_child,
CLUTTER_TYPE_LAYOUT_META);
@@ -743,14 +751,14 @@ count_expand_children (ClutterLayoutManager *layout,
gint *expand_children)
{
ClutterActor *actor, *child;
+ ClutterActorIter iter;
actor = CLUTTER_ACTOR (container);
*visible_children = *expand_children = 0;
- for (child = clutter_actor_get_first_child (actor);
- child != NULL;
- child = clutter_actor_get_next_sibling (child))
+ clutter_actor_iter_init (&iter, actor);
+ while (clutter_actor_iter_next (&iter, &child))
{
if (CLUTTER_ACTOR_IS_VISIBLE (child))
{
@@ -768,22 +776,21 @@ count_expand_children (ClutterLayoutManager *layout,
}
}
-struct _ClutterRequestedSize
+typedef struct _RequestedSize
{
ClutterActor *actor;
gfloat minimum_size;
gfloat natural_size;
-};
+} RequestedSize;
/* Pulled from gtksizerequest.c from Gtk+ */
-
static gint
compare_gap (gconstpointer p1,
gconstpointer p2,
gpointer data)
{
- struct _ClutterRequestedSize *sizes = data;
+ RequestedSize *sizes = data;
const guint *c1 = p1;
const guint *c2 = p2;
@@ -805,16 +812,16 @@ compare_gap (gconstpointer p1,
/*
* distribute_natural_allocation:
* @extra_space: Extra space to redistribute among children after subtracting
- * minimum sizes and any child padding from the overall allocation
+ * minimum sizes and any child padding from the overall allocation
* @n_requested_sizes: Number of requests to fit into the allocation
* @sizes: An array of structs with a client pointer and a minimum/natural size
- * in the orientation of the allocation.
+ * in the orientation of the allocation.
*
* Distributes @extra_space to child @sizes by bringing smaller
* children up to natural size first.
*
* The remaining space will be added to the @minimum_size member of the
- * GtkRequestedSize struct. If all sizes reach their natural size then
+ * RequestedSize struct. If all sizes reach their natural size then
* the remaining space is returned.
*
* Returns: The remainder of @extra_space after redistributing space
@@ -823,9 +830,9 @@ compare_gap (gconstpointer p1,
* Pulled from gtksizerequest.c from Gtk+
*/
static gint
-distribute_natural_allocation (gint extra_space,
- guint n_requested_sizes,
- struct _ClutterRequestedSize *sizes)
+distribute_natural_allocation (gint extra_space,
+ guint n_requested_sizes,
+ RequestedSize *sizes)
{
guint *spreading;
gint i;
@@ -895,9 +902,10 @@ clutter_box_layout_allocate (ClutterLayoutManager *layout,
gint nvis_children;
gint nexpand_children;
gboolean is_rtl;
+ ClutterActorIter iter;
ClutterActorBox child_allocation;
- struct _ClutterRequestedSize *sizes;
+ RequestedSize *sizes;
gint size;
gint extra;
@@ -911,7 +919,7 @@ clutter_box_layout_allocate (ClutterLayoutManager *layout,
if (nvis_children <= 0)
return;
- sizes = g_newa (struct _ClutterRequestedSize, nvis_children);
+ sizes = g_newa (RequestedSize, nvis_children);
if (priv->is_vertical)
size = box->y2 - box->y1 - (nvis_children - 1) * priv->spacing;
@@ -921,9 +929,9 @@ clutter_box_layout_allocate (ClutterLayoutManager *layout,
actor = CLUTTER_ACTOR (container);
/* Retrieve desired size for visible children. */
- for (i = 0, child = clutter_actor_get_first_child (actor);
- child != NULL;
- child = clutter_actor_get_next_sibling (child))
+ i = 0;
+ clutter_actor_iter_init (&iter, actor);
+ while (clutter_actor_iter_next (&iter, &child))
{
if (!CLUTTER_ACTOR_IS_VISIBLE (child))
continue;
@@ -942,16 +950,16 @@ clutter_box_layout_allocate (ClutterLayoutManager *layout,
/* Assert the api is working properly */
if (sizes[i].minimum_size < 0)
- g_error ("GtkBox child %s minimum %s: %f < 0 for %s %f",
- clutter_actor_get_name (child),
+ g_error ("ClutterBoxLayout child %s minimum %s: %f < 0 for %s %f",
+ _clutter_actor_get_debug_name (child),
priv->is_vertical ? "height" : "width",
sizes[i].minimum_size,
priv->is_vertical ? "width" : "height",
priv->is_vertical ? box->x2 - box->x1 : box->y2 - box->y1);
if (sizes[i].natural_size < sizes[i].minimum_size)
- g_error ("GtkBox child %s natural %s: %f < minimum %f for %s %f",
- clutter_actor_get_name (child),
+ g_error ("ClutterBoxLayout child %s natural %s: %f < minimum %f for %s %f",
+ _clutter_actor_get_debug_name (child),
priv->is_vertical ? "height" : "width",
sizes[i].natural_size,
sizes[i].minimum_size,
@@ -962,7 +970,7 @@ clutter_box_layout_allocate (ClutterLayoutManager *layout,
sizes[i].actor = child;
- i++;
+ i += 1;
}
if (priv->is_homogeneous)
@@ -1035,15 +1043,15 @@ clutter_box_layout_allocate (ClutterLayoutManager *layout,
i -= 1;
+ /* If widget is not visible, skip it. */
+ if (!CLUTTER_ACTOR_IS_VISIBLE (child))
+ continue;
+
meta = clutter_layout_manager_get_child_meta (layout,
container,
child);
box_child = CLUTTER_BOX_CHILD (meta);
- /* If widget is not visible, skip it. */
- if (!CLUTTER_ACTOR_IS_VISIBLE (child))
- continue;
-
/* Assign the child's size. */
if (priv->is_homogeneous)
{
@@ -1126,7 +1134,9 @@ clutter_box_layout_allocate (ClutterLayoutManager *layout,
{
gfloat width = child_allocation.x2 - child_allocation.x1;
- child_allocation.x1 = box->x2 - box->x1 - child_allocation.x1 - (child_allocation.x2 - child_allocation.x1);
+ child_allocation.x1 = box->x2 - box->x1
+ - child_allocation.x1
+ - (child_allocation.x2 - child_allocation.x1);
child_allocation.x2 = child_allocation.x1 + width;
}
@@ -1262,21 +1272,14 @@ clutter_box_layout_class_init (ClutterBoxLayoutClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
ClutterLayoutManagerClass *layout_class;
- GParamSpec *pspec;
layout_class = CLUTTER_LAYOUT_MANAGER_CLASS (klass);
- gobject_class->set_property = clutter_box_layout_set_property;
- gobject_class->get_property = clutter_box_layout_get_property;
-
- layout_class->get_preferred_width =
- clutter_box_layout_get_preferred_width;
- layout_class->get_preferred_height =
- clutter_box_layout_get_preferred_height;
+ layout_class->get_preferred_width = clutter_box_layout_get_preferred_width;
+ layout_class->get_preferred_height = clutter_box_layout_get_preferred_height;
layout_class->allocate = clutter_box_layout_allocate;
layout_class->set_container = clutter_box_layout_set_container;
- layout_class->get_child_meta_type =
- clutter_box_layout_get_child_meta_type;
+ layout_class->get_child_meta_type = clutter_box_layout_get_child_meta_type;
layout_class->begin_animation = clutter_box_layout_begin_animation;
layout_class->end_animation = clutter_box_layout_end_animation;
@@ -1290,13 +1293,13 @@ clutter_box_layout_class_init (ClutterBoxLayoutClass *klass)
*
* Since: 1.2
*/
- pspec = g_param_spec_boolean ("vertical",
- P_("Vertical"),
- P_("Whether the layout should be vertical, "
- "rather than horizontal"),
- FALSE,
- CLUTTER_PARAM_READWRITE);
- g_object_class_install_property (gobject_class, PROP_VERTICAL, pspec);
+ obj_props[PROP_VERTICAL] =
+ g_param_spec_boolean ("vertical",
+ P_("Vertical"),
+ P_("Whether the layout should be vertical, "
+ "rather than horizontal"),
+ FALSE,
+ CLUTTER_PARAM_READWRITE);
/**
* ClutterBoxLayout:homogeneous:
@@ -1306,13 +1309,13 @@ clutter_box_layout_class_init (ClutterBoxLayoutClass *klass)
*
* Since: 1.4
*/
- pspec = g_param_spec_boolean ("homogeneous",
- P_("Homogeneous"),
- P_("Whether the layout should be homogeneous, "
- "i.e. all childs get the same size"),
- FALSE,
- CLUTTER_PARAM_READWRITE);
- g_object_class_install_property (gobject_class, PROP_HOMOGENEOUS, pspec);
+ obj_props[PROP_HOMOGENEOUS] =
+ g_param_spec_boolean ("homogeneous",
+ P_("Homogeneous"),
+ P_("Whether the layout should be homogeneous, "
+ "i.e. all childs get the same size"),
+ FALSE,
+ CLUTTER_PARAM_READWRITE);
/**
* ClutterBoxLayout:pack-start:
@@ -1322,12 +1325,12 @@ clutter_box_layout_class_init (ClutterBoxLayoutClass *klass)
*
* Since: 1.2
*/
- pspec = g_param_spec_boolean ("pack-start",
- P_("Pack Start"),
- P_("Whether to pack items at the start of the box"),
- FALSE,
- CLUTTER_PARAM_READWRITE);
- g_object_class_install_property (gobject_class, PROP_PACK_START, pspec);
+ obj_props[PROP_PACK_START] =
+ g_param_spec_boolean ("pack-start",
+ P_("Pack Start"),
+ P_("Whether to pack items at the start of the box"),
+ FALSE,
+ CLUTTER_PARAM_READWRITE);
/**
* ClutterBoxLayout:spacing:
@@ -1336,12 +1339,12 @@ clutter_box_layout_class_init (ClutterBoxLayoutClass *klass)
*
* Since: 1.2
*/
- pspec = g_param_spec_uint ("spacing",
- P_("Spacing"),
- P_("Spacing between children"),
- 0, G_MAXUINT, 0,
- CLUTTER_PARAM_READWRITE);
- g_object_class_install_property (gobject_class, PROP_SPACING, pspec);
+ obj_props[PROP_SPACING] =
+ g_param_spec_uint ("spacing",
+ P_("Spacing"),
+ P_("Spacing between children"),
+ 0, G_MAXUINT, 0,
+ CLUTTER_PARAM_READWRITE);
/**
* ClutterBoxLayout:use-animations:
@@ -1351,12 +1354,12 @@ clutter_box_layout_class_init (ClutterBoxLayoutClass *klass)
*
* Since: 1.2
*/
- pspec = g_param_spec_boolean ("use-animations",
- P_("Use Animations"),
- P_("Whether layout changes should be animated"),
- FALSE,
- CLUTTER_PARAM_READWRITE);
- g_object_class_install_property (gobject_class, PROP_USE_ANIMATIONS, pspec);
+ obj_props[PROP_USE_ANIMATIONS] =
+ g_param_spec_boolean ("use-animations",
+ P_("Use Animations"),
+ P_("Whether layout changes should be animated"),
+ FALSE,
+ CLUTTER_PARAM_READWRITE);
/**
* ClutterBoxLayout:easing-mode:
@@ -1373,13 +1376,13 @@ clutter_box_layout_class_init (ClutterBoxLayoutClass *klass)
*
* Since: 1.2
*/
- pspec = g_param_spec_ulong ("easing-mode",
- P_("Easing Mode"),
- P_("The easing mode of the animations"),
- 0, G_MAXULONG,
- CLUTTER_EASE_OUT_CUBIC,
- CLUTTER_PARAM_READWRITE);
- g_object_class_install_property (gobject_class, PROP_EASING_MODE, pspec);
+ obj_props[PROP_EASING_MODE] =
+ g_param_spec_ulong ("easing-mode",
+ P_("Easing Mode"),
+ P_("The easing mode of the animations"),
+ 0, G_MAXULONG,
+ CLUTTER_EASE_OUT_CUBIC,
+ CLUTTER_PARAM_READWRITE);
/**
* ClutterBoxLayout:easing-duration:
@@ -1391,13 +1394,17 @@ clutter_box_layout_class_init (ClutterBoxLayoutClass *klass)
*
* Since: 1.2
*/
- pspec = g_param_spec_uint ("easing-duration",
- P_("Easing Duration"),
- P_("The duration of the animations"),
- 0, G_MAXUINT,
- 500,
- CLUTTER_PARAM_READWRITE);
- g_object_class_install_property (gobject_class, PROP_EASING_DURATION, pspec);
+ obj_props[PROP_EASING_DURATION] =
+ g_param_spec_uint ("easing-duration",
+ P_("Easing Duration"),
+ P_("The duration of the animations"),
+ 0, G_MAXUINT,
+ 500,
+ CLUTTER_PARAM_READWRITE);
+
+ gobject_class->set_property = clutter_box_layout_set_property;
+ gobject_class->get_property = clutter_box_layout_get_property;
+ g_object_class_install_properties (gobject_class, PROP_LAST, obj_props);
}
static void
diff --git a/clutter/clutter-flow-layout.c b/clutter/clutter-flow-layout.c
index 89d5cee..dd5919a 100644
--- a/clutter/clutter-flow-layout.c
+++ b/clutter/clutter-flow-layout.c
@@ -210,6 +210,7 @@ clutter_flow_layout_get_preferred_width (ClutterLayoutManager *manager,
gfloat line_min_width, line_natural_width;
gfloat max_min_width, max_natural_width;
ClutterActor *actor, *child;
+ ClutterActorIter iter;
gfloat item_y;
n_rows = get_rows (CLUTTER_FLOW_LAYOUT (manager), for_height);
@@ -246,9 +247,8 @@ clutter_flow_layout_get_preferred_width (ClutterLayoutManager *manager,
max_min_width = max_natural_width = 0;
- for (child = clutter_actor_get_first_child (actor);
- child != NULL;
- child = clutter_actor_get_next_sibling (child))
+ clutter_actor_iter_init (&iter, actor);
+ while (clutter_actor_iter_next (&iter, &child))
{
gfloat child_min, child_natural;
gfloat new_y, item_height;
@@ -388,6 +388,7 @@ clutter_flow_layout_get_preferred_height (ClutterLayoutManager *manager,
gfloat line_min_height, line_natural_height;
gfloat max_min_height, max_natural_height;
ClutterActor *actor, *child;
+ ClutterActorIter iter;
gfloat item_x;
n_columns = get_columns (CLUTTER_FLOW_LAYOUT (manager), for_width);
@@ -424,9 +425,8 @@ clutter_flow_layout_get_preferred_height (ClutterLayoutManager *manager,
max_min_height = max_natural_height = 0;
- for (child = clutter_actor_get_first_child (actor);
- child != NULL;
- child = clutter_actor_get_next_sibling (child))
+ clutter_actor_iter_init (&iter, actor);
+ while (clutter_actor_iter_next (&iter, &child))
{
gfloat child_min, child_natural;
gfloat new_x, item_width;
@@ -561,6 +561,7 @@ clutter_flow_layout_allocate (ClutterLayoutManager *manager,
{
ClutterFlowLayoutPrivate *priv = CLUTTER_FLOW_LAYOUT (manager)->priv;
ClutterActor *actor, *child;
+ ClutterActorIter iter;
gfloat x_off, y_off;
gfloat avail_width, avail_height;
gfloat item_x, item_y;
@@ -599,9 +600,8 @@ clutter_flow_layout_allocate (ClutterLayoutManager *manager,
line_item_count = 0;
line_index = 0;
- for (child = clutter_actor_get_first_child (actor);
- child != NULL;
- child = clutter_actor_get_next_sibling (child))
+ clutter_actor_iter_init (&iter, actor);
+ while (clutter_actor_iter_next (&iter, &child))
{
ClutterActorBox child_alloc;
gfloat item_width, item_height;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]