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 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
40 Widget_Data *wd = elm_widget_data_get(obj);
41 if ((!wd) || (!wd->grd)) return;
42 evas_object_grid_mirrored_set(wd->grd, rtl);
46 _theme_hook(Evas_Object *obj)
48 _elm_widget_mirrored_reload(obj);
49 _mirrored_set(obj, elm_widget_mirrored_get(obj));
53 * Add a new grid to the parent
55 * @param parent The parent object
56 * @return The new object or NULL if it cannot be created
61 elm_grid_add(Evas_Object *parent)
67 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
69 ELM_SET_WIDTYPE(widtype, "grid");
71 elm_widget_type_set(obj, "grid");
72 elm_widget_sub_object_add(parent, obj);
73 elm_widget_data_set(obj, wd);
74 elm_widget_del_hook_set(obj, _del_hook);
75 elm_widget_theme_hook_set(obj, _theme_hook);
76 elm_widget_can_focus_set(obj, EINA_FALSE);
78 wd->grd = evas_object_grid_add(e);
79 evas_object_grid_size_set(wd->grd, 100, 100);
80 elm_widget_resize_object_set(obj, wd->grd);
85 * Set the virtual size of the grid
87 * @param obj The grid object
88 * @param w The virtual width of the grid
89 * @param h The virtual height of the grid
94 elm_grid_size_set(Evas_Object *obj, int w, int h)
96 ELM_CHECK_WIDTYPE(obj, widtype);
97 Widget_Data *wd = elm_widget_data_get(obj);
99 evas_object_grid_size_set(wd->grd, w, h);
103 * Get the virtual size of the grid
105 * @param obj The grid object
106 * @param w Pointer to integer to store the virtual width of the grid
107 * @param h Pointer to integer to store the virtual height of the grid
112 elm_grid_size_get(Evas_Object *obj, int *w, int *h)
114 ELM_CHECK_WIDTYPE(obj, widtype);
115 Widget_Data *wd = elm_widget_data_get(obj);
117 evas_object_grid_size_get(wd->grd, w, h);
121 * Pack child at given position and size
123 * @param obj The grid object
124 * @param subobj The child to pack
125 * @param x The virtual x coord at which to pack it
126 * @param y The virtual y coord at which to pack it
127 * @param w The virtual width at which to pack it
128 * @param h The virtual height at which to pack it
133 elm_grid_pack(Evas_Object *obj, Evas_Object *subobj, int x, int y, int w, int h)
135 ELM_CHECK_WIDTYPE(obj, widtype);
136 Widget_Data *wd = elm_widget_data_get(obj);
138 evas_object_grid_pack(wd->grd, subobj, x, y, w, h);
142 * Unpack a child from a grid object
144 * @param obj The grid object
145 * @param subobj The child to unpack
150 elm_grid_unpack(Evas_Object *obj, Evas_Object *subobj)
152 ELM_CHECK_WIDTYPE(obj, widtype);
153 Widget_Data *wd = elm_widget_data_get(obj);
155 elm_widget_sub_object_del(obj, subobj);
156 evas_object_grid_unpack(wd->grd, subobj);
160 * Faster way to remove all child objects from a grid object.
162 * @param obj The grid object
163 * @param clear If true, it will delete just removed children
168 elm_grid_clear(Evas_Object *obj, Eina_Bool clear)
172 ELM_CHECK_WIDTYPE(obj, widtype);
173 Widget_Data *wd = elm_widget_data_get(obj);
175 chld = evas_object_grid_children_get(wd->grd);
176 EINA_LIST_FREE(chld, o) elm_widget_sub_object_del(obj, o);
177 evas_object_grid_clear(wd->grd, clear);
181 * Set packing of an existing child at to position and size
183 * @param subobj The child to set packing of
184 * @param x The virtual x coord at which to pack it
185 * @param y The virtual y coord at which to pack it
186 * @param w The virtual width at which to pack it
187 * @param h The virtual height at which to pack it
192 elm_grid_pack_set(Evas_Object *subobj, int x, int y, int w, int h)
194 Evas_Object *obj = elm_widget_parent_widget_get(subobj);
195 ELM_CHECK_WIDTYPE(obj, widtype);
196 Widget_Data *wd = elm_widget_data_get(obj);
198 evas_object_grid_pack(wd->grd, subobj, x, y, w, h);
202 * get packing of a child
204 * @param subobj The child to query
205 * @param x Pointer to integer to store the virtual x coord
206 * @param y Pointer to integer to store the virtual y coord
207 * @param w Pointer to integer to store the virtual width
208 * @param h Pointer to integer to store the virtual height
213 elm_grid_pack_get(Evas_Object *subobj, int *x, int *y, int *w, int *h)
215 Evas_Object *obj = elm_widget_parent_widget_get(subobj);
216 ELM_CHECK_WIDTYPE(obj, widtype);
217 Widget_Data *wd = elm_widget_data_get(obj);
219 evas_object_grid_pack_get(wd->grd, subobj, x, y, w, h);