Change Bar Style

Description

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

I’m using an ESP32

What do you want to achieve?

I would like to change the color of a bar.

What have you tried so far?

I know I should change the color of the LV_BAR_PART_INDIC part of the bar.

So I’ve tried this

    lv_obj_set_style_local_indic_color(timoutBar,LV_BAR_PART_INDIC , LV_STATE_DEFAULT, LV_COLOR_RED);

or this:

  lv_obj_set_style_local_bg_color(timoutBar,LV_BAR_STYLE_INDIC , LV_STATE_DEFAULT, LV_COLOR_RED);

Code to reproduce

    timoutBar = lv_bar_create(unlockedCont, NULL);
    lv_obj_set_size(timoutBar, 200, 20);
    lv_obj_align(timoutBar, NULL, LV_ALIGN_CENTER, -40, 0);
    lv_bar_set_range(timoutBar, 0, 100);
    lv_bar_set_value(timoutBar, 100, LV_ANIM_ON);

    //lv_obj_set_style_local_bg_color(timoutBar,LV_BAR_STYLE_INDIC , LV_STATE_DEFAULT, LV_COLOR_RED);

Screenshot and/or video

NA

Hi @DavidTruyens,

It should work with this:

lv_obj_set_style_local_bg_color(timoutBar,LV_BAR_PART_INDIC , LV_STATE_DEFAULT, LV_COLOR_RED);

Kind Regards,

Pete

Hi Pete,

Thanks for your reaction, I’ve tried that before but that just doesn’t compile:

image

Could it be a difference between C++ and C? Right now it’s a C++ file I’m working in… With your suggestion added it looks now like this:

timoutBar = lv_bar_create(unlockedCont, NULL);
    lv_obj_set_size(timoutBar, 200, 20);
    lv_obj_align(timoutBar, NULL, LV_ALIGN_CENTER, -60, 0);
    lv_bar_set_range(timoutBar, 0, 100);
    lv_bar_set_value(timoutBar, 100, LV_ANIM_ON);

    lv_obj_set_style_local_bg_color(timoutBar,LV_BAR_PART_INDIC , LV_STATE_DEFAULT, LV_COLOR_RED);

Regards,
David

Did you include lvgl/lvgl.h at the top of your file, or individual header files? These symbols definitely exist.

Hi @embeddedt,

Might be important to mention that I’m working with Visual Code and Platformio on Windows. And everything worked perfect until I wanted to change the colors.

And I just found out that I didn’t changed this project to V7 yet… So let me do that first. That’s probably the issue…

That’s the issue. lv_obj_set_style_local_bg_color doesn’t exist in 6.x.