Change indicator color from arc-widget during runtime (not at initialization)?

Hello,

How can I change the color from arc indicator during runtime (not at initialization), see picture red arrow?
I already tried different codes but without success :frowning: (see below)

image

lv_obj_remove_style(ui.screen_arc_1, &style_screen_arc_1_main_indicator_default, LV_PART_INDICATOR|LV_STATE_DEFAULT);
lv_style_set_arc_color(&style_screen_arc_1_main_indicator_default, lv_color_make(0x00, 0x00, 0xff));
lv_obj_add_style(ui.screen_arc_1, &style_screen_arc_1_main_indicator_default, LV_PART_INDICATOR|LV_STATE_DEFAULT);

or

lv_obj_remove_style(ui.screen_arc_1, &style_screen_arc_1_main_knob_default, LV_PART_KNOB|LV_ARC_DRAW_PART_FOREGROUND);
lv_style_set_arc_color(&style_screen_arc_1_main_knob_default, lv_color_make(0x00, 0x00, 0xff));
lv_obj_add_style(ui.screen_arc_1, &style_screen_arc_1_main_knob_default, LV_PART_KNOB|LV_ARC_DRAW_PART_FOREGROUND);

Thank you

Try this
lv_obj_set_style_arc_color(ui.screen_arc_1, lv_color_hex(0x4040FF), LV_PART_INDICATOR | LV_STATE_DEFAULT );

sorry, I forgot to mention, that I use lvgl version 8.3.7

I now try to change to color of knob too, but that does not work. See below my code:
What’s wrong here?

lv_obj_remove_style(ui.screen_arc_1, &style_screen_arc_1_main_knob_default, LV_PART_KNOB|LV_STATE_DEFAULT);
lv_obj_set_style_arc_color(ui.screen_arc_1, lv_color_make(0xff, 0x00, 0x00), LV_PART_KNOB|LV_STATE_DEFAULT);
lv_obj_add_style(ui.screen_arc_1, &style_screen_arc_1_main_knob_default, LV_PART_KNOB|LV_STATE_DEFAULT);

Hi @epikao ,

I am a little confused by your code but I think if you just have the second line it will work fine:

//lv_obj_remove_style(ui.screen_arc_1, &style_screen_arc_1_main_knob_default, LV_PART_KNOB|LV_STATE_DEFAULT);
lv_obj_set_style_arc_color(ui.screen_arc_1, lv_color_make(0xff, 0x00, 0x00), LV_PART_KNOB|LV_STATE_DEFAULT);
//lv_obj_add_style(ui.screen_arc_1, &style_screen_arc_1_main_knob_default, LV_PART_KNOB|LV_STATE_DEFAULT);

In your original code the first line removes the style from the object(I don’t know why? :slight_smile: ) Then you are directly modifying the colour of the knob with the next line, which will change the colour but in the third line you are then adding the unmodified style back to the object which will overwrite the direct change in the previous line if that makes sense?

Or you could do this to continue using the style_screen_arc_1_main_knob_default style which is defined:

//lv_obj_remove_style(ui.screen_arc_1, &style_screen_arc_1_main_knob_default, LV_PART_KNOB|LV_STATE_DEFAULT);
lv_style_set_arc_color(&style_screen_arc_1_main_knob_default, lv_color_make(0xff, 0x00, 0x00) ); 
//lv_obj_add_style(ui.screen_arc_1, &style_screen_arc_1_main_knob_default, LV_PART_KNOB|LV_STATE_DEFAULT);

I hope that helps :smiling_face:

Kind Regards,

Pete

Thank you.
If I don’t remove the object and change the color during runtime too frequently, I encounter a hard fault.

Following code works:

lv_obj_remove_style(ui.screen_arc_1, &style_screen_arc_1_main_knob_default, LV_PART_KNOB|LV_STATE_DEFAULT);
lv_style_set_bg_color(&style_screen_arc_1_main_knob_default, lv_color_make(0xff, 0xff, 0xff));
LV_PART_KNOB|LV_STATE_DEFAULT);
lv_obj_add_style(ui.screen_arc_1, &style_screen_arc_1_main_knob_default, LV_PART_KNOB|LV_STATE_DEFAULT);