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;
20 Ecore_Job *deferred_recalc_job;
23 Eina_Bool linewrap : 1;
24 Eina_Bool wrapmode : 1;
25 Eina_Bool slidingmode : 1;
26 Eina_Bool slidingellipsis : 1;
27 Eina_Bool changed : 1;
28 Eina_Bool bgcolor : 1;
29 Eina_Bool ellipsis : 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, char *key, char **value);
38 static int _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag);
39 static int _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag);
40 static int _is_width_over(Evas_Object *obj, int linemode);
41 static void _ellipsis_label_to_width(Evas_Object *obj, int linemode);
44 _elm_win_recalc_job(void *data)
46 Widget_Data *wd = elm_widget_data_get(data);
47 Evas_Coord minw = -1, minh = -1, maxh = -1;
48 Evas_Coord resw, resh, minminw, minminh;
50 wd->deferred_recalc_job = NULL;
51 evas_object_geometry_get(wd->lbl, NULL, NULL, &resw, &resh);
54 edje_object_size_min_restricted_calc(wd->lbl, &minw, &minh, 0, 0);
57 if (wd->wrap_w >= resw)
60 edje_object_size_min_restricted_calc(wd->lbl, &minw, &minh, resw, 0);
61 evas_object_size_hint_min_set(data, minw, minh);
65 if (wd->wrap_w > minminw) minminw = wd->wrap_w;
66 edje_object_size_min_restricted_calc(wd->lbl, &minw, &minh, resw, 0);
67 evas_object_size_hint_min_set(data, minminw, minh);
70 if (wd->ellipsis && wd->linewrap && wd->wrap_h > 0 && _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", elm_widget_style_get(obj));
99 _elm_theme_object_set(obj, wd->lbl, "label", "base_wrap", elm_widget_style_get(obj));
102 _elm_theme_object_set(obj, wd->lbl, "label", "base", elm_widget_style_get(obj));
107 _theme_hook(Evas_Object *obj)
109 Widget_Data *wd = elm_widget_data_get(obj);
112 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
113 edje_object_scale_set(wd->lbl, elm_widget_scale_get(obj) *
119 _sizing_eval(Evas_Object *obj)
121 Widget_Data *wd = elm_widget_data_get(obj);
122 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
123 Evas_Coord resw, resh;
127 evas_object_geometry_get(wd->lbl, NULL, NULL, &resw, &resh);
128 if ((resw == wd->lastw) && (!wd->changed)) return;
129 wd->changed = EINA_FALSE;
131 _elm_win_recalc_job(obj);
132 // FIXME: works ok. but NOT for genlist. what should genlist do?
133 // if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
134 // wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
138 evas_object_geometry_get(wd->lbl, NULL, NULL, &resw, &resh);
139 edje_object_size_min_calc(wd->lbl, &minw, &minh);
140 if (wd->wrap_w > 0 && minw > wd->wrap_w)
142 evas_object_size_hint_min_set(obj, minw, minh);
144 evas_object_size_hint_max_set(obj, maxw, maxh);
146 if (wd->ellipsis && _is_width_over(obj, 0) == 1)
147 _ellipsis_label_to_width(obj, 0);
152 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
154 Widget_Data *wd = elm_widget_data_get(data);
156 if (wd->linewrap) _sizing_eval(data);
160 _get_value_in_key_string(const char *oldstring, char *key, char **value)
162 char *curlocater, *starttag, *endtag;
163 int firstindex = 0, foundflag = -1;
165 curlocater = strstr(oldstring, key);
168 starttag = curlocater;
169 endtag = curlocater + strlen(key);
170 if (endtag == NULL || *endtag != '=')
176 firstindex = abs(oldstring - curlocater);
177 firstindex += strlen(key)+1; // strlen("key") + strlen("=")
178 *value = (char*)oldstring + firstindex;
180 while (oldstring != starttag)
182 if (*starttag == '>')
187 if (*starttag == '<')
191 if (starttag == NULL) break;
194 while (NULL != endtag)
205 if (endtag == NULL) break;
208 if (foundflag != 0 && *starttag == '<' && *endtag == '>')
218 if (foundflag == 1) return 0;
224 _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag)
226 const char *srcstring = NULL;
227 Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
228 char *curlocater, *replocater;
229 char *starttag, *endtag;
230 int tagtxtlen = 0, insertflag = 0;
232 srcstring = eina_strbuf_string_get(srcbuf);
233 curlocater = strstr(srcstring, key);
235 if (curlocater == NULL)
243 starttag = strchr(srcstring, '<');
244 endtag = strchr(srcstring, '>');
245 tagtxtlen = endtag - starttag;
246 if (tagtxtlen <= 0) tagtxtlen = 0;
247 if (starttag < curlocater && curlocater < endtag) break;
248 if (endtag != NULL && endtag+1 != NULL)
249 srcstring = endtag+1;
252 } while (strlen(srcstring) > 1);
254 if (starttag && endtag && tagtxtlen > strlen(key))
256 repbuf = eina_strbuf_new();
257 diffbuf = eina_strbuf_new();
258 eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
259 srcstring = eina_strbuf_string_get(repbuf);
260 curlocater = strstr(srcstring, key);
262 if (curlocater != NULL)
264 replocater = curlocater + strlen(key) + 1;
266 while (*replocater == ' ' || *replocater == '=')
271 while (*replocater != NULL && *replocater != ' ' && *replocater != '>')
274 if (replocater-curlocater > strlen(key)+1)
277 eina_strbuf_append_n(diffbuf, curlocater, replocater-curlocater+1);
286 eina_strbuf_reset(repbuf);
294 if (repbuf == NULL) repbuf = eina_strbuf_new();
295 if (diffbuf == NULL) diffbuf = eina_strbuf_new();
299 eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
300 eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
306 eina_strbuf_prepend(diffbuf, "<");
307 eina_strbuf_append(diffbuf, ">");
308 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
312 eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
313 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
317 if (repbuf) eina_strbuf_free(repbuf);
318 if (diffbuf) eina_strbuf_free(diffbuf);
324 _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag)
326 Eina_Strbuf *sharebuf = NULL;
328 sharebuf = eina_strbuf_new();
329 eina_strbuf_append(sharebuf, *srcstring);
330 _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
331 eina_stringshare_del(*srcstring);
332 *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
333 eina_strbuf_free(sharebuf);
339 _is_width_over(Evas_Object *obj, int linemode)
341 Evas_Coord x, y, w, h;
342 Evas_Coord vx, vy, vw, vh;
343 Widget_Data *wd = elm_widget_data_get(obj);
344 const char *ellipsis_string = "...";
345 size_t ellen = strlen(ellipsis_string)+1;
349 // too short to ellipsis
350 if (strlen(edje_object_part_text_get(wd->lbl, "elm.text")) <= ellen)
353 edje_object_part_geometry_get(wd->lbl,"elm.text",&x,&y,&w,&h);
355 evas_object_geometry_get (obj, &vx,&vy,&vw,&vh);
358 fprintf(stderr, "## _is_width_over\n");
359 fprintf(stderr, "## x = %d, y = %d, w = %d, h = %d\n", x, y, w, h);
360 fprintf(stderr, "## vx = %d, vy = %d, vw = %d, vh = %d\n", vx, vy, vw, vh);
362 fprintf(stderr, "## wd->wrap_w = %d, wd->wrap_h = %d\n", wd->wrap_w, wd->wrap_h);
364 fprintf(stderr, "## wd->wrap_w = %d\n", wd->wrap_w);
367 if (linemode == 0) // single line
369 // skip if too early to check widget size
372 // if string fits at widget
373 if ((x >= 0) && (y >= 0))
375 if ((wd->wrap_w > 0) && (wd->wrap_w < w))
377 Evas_Coord minw, minh;
378 edje_object_size_min_calc(wd->lbl, &minw, &minh);
380 if (minw < wd->wrap_w)
381 { // min insufficient
391 if (ellen < wd->wrap_w && w > wd->wrap_w) return 1;
395 // if (vy > h && h > wd->wrap_h) return 1;
396 if ((x >= 0 || y >= 0) && h > wd->wrap_h) return 1;
403 _ellipsis_fontsize_set(Evas_Object *obj, int fontsize, Eina_Strbuf *txtbuf)
405 Widget_Data *wd = elm_widget_data_get(obj);
408 Eina_Strbuf *fontbuf = NULL;
409 fontbuf = eina_strbuf_new();
410 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
411 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
412 edje_object_part_text_set(wd->lbl, "elm.text", eina_strbuf_string_get(txtbuf));
413 eina_strbuf_free(fontbuf);
417 _ellipsis_cut_chars_to_widget(Evas_Object *obj, int fontsize, int linemode)
419 Widget_Data *wd = elm_widget_data_get(obj);
420 if (!wd) return EINA_FALSE;
422 const char *ellipsis_string = "...";
423 int minshowcount = strlen(ellipsis_string);
425 Evas_Textblock_Cursor *tc1, *tc2;
426 char *cutstr, *elstr;
431 edje_object_part_geometry_get(wd->lbl,"elm.text",NULL,NULL,&w,&h);
434 tc1 = evas_object_textblock_cursor_new(edje_object_part_object_get(wd->lbl, "elm.text"));
435 tc2 = evas_object_textblock_cursor_new(edje_object_part_object_get(wd->lbl, "elm.text"));
437 if (wd->wrap_w > 0 && wd->wrap_w < w)
441 evas_textblock_cursor_pos_set(tc1, 0);
442 evas_textblock_cursor_char_coord_set(tc2, limitw, 0);
443 for (i = 0; i <= minshowcount; i++)
444 evas_textblock_cursor_char_prev(tc2);
445 cutstr = evas_textblock_cursor_range_text_get(tc1, tc2, EVAS_TEXTBLOCK_TEXT_PLAIN);
447 // FIXME: consider other unicode encoding, currently only care about utf-8
448 lencutstr = strlen(cutstr);
449 elstr = malloc(sizeof(char)*(lencutstr+minshowcount+1));
450 strcpy(elstr, cutstr);
451 strcat(elstr, ellipsis_string);
453 edje_object_part_text_set(wd->lbl, "elm.text", elstr);
456 evas_textblock_cursor_free(tc1);
457 evas_textblock_cursor_free(tc2);
463 _ellipsis_cut_lines_to_widget(Evas_Object *obj, int fontsize, int linemode)
465 Widget_Data *wd = elm_widget_data_get(obj);
466 if (!wd) return EINA_FALSE;
468 const char *ellipsis_string = "...";
469 int minshowcount = strlen(ellipsis_string);
471 Evas_Textblock_Cursor *tc1, *tc2;
472 int linenum = 0, cutline = 0;
473 double lineheight = 0.0;
474 char *cutstr, *elstr;
479 edje_object_part_geometry_get(wd->lbl,"elm.text", NULL, NULL, &w, &h);
481 tc1 = evas_object_textblock_cursor_new(edje_object_part_object_get(wd->lbl, "elm.text"));
482 tc2 = evas_object_textblock_cursor_new(edje_object_part_object_get(wd->lbl, "elm.text"));
483 // goto last paragraph
484 while (evas_textblock_cursor_paragraph_next(tc2) == EINA_TRUE)
486 evas_textblock_cursor_paragraph_last(tc2);
487 // get total linenumber
488 linenum = evas_textblock_cursor_line_geometry_get(tc2, NULL, NULL, NULL, NULL);
489 lineheight = h/linenum * 1.0;
490 if (wd->wrap_h > 0 && wd->wrap_h < h)
494 cutline = limith / lineheight;
498 evas_textblock_cursor_pos_set(tc1, 0);
499 evas_textblock_cursor_line_set(tc2, cutline-1);
500 evas_textblock_cursor_line_char_last(tc2);
501 for (i = 0; i <= minshowcount; i++)
502 evas_textblock_cursor_char_prev(tc2);
503 cutstr = evas_textblock_cursor_range_text_get(tc1, tc2, EVAS_TEXTBLOCK_TEXT_PLAIN);
505 // FIXME: consider other unicode encoding, currently only care about utf-8
506 lencutstr = strlen(cutstr);
507 elstr = malloc(sizeof(char)*(lencutstr+minshowcount+1));
508 strcpy(elstr, cutstr);
509 strcat(elstr, ellipsis_string);
511 edje_object_part_text_set(wd->lbl, "elm.text", elstr);
514 evas_textblock_cursor_free(tc1);
515 evas_textblock_cursor_free(tc2);
521 _ellipsis_label_to_width(Evas_Object *obj, int linemode)
523 Widget_Data *wd = elm_widget_data_get(obj);
526 int cur_fontsize = 0;
527 Eina_Strbuf *txtbuf = NULL;
528 char **kvalue = NULL;
529 const char *minfont, *deffont, *maxfont;
530 int minfontsize, maxfontsize;
532 minfont = edje_object_data_get(wd->lbl, "min_font_size");
533 if (minfont) minfontsize = atoi(minfont);
534 else minfontsize = 1;
535 maxfont = edje_object_data_get(wd->lbl, "max_font_size");
536 if (maxfont) maxfontsize = atoi(maxfont);
537 else maxfontsize = 1;
538 deffont = edje_object_data_get(wd->lbl, "default_font_size");
539 if (deffont) cur_fontsize = atoi(deffont);
540 else cur_fontsize = 1;
541 if (minfontsize > maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
542 if (eina_stringshare_strlen(wd->label) <= 0) return;
544 if (_get_value_in_key_string(wd->label, "font_size", &kvalue) == 0)
546 if (*kvalue != NULL) cur_fontsize = atoi((char*)kvalue);
549 txtbuf = eina_strbuf_new();
550 eina_strbuf_append(txtbuf, wd->label);
552 while (_is_width_over(obj, linemode))
554 if (cur_fontsize > minfontsize)
557 if (cur_fontsize < minfontsize)
558 cur_fontsize = minfontsize;
559 _ellipsis_fontsize_set(obj, cur_fontsize, txtbuf);
563 if (linemode == 0) // single line
565 _ellipsis_cut_chars_to_widget(obj, cur_fontsize, linemode);
570 _ellipsis_cut_lines_to_widget(obj, cur_fontsize, linemode);
576 if (txtbuf) eina_strbuf_free(txtbuf);
582 * setting internal state of mulitline entry
583 * singleline doesn't need it
586 void _label_state_change(Evas_Object *obj)
588 Widget_Data *wd = elm_widget_data_get(obj);
594 edje_object_signal_emit(wd->lbl, "elm,state,wordwrap", "elm");
596 edje_object_signal_emit(wd->lbl, "elm,state,default", "elm");
600 void _label_sliding_change(Evas_Object *obj)
602 Widget_Data *wd = elm_widget_data_get(obj);
607 wd->slidingmode = EINA_FALSE;
608 fprintf(stderr, "ERR: elm_label dosen't support multiline sliding effect!!!\n");
609 fprintf(stderr, "ERR: elm_label dosen't support multiline sliding effect!!!\n");
610 fprintf(stderr, "ERR: elm_label dosen't support multiline sliding effect!!!\n");
617 wd->slidingellipsis = EINA_TRUE;
618 elm_label_ellipsis_set(obj, EINA_FALSE);
620 Edje_Message_Int_Set *msg = alloca(sizeof(Edje_Message_Int_Set) + (sizeof(int)));
623 msg->val[0] = (int)wd->slide_duration;
625 edje_object_message_send(wd->lbl, EDJE_MESSAGE_INT_SET, 0, msg);
626 edje_object_signal_emit(wd->lbl, "elm,state,slide,start", "elm");
630 edje_object_signal_emit(wd->lbl, "elm,state,slide,stop", "elm");
631 if (wd->slidingellipsis)
633 wd->slidingellipsis = EINA_FALSE;
634 elm_label_ellipsis_set(obj, EINA_TRUE);
640 * Add a new label to the parent
642 * @param parent The parent object
643 * @return The new object or NULL if it cannot be created
648 elm_label_add(Evas_Object *parent)
654 wd = ELM_NEW(Widget_Data);
655 e = evas_object_evas_get(parent);
656 wd->bg = evas_object_rectangle_add(e);
657 evas_object_color_set(wd->bg, 0, 0, 0, 0);
658 obj = elm_widget_add(e);
659 ELM_SET_WIDTYPE(widtype, "label");
660 elm_widget_type_set(obj, "label");
661 elm_widget_sub_object_add(parent, obj);
662 elm_widget_data_set(obj, wd);
663 elm_widget_del_hook_set(obj, _del_hook);
664 elm_widget_theme_hook_set(obj, _theme_hook);
665 elm_widget_can_focus_set(obj, 0);
667 wd->linewrap = EINA_FALSE;
668 wd->bgcolor = EINA_FALSE;
669 wd->ellipsis = EINA_FALSE;
670 wd->wrapmode = EINA_FALSE;
671 wd->slidingmode = EINA_FALSE;
672 wd->slidingellipsis = EINA_FALSE;
675 wd->slide_duration = 10;
677 wd->lbl = edje_object_add(e);
678 _elm_theme_object_set(obj, wd->lbl, "label", "base", "default");
679 wd->label = eina_stringshare_add("<br>");
680 edje_object_part_text_set(wd->lbl, "elm.text", "<br>");
681 elm_widget_resize_object_set(obj, wd->lbl);
683 evas_object_event_callback_add(wd->lbl, EVAS_CALLBACK_RESIZE, _resize, obj);
691 * Set the label on the label object
693 * @param obj The label object
694 * @param label The label will be used on the label object
699 elm_label_label_set(Evas_Object *obj, const char *label)
701 ELM_CHECK_WIDTYPE(obj, widtype);
702 Widget_Data *wd = elm_widget_data_get(obj);
704 if (!label) label = "";
705 eina_stringshare_replace(&wd->label, label);
706 edje_object_part_text_set(wd->lbl, "elm.text", label);
712 * Get the label used on the label object
714 * @param obj The label object
715 * @return The string inside the label
719 elm_label_label_get(const Evas_Object *obj)
721 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
722 Widget_Data *wd = elm_widget_data_get(obj);
723 if (!wd) return NULL;
728 * Set the wrapping behavior of the label
730 * @param obj The label object
731 * @param wrap To wrap text or not
735 elm_label_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
737 ELM_CHECK_WIDTYPE(obj, widtype);
738 Widget_Data *wd = elm_widget_data_get(obj);
741 if (wd->linewrap == wrap) return;
743 t = eina_stringshare_add(elm_label_label_get(obj));
745 elm_label_label_set(obj, t);
746 eina_stringshare_del(t);
752 * Get the wrapping behavior of the label
754 * @param obj The label object
755 * @return To wrap text or not
759 elm_label_line_wrap_get(const Evas_Object *obj)
761 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
762 Widget_Data *wd = elm_widget_data_get(obj);
763 if (!wd) return EINA_FALSE;
768 * Set wrap width of the label
770 * @param obj The label object
771 * @param w The wrap width in pixels at a minimum where words need to wrap
775 elm_label_wrap_width_set(Evas_Object *obj, Evas_Coord w)
777 ELM_CHECK_WIDTYPE(obj, widtype);
778 Widget_Data *wd = elm_widget_data_get(obj);
781 if (wd->wrap_w == w) return;
782 if (wd->ellipsis) edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
788 * get wrap width of the label
790 * @param obj The label object
791 * @return The wrap width in pixels at a minimum where words need to wrap
795 elm_label_wrap_width_get(const Evas_Object *obj)
797 ELM_CHECK_WIDTYPE(obj, widtype) 0;
798 Widget_Data *wd = elm_widget_data_get(obj);
804 * Set wrap height of the label
806 * @param obj The label object
807 * @param w The wrap width in pixels at a minimum where words need to wrap
811 elm_label_wrap_height_set(Evas_Object *obj, Evas_Coord h)
813 ELM_CHECK_WIDTYPE(obj, widtype);
814 Widget_Data *wd = elm_widget_data_get(obj);
817 if (wd->wrap_h == h) return;
818 if (wd->ellipsis) edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
824 * get wrap width of the label
826 * @param obj The label object
827 * @return The wrap height in pixels at a minimum where words need to wrap
831 elm_label_wrap_height_get(const Evas_Object *obj)
833 ELM_CHECK_WIDTYPE(obj, widtype) 0;
834 Widget_Data *wd = elm_widget_data_get(obj);
840 * Set the font size on the label object
842 * @param obj The label object
843 * @param size font size
848 elm_label_fontsize_set(Evas_Object *obj, int fontsize)
850 ELM_CHECK_WIDTYPE(obj, widtype);
851 Widget_Data *wd = elm_widget_data_get(obj);
852 Eina_Strbuf *fontbuf = NULL;
853 int len, removeflag = 0;
856 len = strlen(wd->label);
857 if (len <= 0) return;
858 fontbuf = eina_strbuf_new();
859 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
861 if (fontsize == 0) removeflag = 1; // remove fontsize tag
863 if (_stringshare_key_value_replace(&wd->label, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
865 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
869 eina_strbuf_free(fontbuf);
873 * Set the text align on the label object
875 * @param obj The label object
876 * @param align align mode ("left", "center", "right")
881 elm_label_text_align_set(Evas_Object *obj, const char *alignmode)
883 ELM_CHECK_WIDTYPE(obj, widtype);
884 Widget_Data *wd = elm_widget_data_get(obj);
888 len = strlen(wd->label);
889 if (len <= 0) return;
891 if (_stringshare_key_value_replace(&wd->label, "align", alignmode, 0) == 0)
892 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
899 * Set the text color on the label object
901 * @param obj The label object
902 * @param r Red property background color of The label object
903 * @param g Green property background color of The label object
904 * @param b Blue property background color of The label object
905 * @param a Alpha property background alpha of The label object
910 elm_label_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
912 ELM_CHECK_WIDTYPE(obj, widtype);
913 Widget_Data *wd = elm_widget_data_get(obj);
914 Eina_Strbuf *colorbuf = NULL;
918 len = strlen(wd->label);
919 if (len <= 0) return;
920 colorbuf = eina_strbuf_new();
921 eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
923 if (_stringshare_key_value_replace(&wd->label, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
925 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
929 eina_strbuf_free(colorbuf);
934 * Set background color of the label
936 * @param obj The label object
937 * @param r Red property background color of The label object
938 * @param g Green property background color of The label object
939 * @param b Blue property background color of The label object
940 * @param a Alpha property background alpha of The label object
944 elm_label_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
946 ELM_CHECK_WIDTYPE(obj, widtype);
947 Widget_Data *wd = elm_widget_data_get(obj);
949 evas_object_color_set(wd->bg, r, g, b, a);
951 if (wd->bgcolor == EINA_FALSE)
954 edje_object_part_swallow(wd->lbl, "label.swallow.background", wd->bg);
959 * Set the ellipsis behavior of the label
961 * @param obj The label object
962 * @param ellipsis To ellipsis text or not
966 elm_label_ellipsis_set(Evas_Object *obj, Eina_Bool ellipsis)
968 ELM_CHECK_WIDTYPE(obj, widtype);
969 Widget_Data *wd = elm_widget_data_get(obj);
971 if (wd->ellipsis == ellipsis) return;
972 wd->ellipsis = ellipsis;
973 if (wd->linewrap) _theme_change(obj);
974 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
980 * Set the wrapmode of the label
982 * @param obj The label object
983 * @param wrapmode 0 is charwrap, 1 is wordwrap
987 elm_label_wrap_mode_set(Evas_Object *obj, Eina_Bool wrapmode)
989 ELM_CHECK_WIDTYPE(obj, widtype);
990 Widget_Data *wd = elm_widget_data_get(obj);
992 if (wd->wrapmode == wrapmode) return;
993 wd->wrapmode = wrapmode;
994 _label_state_change(obj);
1000 * Set the text slide of the label
1002 * @param obj The label object
1003 * @param slide To start slide or stop
1007 elm_label_slide_set(Evas_Object *obj, Eina_Bool slide)
1009 ELM_CHECK_WIDTYPE(obj, widtype);
1010 Widget_Data *wd = elm_widget_data_get(obj);
1013 if (wd->slidingmode == slide) return;
1014 wd->slidingmode = slide;
1015 _label_sliding_change(obj);
1021 * get the text slide mode of the label
1023 * @param obj The label object
1024 * @return slide slide mode value
1028 elm_label_slide_get(Evas_Object *obj)
1030 ELM_CHECK_WIDTYPE(obj, widtype);
1031 Widget_Data *wd = elm_widget_data_get(obj);
1032 if (!wd) return EINA_FALSE;
1034 return wd->slidingmode;
1038 * set the slide duration(speed) of the label
1040 * @param obj The label object
1041 * @return The duration time in moving text from slide begin position to slide end position
1045 elm_label_slide_duration_set(Evas_Object *obj, int duration)
1047 ELM_CHECK_WIDTYPE(obj, widtype);
1048 Widget_Data *wd = elm_widget_data_get(obj);
1049 Edje_Message_Int_Set *msg = alloca(sizeof(Edje_Message_Int_Set) + (sizeof(int)));
1052 wd->slide_duration = duration;
1055 msg->val[0] = (int)wd->slide_duration;
1057 edje_object_message_send(wd->lbl, EDJE_MESSAGE_INT_SET, 0, msg);
1061 * get the slide duration(speed) of the label
1063 * @param obj The label object
1064 * @return The duration time in moving text from slide begin position to slide end position
1068 elm_label_slide_duration_get(Evas_Object *obj)
1070 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1071 Widget_Data *wd = elm_widget_data_get(obj);
1073 return wd->slide_duration;