[JungWooHyun] doing merge job ~
[framework/uifw/elementary.git] / src / examples / layout_example_03.c
1 //Compile with:
2 //gcc -g `pkg-config --cflags --libs elementary` layout_example_03.c -o layout_example_03
3
4 #include <Elementary.h>
5 #ifdef HAVE_CONFIG_H
6 # include "elementary_config.h"
7 #else
8 # define __UNUSED__
9 # define PACKAGE_DATA_DIR "."
10 #endif
11
12 #define TITLE "example/title"
13 #define SWALLOW "example/custom"
14
15 static Eina_Bool _btn_large = EINA_FALSE;
16
17 static void
18 _swallow_btn_cb(void *data, Evas_Object *btn, void *event_info __UNUSED__)
19 {
20    Evas_Object *layout = data;
21
22    if (_btn_large == EINA_FALSE)
23      {
24         _btn_large = EINA_TRUE;
25         elm_object_signal_emit(layout, "button,enlarge", "");
26         elm_object_text_set(btn, "Reduce me!");
27      }
28    else
29      {
30         _btn_large = EINA_FALSE;
31         elm_object_signal_emit(layout, "button,reduce", "");
32         elm_object_text_set(btn, "Enlarge me!");
33      }
34 }
35
36 static void
37 _size_changed_cb(void *data __UNUSED__, Evas_Object *layout, const char *emission __UNUSED__, const char *source __UNUSED__)
38 {
39    Evas_Object *edje;
40    Evas_Coord w, h;
41
42    elm_layout_sizing_eval(layout);
43    edje = elm_layout_edje_get(layout);
44    edje_object_size_min_calc(edje, &w, &h);
45    printf("Minimum size for this theme: %dx%d\n", w, h);
46 }
47
48 int
49 elm_main(int argc __UNUSED__, char **argv __UNUSED__)
50 {
51    Evas_Object *win, *bg, *btn, *layout;
52
53    win = elm_win_add(NULL, "layout", ELM_WIN_BASIC);
54    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
55    elm_win_autodel_set(win, EINA_TRUE);
56
57    bg = elm_bg_add(win);
58    elm_bg_color_set(bg, 255,255 ,255);
59    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
60    elm_win_resize_object_add(win, bg);
61    evas_object_show(bg);
62
63    // Adding layout
64    layout = elm_layout_add(win);
65    evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
66    elm_win_resize_object_add(win, layout);
67    elm_layout_file_set(
68        layout, PACKAGE_DATA_DIR "/examples/layout_example.edj",
69        "example/mylayout3");
70    evas_object_show(layout);
71
72    elm_object_signal_callback_add(layout, "size,changed", "", _size_changed_cb, layout);
73
74    // Setting title
75    const char *title = elm_layout_data_get(layout, "title");
76    if (title)
77      {
78         elm_win_title_set(win, title);
79         elm_object_part_text_set(layout, TITLE, title);
80      }
81
82    btn = elm_button_add(win);
83    elm_object_text_set(btn, "Enlarge me!");
84    evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
85    evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
86    elm_object_part_content_set(layout, SWALLOW, btn);
87    evas_object_smart_callback_add(btn, "clicked", _swallow_btn_cb, layout);
88
89    evas_object_size_hint_min_set(bg, 160, 160);
90    evas_object_size_hint_max_set(bg, 640, 640);
91    evas_object_resize(win, 160, 160);
92    evas_object_show(win);
93
94    elm_run();
95
96    return 0;
97 }
98
99 ELM_MAIN()