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;
32 static const char *widtype = NULL;
33 static void _del_hook(Evas_Object *obj);
34 static void _sizing_eval(Evas_Object *obj);
35 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
36 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
39 _del_pre_hook(Evas_Object *obj)
41 Widget_Data *wd = elm_widget_data_get(obj);
43 evas_object_event_callback_del_full
44 (wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
45 evas_object_box_remove_all(wd->box, 0);
49 _del_hook(Evas_Object *obj)
51 Widget_Data *wd = elm_widget_data_get(obj);
57 _sizing_eval(Evas_Object *obj)
59 Widget_Data *wd = elm_widget_data_get(obj);
60 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
63 evas_object_size_hint_min_get(wd->box, &minw, &minh);
64 evas_object_size_hint_max_get(wd->box, &maxw, &maxh);
65 evas_object_size_hint_min_set(obj, minw, minh);
66 evas_object_size_hint_max_set(obj, maxw, maxh);
67 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
68 if (w < minw) w = minw;
69 if (h < minh) h = minh;
70 if ((maxw >= 0) && (w > maxw)) w = maxw;
71 if ((maxh >= 0) && (h > maxh)) h = maxh;
72 evas_object_resize(obj, w, h);
76 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
82 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
88 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
90 Widget_Data *wd = data;
92 _els_box_layout_ex(o, priv, wd->horizontal, wd->homogeneous, wd->extended);
97 * Add a new box to the parent
99 * @param parent The parent object
100 * @return The new object or NULL if it cannot be created
105 elm_box_add(Evas_Object *parent)
111 wd = ELM_NEW(Widget_Data);
112 e = evas_object_evas_get(parent);
113 obj = elm_widget_add(e);
114 ELM_SET_WIDTYPE(widtype, "box");
115 elm_widget_type_set(obj, "box");
116 elm_widget_sub_object_add(parent, obj);
117 elm_widget_data_set(obj, wd);
118 elm_widget_del_hook_set(obj, _del_hook);
119 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
121 wd->box = evas_object_box_add(e);
122 /*evas_object_box_layout_set(wd->box, evas_object_box_layout_vertical,
124 evas_object_box_layout_set(wd->box, _layout, wd, NULL);
126 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
127 _changed_size_hints, obj);
128 elm_widget_resize_object_set(obj, wd->box);
130 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
136 * Set the horizontal orientation
138 * By default box object arrange their contents vertically from top to bottom.
139 * By calling this and providing @p orizontal as true, the box will become
140 * horizontal arranging contents left to right.
142 * @param obj The box object
143 * @param horizontal The horizontal flag (1 = horizontal, 0 = vertical)
148 elm_box_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
150 ELM_CHECK_WIDTYPE(obj, widtype);
151 Widget_Data *wd = elm_widget_data_get(obj);
153 wd->horizontal = !!horizontal;
154 evas_object_smart_calculate(wd->box);
155 /*if (wd->horizontal)
158 evas_object_box_layout_set(wd->box,
159 evas_object_box_layout_homogeneous_horizontal, NULL, NULL);
161 evas_object_box_layout_set(wd->box, evas_object_box_layout_horizontal,
167 evas_object_box_layout_set(wd->box,
168 evas_object_box_layout_homogeneous_vertical, NULL, NULL);
170 evas_object_box_layout_set(wd->box, evas_object_box_layout_horizontal,
176 * Set homogenous layout
178 * If enabled, homogenous layout makes all items the same size. This size is
179 * of course governed by the size of the largest item in the box.
181 * @param obj The box object
182 * @param homogenous The homogenous flag (1 = on, 2 = off)
187 elm_box_homogenous_set(Evas_Object *obj, Eina_Bool homogenous)
189 ELM_CHECK_WIDTYPE(obj, widtype);
190 Widget_Data *wd = elm_widget_data_get(obj);
192 wd->homogeneous = !!homogenous;
193 evas_object_smart_calculate(wd->box);
194 /*if (wd->horizontal)
197 evas_object_box_layout_set(wd->box,
198 evas_object_box_layout_homogeneous_horizontal, NULL, NULL);
200 evas_object_box_layout_set(wd->box, evas_object_box_layout_horizontal,
206 evas_object_box_layout_set(wd->box,
207 evas_object_box_layout_homogeneous_vertical, NULL, NULL);
209 evas_object_box_layout_set(wd->box, evas_object_box_layout_horizontal,
215 * This adds a box at the start of the box (top or left based on orientation)
217 * This will add the @p subobj to the box object indicated at the beginning
218 * of the box (the left or top end).
220 * @param obj The box object
221 * @param subobj The object to add to the box
226 elm_box_pack_start(Evas_Object *obj, Evas_Object *subobj)
228 ELM_CHECK_WIDTYPE(obj, widtype);
229 Widget_Data *wd = elm_widget_data_get(obj);
231 elm_widget_sub_object_add(obj, subobj);
232 evas_object_box_prepend(wd->box, subobj);
236 * This adds a box at the end of the box (bottom or right based on orientation)
238 * This will add the @p subobj to the box object indicated at the end
239 * of the box (the right or bottom end).
241 * @param obj The box object
242 * @param subobj The object to add to the box
247 elm_box_pack_end(Evas_Object *obj, Evas_Object *subobj)
249 ELM_CHECK_WIDTYPE(obj, widtype);
250 Widget_Data *wd = elm_widget_data_get(obj);
252 elm_widget_sub_object_add(obj, subobj);
253 evas_object_box_append(wd->box, subobj);
257 * This adds adds an object to the box before the indicated object
259 * This will add the @p subobj to the box indicated before the object
260 * indicated with @p before. If @p before is not already in the box, results
261 * are undefined. Before means either to the left of the indicated object or
262 * above it depending on orientation.
264 * @param obj The box object
265 * @param subobj The object to add to the box
266 * @param before The object before which to add it
271 elm_box_pack_before(Evas_Object *obj, Evas_Object *subobj, Evas_Object *before)
273 ELM_CHECK_WIDTYPE(obj, widtype);
274 Widget_Data *wd = elm_widget_data_get(obj);
276 elm_widget_sub_object_add(obj, subobj);
277 evas_object_box_insert_before(wd->box, subobj, before);
281 * This adds adds an object to the box after the indicated object
283 * This will add the @p subobj to the box indicated after the object
284 * indicated with @p after. If @p after is not already in the box, results
285 * are undefined. After means either to the right of the indicated object or
286 * below it depending on orientation.
288 * @param obj The box object
289 * @param subobj The object to add to the box
290 * @param after The object after which to add it
295 elm_box_pack_after(Evas_Object *obj, Evas_Object *subobj, Evas_Object *after)
297 ELM_CHECK_WIDTYPE(obj, widtype);
298 Widget_Data *wd = elm_widget_data_get(obj);
300 elm_widget_sub_object_add(obj, subobj);
301 evas_object_box_insert_after(wd->box, subobj, after);
305 * This clears the box items
307 * This delete all members of the box object, but not the box itself.
309 * @param obj The box object
314 elm_box_clear(Evas_Object *obj)
316 ELM_CHECK_WIDTYPE(obj, widtype);
317 Widget_Data *wd = elm_widget_data_get(obj);
319 evas_object_box_remove_all(wd->box, 1);
323 * This unpack a box item
325 * This unpack the selected member from the box object, but does not delete
326 * the box itself or the packed items.
328 * @param obj The box object
333 elm_box_unpack(Evas_Object *obj, Evas_Object *subobj)
335 ELM_CHECK_WIDTYPE(obj, widtype);
336 Widget_Data *wd = elm_widget_data_get(obj);
338 evas_object_box_remove(wd->box, subobj);
342 * This unpack the box items
344 * This unpack all members from the box object, but does not delete
345 * the box itself or the packed items.
347 * @param obj The box object
352 elm_box_unpack_all(Evas_Object *obj)
354 ELM_CHECK_WIDTYPE(obj, widtype);
355 Widget_Data *wd = elm_widget_data_get(obj);
357 evas_object_box_remove_all(wd->box, 0);
362 elm_box_extended_set(Evas_Object *obj, Eina_Bool extended)
364 ELM_CHECK_WIDTYPE(obj, widtype);
365 Widget_Data *wd = elm_widget_data_get(obj);
367 wd->extended = !!extended;
369 wd->horizontal = 1; /* Do NOT support vertical extended mode */
370 evas_object_smart_calculate(wd->box);