From: Bluezery <ohpowel@gmail.com>
[framework/uifw/elementary.git] / src / examples / actionslider_example_01.c
1 //Compile with:
2 //gcc -g `pkg-config --cflags --libs elementary` actionslider_example_01.c -o actionslider_example_01
3
4 #include <Elementary.h>
5 #ifdef HAVE_CONFIG_H
6 # include "elementary_config.h"
7 #else
8 # define __UNUSED__
9 #endif
10
11 static void _pos_selected_cb(void *data __UNUSED__, Evas_Object *obj, void *event_info)
12 {
13    printf("Selection: %s\n", (char *)event_info);
14    printf("Label selected: %s\n", elm_actionslider_selected_label_get(obj));
15 }
16
17 static void
18 _position_change_magnetic_cb(void *data __UNUSED__, Evas_Object * obj, void *event_info)
19 {
20    if (!strcmp((char *)event_info, "left"))
21      elm_actionslider_magnet_pos_set(obj, ELM_ACTIONSLIDER_LEFT);
22    else if (!strcmp((char *)event_info, "right"))
23      elm_actionslider_magnet_pos_set(obj, ELM_ACTIONSLIDER_RIGHT);
24 }
25
26 static void
27 _magnet_enable_disable_cb(void *data __UNUSED__, Evas_Object *obj, void *event_info)
28 {
29    if (!strcmp((char *)event_info, "left"))
30       elm_actionslider_magnet_pos_set(obj, ELM_ACTIONSLIDER_CENTER);
31    else if (!strcmp((char *)event_info, "right"))
32       elm_actionslider_magnet_pos_set(obj, ELM_ACTIONSLIDER_NONE);
33 }
34
35 static void
36 on_done(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
37 {
38    elm_exit();
39 }
40
41 EAPI_MAIN int
42 elm_main(int argc __UNUSED__, char **argv __UNUSED__)
43 {
44    Evas_Object *win, *bg, *bx, *as;
45
46    win = elm_win_add(NULL, "actionslider", ELM_WIN_BASIC);
47    elm_win_title_set(win, "Actionslider");
48    evas_object_smart_callback_add(win, "delete,request", on_done, NULL);
49
50    bg = elm_bg_add(win);
51    elm_win_resize_object_add(win, bg);
52    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, 0);
53    evas_object_show(bg);
54
55    bx = elm_box_add(win);
56    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, 0);
57    elm_win_resize_object_add(win, bx);
58    evas_object_show(bx);
59
60    as = elm_actionslider_add(win);
61    evas_object_size_hint_weight_set(as, EVAS_HINT_EXPAND, 0);
62    evas_object_size_hint_align_set(as, EVAS_HINT_FILL, 0);
63    elm_actionslider_indicator_pos_set(as, ELM_ACTIONSLIDER_RIGHT);
64    elm_actionslider_magnet_pos_set(as, ELM_ACTIONSLIDER_RIGHT);
65    elm_object_part_text_set(as, "left", "Snooze");
66    elm_object_part_text_set(as, "right", "Stop");
67    elm_actionslider_enabled_pos_set(as, ELM_ACTIONSLIDER_LEFT |
68                                     ELM_ACTIONSLIDER_RIGHT);
69    evas_object_smart_callback_add(as, "pos_changed",
70                                   _position_change_magnetic_cb, NULL);
71    evas_object_smart_callback_add(as, "selected", _pos_selected_cb, NULL);
72    evas_object_show(as);
73    elm_box_pack_end(bx, as);
74
75    as = elm_actionslider_add(win);
76    evas_object_size_hint_weight_set(as, EVAS_HINT_EXPAND, 0);
77    evas_object_size_hint_align_set(as, EVAS_HINT_FILL, 0);
78    elm_actionslider_indicator_pos_set(as, ELM_ACTIONSLIDER_CENTER);
79    elm_actionslider_magnet_pos_set(as, ELM_ACTIONSLIDER_CENTER);
80    elm_object_part_text_set(as, "left", "Snooze");
81    elm_object_part_text_set(as, "right", "Stop");
82    elm_actionslider_enabled_pos_set(as, ELM_ACTIONSLIDER_LEFT |
83                                     ELM_ACTIONSLIDER_RIGHT);
84    evas_object_smart_callback_add(as, "selected", _pos_selected_cb, NULL);
85    evas_object_show(as);
86    elm_box_pack_end(bx, as);
87
88    as = elm_actionslider_add(win);
89    elm_object_style_set(as, "bar");
90    evas_object_size_hint_weight_set(as, EVAS_HINT_EXPAND, 0);
91    evas_object_size_hint_align_set(as, EVAS_HINT_FILL, 0);
92    elm_actionslider_indicator_pos_set(as, ELM_ACTIONSLIDER_LEFT);
93    elm_actionslider_magnet_pos_set(as, ELM_ACTIONSLIDER_CENTER|
94                                    ELM_ACTIONSLIDER_RIGHT);
95    elm_actionslider_enabled_pos_set(as, ELM_ACTIONSLIDER_CENTER |
96                                     ELM_ACTIONSLIDER_RIGHT);
97    elm_object_part_text_set(as, "center", "Accept");
98    elm_object_part_text_set(as, "right", "Reject");
99    evas_object_smart_callback_add(as, "selected", _pos_selected_cb, NULL);
100    evas_object_show(as);
101    elm_box_pack_end(bx, as);
102
103    as = elm_actionslider_add(win);
104    elm_object_style_set(as, "bar");
105    evas_object_size_hint_weight_set(as, EVAS_HINT_EXPAND, 0);
106    evas_object_size_hint_align_set(as, EVAS_HINT_FILL, 0);
107    elm_actionslider_indicator_pos_set(as, ELM_ACTIONSLIDER_LEFT);
108    elm_actionslider_magnet_pos_set(as, ELM_ACTIONSLIDER_LEFT);
109    elm_object_part_text_set(as, "center", "Accept");
110    elm_object_part_text_set(as, "right", "Reject");
111    elm_object_text_set(as, "Go");
112    evas_object_smart_callback_add(as, "pos_changed",
113                                   _position_change_magnetic_cb, NULL);
114    evas_object_smart_callback_add(as, "selected", _pos_selected_cb, NULL);
115    evas_object_show(as);
116    elm_box_pack_end(bx, as);
117
118
119    as = elm_actionslider_add(win);
120    evas_object_size_hint_weight_set(as, EVAS_HINT_EXPAND, 0);
121    evas_object_size_hint_align_set(as, EVAS_HINT_FILL, 0);
122    elm_actionslider_indicator_pos_set(as, ELM_ACTIONSLIDER_LEFT);
123    elm_actionslider_magnet_pos_set(as, ELM_ACTIONSLIDER_ALL);
124    elm_object_part_text_set(as, "left", "Left");
125    elm_object_part_text_set(as, "center", "Center");
126    elm_object_part_text_set(as, "right", "Right");
127    elm_object_text_set(as, "Go");
128    evas_object_smart_callback_add(as, "selected", _pos_selected_cb, NULL);
129    evas_object_show(as);
130    elm_box_pack_end(bx, as);
131
132    as = elm_actionslider_add(win);
133    evas_object_size_hint_weight_set(as, EVAS_HINT_EXPAND, 0);
134    evas_object_size_hint_align_set(as, EVAS_HINT_FILL, 0);
135    elm_actionslider_indicator_pos_set(as, ELM_ACTIONSLIDER_CENTER);
136    elm_actionslider_magnet_pos_set(as, ELM_ACTIONSLIDER_CENTER);
137    elm_object_part_text_set(as, "left", "Enable");
138    elm_object_part_text_set(as, "center", "Magnet");
139    elm_object_part_text_set(as, "right", "Disable");
140    evas_object_smart_callback_add(as, "pos_changed",
141                                   _magnet_enable_disable_cb, NULL);
142    evas_object_smart_callback_add(as, "selected", _pos_selected_cb, NULL);
143    evas_object_show(as);
144    elm_box_pack_end(bx, as);
145
146    evas_object_resize(win, 320, 400);
147    evas_object_show(win);
148
149    elm_run();
150    return 0;
151 }
152 ELM_MAIN()