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