elementary: fix raster's bork.
[framework/uifw/elementary.git] / src / examples / general_funcs_example.c
1 /* Compile with:
2  * gcc -g `pkg-config --cflags --libs elementary` general_funcs_example.c -o general_funcs_example
3  */
4
5 #include <Elementary.h>
6
7 #ifdef HAVE_CONFIG_H
8 # include "elementary_config.h"
9 #else
10 # define __UNUSED__
11 # define PACKAGE_BIN_DIR  "/usr/bin"
12 # define PACKAGE_LIB_DIR  "/usr/lib"
13 # define PACKAGE_DATA_DIR "/usr/share/elementary"
14 #endif
15
16 #define WIDTH             300
17 #define HEIGHT            300
18
19 struct test_data
20 {
21    Evas_Object *btn;
22    Eina_Bool    btn_enabled;
23    Eina_Bool    btn_gets_focus;
24 };
25
26 struct test_data d = {NULL, EINA_TRUE, EINA_TRUE};
27
28 static void
29 _btn_enabled_cb(void        *data __UNUSED__,
30                 Evas_Object *obj __UNUSED__,
31                 void        *event __UNUSED__)
32 {
33    elm_object_disabled_set(d.btn, !d.btn_enabled);
34 }
35
36 static void
37 /* focus callback */
38 _btn_focus_cb(void        *data __UNUSED__,
39               Evas_Object *obj __UNUSED__,
40               void        *event __UNUSED__)
41 {
42    elm_object_focus_set(d.btn, EINA_TRUE);
43 }
44
45 static void
46 /* unfocus callback */
47 _btn_unfocus_cb(void        *data __UNUSED__,
48               Evas_Object *obj __UNUSED__,
49               void        *event __UNUSED__)
50 {
51    elm_object_focus_set(d.btn, EINA_FALSE);
52 }
53
54 static void
55 /* focus allow callback */
56 _btn_focus_allow_cb(void        *data __UNUSED__,
57                     Evas_Object *obj __UNUSED__,
58                     void        *event __UNUSED__)
59 {
60    elm_object_focus_allow_set(d.btn, d.btn_gets_focus);
61 }
62
63 static void /* scaling callback */
64 _btn_scale_cb(void        *data __UNUSED__,
65               Evas_Object *obj,
66               void        *event __UNUSED__)
67 {
68    elm_object_scale_set(d.btn, elm_slider_value_get(obj));
69 }
70
71 int
72 elm_main(int    argc __UNUSED__,
73          char **argv __UNUSED__)
74 {
75    int h;
76    Evas_Object *win, *bg, *box, *frame, *check, *b, *slider;
77
78    /* tell elm about our app so it can figure out where to get files */
79    elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR);
80    elm_app_compile_data_dir_set(PACKAGE_DATA_DIR);
81    elm_app_compile_lib_dir_set(PACKAGE_LIB_DIR);
82    elm_app_info_set(elm_main, "elementary", "images/logo.png");
83
84    fprintf(stdout, "prefix was set to: %s\n", elm_app_prefix_dir_get());
85    fprintf(stdout, "data directory is: %s\n", elm_app_data_dir_get());
86    fprintf(stdout, "library directory is: %s\n", elm_app_lib_dir_get());
87    fprintf(stdout, "locale directory is: %s\n", elm_app_locale_dir_get());
88
89    win = elm_win_add(NULL, "top-level-funcs-example", ELM_WIN_BASIC);
90    elm_win_title_set(win, "Elementary Top-level Functions Example");
91
92    /* by using this policy value, we avoid having to
93     * evas_object_smart_callback_add(win, "delete,request", _on_exit, NULL),
94     * calling elm_exit() on that callback ourselves.
95     */
96    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
97    elm_win_autodel_set(win, EINA_TRUE);
98
99    bg = elm_bg_add(win);
100    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
101    elm_win_resize_object_add(win, bg);
102    evas_object_show(bg);
103    evas_object_size_hint_min_set(bg, 160, 160);
104
105    /* outer box */
106    box = elm_box_add(win);
107    evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
108    evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
109    elm_win_resize_object_add(win, box);
110    evas_object_show(box);
111
112    frame = elm_frame_add(win);
113    elm_object_text_set(frame, "Button");
114    evas_object_size_hint_align_set(frame, EVAS_HINT_FILL, EVAS_HINT_FILL);
115    evas_object_show(frame);
116    elm_box_pack_end(box, frame);
117
118    d.btn = elm_button_add(win);
119    elm_object_text_set(d.btn, "Click me");
120    elm_object_content_set(frame, d.btn);
121
122    fprintf(stdout, "Elementary's finger size is set to %d pixels\n.",
123            elm_config_finger_size_get());
124    elm_coords_finger_size_adjust(0, NULL, 3, &h);
125    /* so, button will be 3 fingers tall */
126    evas_object_size_hint_min_set(d.btn, 0, h);
127    evas_object_show(d.btn);
128
129    b = elm_box_add(win);
130    elm_box_horizontal_set(b, EINA_FALSE);
131    evas_object_size_hint_weight_set(b, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
132    evas_object_size_hint_align_set(b, EVAS_HINT_FILL, EVAS_HINT_FILL);
133    elm_win_resize_object_add(win, b);
134    elm_box_pack_end(box, b);
135    evas_object_show(b);
136
137    check = elm_check_add(win);
138    evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
139    evas_object_size_hint_align_set(check, 0.0, 0.0);
140    elm_object_text_set(check, "Button enabled");
141    elm_check_state_pointer_set(check, &d.btn_enabled);
142    evas_object_smart_callback_add(check, "changed", _btn_enabled_cb, NULL);
143    elm_box_pack_end(box, check);
144    evas_object_show(check);
145
146    b = elm_button_add(win);
147    evas_object_size_hint_weight_set(b, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
148    evas_object_size_hint_align_set(b, 0.0, 0.0);
149    elm_object_text_set(b, "Focus top button");
150    evas_object_smart_callback_add(b, "clicked", _btn_focus_cb, NULL);
151    elm_box_pack_end(box, b);
152    evas_object_show(b);
153
154    b = elm_button_add(win);
155    evas_object_size_hint_weight_set(b, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
156    evas_object_size_hint_align_set(b, 0.0, 0.0);
157    elm_object_text_set(b, "Unfocus top button");
158    evas_object_smart_callback_add(b, "clicked", _btn_unfocus_cb, NULL);
159    elm_box_pack_end(box, b);
160    evas_object_show(b);
161
162    check = elm_check_add(win);
163    evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
164    evas_object_size_hint_align_set(check, 0.0, 0.0);
165    elm_object_text_set(check, "Button gets focus");
166    elm_check_state_pointer_set(check, &d.btn_gets_focus);
167    evas_object_smart_callback_add(check, "changed", _btn_focus_allow_cb, NULL);
168    elm_box_pack_end(box, check);
169    evas_object_show(check);
170
171    slider = elm_slider_add(win);
172    elm_slider_min_max_set(slider, 0, 4);
173    elm_slider_unit_format_set(slider, "%1.1f");
174    elm_slider_indicator_format_set(slider, "%1.1f");
175    evas_object_size_hint_weight_set(
176      slider, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
177    evas_object_size_hint_align_set(slider, EVAS_HINT_FILL, EVAS_HINT_FILL);
178    evas_object_smart_callback_add(slider, "changed", _btn_scale_cb, NULL);
179    elm_box_pack_end(box, slider);
180    evas_object_show(slider);
181
182    evas_object_resize(win, WIDTH, HEIGHT);
183    elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
184    evas_object_show(win);
185
186    elm_run(); /* and run the program now, starting to handle all
187                * events, etc. */
188    elm_shutdown(); /* clean up and shut down */
189
190    /* exit code */
191    return 0;
192 }
193
194 ELM_MAIN()