How do I right-align text in a drop-down list, the default is left aligned, I want right aligned

Important: unclear posts may not receive useful answers.

Before posting

  • Get familiar with Markdown to format and structure your post
  • Be sure to update lvgl from the latest version from the master branch.
  • Be sure you have checked the FAQ and read the relevant part of the documentation.
  • If applicable use the Simulator to eliminate hardware related issues.

Delete this section if you read and applied the mentioned points.

Description

What MCU/Processor/Board and compiler are you using?

STM32H7 MDK

What LVGL version are you using?

8.0.3

What do you want to achieve?

I want the text of the drop-down list to be right aligned.

What have you tried so far?

lv_obj_set_style_text_align() …

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

/*You code here*/

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

You can do it like this:

    lv_obj_set_style_text_align(lv_dropdown_get_list(dd), LV_TEXT_ALIGN_RIGHT, 0);

I tried, but it didn’t achieve right-aligned text. :sob:

In v8.3.3 this code:

    lv_obj_t * dd = lv_dropdown_create(lv_scr_act());
    lv_obj_set_style_text_align(lv_dropdown_get_list(dd), LV_TEXT_ALIGN_RIGHT, 0);
    lv_dropdown_set_options(dd, "Apple\n"
                            "Banana\n"
                            "Orange\n"
                            "Cherry\n"
                            "Grape\n"
                            "Raspberry\n"
                            "Melon\n"
                            "Orange\n"
                            "Lemon\n"
                            "Nuts");

results in:

image

1 Like