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