Revert a wrong commit. Un-wanted files are committed together.
[framework/uifw/elementary.git] / src / bin / test_label.c
1 #ifdef HAVE_CONFIG_H
2 # include "elementary_config.h"
3 #endif
4 #include <Elementary.h>
5 #ifndef ELM_LIB_QUICKLAUNCH
6
7 enum _slide_style
8 {
9    SLIDE_SHORT,
10    SLIDE_LONG,
11    SLIDE_BOUNCE,
12    SLIDE_STYLE_LAST
13 };
14
15 void
16 test_label(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
17 {
18    Evas_Object *win, *bg, *bx, *lb;
19
20    win = elm_win_add(NULL, "label", ELM_WIN_BASIC);
21    elm_win_title_set(win, "Label");
22    elm_win_autodel_set(win, EINA_TRUE);
23
24    bg = elm_bg_add(win);
25    elm_win_resize_object_add(win, bg);
26    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
27    evas_object_show(bg);
28
29    bx = elm_box_add(win);
30    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
31    evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
32
33    lb = elm_label_add(win);
34    elm_object_text_set(lb,
35                        "<b>This is a small label</b>"
36                        );
37    evas_object_size_hint_weight_set(lb, 0.0, 0.0);
38    evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, EVAS_HINT_FILL);
39    elm_box_pack_end(bx, lb);
40    evas_object_show(lb);
41
42    lb = elm_label_add(win);
43    elm_object_text_set(lb,
44                        "This is a larger label with newlines<br/>"
45                        "to make it bigger, bit it won't expand or wrap<br/>"
46                        "just be a block of text that can't change its<br/>"
47                        "formatting as it's fixed based on text<br/>"
48                        );
49    evas_object_size_hint_weight_set(lb, 0.0, 0.0);
50    evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, EVAS_HINT_FILL);
51    elm_box_pack_end(bx, lb);
52    evas_object_show(lb);
53
54    lb = elm_label_add(win);
55    elm_label_line_wrap_set(lb, ELM_WRAP_CHAR);
56    elm_object_text_set(lb,
57                        "<b>"
58                        "This is more text designed to line-wrap here as "
59                        "This object is resized horizontally. As it is "
60                        "resized vertically though, nothing should change. "
61                        "The amount of space allocated vertically should "
62                        "change as horizontal size changes."
63                        "</b>"
64                        );
65    evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, 0.0);
66    evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, EVAS_HINT_FILL);
67    elm_box_pack_end(bx, lb);
68    evas_object_show(lb);
69
70    lb = elm_label_add(win);
71    elm_object_text_set(lb,
72                        "This small label set to wrap"
73                        );
74    evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, 0.0);
75    evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, EVAS_HINT_FILL);
76    elm_box_pack_end(bx, lb);
77    evas_object_show(lb);
78
79
80    evas_object_resize(win, 320, 300);
81
82    evas_object_show(bx);
83    evas_object_show(win);
84    elm_win_resize_object_add(win, bx);
85 }
86
87 static void
88 _cb_size_radio_changed(void *data, Evas_Object *obj, void *event __UNUSED__)
89 {
90    Evas_Object *lb = (Evas_Object *)data;
91    int style =  elm_radio_value_get((Evas_Object *)obj);
92    switch (style)
93      {
94       case SLIDE_SHORT:
95          elm_object_style_set(lb, "slide_short");
96          break;
97
98       case SLIDE_LONG:
99          elm_object_style_set(lb, "slide_long");
100          break;
101
102       case SLIDE_BOUNCE:
103          elm_object_style_set(lb, "slide_bounce");
104          break;
105
106       default:
107          return;
108      }
109 }
110
111 static void
112 _change_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
113 {
114    Evas_Object *lb = (Evas_Object *)data;
115    double val = elm_slider_value_get(obj);
116    elm_label_slide_set(lb, EINA_FALSE);
117    elm_label_slide_duration_set(lb, val);
118    elm_label_slide_set(lb, EINA_TRUE);
119 }
120
121 void
122 test_label2(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
123 {
124    Evas_Object *win, *gd, *rect, *lb, *rd, *rdg, *sl;
125
126    win = elm_win_util_standard_add("label2", "Label 2");
127    elm_win_autodel_set(win, EINA_TRUE);
128
129    gd = elm_grid_add(win);
130    elm_grid_size_set(gd, 100, 100);
131    evas_object_size_hint_weight_set(gd, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
132    elm_win_resize_object_add(win, gd);
133    evas_object_show(gd);
134
135    /* Test Label Ellipsis */
136    lb = elm_label_add(win);
137    elm_object_text_set(lb, "Test Label Ellipsis:");
138    elm_label_slide_set(lb, EINA_TRUE);
139    elm_grid_pack(gd, lb, 5, 5, 90, 10);
140    evas_object_show(lb);
141
142    rect = evas_object_rectangle_add(evas_object_evas_get(win));
143    elm_grid_pack(gd, rect, 5, 15, 90, 10);
144    evas_object_color_set(rect, 255, 125, 125, 255);
145    evas_object_show(rect);
146
147    lb = elm_label_add(win);
148    elm_object_text_set(lb,
149                        "This is a label set to ellipsis. "
150                        "If set ellipsis to true and the text doesn't fit "
151                        "in the label an ellipsis(\"...\") will be shown "
152                        "at the end of the widget."
153                        );
154    elm_label_ellipsis_set(lb, EINA_TRUE);
155    elm_grid_pack(gd, lb, 5, 15, 90, 10);
156    evas_object_show(lb);
157
158    /* Test Label Slide */
159    lb = elm_label_add(win);
160    elm_object_text_set(lb, "Test Label Slide:");
161    elm_label_slide_set(lb, EINA_TRUE);
162    elm_grid_pack(gd, lb, 5, 30, 90, 10);
163    evas_object_show(lb);
164
165    rect = evas_object_rectangle_add(evas_object_evas_get(win));
166    elm_grid_pack(gd, rect, 5, 40, 90, 10);
167    evas_object_color_set(rect, 255, 125, 125, 255);
168    evas_object_show(rect);
169
170    lb = elm_label_add(win);
171    elm_object_style_set(lb, "slide_short");
172    elm_object_text_set(lb,
173                        "This is a label set to slide. "
174                        "If set slide to true the text of the label "
175                        "will slide/scroll through the length of label."
176                        "This only works with the themes \"slide_short\", "
177                        "\"slide_long\" and \"slide_bounce\"."
178                        );
179    elm_label_slide_set(lb, EINA_TRUE);
180    elm_grid_pack(gd, lb, 5, 40, 90, 10);
181    evas_object_show(lb);
182
183    rd = elm_radio_add(win);
184    elm_radio_state_value_set(rd, SLIDE_SHORT);
185    elm_object_text_set(rd, "slide_short");
186    evas_object_size_hint_weight_set(rd, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
187    evas_object_smart_callback_add(rd, "changed", _cb_size_radio_changed, lb);
188    elm_grid_pack(gd, rd, 5, 50, 30, 10);
189    evas_object_show(rd);
190    rdg = rd;
191
192    rd = elm_radio_add(win);
193    elm_radio_state_value_set(rd, SLIDE_LONG);
194    elm_radio_group_add(rd, rdg);
195    elm_object_text_set(rd, "slide_long");
196    evas_object_size_hint_weight_set(rd, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
197    evas_object_smart_callback_add(rd, "changed", _cb_size_radio_changed, lb);
198    elm_grid_pack(gd, rd, 35, 50, 30, 10);
199    evas_object_show(rd);
200
201    rd = elm_radio_add(win);
202    elm_radio_state_value_set(rd, SLIDE_BOUNCE);
203    elm_radio_group_add(rd, rdg);
204    elm_object_text_set(rd, "slide_bounce");
205    evas_object_size_hint_weight_set(rd, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
206    evas_object_smart_callback_add(rd, "changed", _cb_size_radio_changed, lb);
207    elm_grid_pack(gd, rd, 65, 50, 30, 10);
208    evas_object_show(rd);
209
210    sl = elm_slider_add(win);
211    elm_object_text_set(sl, "Slide Duration");
212    elm_slider_unit_format_set(sl, "%1.1f units");
213    elm_slider_min_max_set(sl, 1, 20);
214    elm_slider_value_set(sl, 10);
215    evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
216    evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
217    evas_object_smart_callback_add(sl, "changed", _change_cb, lb);
218    elm_grid_pack(gd, sl, 5, 60, 90, 10);
219    evas_object_show(sl);
220
221    evas_object_resize(win, 320, 320);
222    evas_object_show(win);
223 }
224 #endif