0

I want align text to center on elm_label widget. I can't find any functions about text align as evas object text function or elm_label function. Also, I can't find a function that can get the text size (absolute pixel or relative size) on a label.

I have tried elm_object_style_set with marker, it was showed bold text on center of label, but font size was too small (smaller than default style). (and I don't want bold on text.)

How I can align text to the center of a label?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
pius lee
  • 1,164
  • 1
  • 12
  • 28
  • it's not question about qt widget. why you advise to read qt doc? and also I can't find function on evas doc like setAlignment(). – pius lee Jul 15 '14 at 08:33
  • Sorry it was a mistake ;) I deleted it – Martin Jul 15 '14 at 08:40
  • possible duplicate of [How to add background to elementary(EFL) widget?](http://stackoverflow.com/questions/24730499/how-to-add-background-to-elementaryefl-widget) – ozbek Oct 13 '14 at 02:43

2 Answers2

2

You can use HTML like markup to customize the way you want to the display the text in elm_label.

To align the text to the center, you can use <align> markup tag with value center .

std::string text = "<align = center> TEXT TO DISPLAY </align>";
Evas_Object *label = elm_label_add(parent);
elm_object_text_set(label,text.c_str());
evas_object_show(label);

You can also use other tags like font_weight, font_style to customize your display text. List of all possible tags can be found here

1

You can set the alignment of the label through the evas_object API. Likely what you are looking for is:

evas_object_size_hint_align_set(label, 0.5, EVAS_HINT_FILL);
evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);

The 0.5 is center, you could try 0.0 for left align and 1.0 for right.

prajmus
  • 3,171
  • 3
  • 31
  • 41
andy.xyz
  • 2,567
  • 1
  • 13
  • 18