1
0
Fork 0

Use ClutterActorIter inside layout managers

Whenever it is possible, or convenient.
This commit is contained in:
Emmanuele Bassi 2012-01-30 10:55:30 +00:00
parent 8b47ddbce6
commit 986307f5e4
3 changed files with 118 additions and 119 deletions

View file

@ -339,14 +339,14 @@ clutter_bin_layout_get_preferred_width (ClutterLayoutManager *manager,
gfloat *nat_width_p) gfloat *nat_width_p)
{ {
ClutterActor *actor = CLUTTER_ACTOR (container); ClutterActor *actor = CLUTTER_ACTOR (container);
ClutterActorIter iter;
ClutterActor *child; ClutterActor *child;
gfloat min_width, nat_width; gfloat min_width, nat_width;
min_width = nat_width = 0.0; min_width = nat_width = 0.0;
for (child = clutter_actor_get_first_child (actor); clutter_actor_iter_init (&iter, actor);
child != NULL; while (clutter_actor_iter_next (&iter, &child))
child = clutter_actor_get_next_sibling (child))
{ {
gfloat minimum, natural; gfloat minimum, natural;
@ -373,14 +373,14 @@ clutter_bin_layout_get_preferred_height (ClutterLayoutManager *manager,
gfloat *nat_height_p) gfloat *nat_height_p)
{ {
ClutterActor *actor = CLUTTER_ACTOR (container); ClutterActor *actor = CLUTTER_ACTOR (container);
ClutterActorIter iter;
ClutterActor *child; ClutterActor *child;
gfloat min_height, nat_height; gfloat min_height, nat_height;
min_height = nat_height = 0.0; min_height = nat_height = 0.0;
for (child = clutter_actor_get_first_child (actor); clutter_actor_iter_init (&iter, actor);
child != NULL; while (clutter_actor_iter_next (&iter, &child))
child = clutter_actor_get_next_sibling (child))
{ {
gfloat minimum, natural; gfloat minimum, natural;
@ -430,15 +430,15 @@ clutter_bin_layout_allocate (ClutterLayoutManager *manager,
gfloat allocation_x, allocation_y; gfloat allocation_x, allocation_y;
gfloat available_w, available_h; gfloat available_w, available_h;
ClutterActor *actor, *child; ClutterActor *actor, *child;
ClutterActorIter iter;
clutter_actor_box_get_origin (allocation, &allocation_x, &allocation_y); clutter_actor_box_get_origin (allocation, &allocation_x, &allocation_y);
clutter_actor_box_get_size (allocation, &available_w, &available_h); clutter_actor_box_get_size (allocation, &available_w, &available_h);
actor = CLUTTER_ACTOR (container); actor = CLUTTER_ACTOR (container);
for (child = clutter_actor_get_first_child (actor); clutter_actor_iter_init (&iter, actor);
child != NULL; while (clutter_actor_iter_next (&iter, &child))
child = clutter_actor_get_next_sibling (child))
{ {
ClutterLayoutMeta *meta; ClutterLayoutMeta *meta;
ClutterBinLayer *layer; ClutterBinLayer *layer;
@ -609,22 +609,14 @@ clutter_bin_layout_class_init (ClutterBinLayoutClass *klass)
gobject_class->set_property = clutter_bin_layout_set_property; gobject_class->set_property = clutter_bin_layout_set_property;
gobject_class->get_property = clutter_bin_layout_get_property; gobject_class->get_property = clutter_bin_layout_get_property;
g_object_class_install_properties (gobject_class, g_object_class_install_properties (gobject_class, PROP_LAST, bin_props);
PROP_LAST,
bin_props);
layout_class->get_preferred_width = layout_class->get_preferred_width = clutter_bin_layout_get_preferred_width;
clutter_bin_layout_get_preferred_width; layout_class->get_preferred_height = clutter_bin_layout_get_preferred_height;
layout_class->get_preferred_height = layout_class->allocate = clutter_bin_layout_allocate;
clutter_bin_layout_get_preferred_height; layout_class->create_child_meta = clutter_bin_layout_create_child_meta;
layout_class->allocate = layout_class->get_child_meta_type = clutter_bin_layout_get_child_meta_type;
clutter_bin_layout_allocate; layout_class->set_container = clutter_bin_layout_set_container;
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 static void

View file

@ -79,6 +79,8 @@
#include "deprecated/clutter-container.h" #include "deprecated/clutter-container.h"
#include "clutter-box-layout.h" #include "clutter-box-layout.h"
#include "clutter-actor-private.h"
#include "clutter-debug.h" #include "clutter-debug.h"
#include "clutter-enum-types.h" #include "clutter-enum-types.h"
#include "clutter-layout-meta.h" #include "clutter-layout-meta.h"
@ -133,7 +135,9 @@ enum
PROP_CHILD_Y_ALIGN, PROP_CHILD_Y_ALIGN,
PROP_CHILD_X_FILL, PROP_CHILD_X_FILL,
PROP_CHILD_Y_FILL, PROP_CHILD_Y_FILL,
PROP_CHILD_EXPAND PROP_CHILD_EXPAND,
PROP_CHILD_LAST
}; };
enum enum
@ -146,9 +150,13 @@ enum
PROP_PACK_START, PROP_PACK_START,
PROP_USE_ANIMATIONS, PROP_USE_ANIMATIONS,
PROP_EASING_MODE, PROP_EASING_MODE,
PROP_EASING_DURATION PROP_EASING_DURATION,
PROP_LAST
}; };
static GParamSpec *obj_props[PROP_LAST] = { NULL, };
G_DEFINE_TYPE (ClutterBoxChild, G_DEFINE_TYPE (ClutterBoxChild,
clutter_box_child, clutter_box_child,
CLUTTER_TYPE_LAYOUT_META); CLUTTER_TYPE_LAYOUT_META);
@ -743,14 +751,14 @@ count_expand_children (ClutterLayoutManager *layout,
gint *expand_children) gint *expand_children)
{ {
ClutterActor *actor, *child; ClutterActor *actor, *child;
ClutterActorIter iter;
actor = CLUTTER_ACTOR (container); actor = CLUTTER_ACTOR (container);
*visible_children = *expand_children = 0; *visible_children = *expand_children = 0;
for (child = clutter_actor_get_first_child (actor); clutter_actor_iter_init (&iter, actor);
child != NULL; while (clutter_actor_iter_next (&iter, &child))
child = clutter_actor_get_next_sibling (child))
{ {
if (CLUTTER_ACTOR_IS_VISIBLE (child)) if (CLUTTER_ACTOR_IS_VISIBLE (child))
{ {
@ -768,22 +776,21 @@ count_expand_children (ClutterLayoutManager *layout,
} }
} }
struct _ClutterRequestedSize typedef struct _RequestedSize
{ {
ClutterActor *actor; ClutterActor *actor;
gfloat minimum_size; gfloat minimum_size;
gfloat natural_size; gfloat natural_size;
}; } RequestedSize;
/* Pulled from gtksizerequest.c from Gtk+ */ /* Pulled from gtksizerequest.c from Gtk+ */
static gint static gint
compare_gap (gconstpointer p1, compare_gap (gconstpointer p1,
gconstpointer p2, gconstpointer p2,
gpointer data) gpointer data)
{ {
struct _ClutterRequestedSize *sizes = data; RequestedSize *sizes = data;
const guint *c1 = p1; const guint *c1 = p1;
const guint *c2 = p2; const guint *c2 = p2;
@ -805,16 +812,16 @@ compare_gap (gconstpointer p1,
/* /*
* distribute_natural_allocation: * distribute_natural_allocation:
* @extra_space: Extra space to redistribute among children after subtracting * @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 * @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 * @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 * Distributes @extra_space to child @sizes by bringing smaller
* children up to natural size first. * children up to natural size first.
* *
* The remaining space will be added to the @minimum_size member of the * 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. * the remaining space is returned.
* *
* Returns: The remainder of @extra_space after redistributing space * Returns: The remainder of @extra_space after redistributing space
@ -823,9 +830,9 @@ compare_gap (gconstpointer p1,
* Pulled from gtksizerequest.c from Gtk+ * Pulled from gtksizerequest.c from Gtk+
*/ */
static gint static gint
distribute_natural_allocation (gint extra_space, distribute_natural_allocation (gint extra_space,
guint n_requested_sizes, guint n_requested_sizes,
struct _ClutterRequestedSize *sizes) RequestedSize *sizes)
{ {
guint *spreading; guint *spreading;
gint i; gint i;
@ -895,9 +902,10 @@ clutter_box_layout_allocate (ClutterLayoutManager *layout,
gint nvis_children; gint nvis_children;
gint nexpand_children; gint nexpand_children;
gboolean is_rtl; gboolean is_rtl;
ClutterActorIter iter;
ClutterActorBox child_allocation; ClutterActorBox child_allocation;
struct _ClutterRequestedSize *sizes; RequestedSize *sizes;
gint size; gint size;
gint extra; gint extra;
@ -911,7 +919,7 @@ clutter_box_layout_allocate (ClutterLayoutManager *layout,
if (nvis_children <= 0) if (nvis_children <= 0)
return; return;
sizes = g_newa (struct _ClutterRequestedSize, nvis_children); sizes = g_newa (RequestedSize, nvis_children);
if (priv->is_vertical) if (priv->is_vertical)
size = box->y2 - box->y1 - (nvis_children - 1) * priv->spacing; size = box->y2 - box->y1 - (nvis_children - 1) * priv->spacing;
@ -921,9 +929,9 @@ clutter_box_layout_allocate (ClutterLayoutManager *layout,
actor = CLUTTER_ACTOR (container); actor = CLUTTER_ACTOR (container);
/* Retrieve desired size for visible children. */ /* Retrieve desired size for visible children. */
for (i = 0, child = clutter_actor_get_first_child (actor); i = 0;
child != NULL; clutter_actor_iter_init (&iter, actor);
child = clutter_actor_get_next_sibling (child)) while (clutter_actor_iter_next (&iter, &child))
{ {
if (!CLUTTER_ACTOR_IS_VISIBLE (child)) if (!CLUTTER_ACTOR_IS_VISIBLE (child))
continue; continue;
@ -942,16 +950,16 @@ clutter_box_layout_allocate (ClutterLayoutManager *layout,
/* Assert the api is working properly */ /* Assert the api is working properly */
if (sizes[i].minimum_size < 0) if (sizes[i].minimum_size < 0)
g_error ("GtkBox child %s minimum %s: %f < 0 for %s %f", g_error ("ClutterBoxLayout child %s minimum %s: %f < 0 for %s %f",
clutter_actor_get_name (child), _clutter_actor_get_debug_name (child),
priv->is_vertical ? "height" : "width", priv->is_vertical ? "height" : "width",
sizes[i].minimum_size, sizes[i].minimum_size,
priv->is_vertical ? "width" : "height", priv->is_vertical ? "width" : "height",
priv->is_vertical ? box->x2 - box->x1 : box->y2 - box->y1); priv->is_vertical ? box->x2 - box->x1 : box->y2 - box->y1);
if (sizes[i].natural_size < sizes[i].minimum_size) if (sizes[i].natural_size < sizes[i].minimum_size)
g_error ("GtkBox child %s natural %s: %f < minimum %f for %s %f", g_error ("ClutterBoxLayout child %s natural %s: %f < minimum %f for %s %f",
clutter_actor_get_name (child), _clutter_actor_get_debug_name (child),
priv->is_vertical ? "height" : "width", priv->is_vertical ? "height" : "width",
sizes[i].natural_size, sizes[i].natural_size,
sizes[i].minimum_size, sizes[i].minimum_size,
@ -962,7 +970,7 @@ clutter_box_layout_allocate (ClutterLayoutManager *layout,
sizes[i].actor = child; sizes[i].actor = child;
i++; i += 1;
} }
if (priv->is_homogeneous) if (priv->is_homogeneous)
@ -1035,15 +1043,15 @@ clutter_box_layout_allocate (ClutterLayoutManager *layout,
i -= 1; i -= 1;
/* If widget is not visible, skip it. */
if (!CLUTTER_ACTOR_IS_VISIBLE (child))
continue;
meta = clutter_layout_manager_get_child_meta (layout, meta = clutter_layout_manager_get_child_meta (layout,
container, container,
child); child);
box_child = CLUTTER_BOX_CHILD (meta); 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. */ /* Assign the child's size. */
if (priv->is_homogeneous) if (priv->is_homogeneous)
{ {
@ -1126,7 +1134,9 @@ clutter_box_layout_allocate (ClutterLayoutManager *layout,
{ {
gfloat width = child_allocation.x2 - child_allocation.x1; 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; 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); GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
ClutterLayoutManagerClass *layout_class; ClutterLayoutManagerClass *layout_class;
GParamSpec *pspec;
layout_class = CLUTTER_LAYOUT_MANAGER_CLASS (klass); layout_class = CLUTTER_LAYOUT_MANAGER_CLASS (klass);
gobject_class->set_property = clutter_box_layout_set_property; layout_class->get_preferred_width = clutter_box_layout_get_preferred_width;
gobject_class->get_property = clutter_box_layout_get_property; 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->allocate = clutter_box_layout_allocate;
layout_class->set_container = clutter_box_layout_set_container; layout_class->set_container = clutter_box_layout_set_container;
layout_class->get_child_meta_type = layout_class->get_child_meta_type = clutter_box_layout_get_child_meta_type;
clutter_box_layout_get_child_meta_type;
layout_class->begin_animation = clutter_box_layout_begin_animation; layout_class->begin_animation = clutter_box_layout_begin_animation;
layout_class->end_animation = clutter_box_layout_end_animation; layout_class->end_animation = clutter_box_layout_end_animation;
@ -1290,13 +1293,13 @@ clutter_box_layout_class_init (ClutterBoxLayoutClass *klass)
* *
* Since: 1.2 * Since: 1.2
*/ */
pspec = g_param_spec_boolean ("vertical", obj_props[PROP_VERTICAL] =
P_("Vertical"), g_param_spec_boolean ("vertical",
P_("Whether the layout should be vertical, " P_("Vertical"),
"rather than horizontal"), P_("Whether the layout should be vertical, "
FALSE, "rather than horizontal"),
CLUTTER_PARAM_READWRITE); FALSE,
g_object_class_install_property (gobject_class, PROP_VERTICAL, pspec); CLUTTER_PARAM_READWRITE);
/** /**
* ClutterBoxLayout:homogeneous: * ClutterBoxLayout:homogeneous:
@ -1306,13 +1309,13 @@ clutter_box_layout_class_init (ClutterBoxLayoutClass *klass)
* *
* Since: 1.4 * Since: 1.4
*/ */
pspec = g_param_spec_boolean ("homogeneous", obj_props[PROP_HOMOGENEOUS] =
P_("Homogeneous"), g_param_spec_boolean ("homogeneous",
P_("Whether the layout should be homogeneous, " P_("Homogeneous"),
"i.e. all childs get the same size"), P_("Whether the layout should be homogeneous, "
FALSE, "i.e. all childs get the same size"),
CLUTTER_PARAM_READWRITE); FALSE,
g_object_class_install_property (gobject_class, PROP_HOMOGENEOUS, pspec); CLUTTER_PARAM_READWRITE);
/** /**
* ClutterBoxLayout:pack-start: * ClutterBoxLayout:pack-start:
@ -1322,12 +1325,12 @@ clutter_box_layout_class_init (ClutterBoxLayoutClass *klass)
* *
* Since: 1.2 * Since: 1.2
*/ */
pspec = g_param_spec_boolean ("pack-start", obj_props[PROP_PACK_START] =
P_("Pack Start"), g_param_spec_boolean ("pack-start",
P_("Whether to pack items at the start of the box"), P_("Pack Start"),
FALSE, P_("Whether to pack items at the start of the box"),
CLUTTER_PARAM_READWRITE); FALSE,
g_object_class_install_property (gobject_class, PROP_PACK_START, pspec); CLUTTER_PARAM_READWRITE);
/** /**
* ClutterBoxLayout:spacing: * ClutterBoxLayout:spacing:
@ -1336,12 +1339,12 @@ clutter_box_layout_class_init (ClutterBoxLayoutClass *klass)
* *
* Since: 1.2 * Since: 1.2
*/ */
pspec = g_param_spec_uint ("spacing", obj_props[PROP_SPACING] =
P_("Spacing"), g_param_spec_uint ("spacing",
P_("Spacing between children"), P_("Spacing"),
0, G_MAXUINT, 0, P_("Spacing between children"),
CLUTTER_PARAM_READWRITE); 0, G_MAXUINT, 0,
g_object_class_install_property (gobject_class, PROP_SPACING, pspec); CLUTTER_PARAM_READWRITE);
/** /**
* ClutterBoxLayout:use-animations: * ClutterBoxLayout:use-animations:
@ -1351,12 +1354,12 @@ clutter_box_layout_class_init (ClutterBoxLayoutClass *klass)
* *
* Since: 1.2 * Since: 1.2
*/ */
pspec = g_param_spec_boolean ("use-animations", obj_props[PROP_USE_ANIMATIONS] =
P_("Use Animations"), g_param_spec_boolean ("use-animations",
P_("Whether layout changes should be animated"), P_("Use Animations"),
FALSE, P_("Whether layout changes should be animated"),
CLUTTER_PARAM_READWRITE); FALSE,
g_object_class_install_property (gobject_class, PROP_USE_ANIMATIONS, pspec); CLUTTER_PARAM_READWRITE);
/** /**
* ClutterBoxLayout:easing-mode: * ClutterBoxLayout:easing-mode:
@ -1373,13 +1376,13 @@ clutter_box_layout_class_init (ClutterBoxLayoutClass *klass)
* *
* Since: 1.2 * Since: 1.2
*/ */
pspec = g_param_spec_ulong ("easing-mode", obj_props[PROP_EASING_MODE] =
P_("Easing Mode"), g_param_spec_ulong ("easing-mode",
P_("The easing mode of the animations"), P_("Easing Mode"),
0, G_MAXULONG, P_("The easing mode of the animations"),
CLUTTER_EASE_OUT_CUBIC, 0, G_MAXULONG,
CLUTTER_PARAM_READWRITE); CLUTTER_EASE_OUT_CUBIC,
g_object_class_install_property (gobject_class, PROP_EASING_MODE, pspec); CLUTTER_PARAM_READWRITE);
/** /**
* ClutterBoxLayout:easing-duration: * ClutterBoxLayout:easing-duration:
@ -1391,13 +1394,17 @@ clutter_box_layout_class_init (ClutterBoxLayoutClass *klass)
* *
* Since: 1.2 * Since: 1.2
*/ */
pspec = g_param_spec_uint ("easing-duration", obj_props[PROP_EASING_DURATION] =
P_("Easing Duration"), g_param_spec_uint ("easing-duration",
P_("The duration of the animations"), P_("Easing Duration"),
0, G_MAXUINT, P_("The duration of the animations"),
500, 0, G_MAXUINT,
CLUTTER_PARAM_READWRITE); 500,
g_object_class_install_property (gobject_class, PROP_EASING_DURATION, pspec); 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 static void

View file

@ -210,6 +210,7 @@ clutter_flow_layout_get_preferred_width (ClutterLayoutManager *manager,
gfloat line_min_width, line_natural_width; gfloat line_min_width, line_natural_width;
gfloat max_min_width, max_natural_width; gfloat max_min_width, max_natural_width;
ClutterActor *actor, *child; ClutterActor *actor, *child;
ClutterActorIter iter;
gfloat item_y; gfloat item_y;
n_rows = get_rows (CLUTTER_FLOW_LAYOUT (manager), for_height); 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; max_min_width = max_natural_width = 0;
for (child = clutter_actor_get_first_child (actor); clutter_actor_iter_init (&iter, actor);
child != NULL; while (clutter_actor_iter_next (&iter, &child))
child = clutter_actor_get_next_sibling (child))
{ {
gfloat child_min, child_natural; gfloat child_min, child_natural;
gfloat new_y, item_height; 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 line_min_height, line_natural_height;
gfloat max_min_height, max_natural_height; gfloat max_min_height, max_natural_height;
ClutterActor *actor, *child; ClutterActor *actor, *child;
ClutterActorIter iter;
gfloat item_x; gfloat item_x;
n_columns = get_columns (CLUTTER_FLOW_LAYOUT (manager), for_width); 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; max_min_height = max_natural_height = 0;
for (child = clutter_actor_get_first_child (actor); clutter_actor_iter_init (&iter, actor);
child != NULL; while (clutter_actor_iter_next (&iter, &child))
child = clutter_actor_get_next_sibling (child))
{ {
gfloat child_min, child_natural; gfloat child_min, child_natural;
gfloat new_x, item_width; gfloat new_x, item_width;
@ -561,6 +561,7 @@ clutter_flow_layout_allocate (ClutterLayoutManager *manager,
{ {
ClutterFlowLayoutPrivate *priv = CLUTTER_FLOW_LAYOUT (manager)->priv; ClutterFlowLayoutPrivate *priv = CLUTTER_FLOW_LAYOUT (manager)->priv;
ClutterActor *actor, *child; ClutterActor *actor, *child;
ClutterActorIter iter;
gfloat x_off, y_off; gfloat x_off, y_off;
gfloat avail_width, avail_height; gfloat avail_width, avail_height;
gfloat item_x, item_y; gfloat item_x, item_y;
@ -599,9 +600,8 @@ clutter_flow_layout_allocate (ClutterLayoutManager *manager,
line_item_count = 0; line_item_count = 0;
line_index = 0; line_index = 0;
for (child = clutter_actor_get_first_child (actor); clutter_actor_iter_init (&iter, actor);
child != NULL; while (clutter_actor_iter_next (&iter, &child))
child = clutter_actor_get_next_sibling (child))
{ {
ClutterActorBox child_alloc; ClutterActorBox child_alloc;
gfloat item_width, item_height; gfloat item_width, item_height;