tizen 2.4 release
[framework/uifw/elementary.git] / src / examples / segment_control_example.c
1 /**
2  * Simple Elementary's <b>segment_control widget</b> example, illustrating its
3  * usage and API.
4  *
5  * See stdout/stderr for output. Compile with:
6  *
7  * @verbatim
8  * gcc -g segment_control_example.c -o segment_control_example `pkg-config --cflags --libs elementary`
9  * @endverbatim
10  */
11
12 #include <Elementary.h>
13
14 EAPI_MAIN int
15 elm_main(int argc, char **argv)
16 {
17    Evas_Object *win, *sc, *ic;
18    Elm_Object_Item *seg_it;
19    int count, idx;
20
21    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
22
23    win = elm_win_util_standard_add("segment_control", "Segment Control Example");
24    elm_win_autodel_set(win, EINA_TRUE);
25
26    sc = elm_segment_control_add(win);
27    evas_object_size_hint_weight_set(sc, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
28    elm_win_resize_object_add(win, sc);
29    evas_object_show(sc);
30
31    elm_segment_control_item_add(sc, NULL, "only text");
32
33    ic = elm_icon_add(win);
34    elm_icon_standard_set(ic, "close");
35    elm_segment_control_item_add(sc, ic, NULL);
36
37    ic = elm_icon_add(win);
38    elm_icon_standard_set(ic, "home");
39    elm_segment_control_item_add(sc, ic, "Home");
40
41    ic = elm_icon_add(win);
42    elm_icon_standard_set(ic, "close");
43    elm_segment_control_item_add(sc, ic, "");
44
45    count = elm_segment_control_item_count_get(sc);
46    elm_segment_control_item_insert_at(sc, NULL, "Inserted at", count - 1);
47
48    seg_it = elm_segment_control_item_insert_at(sc, NULL, "To be deleted", 2);
49    elm_object_item_del(seg_it);
50
51    elm_segment_control_item_insert_at(sc, NULL, "To be deleted", 2);
52    elm_segment_control_item_del_at(sc, 2);
53
54    seg_it = elm_segment_control_item_get(sc, 0);
55    elm_object_item_text_set(seg_it, "Only Text");
56
57    count = elm_segment_control_item_count_get(sc);
58    seg_it = elm_segment_control_item_get(sc, count / 2);
59    elm_segment_control_item_selected_set(seg_it, EINA_TRUE);
60    seg_it = elm_segment_control_item_selected_get(sc);
61    idx = elm_segment_control_item_index_get(seg_it);
62    printf("Item selected: %i\n", idx);
63
64    evas_object_show(win);
65
66    elm_run();
67
68    return 0;
69 }
70 ELM_MAIN()