SVN Merging for button, radio, check and toggle
[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 `pkg-config --cflags --libs elementary` segment_control_example.c -o segment_control_example
9  * @endverbatim
10  */
11
12 #include <Elementary.h>
13 #ifdef HAVE_CONFIG_H
14 # include "elementary_config.h"
15 #else
16 # define __UNUSED__
17 #endif
18
19 static void
20 _on_done(void *data __UNUSED__,
21         Evas_Object *obj __UNUSED__,
22         void *event_info __UNUSED__)
23 {
24    elm_exit();
25 }
26
27 int
28 elm_main(int argc __UNUSED__, char **argv __UNUSED__)
29 {
30    Evas_Object *win, *bg, *sc, *ic;
31    Elm_Object_Item *seg_it;
32    int count, index;
33
34    win = elm_win_add(NULL, "segment_control", ELM_WIN_BASIC);
35    elm_win_title_set(win, "Segment Control Example");
36    evas_object_smart_callback_add(win, "delete,request", _on_done, NULL);
37
38    bg = elm_bg_add(win);
39    elm_win_resize_object_add(win, bg);
40    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
41    evas_object_show(bg);
42
43    sc = elm_segment_control_add(win);
44    evas_object_size_hint_weight_set(sc, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
45    elm_win_resize_object_add(win, sc);
46    evas_object_show(sc);
47
48    elm_segment_control_item_add(sc, NULL, "only text");
49
50    ic = elm_icon_add(win);
51    elm_icon_standard_set(ic, "close");
52    elm_segment_control_item_add(sc, ic, NULL);
53
54    ic = elm_icon_add(win);
55    elm_icon_standard_set(ic, "home");
56    elm_segment_control_item_add(sc, ic, "Home");
57
58    ic = elm_icon_add(win);
59    elm_icon_standard_set(ic, "close");
60    elm_segment_control_item_add(sc, ic, "");
61
62    count = elm_segment_control_item_count_get(sc);
63    elm_segment_control_item_insert_at(sc, NULL, "Inserted at", count - 1);
64
65    seg_it = elm_segment_control_item_insert_at(sc, NULL, "To be deleted", 2);
66    elm_object_item_del(seg_it);
67
68    elm_segment_control_item_insert_at(sc, NULL, "To be deleted", 2);
69    elm_segment_control_item_del_at(sc, 2);
70
71    seg_it = elm_segment_control_item_get(sc, 0);
72    elm_object_item_text_set(seg_it, "Only Text");
73
74    count = elm_segment_control_item_count_get(sc);
75    seg_it = elm_segment_control_item_get(sc, count / 2);
76    elm_segment_control_item_selected_set(seg_it, EINA_TRUE);
77    seg_it = elm_segment_control_item_selected_get(sc);
78    index = elm_segment_control_item_index_get(seg_it);
79    printf("Item selected: %i\n", index);
80
81    evas_object_show(win);
82
83    elm_run();
84    return 0;
85 }
86 ELM_MAIN()