How to disable the 'critical' color of LV GAUGE?


I am using lv gauge and would like to disable the critical color. Setting the critical value to max+1 doesn’t help.

lv_gauge_set_range(lv_guage, min, max);
lv_gauge_set_critical_value(lv_guage, max+1);

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

STM32F401, Platformio/Arduino.

What LVGL version are you using?

#define LVGL_VERSION_INFO “dev”

What do you want to achieve?

Eliminate the different color on the last major tick. (see screenshot in image below)

What have you tried so far?

Setting critical value to max + 1;

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.

Looks like a bug to me… I think setting the critical value to max has to be allowed, otherwise there is no way of disabling it without changing styles.

@kisvegabor Can you take a look at this?

In the meantime, you can use this workaround when creating the gauge:

    lv_obj_set_style_local_scale_end_color(lv_guage, LV_GAUGE_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex3(0x888));
    lv_obj_set_style_local_scale_end_color(lv_guage, LV_GAUGE_PART_MAJOR, LV_STATE_DEFAULT, lv_color_hex3(0x888));

Thanks @embeddedt. A side question if I may, how the color and other look and feel parameters of the critical range of a gauge are set?

The documentation mentions a few gauge ‘parts’ but none of them seem to be related to the ‘critical’ section of scale. (I tried to include here a link to the lvgl official Gauge documentation but this forum tool doesn’t let me. That’s strange. Please search for it yourself).

(If i can set it to match the color and line width of the rest of the gauge’s scale, I can make it ‘disappears’, as a workaround).

The style properties relating to the gauge are here and there is an example of how to use them:

Thanks @embeddedt. I read your posts again. I think I have all the information to make the end/critical region tick look like the normal one. Will try and will report here.

Adding this to the gauge’s initialization hid the problem and gauges look now as intended. Thanks. I had to reduce the major ticks to 5 to match my gauge’s style.

  lv_obj_set_style_local_scale_end_color(lv_guage, LV_GAUGE_PART_MAJOR,
                                         LV_STATE_DEFAULT, LV_COLOR_GRAY);
  lv_obj_set_style_local_scale_end_line_width(lv_guage, LV_GAUGE_PART_MAJOR,
                                              LV_STATE_DEFAULT, 5);

I couldn’t figure out a way to do the same via one of the gauge’s styles rather than having to set it ‘locally’ per instance.

It’s mostly just changing the lv_obj_set_style_local to lv_style_set. Remove the part from the individual property set calls, as style objects don’t have a part associated with them. Then, call lv_obj_add_style(gauge, LV_GAUGE_PART_MAJOR, &style);.

That worked. Thanks.