1 #include <Elementary.h>
5 * @defgroup Table Table
8 * Arranges widgets in a table where items can also span multiple
9 * columns or rows - even overlap (and then be raised or lowered
10 * accordingly to adjust stacking if they do overlap).
13 typedef struct _Widget_Data Widget_Data;
20 static const char *widtype = NULL;
21 static void _del_hook(Evas_Object *obj);
22 static void _sizing_eval(Evas_Object *obj);
23 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
24 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
27 _del_pre_hook(Evas_Object *obj)
29 Widget_Data *wd = elm_widget_data_get(obj);
31 evas_object_event_callback_del_full
32 (wd->tbl, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
33 evas_object_del(wd->tbl);
37 _del_hook(Evas_Object *obj)
39 Widget_Data *wd = elm_widget_data_get(obj);
45 _sizing_eval(Evas_Object *obj)
47 Widget_Data *wd = elm_widget_data_get(obj);
48 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
51 evas_object_size_hint_min_get(wd->tbl, &minw, &minh);
52 evas_object_size_hint_max_get(wd->tbl, &maxw, &maxh);
53 evas_object_size_hint_min_set(obj, minw, minh);
54 evas_object_size_hint_max_set(obj, maxw, maxh);
55 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
56 if (w < minw) w = minw;
57 if (h < minh) h = minh;
58 if ((maxw >= 0) && (w > maxw)) w = maxw;
59 if ((maxh >= 0) && (h > maxh)) h = maxh;
60 evas_object_resize(obj, w, h);
64 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
70 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
72 /* We do not add this callback, consequently we do not need to delete it
74 Widget_Data *wd = elm_widget_data_get(obj);
75 evas_Object *sub = event_info;
77 evas_object_event_callback_del_full
78 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
84 * Add a new table to the parent
86 * @param parent The parent object
87 * @return The new object or NULL if it cannot be created
92 elm_table_add(Evas_Object *parent)
98 wd = ELM_NEW(Widget_Data);
99 e = evas_object_evas_get(parent);
100 obj = elm_widget_add(e);
101 ELM_SET_WIDTYPE(widtype, "table");
102 elm_widget_type_set(obj, "table");
103 elm_widget_sub_object_add(parent, obj);
104 elm_widget_data_set(obj, wd);
105 elm_widget_del_hook_set(obj, _del_hook);
106 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
108 wd->tbl = evas_object_table_add(e);
109 evas_object_event_callback_add(wd->tbl, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
110 _changed_size_hints, obj);
111 elm_widget_resize_object_set(obj, wd->tbl);
113 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
119 * Set the homogenous layout in the table
121 * @param obj The layout object
122 * @param homogenous A boolean to set (or no) layout homogenous
124 * (1 = homogenous, 0 = no homogenous)
129 elm_table_homogenous_set(Evas_Object *obj, Eina_Bool homogenous)
131 ELM_CHECK_WIDTYPE(obj, widtype);
132 Widget_Data *wd = elm_widget_data_get(obj);
134 evas_object_table_homogeneous_set(wd->tbl, homogenous);
138 * Set padding between cells.
140 * @param obj The layout object.
141 * @param horizontal set the horizontal padding.
142 * @param vertical set the vertical padding.
147 elm_table_padding_set(Evas_Object *obj, Evas_Coord horizontal, Evas_Coord vertical)
149 ELM_CHECK_WIDTYPE(obj, widtype);
150 Widget_Data *wd = elm_widget_data_get(obj);
152 evas_object_table_padding_set(wd->tbl, horizontal, vertical);
156 * Add a subobject on the table with the coordinates passed
158 * @param obj The table object
159 * @param subobj The subobject to be added to the table
160 * @param x Coordinate to X axis
161 * @param y Coordinate to Y axis
162 * @param w Horizontal length
163 * @param h Vertical length
168 elm_table_pack(Evas_Object *obj, Evas_Object *subobj, int x, int y, int w, int h)
170 ELM_CHECK_WIDTYPE(obj, widtype);
171 Widget_Data *wd = elm_widget_data_get(obj);
173 elm_widget_sub_object_add(obj, subobj);
174 evas_object_table_pack(wd->tbl, subobj, x, y, w, h);
178 * Remove child from table.
180 * @param obj The table object
181 * @param subobj The subobject
186 elm_table_unpack(Evas_Object *obj, Evas_Object *subobj)
188 ELM_CHECK_WIDTYPE(obj, widtype);
189 Widget_Data *wd = elm_widget_data_get(obj);
191 elm_widget_sub_object_del(obj, subobj);
192 evas_object_table_unpack(wd->tbl, subobj);
196 * Faster way to remove all child objects from a table object.
198 * @param obj The table object
199 * @param clear If true, it will delete just removed children
204 elm_table_clear(Evas_Object *obj, Eina_Bool clear)
206 ELM_CHECK_WIDTYPE(obj, widtype);
207 Widget_Data *wd = elm_widget_data_get(obj);
209 evas_object_table_clear(wd->tbl, clear);