summaryrefslogtreecommitdiff
path: root/src/examples/elementary/slider_example.c
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2016-03-23 12:56:14 -0700
committerCedric BAIL <cedric@osg.samsung.com>2016-03-23 13:24:41 -0700
commitc2a1c49ab2042f559b28e840e54feb8494888e0e (patch)
treec6eb110b7c479499854eede9d0c3ab0a80c9a11a /src/examples/elementary/slider_example.c
parent9340855597e7e465435c69b6278650346688da14 (diff)
elementary: move all legacy files to their expected new location.
Diffstat (limited to 'src/examples/elementary/slider_example.c')
-rw-r--r--src/examples/elementary/slider_example.c136
1 files changed, 136 insertions, 0 deletions
diff --git a/src/examples/elementary/slider_example.c b/src/examples/elementary/slider_example.c
new file mode 100644
index 0000000000..53fdc922f7
--- /dev/null
+++ b/src/examples/elementary/slider_example.c
@@ -0,0 +1,136 @@
1/**
2 * Simple Elementary's <b>slider widget</b> example, illustrating its
3 * usage and API.
4 *
5 * See stdout/stderr for output. Compile with:
6 *
7 * @verbatim
8 * gcc -g slider_example.c -o slider_example `pkg-config --cflags --libs elementary`
9 * @endverbatim
10 */
11
12#include <Elementary.h>
13
14static void
15_changed_cb(void *data, Evas_Object *obj, void *event_info)
16{
17 double val = elm_slider_value_get(obj);
18 printf("Changed to %1.2f\n", val);
19}
20
21static void
22_delay_changed_cb(void *data, Evas_Object *obj, void *event_info)
23{
24 double val = elm_slider_value_get(obj);
25 printf("Delay changed to %1.2f\n", val);
26}
27
28static char*
29_indicator_format(double val)
30{
31 char *indicator = malloc(sizeof(char) * 32);
32 snprintf(indicator, 32, "%1.2f u", val);
33 return indicator;
34}
35
36static void
37_indicator_free(char *str)
38{
39 free(str);
40}
41
42EAPI_MAIN int
43elm_main(int argc, char **argv)
44{
45 Evas_Object *win, *bx, *sl, *ic;
46
47 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
48
49 win = elm_win_util_standard_add("slider", "Slider Example");
50 elm_win_autodel_set(win, EINA_TRUE);
51
52 bx = elm_box_add(win);
53 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
54 elm_win_resize_object_add(win, bx);
55 evas_object_show(bx);
56
57 /* default */
58 sl = elm_slider_add(win);
59 evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
60 evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
61 elm_box_pack_end(bx, sl);
62 evas_object_show(sl);
63
64 /* with icon, end and label */
65 sl = elm_slider_add(win);
66 elm_object_text_set(sl, "Counter");
67
68 ic = elm_icon_add(win);
69 elm_icon_standard_set(ic, "home");
70 elm_image_resizable_set(ic, EINA_FALSE, EINA_FALSE);
71 elm_object_part_content_set(sl, "icon", ic);
72
73 ic = elm_icon_add(win);
74 elm_icon_standard_set(ic, "folder");
75 elm_image_resizable_set(ic, EINA_FALSE, EINA_FALSE);
76 elm_object_part_content_set(sl, "end", ic);
77
78 evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
79 evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
80 elm_box_pack_end(bx, sl);
81 evas_object_show(sl);
82
83 /* value set and span size */
84 sl = elm_slider_add(win);
85 elm_slider_value_set(sl, 1);
86 elm_slider_span_size_set(sl, 200);
87 evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
88 evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
89 elm_box_pack_end(bx, sl);
90 evas_object_show(sl);
91
92 /* with unit label and min - max */
93 sl = elm_slider_add(win);
94 elm_slider_unit_format_set(sl, "%1.0f units");
95 elm_slider_min_max_set(sl, 0, 100);
96 evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
97 evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
98 elm_box_pack_end(bx, sl);
99 evas_object_show(sl);
100
101 /* with indicator label and inverted */
102 sl = elm_slider_add(win);
103 elm_slider_indicator_format_set(sl, "%1.2f");
104 elm_slider_inverted_set(sl, EINA_TRUE);
105 evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
106 evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
107 elm_box_pack_end(bx, sl);
108 evas_object_show(sl);
109
110 /* vertical with indicator format func */
111 sl = elm_slider_add(win);
112 elm_slider_horizontal_set(sl, EINA_FALSE);
113 elm_slider_indicator_format_function_set(sl, _indicator_format,
114 _indicator_free);
115 evas_object_size_hint_align_set(sl, 0.5, EVAS_HINT_FILL);
116 evas_object_size_hint_weight_set(sl, 0, EVAS_HINT_EXPAND);
117 elm_box_pack_end(bx, sl);
118 evas_object_show(sl);
119
120 /* callbacks */
121 sl = elm_slider_add(win);
122 elm_slider_unit_format_set(sl, "%1.3f units");
123 evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
124 evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
125 elm_box_pack_end(bx, sl);
126 evas_object_show(sl);
127 evas_object_smart_callback_add(sl, "changed", _changed_cb, NULL);
128 evas_object_smart_callback_add(sl, "delay,changed", _delay_changed_cb, NULL);
129
130 evas_object_show(win);
131
132 elm_run();
133
134 return 0;
135}
136ELM_MAIN()