tizen 2.4 release
[framework/uifw/elementary.git] / src / examples / layout_example_02.c
1 //Compile with:
2 //gcc -g layout_example_02.c -o layout_example_02 `pkg-config --cflags --libs elementary`
3
4 #include <Elementary.h>
5
6 #define TABLE "example/table"
7 #define BOX "example/box"
8 #define TITLE "example/title"
9 #define SWALLOW "example/custom"
10
11 static const char *images[] = { "home", "close", "arrow_up", "arrow_down", NULL };
12
13 struct _App {
14      int current;
15 };
16
17 static void
18 _signal_cb(void *data, Evas_Object *o, const char *emission, const char *source)
19 {
20    struct _App *app = data;
21    Evas_Object *icon = elm_object_part_content_get(o, "elm.swallow.content");
22
23    printf("signal received\n");
24
25    if (!strcmp("elm,action,back", emission))
26      app->current--;
27    else if (!strcmp("elm,action,next", emission))
28      app->current++;
29
30    if (app->current < 0)
31      app->current = (sizeof(images) / sizeof(images[0])) - 2;
32    else if (images[app->current] == NULL)
33      app->current = 0;
34
35    elm_icon_standard_set(icon, images[app->current]);
36 }
37
38 EAPI_MAIN int
39 elm_main(int argc, char **argv)
40 {
41    Evas_Object *win, *layout, *icon;
42    struct _App app;
43
44    app.current = 0;
45
46    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
47
48    win = elm_win_util_standard_add("layout", "Layout");
49    elm_win_autodel_set(win, EINA_TRUE);
50
51    // Adding layout and filling it with widgets
52    layout = elm_layout_add(win);
53    evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
54    elm_win_resize_object_add(win, layout);
55    if (!elm_layout_theme_set(
56          layout, "layout", "application", "content-back-next"))
57      fprintf(stderr, "Failed to set layout");
58    evas_object_show(layout);
59
60    icon = elm_icon_add(win);
61    elm_icon_standard_set(icon, images[app.current]);
62    evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
63    elm_object_part_content_set(layout, "elm.swallow.content", icon);
64
65    elm_object_signal_callback_add(layout, "elm,action,back", "elm", _signal_cb, &app);
66    elm_object_signal_callback_add(layout, "elm,action,next", "elm", _signal_cb, &app);
67
68    evas_object_resize(win, 320, 320);
69    evas_object_show(win);
70
71    elm_run();
72
73    return 0;
74 }
75 ELM_MAIN()