1 #include <Elementary.h>
5 * @defgroup Panel Panel
7 * A panel is a type of animated container that contains subobjects. It
8 * can be expanded or contracted.
10 * Orientations are as follows:
11 * ELM_PANEL_ORIENT_TOP
12 * ELM_PANEL_ORIENT_BOTTOM
13 * ELM_PANEL_ORIENT_LEFT
14 * ELM_PANEL_ORIENT_RIGHT
15 * NOTE: Only LEFT and RIGHT orientations are implemented.
17 * THIS WIDGET IS UNDER CONSTRUCTION!
20 typedef struct _Widget_Data Widget_Data;
23 Evas_Object *scr, *bx;
24 Elm_Panel_Orient orient;
28 static const char *widtype = NULL;
29 static void _del_hook(Evas_Object *obj);
30 static void _theme_hook(Evas_Object *obj);
31 static void _sizing_eval(Evas_Object *obj);
32 static void _resize(void *data, Evas *evas, Evas_Object *obj, void *event);
33 static void _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data);
34 static void _toggle_panel(void *data, Evas_Object *obj, const char *emission, const char *source);
37 _del_hook(Evas_Object *obj)
39 Widget_Data *wd = elm_widget_data_get(obj);
45 _theme_hook(Evas_Object *obj)
47 Widget_Data *wd = elm_widget_data_get(obj);
49 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", elm_widget_style_get(obj));
50 // scale = (elm_widget_scale_get(obj) * _elm_config->scale);
51 // edje_object_scale_set(wd->scr, scale);
56 _sizing_eval(Evas_Object *obj)
58 Widget_Data *wd = elm_widget_data_get(obj);
59 Evas_Coord mw = -1, mh = -1;
60 Evas_Coord vw = 0, vh = 0;
63 evas_object_smart_calculate(wd->bx);
64 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
66 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
69 evas_object_resize(wd->scr, w, h);
71 evas_object_size_hint_min_get(wd->bx, &mw, &mh);
74 evas_object_resize(wd->bx, mw, mh);
76 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
79 evas_object_size_hint_min_set(obj, mw, mh);
80 evas_object_size_hint_max_set(obj, -1, -1);
84 _resize(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
86 Widget_Data *wd = elm_widget_data_get(data);
87 Evas_Coord mw, mh, vw, vh, w, h;
89 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
90 evas_object_size_hint_min_get(wd->bx, &mw, &mh);
91 evas_object_geometry_get(wd->bx, NULL, NULL, &w, &h);
92 if ((vw >= mw) || (vh >= mh))
94 if ((w != vw) || (h != vh)) evas_object_resize(wd->bx, vw, vh);
99 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
101 Widget_Data *wd = data;
103 _els_box_layout(o, priv, EINA_TRUE, EINA_FALSE);
107 _toggle_panel(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
109 Widget_Data *wd = elm_widget_data_get(data);
113 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
114 "elm,action,show", "elm");
115 wd->hidden = EINA_FALSE;
119 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
120 "elm,action,hide", "elm");
121 wd->hidden = EINA_TRUE;
126 * Adds a panel object
128 * @param parent The parent object
130 * @return The panel object, or NULL on failure
135 elm_panel_add(Evas_Object *parent)
141 wd = ELM_NEW(Widget_Data);
142 evas = evas_object_evas_get(parent);
143 obj = elm_widget_add(evas);
144 ELM_SET_WIDTYPE(widtype, "panel");
145 elm_widget_type_set(obj, "panel");
146 elm_widget_sub_object_add(parent, obj);
147 elm_widget_data_set(obj, wd);
148 elm_widget_del_hook_set(obj, _del_hook);
149 elm_widget_theme_hook_set(obj, _theme_hook);
150 elm_widget_can_focus_set(obj, 0);
152 wd->scr = elm_smart_scroller_add(evas);
153 elm_smart_scroller_widget_set(wd->scr, obj);
154 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", "left");
155 elm_smart_scroller_bounce_allow_set(wd->scr, 0, 0);
156 elm_widget_resize_object_set(obj, wd->scr);
157 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
158 ELM_SMART_SCROLLER_POLICY_OFF);
160 wd->hidden = EINA_FALSE;
161 wd->orient = ELM_PANEL_ORIENT_LEFT;
163 wd->bx = evas_object_box_add(evas);
164 evas_object_size_hint_align_set(wd->bx, 0.5, 0.5);
165 evas_object_box_layout_set(wd->bx, _layout, wd, NULL);
166 elm_widget_sub_object_add(obj, wd->bx);
167 elm_smart_scroller_child_set(wd->scr, wd->bx);
168 evas_object_show(wd->bx);
170 edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scr),
171 "elm,action,panel,toggle", "*",
174 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE, _resize, obj);
181 * Sets the orientation of the panel
183 * @param parent The parent object
184 * @param orient The panel orientation. Can be one of the following:
185 * ELM_PANEL_ORIENT_TOP
186 * ELM_PANEL_ORIENT_BOTTOM
187 * ELM_PANEL_ORIENT_LEFT
188 * ELM_PANEL_ORIENT_RIGHT
190 * NOTE: Only LEFT and RIGHT orientations are implemented.
195 elm_panel_orient_set(Evas_Object *obj, Elm_Panel_Orient orient)
197 ELM_CHECK_WIDTYPE(obj, widtype);
198 Widget_Data *wd = elm_widget_data_get(obj);
203 case ELM_PANEL_ORIENT_TOP:
204 case ELM_PANEL_ORIENT_BOTTOM:
206 case ELM_PANEL_ORIENT_LEFT:
207 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", "left");
209 case ELM_PANEL_ORIENT_RIGHT:
210 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", "right");
219 * Get the orientation of the panel.
221 * @param obj The panel object
222 * @return The Elm_Panel_Orient, or ELM_PANEL_ORIENT_LEFT on failure.
226 EAPI Elm_Panel_Orient
227 elm_panel_orient_get(Evas_Object *obj)
229 ELM_CHECK_WIDTYPE(obj, widtype) ELM_PANEL_ORIENT_LEFT;
230 Widget_Data *wd = elm_widget_data_get(obj);
231 if (!wd) return ELM_PANEL_ORIENT_LEFT;
236 * Set the content of the panel.
238 * @param obj The panel object
239 * @param content The panel content
244 elm_panel_content_set(Evas_Object *obj, Evas_Object *content)
246 ELM_CHECK_WIDTYPE(obj, widtype);
247 Widget_Data *wd = elm_widget_data_get(obj);
249 evas_object_box_remove_all(wd->bx, EINA_TRUE);
250 if (!content) return;
251 evas_object_box_append(wd->bx, content);
252 evas_object_show(content);
257 * Set the state of the panel.
259 * @param obj The panel object
260 * @param hidden If true, the panel will run the edje animation to contract
265 elm_panel_hidden_set(Evas_Object *obj, Eina_Bool hidden)
267 ELM_CHECK_WIDTYPE(obj, widtype);
268 Widget_Data *wd = elm_widget_data_get(obj);
270 if (wd->hidden == hidden) return;
272 _toggle_panel(obj, NULL, "elm,action,panel,toggle", "*");
276 * Get the state of the panel.
278 * @param obj The panel object
279 * @param hidden If true, the panel is in the "hide" state
284 elm_panel_hidden_get(Evas_Object *obj)
286 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
287 Widget_Data *wd = elm_widget_data_get(obj);
288 if (!wd) return EINA_FALSE;
293 * Toggle the state of the panel from code
295 * @param obj The panel object
300 elm_panel_toggle(Evas_Object *obj)
302 ELM_CHECK_WIDTYPE(obj, widtype);
303 Widget_Data *wd = elm_widget_data_get(obj);
305 wd->hidden = !(wd->hidden);
306 _toggle_panel(obj, NULL, "elm,action,panel,toggle", "*");