summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornirajkr <niraj.kr@samsung.com>2014-02-09 22:55:38 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-02-09 22:55:38 +0900
commit56a2c96ea7a731d6066aa7cb0964a633c5bed35c (patch)
tree7397843dad03fe090742783596d42a1ebdd57c80
parent1be00340149b249bca8293179fc8093a2c2de0ea (diff)
label : Added the API to match the speed of label to different label
Summary: Currently we do not set the speed of two label same This patch fetch the information of the previous label to set it to the next label to match the speed of the previous label Reviewers: seoz, raster Reviewed By: raster CC: singh.amitesh Differential Revision: https://phab.enlightenment.org/D531
-rw-r--r--src/bin/test_label.c47
-rw-r--r--src/lib/elm_label.c68
-rw-r--r--src/lib/elm_label_eo.h32
-rw-r--r--src/lib/elm_label_legacy.h32
-rw-r--r--src/lib/elm_widget_label.h5
5 files changed, 180 insertions, 4 deletions
diff --git a/src/bin/test_label.c b/src/bin/test_label.c
index 7e6a73d68..d5e789876 100644
--- a/src/bin/test_label.c
+++ b/src/bin/test_label.c
@@ -113,6 +113,8 @@ void
113test_label2(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) 113test_label2(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
114{ 114{
115 Evas_Object *win, *gd, *rect, *lb, *rd, *rdg, *sl; 115 Evas_Object *win, *gd, *rect, *lb, *rd, *rdg, *sl;
116 double duration;
117 Evas_Coord textlen;
116 118
117 win = elm_win_util_standard_add("label2", "Label 2"); 119 win = elm_win_util_standard_add("label2", "Label 2");
118 elm_win_autodel_set(win, EINA_TRUE); 120 elm_win_autodel_set(win, EINA_TRUE);
@@ -212,6 +214,51 @@ test_label2(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_in
212 elm_grid_pack(gd, sl, 5, 60, 90, 10); 214 elm_grid_pack(gd, sl, 5, 60, 90, 10);
213 evas_object_show(sl); 215 evas_object_show(sl);
214 216
217 /*Test label slide speed */
218 lb = elm_label_add(win);
219 elm_object_text_set(lb, "Test Label Slide Speed:");
220 elm_label_slide_mode_set(lb, ELM_LABEL_SLIDE_MODE_ALWAYS);
221 elm_label_slide_go(lb);
222 elm_grid_pack(gd, lb, 5, 70, 90, 10);
223 evas_object_show(lb);
224
225 rect = evas_object_rectangle_add(evas_object_evas_get(win));
226 elm_grid_pack(gd, rect, 5, 80, 90, 10);
227 evas_object_color_set(rect, 255, 125, 125, 255);
228 evas_object_show(rect);
229
230 lb = elm_label_add(win);
231 elm_object_style_set(lb, "slide_long");
232 elm_object_text_set(lb,
233 "This is a label set to slide and this will"
234 " test the speed of label with the below label."
235 " This label has few extra char to test");
236 elm_label_slide_duration_set(lb, 8.0);
237 elm_label_slide_mode_set(lb, ELM_LABEL_SLIDE_MODE_ALWAYS);
238 elm_label_slide_go(lb);
239 elm_grid_pack(gd, lb, 5, 80, 90, 10);
240 evas_object_show(lb);
241
242 //Get the required parameter of the previous label
243 duration = elm_label_slide_duration_get(lb);
244 textlen = elm_label_slide_text_length_get(lb);
245
246 rect = evas_object_rectangle_add(evas_object_evas_get(win));
247 elm_grid_pack(gd, rect, 5, 90, 90, 10);
248 evas_object_color_set(rect, 255, 125, 125, 255);
249 evas_object_show(rect);
250
251 lb = elm_label_add(win);
252 elm_object_style_set(lb, "slide_long");
253 elm_object_text_set(lb,
254 "This is a label set to slide and this will"
255 " match the speed of the upper label.");
256 elm_label_slide_mode_set(lb, ELM_LABEL_SLIDE_MODE_ALWAYS);
257 elm_label_slide_speed_match(lb, duration, textlen);
258 elm_label_slide_go(lb);
259 elm_grid_pack(gd, lb, 5, 90, 90, 10);
260 evas_object_show(lb);
261
215 evas_object_resize(win, 320, 320); 262 evas_object_resize(win, 320, 320);
216 evas_object_show(win); 263 evas_object_show(win);
217} 264}
diff --git a/src/lib/elm_label.c b/src/lib/elm_label.c
index 976b18610..a46badfff 100644
--- a/src/lib/elm_label.c
+++ b/src/lib/elm_label.c
@@ -78,7 +78,9 @@ static void
78_label_slide_change(Evas_Object *obj) 78_label_slide_change(Evas_Object *obj)
79{ 79{
80 Evas_Object *tb; 80 Evas_Object *tb;
81 Evas_Coord lw;
81 char *plaintxt; 82 char *plaintxt;
83 double speed;
82 int plainlen = 0; 84 int plainlen = 0;
83 85
84 ELM_LABEL_DATA_GET(obj, sd); 86 ELM_LABEL_DATA_GET(obj, sd);
@@ -138,6 +140,17 @@ _label_slide_change(Evas_Object *obj)
138 Edje_Message_Float_Set *msg = 140 Edje_Message_Float_Set *msg =
139 alloca(sizeof(Edje_Message_Float_Set) + (sizeof(double))); 141 alloca(sizeof(Edje_Message_Float_Set) + (sizeof(double)));
140 142
143 evas_object_geometry_get(wd->resize_obj,
144 NULL, NULL, &lw, NULL);
145 if ((sd->slide_duration_recalc) &&
146 (lw > 0) &&
147 (sd->matchslide_duration > 0))
148 {
149 speed = (sd->matchslide_textlen + lw) / (sd->matchslide_duration);
150 sd->slide_duration = (sd->text_formatted_length + lw) / (speed);
151 sd->slide_duration_recalc = EINA_FALSE;
152 }
153
141 msg->count = 1; 154 msg->count = 1;
142 msg->val[0] = sd->slide_duration; 155 msg->val[0] = sd->slide_duration;
143 156
@@ -214,9 +227,10 @@ _on_label_resize(void *data,
214 Evas_Object *obj EINA_UNUSED, 227 Evas_Object *obj EINA_UNUSED,
215 void *event_info EINA_UNUSED) 228 void *event_info EINA_UNUSED)
216{ 229{
217 ELM_LABEL_DATA_GET(data, sd); 230 ELM_LABEL_DATA_GET(data, sd);
218 231
219 if (sd->linewrap) elm_layout_sizing_eval(data); 232 if (sd->slide_duration_recalc) _label_slide_change(data);
233 if (sd->linewrap) elm_layout_sizing_eval(data);
220} 234}
221 235
222static int 236static int
@@ -324,6 +338,8 @@ _stringshare_key_value_replace(const char **srcstring,
324static void 338static void
325_elm_label_smart_text_set(Eo *obj, void *_pd, va_list *list) 339_elm_label_smart_text_set(Eo *obj, void *_pd, va_list *list)
326{ 340{
341 Evas_Object *tb;
342
327 Elm_Label_Smart_Data *sd = _pd; 343 Elm_Label_Smart_Data *sd = _pd;
328 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd); 344 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
329 const char *part = va_arg(*list, const char *); 345 const char *part = va_arg(*list, const char *);
@@ -341,6 +357,11 @@ _elm_label_smart_text_set(Eo *obj, void *_pd, va_list *list)
341 sd->lastw = 0; 357 sd->lastw = 0;
342 eo_do(obj, elm_obj_layout_sizing_eval()); 358 eo_do(obj, elm_obj_layout_sizing_eval());
343 } 359 }
360
361 tb = (Evas_Object *)edje_object_part_object_get(wd->resize_obj,
362 "elm.text");
363 evas_object_textblock_size_formatted_get(tb, &sd->text_formatted_length, NULL);
364
344 if (ret) *ret = int_ret; 365 if (ret) *ret = int_ret;
345} 366}
346 367
@@ -674,6 +695,41 @@ elm_label_slide_duration_get(const Evas_Object *obj)
674} 695}
675 696
676EAPI void 697EAPI void
698elm_label_slide_speed_match(Evas_Object *obj, double duration, Evas_Coord textlen)
699{
700 ELM_LABEL_CHECK(obj);
701 eo_do(obj, elm_obj_label_slide_speed_match(duration, textlen));
702}
703
704static void
705_slide_speed_match(Eo *obj EINA_UNUSED, void *_pd, va_list *list)
706{
707 double duration = va_arg(*list, double);
708 Evas_Coord textlen = va_arg(*list, Evas_Coord);
709 Elm_Label_Smart_Data *sd = _pd;
710 sd->matchslide_duration = duration;
711 sd->matchslide_textlen = textlen;
712 sd->slide_duration_recalc = EINA_TRUE;
713}
714
715EAPI Evas_Coord
716elm_label_slide_text_length_get(const Evas_Object *obj)
717{
718 ELM_LABEL_CHECK(obj) 0;
719 Evas_Coord ret = 0;
720 eo_do((Eo *) obj, elm_obj_label_slide_text_length_get(&ret));
721 return ret;
722}
723
724static void
725_slide_textlen_get(Eo *obj EINA_UNUSED, void *_pd, va_list *list)
726{
727 Evas_Coord *ret = va_arg(*list, Evas_Coord *);
728 Elm_Label_Smart_Data *sd = _pd;
729 *ret = sd->text_formatted_length;
730}
731
732EAPI void
677elm_label_slide_go(Evas_Object *obj) 733elm_label_slide_go(Evas_Object *obj)
678{ 734{
679 ELM_LABEL_CHECK(obj); 735 ELM_LABEL_CHECK(obj);
@@ -743,6 +799,8 @@ _class_constructor(Eo_Class *klass)
743 EO_OP_FUNC(ELM_OBJ_LABEL_ID(ELM_OBJ_LABEL_SUB_ID_SLIDE_DURATION_SET), _slide_duration_set), 799 EO_OP_FUNC(ELM_OBJ_LABEL_ID(ELM_OBJ_LABEL_SUB_ID_SLIDE_DURATION_SET), _slide_duration_set),
744 EO_OP_FUNC(ELM_OBJ_LABEL_ID(ELM_OBJ_LABEL_SUB_ID_SLIDE_DURATION_GET), _slide_duration_get), 800 EO_OP_FUNC(ELM_OBJ_LABEL_ID(ELM_OBJ_LABEL_SUB_ID_SLIDE_DURATION_GET), _slide_duration_get),
745 EO_OP_FUNC(ELM_OBJ_LABEL_ID(ELM_OBJ_LABEL_SUB_ID_SLIDE_GO), _slide_go), 801 EO_OP_FUNC(ELM_OBJ_LABEL_ID(ELM_OBJ_LABEL_SUB_ID_SLIDE_GO), _slide_go),
802 EO_OP_FUNC(ELM_OBJ_LABEL_ID(ELM_OBJ_LABEL_SUB_ID_SLIDE_SPEED_MATCH), _slide_speed_match),
803 EO_OP_FUNC(ELM_OBJ_LABEL_ID(ELM_OBJ_LABEL_SUB_ID_TEXT_LENGTH_GET), _slide_textlen_get),
746 EO_OP_FUNC_SENTINEL 804 EO_OP_FUNC_SENTINEL
747 }; 805 };
748 eo_class_funcs_set(klass, func_desc); 806 eo_class_funcs_set(klass, func_desc);
@@ -758,9 +816,11 @@ static const Eo_Op_Description op_desc[] = {
758 EO_OP_DESCRIPTION(ELM_OBJ_LABEL_SUB_ID_ELLIPSIS_GET, "Get the ellipsis behavior of the label."), 816 EO_OP_DESCRIPTION(ELM_OBJ_LABEL_SUB_ID_ELLIPSIS_GET, "Get the ellipsis behavior of the label."),
759 EO_OP_DESCRIPTION(ELM_OBJ_LABEL_SUB_ID_SLIDE_MODE_SET, "Set slide effect mode of label widget."), 817 EO_OP_DESCRIPTION(ELM_OBJ_LABEL_SUB_ID_SLIDE_MODE_SET, "Set slide effect mode of label widget."),
760 EO_OP_DESCRIPTION(ELM_OBJ_LABEL_SUB_ID_SLIDE_MODE_GET, "Get current slide effect mode."), 818 EO_OP_DESCRIPTION(ELM_OBJ_LABEL_SUB_ID_SLIDE_MODE_GET, "Get current slide effect mode."),
761 EO_OP_DESCRIPTION(ELM_OBJ_LABEL_SUB_ID_SLIDE_DURATION_SET, "Set the slide duration (speed) of the label."), 819 EO_OP_DESCRIPTION(ELM_OBJ_LABEL_SUB_ID_SLIDE_DURATION_SET, "Set the slide duration of the label."),
762 EO_OP_DESCRIPTION(ELM_OBJ_LABEL_SUB_ID_SLIDE_DURATION_GET, "Get the slide duration(speed) of the label."), 820 EO_OP_DESCRIPTION(ELM_OBJ_LABEL_SUB_ID_SLIDE_DURATION_GET, "Get the slide duration of the label."),
763 EO_OP_DESCRIPTION(ELM_OBJ_LABEL_SUB_ID_SLIDE_GO, "Start slide effect."), 821 EO_OP_DESCRIPTION(ELM_OBJ_LABEL_SUB_ID_SLIDE_GO, "Start slide effect."),
822 EO_OP_DESCRIPTION(ELM_OBJ_LABEL_SUB_ID_SLIDE_SPEED_MATCH, "Set the required parameter to match slide speed."),
823 EO_OP_DESCRIPTION(ELM_OBJ_LABEL_SUB_ID_TEXT_LENGTH_GET, "Get the text length of the label."),
764 EO_OP_DESCRIPTION_SENTINEL 824 EO_OP_DESCRIPTION_SENTINEL
765}; 825};
766static const Eo_Class_Description class_desc = { 826static const Eo_Class_Description class_desc = {
diff --git a/src/lib/elm_label_eo.h b/src/lib/elm_label_eo.h
index f79cb95f5..efd401361 100644
--- a/src/lib/elm_label_eo.h
+++ b/src/lib/elm_label_eo.h
@@ -22,6 +22,8 @@ enum
22 ELM_OBJ_LABEL_SUB_ID_SLIDE_DURATION_SET, 22 ELM_OBJ_LABEL_SUB_ID_SLIDE_DURATION_SET,
23 ELM_OBJ_LABEL_SUB_ID_SLIDE_DURATION_GET, 23 ELM_OBJ_LABEL_SUB_ID_SLIDE_DURATION_GET,
24 ELM_OBJ_LABEL_SUB_ID_SLIDE_GO, 24 ELM_OBJ_LABEL_SUB_ID_SLIDE_GO,
25 ELM_OBJ_LABEL_SUB_ID_SLIDE_SPEED_MATCH,
26 ELM_OBJ_LABEL_SUB_ID_TEXT_LENGTH_GET,
25 ELM_OBJ_LABEL_SUB_ID_LAST 27 ELM_OBJ_LABEL_SUB_ID_LAST
26}; 28};
27 29
@@ -179,6 +181,36 @@ enum
179 * @ingroup Label 181 * @ingroup Label
180 */ 182 */
181#define elm_obj_label_slide_go() ELM_OBJ_LABEL_ID(ELM_OBJ_LABEL_SUB_ID_SLIDE_GO) 183#define elm_obj_label_slide_go() ELM_OBJ_LABEL_ID(ELM_OBJ_LABEL_SUB_ID_SLIDE_GO)
184
185/**
186 * @def elm_obj_label_slide_speed_match
187 * @since 1.9
188 *
189 * @brief Set the required parameter to set the same speed of the label
190 *
191 * @param[in] duration
192 * @param[in] textlen
193 *
194 * @see elm_label_slide_duration_set
195 *
196 * @ingroup Label
197 */
198#define elm_obj_label_slide_speed_match(duration, textlen) ELM_OBJ_LABEL_ID(ELM_OBJ_LABEL_SUB_ID_SLIDE_SPEED_MATCH), EO_TYPECHECK(double, duration), EO_TYPECHECK(Evas_Coord, textlen)
199
200/**
201 * @def elm_obj_label_slide_text_length_get
202 * @since 1.9
203 *
204 * @brief Get the text label length
205 *
206 * @param[out] ret
207 *
208 * @see elm_object_text_set
209 *
210 * @ingroup Label
211 */
212#define elm_obj_label_slide_text_length_get(ret) ELM_OBJ_LABEL_ID(ELM_OBJ_LABEL_SUB_ID_TEXT_LENGTH_GET), EO_TYPECHECK(Evas_Coord * , ret)
213
182/** 214/**
183 * @} 215 * @}
184 */ 216 */
diff --git a/src/lib/elm_label_legacy.h b/src/lib/elm_label_legacy.h
index b3222b800..04cfc7e5d 100644
--- a/src/lib/elm_label_legacy.h
+++ b/src/lib/elm_label_legacy.h
@@ -162,3 +162,35 @@ EAPI double elm_label_slide_duration_get(const Evas_Object
162 * @ingroup Label 162 * @ingroup Label
163 */ 163 */
164EAPI void elm_label_slide_go(Evas_Object *obj); 164EAPI void elm_label_slide_go(Evas_Object *obj);
165
166/**
167 * @brief Set the required parameter to set the same speed of the label
168 *
169 * @param obj The label object
170 * @param duration The duration of the previous slide label
171 * @param duration The textlen of the previous slide label text
172 *
173 * @note If this API is called then it is not required to set the
174 * duration of the label. Internally it will calcuate the duration
175 * which will match the speed of the previous label. If the duration
176 * is explicitly set it will override these parameters.
177 *
178 * @see elm_label_slide_duration_set()
179 * @since 1.9
180 *
181 * @ingroup Label
182 */
183EAPI void elm_label_slide_speed_match(Evas_Object *obj, double duration, Evas_Coord textlen);
184
185/**
186 * @brief Get the text length of the label
187 *
188 * @param obj The label object
189 * @return The text length of the label
190 *
191 * @see elm_object_text_set()
192 * @since 1.9
193 *
194 * @ingroup Label
195 */
196EAPI Evas_Coord elm_label_slide_text_length_get(const Evas_Object *obj);
diff --git a/src/lib/elm_widget_label.h b/src/lib/elm_widget_label.h
index 4e2ac7254..4464e7607 100644
--- a/src/lib/elm_widget_label.h
+++ b/src/lib/elm_widget_label.h
@@ -13,13 +13,18 @@ struct _Elm_Label_Smart_Data
13{ 13{
14 const char *format; 14 const char *format;
15 double slide_duration; 15 double slide_duration;
16 double matchslide_duration;
17
16 Evas_Coord lastw; 18 Evas_Coord lastw;
17 Evas_Coord wrap_w; 19 Evas_Coord wrap_w;
20 Evas_Coord text_formatted_length;
21 Evas_Coord matchslide_textlen;
18 Elm_Wrap_Type linewrap; 22 Elm_Wrap_Type linewrap;
19 Elm_Label_Slide_Mode slide_mode; 23 Elm_Label_Slide_Mode slide_mode;
20 24
21 Eina_Bool ellipsis : 1; 25 Eina_Bool ellipsis : 1;
22 Eina_Bool slide_ellipsis : 1; 26 Eina_Bool slide_ellipsis : 1;
27 Eina_Bool slide_duration_recalc : 1;
23}; 28};
24 29
25#define ELM_LABEL_DATA_GET(o, sd) \ 30#define ELM_LABEL_DATA_GET(o, sd) \