SVN Merging for button, radio, check and toggle
[framework/uifw/elementary.git] / src / examples / toggle_example_01.c
1 //Compile with:
2 //gcc -g `pkg-config --cflags --libs elementary` toggle_example_01.c -o toggle_example_01
3
4 #include <Elementary.h>
5 #ifdef HAVE_CONFIG_H
6 # include "elementary_config.h"
7 #endif
8
9 static void _cb(void *data, Evas_Object *obj, void *event_info);
10 static void _cb2(void *data, Evas_Object *obj, void *event_info);
11
12 static Eina_Bool val = EINA_FALSE;
13
14 EAPI_MAIN int
15 elm_main(int argc, char **argv)
16 {
17    Evas_Object *win, *bg, *bx, *toggle, *ic;
18
19    win = elm_win_add(NULL, "toggle", ELM_WIN_BASIC);
20    elm_win_title_set(win, "toggle");
21    elm_win_autodel_set(win, EINA_TRUE);
22    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
23
24    bg = elm_bg_add(win);
25    elm_win_resize_object_add(win, bg);
26    evas_object_show(bg);
27
28    bx = elm_box_add(win);
29    elm_box_horizontal_set(bx, EINA_FALSE);
30    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
31    evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
32    elm_win_resize_object_add(win, bx);
33    evas_object_show(bx);
34
35    toggle = elm_toggle_add(win);
36    elm_object_text_set(toggle, "Toggle 1");
37    ic = elm_icon_add(win);
38    elm_icon_standard_set(ic, "home");
39    elm_toggle_icon_set(toggle, ic);
40    elm_toggle_state_pointer_set(toggle, &val);
41    elm_box_pack_end(bx, toggle);
42    evas_object_size_hint_weight_set(toggle, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
43    evas_object_size_hint_align_set(toggle, EVAS_HINT_FILL, EVAS_HINT_FILL);
44    evas_object_show(toggle);
45    evas_object_smart_callback_add(toggle, "changed", _cb, NULL);
46
47    toggle = elm_toggle_add(win);
48    elm_object_text_set(toggle, "Toggle 2");
49    elm_toggle_states_labels_set(toggle, "Enabled", "Disabled");
50    elm_toggle_state_set(toggle, EINA_TRUE);
51    elm_box_pack_end(bx, toggle);
52    evas_object_size_hint_weight_set(toggle, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
53    evas_object_size_hint_align_set(toggle, EVAS_HINT_FILL, EVAS_HINT_FILL);
54    evas_object_show(toggle);
55    evas_object_smart_callback_add(toggle, "changed", _cb2, NULL);
56
57    evas_object_show(win);
58
59    elm_run();
60
61    return 0;
62 }
63 ELM_MAIN()
64
65 static void
66 _cb(void *data, Evas_Object *obj, void *event_info)
67 {
68    printf("val is now: %s\n", val ? "true" : "false");
69 }
70
71 static void
72 _cb2(void *data, Evas_Object *obj, void *event_info)
73 {
74    printf("toggle2's state is now: %s\n", elm_toggle_state_get(obj) ? "true" : "false");
75 }