1 #include <Elementary.h>
8 * A box object arranges objects in a single row within a box. Sub objects can
9 * be added at the start, end or before or after any existing object in the
10 * box already. It can have its orientation changed too. How a child object is
11 * sized and otherwise arranged within the box depends on evas hints.
12 * evas_object_size_hint_align_set() will set either the alignment within its
13 * region if the region allocated is bigger than the object size. If you want
14 * the sub object sized up to fill the allocated region, use -1.0 for the
15 * apporpriate horizontal or vertical axes. evas_object_size_hint_weight_set()
16 * will set the packing weight. The weights of all items being packed are added
17 * up and if items are to be sized up to fit, those with the higher weights get
18 * proportionally more space.
20 * NOTE: Objects should not be added to box objects using _add() calls.
22 typedef struct _Widget_Data Widget_Data;
27 Eina_Bool horizontal:1;
28 Eina_Bool homogeneous:1;
31 static const char *widtype = NULL;
32 static void _del_hook(Evas_Object *obj);
33 static void _sizing_eval(Evas_Object *obj);
34 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
35 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
38 _del_pre_hook(Evas_Object *obj)
40 Widget_Data *wd = elm_widget_data_get(obj);
42 evas_object_event_callback_del_full
43 (wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
44 evas_object_box_remove_all(wd->box, 0);
48 _del_hook(Evas_Object *obj)
50 Widget_Data *wd = elm_widget_data_get(obj);
56 _sizing_eval(Evas_Object *obj)
58 Widget_Data *wd = elm_widget_data_get(obj);
59 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
62 evas_object_size_hint_min_get(wd->box, &minw, &minh);
63 evas_object_size_hint_max_get(wd->box, &maxw, &maxh);
64 evas_object_size_hint_min_set(obj, minw, minh);
65 evas_object_size_hint_max_set(obj, maxw, maxh);
66 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
67 if (w < minw) w = minw;
68 if (h < minh) h = minh;
69 if ((maxw >= 0) && (w > maxw)) w = maxw;
70 if ((maxh >= 0) && (h > maxh)) h = maxh;
71 evas_object_resize(obj, w, h);
75 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
81 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
87 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
89 Widget_Data *wd = data;
91 _els_box_layout(o, priv, wd->horizontal, wd->homogeneous);
96 * Add a new box to the parent
98 * @param parent The parent object
99 * @return The new object or NULL if it cannot be created
104 elm_box_add(Evas_Object *parent)
110 wd = ELM_NEW(Widget_Data);
111 e = evas_object_evas_get(parent);
112 obj = elm_widget_add(e);
113 ELM_SET_WIDTYPE(widtype, "box");
114 elm_widget_type_set(obj, "box");
115 elm_widget_sub_object_add(parent, obj);
116 elm_widget_data_set(obj, wd);
117 elm_widget_del_hook_set(obj, _del_hook);
118 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
120 wd->box = evas_object_box_add(e);
121 /*evas_object_box_layout_set(wd->box, evas_object_box_layout_vertical,
123 evas_object_box_layout_set(wd->box, _layout, wd, NULL);
125 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
126 _changed_size_hints, obj);
127 elm_widget_resize_object_set(obj, wd->box);
129 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
135 * Set the horizontal orientation
137 * By default box object arrange their contents vertically from top to bottom.
138 * By calling this and providing @p orizontal as true, the box will become
139 * horizontal arranging contents left to right.
141 * @param obj The box object
142 * @param horizontal The horizontal flag (1 = horizontal, 0 = vertical)
147 elm_box_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
149 ELM_CHECK_WIDTYPE(obj, widtype);
150 Widget_Data *wd = elm_widget_data_get(obj);
152 wd->horizontal = !!horizontal;
153 evas_object_smart_calculate(wd->box);
154 /*if (wd->horizontal)
157 evas_object_box_layout_set(wd->box,
158 evas_object_box_layout_homogeneous_horizontal, NULL, NULL);
160 evas_object_box_layout_set(wd->box, evas_object_box_layout_horizontal,
166 evas_object_box_layout_set(wd->box,
167 evas_object_box_layout_homogeneous_vertical, NULL, NULL);
169 evas_object_box_layout_set(wd->box, evas_object_box_layout_horizontal,
175 * Set homogenous layout
177 * If enabled, homogenous layout makes all items the same size. This size is
178 * of course governed by the size of the largest item in the box.
180 * @param obj The box object
181 * @param homogenous The homogenous flag (1 = on, 2 = off)
186 elm_box_homogenous_set(Evas_Object *obj, Eina_Bool homogenous)
188 ELM_CHECK_WIDTYPE(obj, widtype);
189 Widget_Data *wd = elm_widget_data_get(obj);
191 wd->homogeneous = !!homogenous;
192 evas_object_smart_calculate(wd->box);
193 /*if (wd->horizontal)
196 evas_object_box_layout_set(wd->box,
197 evas_object_box_layout_homogeneous_horizontal, NULL, NULL);
199 evas_object_box_layout_set(wd->box, evas_object_box_layout_horizontal,
205 evas_object_box_layout_set(wd->box,
206 evas_object_box_layout_homogeneous_vertical, NULL, NULL);
208 evas_object_box_layout_set(wd->box, evas_object_box_layout_horizontal,
214 * This adds a box at the start of the box (top or left based on orientation)
216 * This will add the @p subobj to the box object indicated at the beginning
217 * of the box (the left or top end).
219 * @param obj The box object
220 * @param subobj The object to add to the box
225 elm_box_pack_start(Evas_Object *obj, Evas_Object *subobj)
227 ELM_CHECK_WIDTYPE(obj, widtype);
228 Widget_Data *wd = elm_widget_data_get(obj);
230 elm_widget_sub_object_add(obj, subobj);
231 evas_object_box_prepend(wd->box, subobj);
235 * This adds a box at the end of the box (bottom or right based on orientation)
237 * This will add the @p subobj to the box object indicated at the end
238 * of the box (the right or bottom end).
240 * @param obj The box object
241 * @param subobj The object to add to the box
246 elm_box_pack_end(Evas_Object *obj, Evas_Object *subobj)
248 ELM_CHECK_WIDTYPE(obj, widtype);
249 Widget_Data *wd = elm_widget_data_get(obj);
251 elm_widget_sub_object_add(obj, subobj);
252 evas_object_box_append(wd->box, subobj);
256 * This adds adds an object to the box before the indicated object
258 * This will add the @p subobj to the box indicated before the object
259 * indicated with @p before. If @p before is not already in the box, results
260 * are undefined. Before means either to the left of the indicated object or
261 * above it depending on orientation.
263 * @param obj The box object
264 * @param subobj The object to add to the box
265 * @param before The object before which to add it
270 elm_box_pack_before(Evas_Object *obj, Evas_Object *subobj, Evas_Object *before)
272 ELM_CHECK_WIDTYPE(obj, widtype);
273 Widget_Data *wd = elm_widget_data_get(obj);
275 elm_widget_sub_object_add(obj, subobj);
276 evas_object_box_insert_before(wd->box, subobj, before);
280 * This adds adds an object to the box after the indicated object
282 * This will add the @p subobj to the box indicated after the object
283 * indicated with @p after. If @p after is not already in the box, results
284 * are undefined. After means either to the right of the indicated object or
285 * below it depending on orientation.
287 * @param obj The box object
288 * @param subobj The object to add to the box
289 * @param after The object after which to add it
294 elm_box_pack_after(Evas_Object *obj, Evas_Object *subobj, Evas_Object *after)
296 ELM_CHECK_WIDTYPE(obj, widtype);
297 Widget_Data *wd = elm_widget_data_get(obj);
299 elm_widget_sub_object_add(obj, subobj);
300 evas_object_box_insert_after(wd->box, subobj, after);
304 * This clears the box items
306 * This delete all members of the box object, but not the box itself.
308 * @param obj The box object
313 elm_box_clear(Evas_Object *obj)
315 ELM_CHECK_WIDTYPE(obj, widtype);
316 Widget_Data *wd = elm_widget_data_get(obj);
318 evas_object_box_remove_all(wd->box, 1);
322 * This unpack a box item
324 * This unpack the selected member from the box object, but does not delete
325 * the box itself or the packed items.
327 * @param obj The box object
332 elm_box_unpack(Evas_Object *obj, Evas_Object *subobj)
334 ELM_CHECK_WIDTYPE(obj, widtype);
335 Widget_Data *wd = elm_widget_data_get(obj);
337 evas_object_box_remove(wd->box, subobj);
341 * This unpack the box items
343 * This unpack all members from the box object, but does not delete
344 * the box itself or the packed items.
346 * @param obj The box object
351 elm_box_unpack_all(Evas_Object *obj)
353 ELM_CHECK_WIDTYPE(obj, widtype);
354 Widget_Data *wd = elm_widget_data_get(obj);
356 evas_object_box_remove_all(wd->box, 0);