Elementary: separator documentation.
[framework/uifw/elementary.git] / src / lib / elm_separator.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 typedef struct _Widget_Data Widget_Data;
5
6 struct _Widget_Data
7 {
8    Evas_Object *sep;
9    Eina_Bool horizontal;
10 };
11
12 static const char *widtype = NULL;
13 static void _del_hook(Evas_Object *obj);
14 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
15 static void _theme_hook(Evas_Object *obj);
16 static void _sizing_eval(Evas_Object *obj);
17
18 static void
19 _del_hook(Evas_Object *obj)
20 {
21    Widget_Data *wd = elm_widget_data_get(obj);
22    if (!wd) return;
23    free(wd);
24 }
25
26 static void
27 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
28 {
29    Widget_Data *wd = elm_widget_data_get(obj);
30    if (!wd) return;
31    edje_object_mirrored_set(wd->sep, rtl);
32 }
33
34 static void
35 _theme_hook(Evas_Object *obj)
36 {
37    Widget_Data *wd = elm_widget_data_get(obj);
38    if (!wd) return;
39    _elm_widget_mirrored_reload(obj);
40    _mirrored_set(obj, elm_widget_mirrored_get(obj));
41    if (wd->horizontal)
42      _elm_theme_object_set(obj, wd->sep, "separator", "horizontal", elm_widget_style_get(obj));
43    else
44      _elm_theme_object_set(obj, wd->sep, "separator", "vertical", elm_widget_style_get(obj));
45    edje_object_scale_set(wd->sep, elm_widget_scale_get(obj) * _elm_config->scale);
46    _sizing_eval(obj);
47 }
48
49 static void
50 _sizing_eval(Evas_Object *obj)
51 {
52    Widget_Data *wd = elm_widget_data_get(obj);
53    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
54    if (!wd) return;
55    edje_object_size_min_calc(wd->sep, &minw, &minh);
56    evas_object_size_hint_min_set(obj, minw, minh);
57    evas_object_size_hint_max_set(obj, maxw, maxh);
58    evas_object_size_hint_align_set(obj, maxw, maxh);
59 }
60
61 EAPI Evas_Object *
62 elm_separator_add(Evas_Object *parent)
63 {
64    Evas_Object *obj;
65    Evas *e;
66    Widget_Data *wd;
67
68    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
69
70    ELM_SET_WIDTYPE(widtype, "separator");
71    wd->horizontal = EINA_FALSE;
72    elm_widget_type_set(obj, "separator");
73    elm_widget_sub_object_add(parent, obj);
74    elm_widget_data_set(obj, wd);
75    elm_widget_del_hook_set(obj, _del_hook);
76    elm_widget_theme_hook_set(obj, _theme_hook);
77    elm_widget_can_focus_set(obj, EINA_FALSE);
78
79    wd->sep = edje_object_add(e);
80    _elm_theme_object_set(obj, wd->sep, "separator", "vertical", "default");
81    elm_widget_resize_object_set(obj, wd->sep);
82    _mirrored_set(obj, elm_widget_mirrored_get(obj));
83    _sizing_eval(obj);
84    return obj;
85 }
86
87 EAPI void
88 elm_separator_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
89 {
90    ELM_CHECK_WIDTYPE(obj, widtype);
91    Widget_Data *wd = elm_widget_data_get(obj);
92    if (!wd) return;
93    horizontal = !!horizontal;
94    if (wd->horizontal == horizontal) return;
95    wd->horizontal = horizontal;
96    _theme_hook(obj);
97 }
98
99 EAPI Eina_Bool
100 elm_separator_horizontal_get(const Evas_Object *obj)
101 {
102    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
103    Widget_Data *wd = elm_widget_data_get(obj);
104    if (!wd) return EINA_FALSE;
105    return wd->horizontal;
106 }