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 extended mode
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 * extended arranging contents left to right.
142 * @param obj The box object
143 * @param extended The extended flag (1 = extended, 0 = normal)
148 elm_box_extended_set(Evas_Object *obj, Eina_Bool extended)
150 ELM_CHECK_WIDTYPE(obj, widtype);
151 Widget_Data *wd = elm_widget_data_get(obj);
153 wd->extended = !!extended;
155 wd->horizontal = 1; /* Do NOT support vertical extended mode */
156 evas_object_smart_calculate(wd->box);
162 * Set the horizontal orientation
164 * By default box object arrange their contents vertically from top to bottom.
165 * By calling this and providing @p orizontal as true, the box will become
166 * horizontal arranging contents left to right.
168 * @param obj The box object
169 * @param horizontal The horizontal flag (1 = horizontal, 0 = vertical)
174 elm_box_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
176 ELM_CHECK_WIDTYPE(obj, widtype);
177 Widget_Data *wd = elm_widget_data_get(obj);
179 wd->horizontal = !!horizontal;
180 evas_object_smart_calculate(wd->box);
181 /*if (wd->horizontal)
184 evas_object_box_layout_set(wd->box,
185 evas_object_box_layout_homogeneous_horizontal, NULL, NULL);
187 evas_object_box_layout_set(wd->box, evas_object_box_layout_horizontal,
193 evas_object_box_layout_set(wd->box,
194 evas_object_box_layout_homogeneous_vertical, NULL, NULL);
196 evas_object_box_layout_set(wd->box, evas_object_box_layout_horizontal,
202 * Set homogenous layout
204 * If enabled, homogenous layout makes all items the same size. This size is
205 * of course governed by the size of the largest item in the box.
207 * @param obj The box object
208 * @param homogenous The homogenous flag (1 = on, 2 = off)
213 elm_box_homogenous_set(Evas_Object *obj, Eina_Bool homogenous)
215 ELM_CHECK_WIDTYPE(obj, widtype);
216 Widget_Data *wd = elm_widget_data_get(obj);
218 wd->homogeneous = !!homogenous;
219 evas_object_smart_calculate(wd->box);
220 /*if (wd->horizontal)
223 evas_object_box_layout_set(wd->box,
224 evas_object_box_layout_homogeneous_horizontal, NULL, NULL);
226 evas_object_box_layout_set(wd->box, evas_object_box_layout_horizontal,
232 evas_object_box_layout_set(wd->box,
233 evas_object_box_layout_homogeneous_vertical, NULL, NULL);
235 evas_object_box_layout_set(wd->box, evas_object_box_layout_horizontal,
241 * This adds a box at the start of the box (top or left based on orientation)
243 * This will add the @p subobj to the box object indicated at the beginning
244 * of the box (the left or top end).
246 * @param obj The box object
247 * @param subobj The object to add to the box
252 elm_box_pack_start(Evas_Object *obj, Evas_Object *subobj)
254 ELM_CHECK_WIDTYPE(obj, widtype);
255 Widget_Data *wd = elm_widget_data_get(obj);
257 elm_widget_sub_object_add(obj, subobj);
258 evas_object_box_prepend(wd->box, subobj);
262 * This adds a box at the end of the box (bottom or right based on orientation)
264 * This will add the @p subobj to the box object indicated at the end
265 * of the box (the right or bottom end).
267 * @param obj The box object
268 * @param subobj The object to add to the box
273 elm_box_pack_end(Evas_Object *obj, Evas_Object *subobj)
275 ELM_CHECK_WIDTYPE(obj, widtype);
276 Widget_Data *wd = elm_widget_data_get(obj);
278 elm_widget_sub_object_add(obj, subobj);
279 evas_object_box_append(wd->box, subobj);
283 * This adds adds an object to the box before the indicated object
285 * This will add the @p subobj to the box indicated before the object
286 * indicated with @p before. If @p before is not already in the box, results
287 * are undefined. Before means either to the left of the indicated object or
288 * above it depending on orientation.
290 * @param obj The box object
291 * @param subobj The object to add to the box
292 * @param before The object before which to add it
297 elm_box_pack_before(Evas_Object *obj, Evas_Object *subobj, Evas_Object *before)
299 ELM_CHECK_WIDTYPE(obj, widtype);
300 Widget_Data *wd = elm_widget_data_get(obj);
302 elm_widget_sub_object_add(obj, subobj);
303 evas_object_box_insert_before(wd->box, subobj, before);
307 * This adds adds an object to the box after the indicated object
309 * This will add the @p subobj to the box indicated after the object
310 * indicated with @p after. If @p after is not already in the box, results
311 * are undefined. After means either to the right of the indicated object or
312 * below it depending on orientation.
314 * @param obj The box object
315 * @param subobj The object to add to the box
316 * @param after The object after which to add it
321 elm_box_pack_after(Evas_Object *obj, Evas_Object *subobj, Evas_Object *after)
323 ELM_CHECK_WIDTYPE(obj, widtype);
324 Widget_Data *wd = elm_widget_data_get(obj);
326 elm_widget_sub_object_add(obj, subobj);
327 evas_object_box_insert_after(wd->box, subobj, after);
331 * This clears the box items
333 * This delete all members of the box object, but not the box itself.
335 * @param obj The box object
340 elm_box_clear(Evas_Object *obj)
342 ELM_CHECK_WIDTYPE(obj, widtype);
343 Widget_Data *wd = elm_widget_data_get(obj);
345 evas_object_box_remove_all(wd->box, 1);
349 * This unpack a box item
351 * This unpack the selected member from the box object, but does not delete
352 * the box itself or the packed items.
354 * @param obj The box object
359 elm_box_unpack(Evas_Object *obj, Evas_Object *subobj)
361 ELM_CHECK_WIDTYPE(obj, widtype);
362 Widget_Data *wd = elm_widget_data_get(obj);
364 evas_object_box_remove(wd->box, subobj);
368 * This unpack the box items
370 * This unpack all members from the box object, but does not delete
371 * the box itself or the packed items.
373 * @param obj The box object
378 elm_box_unpack_all(Evas_Object *obj)
380 ELM_CHECK_WIDTYPE(obj, widtype);
381 Widget_Data *wd = elm_widget_data_get(obj);
383 evas_object_box_remove_all(wd->box, 0);