How to align text on elmentary label widget?

1.9k Views Asked by At

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?

2

There are 2 best solutions below

0
Mukul Rawal On BEST ANSWER

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

0
andy.xyz On

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.