1 #include <Elementary.h>
5 * @defgroup Label Label
8 * Display text, with simple html-like markup. The theme of course
9 * can invent new markup tags and style them any way it likes
12 typedef struct _Widget_Data Widget_Data;
19 Ecore_Job *deferred_recalc_job;
20 double slide_duration;
24 Eina_Bool wrapmode : 1;
25 Eina_Bool linewrap : 1;
26 Eina_Bool changed : 1;
27 Eina_Bool bgcolor : 1;
28 Eina_Bool ellipsis : 1;
29 Eina_Bool slidingmode : 1;
30 Eina_Bool slidingellipsis : 1;
33 static const char *widtype = NULL;
34 static void _del_hook(Evas_Object *obj);
35 static void _theme_hook(Evas_Object *obj);
36 static void _sizing_eval(Evas_Object *obj);
37 static int _get_value_in_key_string(const char *oldstring, const char *key, char **value);
38 static int _strbuf_key_value_replace(Eina_Strbuf *srcbuf, const char *key, const char *value, int deleteflag);
39 static int _stringshare_key_value_replace(const char **srcstring, const char *key, const char *value, int deleteflag);
40 static int _is_width_over(Evas_Object *obj, Eina_Bool multiline);
41 static void _ellipsis_label_to_width(Evas_Object *obj, Eina_Bool multiline);
42 static void _label_sliding_change(Evas_Object *obj);
45 _elm_win_recalc_job(void *data)
47 Widget_Data *wd = elm_widget_data_get(data);
48 Evas_Coord minw = -1, minh = -1, maxh = -1;
49 Evas_Coord resw, resh, minminw;
51 wd->deferred_recalc_job = NULL;
52 evas_object_geometry_get(wd->lbl, NULL, NULL, &resw, &resh);
54 edje_object_size_min_restricted_calc(wd->lbl, &minw, &minh, 0, 0);
56 if (wd->wrap_w >= resw)
59 edje_object_size_min_restricted_calc(wd->lbl, &minw, &minh, resw, 0);
60 evas_object_size_hint_min_set(data, minw, minh);
64 if (wd->wrap_w > minminw) minminw = wd->wrap_w;
65 edje_object_size_min_restricted_calc(wd->lbl, &minw, &minh, resw, 0);
66 evas_object_size_hint_min_set(data, minminw, minh);
69 if ((wd->ellipsis) && (wd->linewrap) && (wd->wrap_h > 0) &&
70 (_is_width_over(data, 1) == 1))
71 _ellipsis_label_to_width(data, 1);
74 evas_object_size_hint_max_set(data, -1, maxh);
78 _del_hook(Evas_Object *obj)
80 Widget_Data *wd = elm_widget_data_get(obj);
82 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
83 if (wd->label) eina_stringshare_del(wd->label);
84 if (wd->bg) evas_object_del(wd->bg);
89 _theme_change(Evas_Object *obj)
91 Widget_Data *wd = elm_widget_data_get(obj);
97 _elm_theme_object_set(obj, wd->lbl, "label", "base_wrap_ellipsis",
98 elm_widget_style_get(obj));
100 _elm_theme_object_set(obj, wd->lbl, "label", "base_wrap",
101 elm_widget_style_get(obj));
104 _elm_theme_object_set(obj, wd->lbl, "label", "base",
105 elm_widget_style_get(obj));
109 _theme_hook(Evas_Object *obj)
111 Widget_Data *wd = elm_widget_data_get(obj);
114 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
115 edje_object_scale_set(wd->lbl, elm_widget_scale_get(obj) *
117 _label_sliding_change(obj);
122 _sizing_eval(Evas_Object *obj)
124 Widget_Data *wd = elm_widget_data_get(obj);
125 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
126 Evas_Coord resw, resh;
130 evas_object_geometry_get(wd->lbl, NULL, NULL, &resw, &resh);
131 if ((resw == wd->lastw) && (!wd->changed)) return;
132 wd->changed = EINA_FALSE;
134 _elm_win_recalc_job(obj);
135 // FIXME: works ok. but NOT for genlist. what should genlist do?
136 // if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
137 // wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
141 evas_object_geometry_get(wd->lbl, NULL, NULL, &resw, &resh);
142 edje_object_size_min_calc(wd->lbl, &minw, &minh);
143 if (wd->wrap_w > 0 && minw > wd->wrap_w) minw = wd->wrap_w;
144 evas_object_size_hint_min_set(obj, minw, minh);
146 evas_object_size_hint_max_set(obj, maxw, maxh);
147 if ((wd->ellipsis) && (_is_width_over(obj, 0) == 1))
148 _ellipsis_label_to_width(obj, 0);
153 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
155 Widget_Data *wd = elm_widget_data_get(data);
157 if (wd->linewrap) _sizing_eval(data);
161 _get_value_in_key_string(const char *oldstring, const char *key, char **value)
163 char *curlocater, *starttag, *endtag;
164 int firstindex = 0, foundflag = -1;
166 curlocater = strstr(oldstring, key);
169 int key_len = strlen(key);
170 starttag = curlocater;
171 endtag = curlocater + key_len;
172 if ((!endtag) || (*endtag != '='))
177 firstindex = abs(oldstring - curlocater);
178 firstindex += key_len + 1; // strlen("key") + strlen("=")
179 *value = (char *)oldstring + firstindex;
181 while (oldstring != starttag)
183 if (*starttag == '>')
188 if (*starttag == '<')
192 if (!starttag) break;
209 if ((foundflag) && (*starttag == '<') && (*endtag == '>'))
219 if (foundflag == 1) return 0;
226 _strbuf_key_value_replace(Eina_Strbuf *srcbuf, const char *key, const char *value, int deleteflag)
228 const char *srcstring = NULL;
229 Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
230 char *curlocater, *replocater;
231 char *starttag, *endtag;
232 int tagtxtlen = 0, insertflag = 0;
234 srcstring = eina_strbuf_string_get(srcbuf);
235 curlocater = strstr(srcstring, key);
241 int key_len = strlen(key);
244 starttag = strchr(srcstring, '<');
245 endtag = strchr(srcstring, '>');
246 tagtxtlen = endtag - starttag;
247 if (tagtxtlen <= 0) tagtxtlen = 0;
248 if ((starttag < curlocater) && (curlocater < endtag)) break;
249 if ((endtag) && ((endtag + 1)))
250 srcstring = endtag + 1;
253 } while (strlen(srcstring) > 1);
255 if ((starttag) && (endtag) && (tagtxtlen > key_len))
257 repbuf = eina_strbuf_new();
258 diffbuf = eina_strbuf_new();
259 eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
260 srcstring = eina_strbuf_string_get(repbuf);
261 curlocater = strstr(srcstring, key);
264 replocater = curlocater + key_len + 1;
265 while ((*replocater != '=') && (replocater))
268 while (*replocater && *replocater != ' ' && *replocater != '>')
271 if (replocater - curlocater > strlen(key) + 1)
274 eina_strbuf_append_n(diffbuf, curlocater,
275 replocater-curlocater);
282 eina_strbuf_reset(repbuf);
288 if (!repbuf) repbuf = eina_strbuf_new();
289 if (!diffbuf) diffbuf = eina_strbuf_new();
293 eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
294 eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
300 eina_strbuf_prepend(diffbuf, "<");
301 eina_strbuf_append(diffbuf, ">");
302 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
306 eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
307 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
311 if (repbuf) eina_strbuf_free(repbuf);
312 if (diffbuf) eina_strbuf_free(diffbuf);
318 _stringshare_key_value_replace(const char **srcstring, const char *key, const char *value, int deleteflag)
320 Eina_Strbuf *sharebuf = NULL;
322 sharebuf = eina_strbuf_new();
323 eina_strbuf_append(sharebuf, *srcstring);
324 _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
325 eina_stringshare_del(*srcstring);
326 *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
327 eina_strbuf_free(sharebuf);
333 _is_width_over(Evas_Object *obj, Eina_Bool multiline)
335 Evas_Coord x, y, w, h;
336 Evas_Coord vx, vy, vw, vh;
337 Widget_Data *wd = elm_widget_data_get(obj);
339 const char *ellipsis_string = "...";
340 int mincount = sizeof(ellipsis_string) - 1;
344 plaintxt = _elm_util_mkup_to_text(edje_object_part_text_get(wd->lbl, "elm.text"));
347 plainlen = strlen(plaintxt);
350 // too short to ellipsis
351 if (plainlen <= mincount) return 0;
353 edje_object_part_geometry_get(wd->lbl, "elm.text", &x, &y, &w, &h);
354 evas_object_geometry_get(obj, &vx, &vy, &vw, &vh);
357 fprintf(stderr, "## _is_width_over\n");
358 fprintf(stderr, "## x = %d, y = %d, w = %d, h = %d\n", x, y, w, h);
359 fprintf(stderr, "## vx = %d, vy = %d, vw = %d, vh = %d\n", vx, vy, vw, vh);
361 fprintf(stderr, "## wd->wrap_w = %d, wd->wrap_h = %d\n", wd->wrap_w, wd->wrap_h);
363 fprintf(stderr, "## wd->wrap_w = %d\n", wd->wrap_w);
364 fprintf(stderr, "## check str = %s\n", edje_object_part_text_get(wd->lbl, "elm.text"));
367 if (!multiline) // single line
369 // skip if too early to check widget size
370 if ((w < 0) && (h < 0)) return 0;
371 // if string fits at widget
372 if ((x >= 0) && (y >= 0))
374 if ((wd->wrap_w > 0) && (wd->wrap_w < w))
376 Evas_Coord minw, minh;
378 edje_object_size_min_calc(wd->lbl, &minw, &minh);
379 if (minw < wd->wrap_w) return 0; // min insufficient
384 if ((0 < wd->wrap_w) && (w > wd->wrap_w)) return 1;
388 if (((x >= 0) || (y >= 0)) && (h > wd->wrap_h)) return 1;
395 _ellipsis_fontsize_set(Evas_Object *obj, int fontsize)
397 Widget_Data *wd = elm_widget_data_get(obj);
400 Eina_Strbuf *fontbuf = NULL;
401 Eina_Strbuf *txtbuf = NULL;
402 txtbuf = eina_strbuf_new();
403 fontbuf = eina_strbuf_new();
404 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->lbl, "elm.text"));
405 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
406 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
407 edje_object_part_text_set(wd->lbl, "elm.text", eina_strbuf_string_get(txtbuf));
408 eina_strbuf_free(fontbuf);
409 eina_strbuf_free(txtbuf);
413 _ellipsis_cut_chars_to_widget(Evas_Object *obj)
415 Widget_Data *wd = elm_widget_data_get(obj);
416 if (!wd) return EINA_FALSE;
417 const char *ellipsis_string = "...";
418 int mincount = sizeof(ellipsis_string) - 1;
420 Evas_Textblock_Cursor *tc1, *tc2;
421 char *cutstr, *elstr;
426 edje_object_part_geometry_get(wd->lbl, "elm.text", NULL, NULL, &w, &h);
427 if (w <= 0) return EINA_FALSE;
428 tc1 = evas_object_textblock_cursor_new((Evas_Object *)edje_object_part_object_get(wd->lbl, "elm.text"));
429 tc2 = evas_object_textblock_cursor_new((Evas_Object *)edje_object_part_object_get(wd->lbl, "elm.text"));
431 if ((wd->wrap_w > 0) && (wd->wrap_w < w)) limitw = wd->wrap_w;
433 evas_textblock_cursor_pos_set(tc1, 0);
434 evas_textblock_cursor_char_coord_set(tc2, limitw, 0);
436 // if too small to cut,(is it bug? or any other reasons?)
437 // then fallback to one step mode
438 if (evas_textblock_cursor_pos_get(tc2) < mincount)
440 Evas_Coord cx, cy, cw, ch;
441 int eolpos = evas_textblock_cursor_paragraph_text_length_get(tc1);
443 for (i = eolpos; i > mincount; i--)
445 evas_textblock_cursor_pos_set(tc2, i);
446 evas_textblock_cursor_char_geometry_get(tc2, &cx, &cy, &cw, &ch);
447 if (cx <= limitw) break;
450 if (evas_textblock_cursor_pos_get(tc2) < mincount)
452 evas_textblock_cursor_free(tc1);
453 evas_textblock_cursor_free(tc2);
458 for (i = 0; i <= mincount; i++) evas_textblock_cursor_char_prev(tc2);
459 cutstr = evas_textblock_cursor_range_text_get(tc1, tc2, EVAS_TEXTBLOCK_TEXT_PLAIN);
460 if (!cutstr) return EINA_FALSE;
462 lencutstr = strlen(cutstr);
463 elstr = alloca(sizeof(char) * (lencutstr + mincount + 1));
464 strcpy(elstr, cutstr);
466 strcat(elstr, ellipsis_string);
467 edje_object_part_text_set(wd->lbl, "elm.text", elstr);
469 evas_textblock_cursor_free(tc1);
470 evas_textblock_cursor_free(tc2);
476 _ellipsis_cut_lines_to_widget(Evas_Object *obj)
478 Widget_Data *wd = elm_widget_data_get(obj);
479 if (!wd) return EINA_FALSE;
480 const char *ellipsis_string = "...";
481 int mincount = sizeof(ellipsis_string) - 1;
483 Evas_Textblock_Cursor *tc1, *tc2;
484 int linenum = 0, cutline = 0;
485 double lineheight = 0.0;
486 char *cutstr, *elstr;
491 edje_object_part_geometry_get(wd->lbl, "elm.text", NULL, NULL, &w, &h);
493 tc1 = evas_object_textblock_cursor_new((Evas_Object *)edje_object_part_object_get(wd->lbl, "elm.text"));
494 tc2 = evas_object_textblock_cursor_new((Evas_Object *)edje_object_part_object_get(wd->lbl, "elm.text"));
495 // goto last paragraph
496 while (evas_textblock_cursor_paragraph_next(tc2) == EINA_TRUE);
498 evas_textblock_cursor_paragraph_last(tc2);
499 // get total linenumber
500 linenum = evas_textblock_cursor_line_geometry_get(tc2, NULL, NULL, NULL, NULL);
501 lineheight = (double)h / (double)linenum;
502 if ((wd->wrap_h > 0) && (wd->wrap_h < h)) limith = wd->wrap_h;
504 cutline = limith / lineheight;
505 if (cutline < 1) cutline = 1;
507 evas_textblock_cursor_pos_set(tc1, 0);
508 evas_textblock_cursor_line_set(tc2, cutline - 1);
509 evas_textblock_cursor_line_char_last(tc2);
510 for (i = 0; i <= mincount; i++) evas_textblock_cursor_char_prev(tc2);
511 cutstr = evas_textblock_cursor_range_text_get(tc1, tc2, EVAS_TEXTBLOCK_TEXT_PLAIN);
512 if (!cutstr) return EINA_FALSE;
514 lencutstr = strlen(cutstr);
515 elstr = alloca(sizeof(char) * (lencutstr + mincount + 1));
516 strcpy(elstr, cutstr);
518 strcat(elstr, ellipsis_string);
519 edje_object_part_text_set(wd->lbl, "elm.text", elstr);
521 evas_textblock_cursor_free(tc1);
522 evas_textblock_cursor_free(tc2);
528 _ellipsis_label_to_width(Evas_Object *obj, Eina_Bool multiline)
530 Widget_Data *wd = elm_widget_data_get(obj);
532 int cur_fontsize = 0;
534 const char *minfont, *deffont, *maxfont;
535 int minfontsize, maxfontsize;
537 minfont = edje_object_data_get(wd->lbl, "min_font_size");
538 if (minfont) minfontsize = atoi(minfont);
539 else minfontsize = 1;
540 maxfont = edje_object_data_get(wd->lbl, "max_font_size");
541 if (maxfont) maxfontsize = atoi(maxfont);
542 else maxfontsize = 1;
543 deffont = edje_object_data_get(wd->lbl, "default_font_size");
544 if (deffont) cur_fontsize = atoi(deffont);
545 else cur_fontsize = 1;
546 if (minfontsize > maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
547 if (eina_stringshare_strlen(wd->label) <= 0) return;
549 if (_get_value_in_key_string(wd->label, "font_size", &kvalue) == 0)
551 if (kvalue != NULL) cur_fontsize = atoi(kvalue);
554 while (_is_width_over(obj, multiline))
556 if (cur_fontsize > minfontsize)
559 if (cur_fontsize < minfontsize) cur_fontsize = minfontsize;
560 _ellipsis_fontsize_set(obj, cur_fontsize);
564 if (!multiline) // single line
566 _ellipsis_cut_chars_to_widget(obj);
571 _ellipsis_cut_lines_to_widget(obj);
579 * setting internal state of mulitline label.
580 * singleline doesn't need it
584 _label_state_change(Evas_Object *obj)
586 Widget_Data *wd = elm_widget_data_get(obj);
592 edje_object_signal_emit(wd->lbl, "elm,state,wordwrap", "elm");
594 edje_object_signal_emit(wd->lbl, "elm,state,default", "elm");
599 _label_sliding_change(Evas_Object *obj)
601 Widget_Data *wd = elm_widget_data_get(obj);
606 // dosen't support multiline sliding effect
609 wd->slidingmode = EINA_FALSE;
613 plaintxt = _elm_util_mkup_to_text(edje_object_part_text_get(wd->lbl, "elm.text"));
614 if (plaintxt != NULL)
616 plainlen = strlen(plaintxt);
619 // too short to slide label
622 wd->slidingmode = EINA_TRUE;
628 Edje_Message_Float_Set *msg = alloca(sizeof(Edje_Message_Float_Set) + (sizeof(double)));
632 wd->slidingellipsis = EINA_TRUE;
633 elm_label_ellipsis_set(obj, EINA_FALSE);
637 msg->val[0] = wd->slide_duration;
639 edje_object_message_send(wd->lbl, EDJE_MESSAGE_FLOAT_SET, 0, msg);
640 edje_object_signal_emit(wd->lbl, "elm,state,slide,start", "elm");
644 edje_object_signal_emit(wd->lbl, "elm,state,slide,stop", "elm");
645 if (wd->slidingellipsis)
647 wd->slidingellipsis = EINA_FALSE;
648 elm_label_ellipsis_set(obj, EINA_TRUE);
654 * Add a new label to the parent
656 * @param parent The parent object
657 * @return The new object or NULL if it cannot be created
662 elm_label_add(Evas_Object *parent)
668 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
670 wd = ELM_NEW(Widget_Data);
671 e = evas_object_evas_get(parent);
673 wd->bgcolor = EINA_FALSE;
674 wd->bg = evas_object_rectangle_add(e);
675 evas_object_color_set(wd->bg, 0, 0, 0, 0);
676 obj = elm_widget_add(e);
677 ELM_SET_WIDTYPE(widtype, "label");
678 elm_widget_type_set(obj, "label");
679 elm_widget_sub_object_add(parent, obj);
680 elm_widget_data_set(obj, wd);
681 elm_widget_del_hook_set(obj, _del_hook);
682 elm_widget_theme_hook_set(obj, _theme_hook);
683 elm_widget_can_focus_set(obj, EINA_FALSE);
685 wd->linewrap = EINA_FALSE;
686 wd->ellipsis = EINA_FALSE;
687 wd->wrapmode = EINA_FALSE;
688 wd->slidingmode = EINA_FALSE;
689 wd->slidingellipsis = EINA_FALSE;
692 wd->slide_duration = 10;
694 wd->lbl = edje_object_add(e);
695 _elm_theme_object_set(obj, wd->lbl, "label", "base", "default");
696 wd->label = eina_stringshare_add("<br>");
697 edje_object_part_text_set(wd->lbl, "elm.text", "<br>");
698 elm_widget_resize_object_set(obj, wd->lbl);
700 evas_object_event_callback_add(wd->lbl, EVAS_CALLBACK_RESIZE, _resize, obj);
708 * Set the label on the label object
710 * @param obj The label object
711 * @param label The label will be used on the label object
716 elm_label_label_set(Evas_Object *obj, const char *label)
718 ELM_CHECK_WIDTYPE(obj, widtype);
719 Widget_Data *wd = elm_widget_data_get(obj);
721 if (!label) label = "";
722 eina_stringshare_replace(&wd->label, label);
723 edje_object_part_text_set(wd->lbl, "elm.text", label);
729 * Get the label used on the label object
731 * @param obj The label object
732 * @return The string inside the label
736 elm_label_label_get(const Evas_Object *obj)
738 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
739 Widget_Data *wd = elm_widget_data_get(obj);
740 if (!wd) return NULL;
745 * Set the wrapping behavior of the label
747 * @param obj The label object
748 * @param wrap To wrap text or not
752 elm_label_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
754 ELM_CHECK_WIDTYPE(obj, widtype);
755 Widget_Data *wd = elm_widget_data_get(obj);
758 if (wd->linewrap == wrap) return;
760 t = eina_stringshare_add(elm_label_label_get(obj));
762 elm_label_label_set(obj, t);
763 eina_stringshare_del(t);
769 * Get the wrapping behavior of the label
771 * @param obj The label object
772 * @return To wrap text or not
776 elm_label_line_wrap_get(const Evas_Object *obj)
778 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
779 Widget_Data *wd = elm_widget_data_get(obj);
780 if (!wd) return EINA_FALSE;
785 * Set wrap width of the label
787 * @param obj The label object
788 * @param w The wrap width in pixels at a minimum where words need to wrap
792 elm_label_wrap_width_set(Evas_Object *obj, Evas_Coord w)
794 ELM_CHECK_WIDTYPE(obj, widtype);
795 Widget_Data *wd = elm_widget_data_get(obj);
798 if (wd->wrap_w == w) return;
799 if (wd->ellipsis) edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
805 * get wrap width of the label
807 * @param obj The label object
808 * @return The wrap width in pixels at a minimum where words need to wrap
812 elm_label_wrap_width_get(const Evas_Object *obj)
814 ELM_CHECK_WIDTYPE(obj, widtype) 0;
815 Widget_Data *wd = elm_widget_data_get(obj);
821 * Set wrap height of the label
823 * @param obj The label object
824 * @param w The wrap width in pixels at a minimum where words need to wrap
828 elm_label_wrap_height_set(Evas_Object *obj,
831 ELM_CHECK_WIDTYPE(obj, widtype);
832 Widget_Data *wd = elm_widget_data_get(obj);
835 if (wd->wrap_h == h) return;
836 if (wd->ellipsis) edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
842 * get wrap width of the label
844 * @param obj The label object
845 * @return The wrap height in pixels at a minimum where words need to wrap
849 elm_label_wrap_height_get(const Evas_Object *obj)
851 ELM_CHECK_WIDTYPE(obj, widtype) 0;
852 Widget_Data *wd = elm_widget_data_get(obj);
858 * Set the font size on the label object.
860 * NEVER use this. It is for hyper-special cases only. use styles instead. e.g.
861 * "big", "medium", "small" - or better name them by use:
862 * "title", "footnote", "quote" etc.
864 * @param obj The label object
865 * @param size font size
870 elm_label_fontsize_set(Evas_Object *obj, int fontsize)
872 ELM_CHECK_WIDTYPE(obj, widtype);
873 Widget_Data *wd = elm_widget_data_get(obj);
874 Eina_Strbuf *fontbuf = NULL;
875 int len, removeflag = 0;
878 _elm_dangerous_call_check(__FUNCTION__);
879 len = strlen(wd->label);
880 if (len <= 0) return;
881 fontbuf = eina_strbuf_new();
882 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
884 if (fontsize == 0) removeflag = 1; // remove fontsize tag
886 if (_stringshare_key_value_replace(&wd->label, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
888 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
892 eina_strbuf_free(fontbuf);
896 * Set the text align on the label object
898 * NEVER use this. It is for hyper-special cases only. use styles instead. e.g.
899 * "big", "medium", "small" - or better name them by use:
900 * "title", "footnote", "quote" etc.
902 * @param obj The label object
903 * @param align align mode ("left", "center", "right")
908 elm_label_text_align_set(Evas_Object *obj, const char *alignmode)
910 ELM_CHECK_WIDTYPE(obj, widtype);
911 Widget_Data *wd = elm_widget_data_get(obj);
915 _elm_dangerous_call_check(__FUNCTION__);
916 len = strlen(wd->label);
917 if (len <= 0) return;
919 if (_stringshare_key_value_replace(&wd->label, "align", alignmode, 0) == 0)
920 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
927 * Set the text color on the label object
929 * @param obj The label object
930 * @param r Red property background color of The label object
931 * @param g Green property background color of The label object
932 * @param b Blue property background color of The label object
933 * @param a Alpha property background color of The label object
938 elm_label_text_color_set(Evas_Object *obj,
944 ELM_CHECK_WIDTYPE(obj, widtype);
945 Widget_Data *wd = elm_widget_data_get(obj);
946 Eina_Strbuf *colorbuf = NULL;
950 _elm_dangerous_call_check(__FUNCTION__);
951 len = strlen(wd->label);
952 if (len <= 0) return;
953 colorbuf = eina_strbuf_new();
954 eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
956 if (_stringshare_key_value_replace(&wd->label, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
958 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
962 eina_strbuf_free(colorbuf);
966 * Set background color of the label
968 * NEVER use this. It is for hyper-special cases only. use styles instead. e.g.
969 * "big", "medium", "small" - or better name them by use:
970 * "title", "footnote", "quote" etc.
972 * @param obj The label object
973 * @param r Red property background color of The label object
974 * @param g Green property background color of The label object
975 * @param b Blue property background color of The label object
976 * @param a Alpha property background alpha of The label object
981 elm_label_background_color_set(Evas_Object *obj,
987 ELM_CHECK_WIDTYPE(obj, widtype);
988 Widget_Data *wd = elm_widget_data_get(obj);
990 evas_object_color_set(wd->bg, r, g, b, a);
993 _elm_dangerous_call_check(__FUNCTION__);
994 if (wd->bgcolor == EINA_FALSE)
997 edje_object_part_swallow(wd->lbl, "label.swallow.background", wd->bg);
1002 * Set the ellipsis behavior of the label
1004 * @param obj The label object
1005 * @param ellipsis To ellipsis text or not
1009 elm_label_ellipsis_set(Evas_Object *obj, Eina_Bool ellipsis)
1011 ELM_CHECK_WIDTYPE(obj, widtype);
1012 Widget_Data *wd = elm_widget_data_get(obj);
1014 if (wd->ellipsis == ellipsis) return;
1015 wd->ellipsis = ellipsis;
1016 if (wd->linewrap) _theme_change(obj);
1017 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
1023 * Set the wrapmode of the label
1025 * @param obj The label object
1026 * @param wrapmode 0 is charwrap, 1 is wordwrap
1030 elm_label_wrap_mode_set(Evas_Object *obj,
1033 ELM_CHECK_WIDTYPE(obj, widtype);
1034 Widget_Data *wd = elm_widget_data_get(obj);
1036 if (wd->wrapmode == wrapmode) return;
1037 wd->wrapmode = wrapmode;
1038 _label_state_change(obj);
1044 * Set the text slide of the label
1046 * @param obj The label object
1047 * @param slide To start slide or stop
1051 elm_label_slide_set(Evas_Object *obj,
1054 ELM_CHECK_WIDTYPE(obj, widtype);
1055 Widget_Data *wd = elm_widget_data_get(obj);
1058 if (wd->slidingmode == slide) return;
1059 wd->slidingmode = slide;
1060 _label_sliding_change(obj);
1066 * get the text slide mode of the label
1068 * @param obj The label object
1069 * @return slide slide mode value
1073 elm_label_slide_get(Evas_Object *obj)
1075 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1076 Widget_Data *wd = elm_widget_data_get(obj);
1077 if (!wd) return EINA_FALSE;
1078 return wd->slidingmode;
1082 * set the slide duration(speed) of the label
1084 * @param obj The label object
1085 * @return The duration time in moving text from slide begin position to slide end position
1089 elm_label_slide_duration_set(Evas_Object *obj, double duration)
1091 ELM_CHECK_WIDTYPE(obj, widtype);
1092 Widget_Data *wd = elm_widget_data_get(obj);
1093 Edje_Message_Float_Set *msg = alloca(sizeof(Edje_Message_Float_Set) + (sizeof(double)));
1096 wd->slide_duration = duration;
1098 msg->val[0] = wd->slide_duration;
1099 edje_object_message_send(wd->lbl, EDJE_MESSAGE_FLOAT_SET, 0, msg);
1103 * get the slide duration(speed) of the label
1105 * @param obj The label object
1106 * @return The duration time in moving text from slide begin position to slide end position
1110 elm_label_slide_duration_get(Evas_Object *obj)
1112 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
1113 Widget_Data *wd = elm_widget_data_get(obj);
1115 return wd->slide_duration;