2 //gcc -g `pkg-config --cflags --libs elementary` toggle_example_01.c -o toggle_example_01
4 #include <Elementary.h>
6 # include "elementary_config.h"
9 static void _cb(void *data, Evas_Object *obj, void *event_info);
10 static void _cb2(void *data, Evas_Object *obj, void *event_info);
12 static Eina_Bool val = EINA_FALSE;
15 elm_main(int argc, char **argv)
17 Evas_Object *win, *bg, *bx, *toggle, *ic;
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);
25 elm_win_resize_object_add(win, bg);
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);
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);
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);
57 evas_object_show(win);
66 _cb(void *data, Evas_Object *obj, void *event_info)
68 printf("val is now: %s\n", val ? "true" : "false");
72 _cb2(void *data, Evas_Object *obj, void *event_info)
74 printf("toggle2's state is now: %s\n", elm_toggle_state_get(obj) ? "true" : "false");