Languages

Menu
Sites
Language
How to align text inside label widget?

Hello,

Is it possible to align a text inside the label widget vertically and horizontally? By default it’s top-left aligned, but I need it at center of the label.

Responses

5 Replies
Alex Ashirov

Hi,

You can align text horizontally using the following:

elm_object_text_set(label, _("<align=center>Your text</align>"));

But I don’t know how to align it vertically. Probably this isn’t possible.

Daniel Juyung Seo

Thanks for the answer.

As Alex Ashirov suggested use "<align>" tag to align the text horizontally inside label. But "<valign>" tag is used to align your text inside *each line*. So valign=0.0 will align your text at the bottom of each line while 1.0 is for top alignment.

 

To align the text vertically inside label, you need to customize label widget style.

There is a guideline how to customize widgets.

https://developer.tizen.org/documentation/mobile-native-app-programming/programming-guide/ui-creating-application-ui/widgets/widget-customization

In your customized label widget, set "text.align: 0.5 0.5". That should work.

 

 

 

Eric Satkimbaev

Hi,

Thank you for your answer. I have created customized label. But it seems that

text.align: 0.5 0.5

aligns the text only vertically. I tried

text.align: 0.0 0.5

text.align: 1.0 0.5

There is no any difference. So, I still need to use “align=center” in order to align the text horizontally.

Daniel Juyung Seo

Hi can you share how you used the label widget in your source code?

It smells like the label itself is not aligned well.

Thanks.

Eric Satkimbaev

Hi,

Thanks you for suppport! Please let me know if there is something wrong in the following code snippet:

    app_get_resource("edje/label_centered.edj", edj_path, (int)PATH_MAX);

    // Load check custom style as an extension
    elm_theme_extension_add(NULL, edj_path);

    Evas_Object *label1 = elm_label_add(layout);
    elm_object_style_set(label1, "centered");
    elm_object_text_set(label1, "Text");

    evas_object_size_hint_align_set(label1, EVAS_HINT_FILL, EVAS_HINT_FILL);
    evas_object_size_hint_weight_set(label1, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
    elm_object_part_content_set(layout, "swallow.label1", label1);