elgerg
February 13, 2022, 4:58pm
1
Description
I would like to set the colour of the items in a dropdown
What MCU/Processor/Board and compiler are you using?
Simulator
What LVGL version are you using?
8.1
What do you want to achieve?
I would like to set the colour of the items in a dropdown
What have you tried so far?
A number of things includding
lv_obj_set_style_bg_color(roller_temp, lv_color_hex(MAIN_BG_COLOUR), LV_PART_MAIN | LV_PART_ITEMS);
lv_obj_set_style_bg_color(roller_temp, lv_color_hex(MAIN_BG_COLOUR), LV_PART_ITEMS);
Screenshot and/or video
Thanks!
elgerg
February 14, 2022, 9:37pm
2
@embeddedt / @kisvegabor any ideas?
Thanks in anticipation.
Alex
It needs to be set on the dropdown’s list, not the dropdown itself.
lv_obj_set_style_bg_color(lv_dropdown_get_list(roller_temp), lv_color_hex(MAIN_BG_COLOUR), LV_PART_MAIN);
elgerg
February 16, 2022, 5:15pm
4
Hmm, when I add that line here:
lv_dropdown_set_options(roller_temp,
"7.00\n"
"19.00\n"
"19.50\n"
"20.00\n"
"20.50\n"
"21.00\n"
"21.50\n"
"22.00\n"
"22.50\n"
"23.00\n"
"23.50\n"
"24.00\n"
);
lv_obj_set_style_bg_color(roller_temp, lv_color_hex(MAIN_BG_COLOUR), LV_PART_MAIN);
lv_obj_set_style_bg_color(lv_dropdown_get_list(roller_temp), lv_color_hex(MAIN_BG_COLOUR), LV_PART_MAIN);
lv_obj_set_style_border_color(roller_temp, MAIN_BORDER_COLOUR, LV_PART_MAIN);
I get the following:
Any ideas what I’m doing wrong?
elgerg
February 16, 2022, 5:56pm
5
I also tried this:
lv_dropdown_set_options(roller_temp,
"7.00\n"
"19.00\n"
"19.50\n"
"20.00\n"
"20.50\n"
"21.00\n"
"21.50\n"
"22.00\n"
"22.50\n"
"23.00\n"
"23.50\n"
"24.00\n"
);
lv_obj_t * list = lv_dropdown_get_list(roller_temp); /*Get the list*/
static lv_style_t style_list;
lv_style_init(&style_list);
lv_style_set_bg_color(&style_list, lv_color_hex(MAIN_BG_COLOUR));
lv_obj_add_style(list, &style_list, LV_PART_MAIN);
But get the same segfault
Strange. I tested it on the MicroPython simulator (which should behave identically to C) and it worked there. list
isn’t NULL by chance, is it?
elgerg
February 16, 2022, 6:27pm
7
Yes, looks like its NULL…
If I add the following it doesnt crash but doesnt style the list:
lv_obj_t * list = lv_dropdown_get_list(roller_temp); /*Get the list*/
static lv_style_t style_list;
lv_style_init(&style_list);
lv_style_set_bg_color(&style_list, lv_color_hex(MAIN_BG_COLOUR));
if (NULL != list)
{
lv_obj_add_style(list, &style_list, LV_PART_MAIN);
}
I wonder whats wrong?
Prior to v8.2 it was only created when you open the list, that’s why it’s NULL. The change was made at the end of November, about 2 weeks after v8.1 was released.
(The MicroPython simulator is built against a relatively recent master
snapshot.)
elgerg
February 16, 2022, 6:35pm
9
Ah!!!
Well, that would explain it!
So… Either update to 8.2 or add it to a callback when what LV_EVENT_VALUE_CHANGED?
elgerg
February 16, 2022, 6:54pm
10
Fount it (Dropdown list change font - #2 by Titkov_AV ):
LV_EVENT_READY
lv_obj_add_event_cb(roller_temp, heating_ddl_cb_ready, LV_EVENT_READY, NULL);
void heating_ddl_cb_ready(lv_event_t * event)
{
lv_obj_t * list = lv_dropdown_get_list(roller_temp); /*Get the list*/
lv_obj_set_style_bg_color(list, lv_color_hex(MAIN_BG_COLOUR), LV_PART_MAIN);
}
Thanks @embeddedt !!