4 * An OpenGL based 'interactive canvas' library.
6 * Copyright (C) 2009 Intel Corporation.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
22 * Emmanuele Bassi <ebassi@linux.intel.com>
24 * Based on the fixed layout code inside clutter-group.c
28 * SECTION:clutter-fixed-layout
29 * @short_description: A fixed layout manager
31 * #ClutterFixedLayout is a layout manager implementing the same
32 * layout policies as #ClutterGroup.
34 * #ClutterFixedLayout is available since Clutter 1.2
41 #include "clutter-debug.h"
42 #include "clutter-fixed-layout.h"
43 #include "clutter-private.h"
45 G_DEFINE_TYPE (ClutterFixedLayout,
47 CLUTTER_TYPE_LAYOUT_MANAGER);
50 clutter_fixed_layout_get_preferred_width (ClutterLayoutManager *manager,
51 ClutterContainer *container,
56 ClutterActor *actor, *child;
58 gdouble natural_right;
63 actor = CLUTTER_ACTOR (container);
65 for (child = clutter_actor_get_first_child (actor);
67 child = clutter_actor_get_next_sibling (child))
69 gfloat child_x, child_min, child_natural;
71 child_x = clutter_actor_get_x (child);
73 clutter_actor_get_preferred_size (child,
75 &child_natural, NULL);
77 if (child_x + child_min > min_right)
78 min_right = child_x + child_min;
80 if (child_x + child_natural > natural_right)
81 natural_right = child_x + child_natural;
85 *min_width_p = min_right;
88 *nat_width_p = natural_right;
92 clutter_fixed_layout_get_preferred_height (ClutterLayoutManager *manager,
93 ClutterContainer *container,
98 ClutterActor *actor, *child;
100 gdouble natural_bottom;
105 actor = CLUTTER_ACTOR (container);
107 for (child = clutter_actor_get_first_child (actor);
109 child = clutter_actor_get_next_sibling (child))
111 gfloat child_y, child_min, child_natural;
113 child_y = clutter_actor_get_y (child);
115 clutter_actor_get_preferred_size (child,
117 NULL, &child_natural);
119 if (child_y + child_min > min_bottom)
120 min_bottom = child_y + child_min;
122 if (child_y + child_natural > natural_bottom)
123 natural_bottom = child_y + child_natural;
127 *min_height_p = min_bottom;
130 *nat_height_p = natural_bottom;
134 clutter_fixed_layout_allocate (ClutterLayoutManager *manager,
135 ClutterContainer *container,
136 const ClutterActorBox *allocation,
137 ClutterAllocationFlags flags)
141 for (child = clutter_actor_get_first_child (CLUTTER_ACTOR (container));
143 child = clutter_actor_get_next_sibling (child))
145 clutter_actor_allocate_preferred_size (child, flags);
150 clutter_fixed_layout_class_init (ClutterFixedLayoutClass *klass)
152 ClutterLayoutManagerClass *manager_class =
153 CLUTTER_LAYOUT_MANAGER_CLASS (klass);
155 manager_class->get_preferred_width =
156 clutter_fixed_layout_get_preferred_width;
157 manager_class->get_preferred_height =
158 clutter_fixed_layout_get_preferred_height;
159 manager_class->allocate = clutter_fixed_layout_allocate;
163 clutter_fixed_layout_init (ClutterFixedLayout *self)
168 * clutter_fixed_layout_new:
170 * Creates a new #ClutterFixedLayout
172 * Return value: the newly created #ClutterFixedLayout
176 ClutterLayoutManager *
177 clutter_fixed_layout_new (void)
179 return g_object_new (CLUTTER_TYPE_FIXED_LAYOUT, NULL);