Drop-down list, is it a problem?

Before posting

Hello

Description

What’s going on here?!?
my file has UTF8 encoding, every text is ok but drop-down list nothing show’s, what can i DO?

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

VS Simulator

What LVGL version are you using?

7.10.0

What do you want to achieve?

‘’’
lv_style_set_text_font(&style, LV_STATE_DEFAULT,
&lv_font_dejavu_16_persian_hebrew);//change font

lv_dropdown_set_options(ui.ddlist_key_type, ("سلام\nعلیکم\nسلام سلام\nعلیکمعلیکم"));

i also tried this:
lv_dropdown_add_option(ui.ddlist_key_type, “سلام”, 0);
lv_dropdown_add_option(ui.ddlist_key_type, “علیکم”, 1);
lv_dropdown_add_option(ui.ddlist_key_type, “سلام سلام”, 2);
lv_dropdown_add_option(ui.ddlist_key_type, “علیکمعلیکم”, 3);

‘’’

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

another game with style and font:

    static lv_style_t style;
    lv_style_init(&style);
    lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE);
    
    lv_dropdown_set_options(ui.ddlist_key_type, "Image+Text\nImage\nText");
    lv_obj_add_style(ui.ddlist_key_type, LV_OBJ_PART_MAIN, &style);

Result: a

now i just add font to style

    static lv_style_t style;
    lv_style_init(&style);
           lv_style_set_text_font(&style, LV_STATE_DEFAULT, &lv_font_dejavu_16_persian_hebrew);//change font
    lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE);
    
    lv_dropdown_set_options(ui.ddlist_key_type, "Image+Text\nImage\nText");
    lv_obj_add_style(ui.ddlist_key_type, LV_OBJ_PART_MAIN, &style);

Result: s
d
i have shadows on list selected text

it’s seems like LVGL did not find the font data when drawing text. I think you mabe need check the font file,A simple way to do this is to use the label to display the same text and see if the same problem occurs

i belive font table has no problem

i checked on a label and it worked correctly.

    static lv_style_t style;
    lv_style_init(&style);
    lv_style_set_text_font(&style, LV_STATE_DEFAULT, &lv_font_dejavu_16_persian_hebrew);//change font

 lv_obj_t * label1;
    label1 = lv_label_create(ui.tab1, NULL);
    lv_obj_add_style(label1, LV_OBJ_PART_MAIN, &style);
    lv_label_set_text(label1, "سلام\nعلیکم\nسلام سلام\nعلیکمعلیکم");
    lv_obj_set_pos(label1, 250, 50);

2

image

    static lv_style_t *local_style;
    lv_style_init(&local_style);
    
    lv_style_set_text_font(&local_style, LV_STATE_DEFAULT, &lv_font_dejavu_16_persian_hebrew);//change font

    lv_obj_t * ddlist = lv_dropdown_create(lv_scr_act(), NULL);
    //lv_obj_set_style_local_text_font(ddlist,LV_OBJ_PART_MAIN,LV_STATE_DEFAULT,&lv_font_dejavu_16_persian_hebrew);
    lv_obj_add_style(ddlist, LV_DROPDOWN_PART_MAIN, &local_style);
    lv_obj_add_style(ddlist, LV_DROPDOWN_PART_LIST, &local_style);
    lv_obj_add_style(ddlist, LV_DROPDOWN_PART_SELECTED, &local_style);
    lv_dropdown_add_option(ddlist,"سلام",0);
    lv_dropdown_add_option(ddlist, "علیکم", 1);
    lv_dropdown_add_option(ddlist, "سلامسلام", 2);
    lv_dropdown_add_option(ddlist, "علیکمعلیکم", 3);

The main problem is setting the style PART, which requires setting the font for all the parts, as you can see in the Dropdown widget section of the documentation.

I also don’t know how to use ‘lv_dropdown_set_options’ to add options since I don’t understand Farsi.(I entered the newline character in the wrong position, it will destroy the original word)

1 Like

thank you. it’s done. i tried different ways to add text, i should more notice to style parts.jj

1

i need to have a btn like the image, after some search’s found nothing.

char * str = "Ok";
lv_label_set_text(label1, str); // OK
lv_label_set_text(label1, LV_SYMBOL_OK); // OK
lv_label_set_text(label1, str LV_SYMBOL_OK); // error
lv_label_set_text(label1, str + LV_SYMBOL_OK);//error
lv_label_set_text(label1, strcat (str , LV_SYMBOL_OK) );//run time error

any solution?

If you’re talking about achieving the same effect as your images:
lv_label_set_text(label1, LV_SYMBOL_OK "OK");
image
If you are talking about setting the background of the BTN as an image, you can refer to this

if you want to set the BTN shape as an image too, you need to set more style properties.

In addition, it is best not to ask new questions under an already resolved topic, unless the previous answer did‘t solve your question.New problems can be helped by Posting a new topic.

:ok_hand:
i have a str variable not static “STRING”
char * str = “Ok”;
and want to add a symbol to it

lv_label_set_text(label1, str LV_SYMBOL_OK);

I will observe
Thanks

    char str[]= " CLOSE ";
    label = lv_label_create(btn2, NULL);
    lv_label_set_text_fmt(label, LV_SYMBOL_CLOSE"%s",str);
1 Like