1 #include <Elementary.h>
3 #include "els_scroller.h"
6 * @defgroup Panel Panel
9 * A panel is a type of animated container that contains subobjects. It
10 * can be expanded or contracted.
12 * Orientations are as follows:
13 * ELM_PANEL_ORIENT_TOP
14 * ELM_PANEL_ORIENT_BOTTOM
15 * ELM_PANEL_ORIENT_LEFT
16 * ELM_PANEL_ORIENT_RIGHT
17 * NOTE: Only LEFT and RIGHT orientations are implemented.
19 * THIS WIDGET IS UNDER CONSTRUCTION!
22 typedef struct _Widget_Data Widget_Data;
25 Evas_Object *scr, *bx, *content;
26 Elm_Panel_Orient orient;
30 static const char *widtype = NULL;
31 static void _del_hook(Evas_Object *obj);
32 static void _theme_hook(Evas_Object *obj);
33 static void _sizing_eval(Evas_Object *obj);
34 static void _resize(void *data, Evas *evas, Evas_Object *obj, void *event);
35 static void _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data);
36 static void _toggle_panel(void *data, Evas_Object *obj, const char *emission, const char *source);
39 _del_hook(Evas_Object *obj)
41 Widget_Data *wd = elm_widget_data_get(obj);
47 _theme_hook(Evas_Object *obj)
49 Widget_Data *wd = elm_widget_data_get(obj);
51 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", elm_widget_style_get(obj));
52 // scale = (elm_widget_scale_get(obj) * _elm_config->scale);
53 // edje_object_scale_set(wd->scr, scale);
58 _sizing_eval(Evas_Object *obj)
60 Widget_Data *wd = elm_widget_data_get(obj);
61 Evas_Coord mw = -1, mh = -1;
62 Evas_Coord vw = 0, vh = 0;
65 evas_object_smart_calculate(wd->bx);
66 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
68 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
71 evas_object_resize(wd->scr, w, h);
73 evas_object_size_hint_min_get(wd->bx, &mw, &mh);
76 evas_object_resize(wd->bx, mw, mh);
78 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
81 evas_object_size_hint_min_set(obj, mw, mh);
82 evas_object_size_hint_max_set(obj, -1, -1);
86 _resize(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
88 Widget_Data *wd = elm_widget_data_get(data);
89 Evas_Coord mw, mh, vw, vh, w, h;
91 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
92 evas_object_size_hint_min_get(wd->bx, &mw, &mh);
93 evas_object_geometry_get(wd->bx, NULL, NULL, &w, &h);
94 if ((vw >= mw) || (vh >= mh))
96 if ((w != vw) || (h != vh)) evas_object_resize(wd->bx, vw, vh);
101 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
103 Widget_Data *wd = data;
105 _els_box_layout(o, priv, EINA_TRUE, EINA_FALSE);
109 _toggle_panel(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
111 Widget_Data *wd = elm_widget_data_get(data);
115 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
116 "elm,action,show", "elm");
117 wd->hidden = EINA_FALSE;
121 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
122 "elm,action,hide", "elm");
123 wd->hidden = EINA_TRUE;
128 * Adds a panel object
130 * @param parent The parent object
132 * @return The panel object, or NULL on failure
137 elm_panel_add(Evas_Object *parent)
143 wd = ELM_NEW(Widget_Data);
144 evas = evas_object_evas_get(parent);
145 obj = elm_widget_add(evas);
146 ELM_SET_WIDTYPE(widtype, "panel");
147 elm_widget_type_set(obj, "panel");
148 elm_widget_sub_object_add(parent, obj);
149 elm_widget_data_set(obj, wd);
150 elm_widget_del_hook_set(obj, _del_hook);
151 elm_widget_theme_hook_set(obj, _theme_hook);
152 elm_widget_can_focus_set(obj, 0);
154 wd->scr = elm_smart_scroller_add(evas);
155 elm_smart_scroller_widget_set(wd->scr, obj);
156 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", "left");
157 elm_smart_scroller_bounce_allow_set(wd->scr, 0, 0);
158 elm_widget_resize_object_set(obj, wd->scr);
159 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
160 ELM_SMART_SCROLLER_POLICY_OFF);
162 wd->hidden = EINA_FALSE;
163 wd->orient = ELM_PANEL_ORIENT_LEFT;
165 wd->bx = evas_object_box_add(evas);
166 evas_object_size_hint_align_set(wd->bx, 0.5, 0.5);
167 evas_object_box_layout_set(wd->bx, _layout, wd, NULL);
168 elm_widget_sub_object_add(obj, wd->bx);
169 elm_smart_scroller_child_set(wd->scr, wd->bx);
170 evas_object_show(wd->bx);
172 edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scr),
173 "elm,action,panel,toggle", "*",
176 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE, _resize, obj);
183 * Sets the orientation of the panel
185 * @param parent The parent object
186 * @param orient The panel orientation. Can be one of the following:
187 * ELM_PANEL_ORIENT_TOP
188 * ELM_PANEL_ORIENT_BOTTOM
189 * ELM_PANEL_ORIENT_LEFT
190 * ELM_PANEL_ORIENT_RIGHT
192 * NOTE: Only LEFT and RIGHT orientations are implemented.
197 elm_panel_orient_set(Evas_Object *obj, Elm_Panel_Orient orient)
199 ELM_CHECK_WIDTYPE(obj, widtype);
200 Widget_Data *wd = elm_widget_data_get(obj);
205 case ELM_PANEL_ORIENT_TOP:
206 case ELM_PANEL_ORIENT_BOTTOM:
208 case ELM_PANEL_ORIENT_LEFT:
209 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", "left");
211 case ELM_PANEL_ORIENT_RIGHT:
212 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", "right");
221 * Get the orientation of the panel.
223 * @param obj The panel object
224 * @return The Elm_Panel_Orient, or ELM_PANEL_ORIENT_LEFT on failure.
228 EAPI Elm_Panel_Orient
229 elm_panel_orient_get(Evas_Object *obj)
231 ELM_CHECK_WIDTYPE(obj, widtype) ELM_PANEL_ORIENT_LEFT;
232 Widget_Data *wd = elm_widget_data_get(obj);
233 if (!wd) return ELM_PANEL_ORIENT_LEFT;
238 * Set the content of the panel.
240 * Once the content object is set, a previously set one will be deleted.
241 * If you want to keep that old content object, use the
242 * elm_panel_content_unset() function.
244 * @param obj The panel object
245 * @param content The panel content
250 elm_panel_content_set(Evas_Object *obj, Evas_Object *content)
252 ELM_CHECK_WIDTYPE(obj, widtype);
253 Widget_Data *wd = elm_widget_data_get(obj);
255 if (wd->content == content) return;
257 evas_object_box_remove_all(wd->bx, EINA_TRUE);
258 wd->content = content;
261 evas_object_box_append(wd->bx, wd->content);
262 evas_object_show(wd->content);
268 * Unset the content of the panel.
270 * Unparent and return the content object which was set for this widget.
272 * @param obj The panel object
273 * @return The content that was being used
278 elm_panel_content_unset(Evas_Object *obj)
280 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
281 Widget_Data *wd = elm_widget_data_get(obj);
282 Evas_Object *content;
283 if (!wd) return NULL;
284 if (!wd->content) return NULL;
285 content = wd->content;
286 evas_object_box_remove_all(wd->bx, EINA_FALSE);
292 * Set the state of the panel.
294 * @param obj The panel object
295 * @param hidden If true, the panel will run the edje animation to contract
300 elm_panel_hidden_set(Evas_Object *obj, Eina_Bool hidden)
302 ELM_CHECK_WIDTYPE(obj, widtype);
303 Widget_Data *wd = elm_widget_data_get(obj);
305 if (wd->hidden == hidden) return;
307 _toggle_panel(obj, NULL, "elm,action,panel,toggle", "*");
311 * Get the state of the panel.
313 * @param obj The panel object
314 * @param hidden If true, the panel is in the "hide" state
319 elm_panel_hidden_get(Evas_Object *obj)
321 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
322 Widget_Data *wd = elm_widget_data_get(obj);
323 if (!wd) return EINA_FALSE;
328 * Toggle the state of the panel from code
330 * @param obj The panel object
335 elm_panel_toggle(Evas_Object *obj)
337 ELM_CHECK_WIDTYPE(obj, widtype);
338 Widget_Data *wd = elm_widget_data_get(obj);
340 wd->hidden = !(wd->hidden);
341 _toggle_panel(obj, NULL, "elm,action,panel,toggle", "*");