1 #include <Elementary.h>
7 * The grid is a grid layout widget that lays out a series of children as a
8 * fixed "grid" of widgets using a given percentage of the grid width and
9 * height each using the child object.
11 * The Grid uses a "Virtual resolution" that is stretched to fill the grid
12 * widgets size itself. The default is 100 x 100, so that means the
13 * position and sizes of children will effectively be percentages (0 to 100)
14 * of the width or height of the grid widget
18 typedef struct _Widget_Data Widget_Data;
22 Evas_Object *obj, *grd;
25 static const char *widtype = NULL;
26 static void _del_hook(Evas_Object *obj);
27 static void _theme_hook(Evas_Object *obj);
30 _del_hook(Evas_Object *obj)
32 Widget_Data *wd = elm_widget_data_get(obj);
38 _elm_table_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
40 Widget_Data *wd = elm_widget_data_get(obj);
41 const Eina_List *items;
42 void *(*list_data_get) (const Eina_List *list);
43 Eina_List *(*list_free) (Eina_List *list);
45 if ((!wd) || (!wd->tbl))
49 /* TODO: Change this to use other chain */
50 if ((items = elm_widget_focus_custom_chain_get(obj)))
52 list_data_get = eina_list_data_get;
57 items = evas_object_table_children_get(wd->grd);
58 list_data_get = eina_list_data_get;
59 list_free = eina_list_free;
61 if (!items) return EINA_FALSE;
64 Eina_Bool ret = elm_widget_focus_list_next_get(obj, items, list_data_get,
68 list_free((Eina_List *)items);
74 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
76 Widget_Data *wd = elm_widget_data_get(obj);
77 if ((!wd) || (!wd->grd)) return;
78 evas_object_grid_mirrored_set(wd->grd, rtl);
82 _theme_hook(Evas_Object *obj)
84 _elm_widget_mirrored_reload(obj);
85 _mirrored_set(obj, elm_widget_mirrored_get(obj));
89 * Add a new grid to the parent
91 * @param parent The parent object
92 * @return The new object or NULL if it cannot be created
97 elm_grid_add(Evas_Object *parent)
103 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
105 ELM_SET_WIDTYPE(widtype, "grid");
107 elm_widget_type_set(obj, "grid");
108 elm_widget_sub_object_add(parent, obj);
109 elm_widget_data_set(obj, wd);
110 elm_widget_del_hook_set(obj, _del_hook);
111 elm_widget_focus_next_hook_set(obj, _elm_table_focus_next_hook);
112 elm_widget_can_focus_set(obj, EINA_FALSE);
113 elm_widget_theme_hook_set(obj, _theme_hook);
115 wd->grd = evas_object_grid_add(e);
116 evas_object_grid_size_set(wd->grd, 100, 100);
117 elm_widget_resize_object_set(obj, wd->grd);
119 _mirrored_set(obj, elm_widget_mirrored_get(obj));
124 * Set the virtual size of the grid
126 * @param obj The grid object
127 * @param w The virtual width of the grid
128 * @param h The virtual height of the grid
133 elm_grid_size_set(Evas_Object *obj, int w, int h)
135 ELM_CHECK_WIDTYPE(obj, widtype);
136 Widget_Data *wd = elm_widget_data_get(obj);
138 evas_object_grid_size_set(wd->grd, w, h);
142 * Get the virtual size of the grid
144 * @param obj The grid object
145 * @param w Pointer to integer to store the virtual width of the grid
146 * @param h Pointer to integer to store the virtual height of the grid
151 elm_grid_size_get(Evas_Object *obj, int *w, int *h)
153 ELM_CHECK_WIDTYPE(obj, widtype);
154 Widget_Data *wd = elm_widget_data_get(obj);
156 evas_object_grid_size_get(wd->grd, w, h);
160 * Pack child at given position and size
162 * @param obj The grid object
163 * @param subobj The child to pack
164 * @param x The virtual x coord at which to pack it
165 * @param y The virtual y coord at which to pack it
166 * @param w The virtual width at which to pack it
167 * @param h The virtual height at which to pack it
172 elm_grid_pack(Evas_Object *obj, Evas_Object *subobj, int x, int y, int w, int h)
174 ELM_CHECK_WIDTYPE(obj, widtype);
175 Widget_Data *wd = elm_widget_data_get(obj);
177 elm_widget_sub_object_add(obj, subobj);
178 evas_object_grid_pack(wd->grd, subobj, x, y, w, h);
182 * Unpack a child from a grid object
184 * @param obj The grid object
185 * @param subobj The child to unpack
190 elm_grid_unpack(Evas_Object *obj, Evas_Object *subobj)
192 ELM_CHECK_WIDTYPE(obj, widtype);
193 Widget_Data *wd = elm_widget_data_get(obj);
195 elm_widget_sub_object_del(obj, subobj);
196 evas_object_grid_unpack(wd->grd, subobj);
200 * Faster way to remove all child objects from a grid object.
202 * @param obj The grid object
203 * @param clear If true, it will delete just removed children
208 elm_grid_clear(Evas_Object *obj, Eina_Bool clear)
212 ELM_CHECK_WIDTYPE(obj, widtype);
213 Widget_Data *wd = elm_widget_data_get(obj);
215 chld = evas_object_grid_children_get(wd->grd);
216 EINA_LIST_FREE(chld, o) elm_widget_sub_object_del(obj, o);
217 evas_object_grid_clear(wd->grd, clear);
221 * Set packing of an existing child at to position and size
223 * @param subobj The child to set packing of
224 * @param x The virtual x coord at which to pack it
225 * @param y The virtual y coord at which to pack it
226 * @param w The virtual width at which to pack it
227 * @param h The virtual height at which to pack it
232 elm_grid_pack_set(Evas_Object *subobj, int x, int y, int w, int h)
234 Evas_Object *obj = elm_widget_parent_widget_get(subobj);
235 ELM_CHECK_WIDTYPE(obj, widtype);
236 Widget_Data *wd = elm_widget_data_get(obj);
238 evas_object_grid_pack(wd->grd, subobj, x, y, w, h);
242 * get packing of a child
244 * @param subobj The child to query
245 * @param x Pointer to integer to store the virtual x coord
246 * @param y Pointer to integer to store the virtual y coord
247 * @param w Pointer to integer to store the virtual width
248 * @param h Pointer to integer to store the virtual height
253 elm_grid_pack_get(Evas_Object *subobj, int *x, int *y, int *w, int *h)
255 Evas_Object *obj = elm_widget_parent_widget_get(subobj);
256 ELM_CHECK_WIDTYPE(obj, widtype);
257 Widget_Data *wd = elm_widget_data_get(obj);
259 evas_object_grid_pack_get(wd->grd, subobj, x, y, w, h);