Rectangular meter?

I am trying to make the meter widget into a rectangular shape. I have found that the scale is not drawn correctly if the vertical and horizontal sizes are not equal (see pictures). I have tried multiple meter style attributes but have not been able to make the scale size correctly. As seen in the pictures if I set the height equal to the width the sale is drawn correctly but if I set the height to half the width the scale is not drawn as expected. The indicator (needle) is drawn as I would like although I would have expected it to require an offset that wasn’t required to set it at the edge of the rectangle.

The hardware is a custom STM32H7A3 board and I’m using STM32CubeIDE (latest version) with LVGL 8.1.

/* Code for meter. */

/* Create the meter */
meter = lv_meter_create(scr);
lv_obj_align(meter, LV_ALIGN_CENTER, 0, 0);

// lv_obj_center(meter);
lv_obj_set_size(meter, 200, 100);

/*Add a scale first*/
lv_meter_scale_t * scale = lv_meter_add_scale(meter);
lv_meter_set_scale_ticks(meter, scale, 21, 1, 10, lv_palette_main(LV_PALETTE_GREY));
lv_meter_set_scale_major_ticks(meter, scale, 5, 2, 15, lv_color_black(), 10);
lv_meter_set_scale_range(meter, scale, 0, 100, 140,200);

/*Add a needle line indicator*/
indic = lv_meter_add_needle_line(meter, scale, 2, lv_palette_main(LV_PALETTE_RED), -10);
/* Set needle initial value */
lv_meter_set_indicator_value(meter, indic, lv_slider_get_value(slider));


static lv_style_t meter_style;
lv_style_init(&meter_style);

// lv_style_set_width(&meter_style, 200);
// lv_style_set_height(&meter_style, 100);
lv_style_set_radius(&meter_style, 3);

lv_obj_add_style(meter, &meter_style, LV_PART_MAIN);


Thanks in advanced for your response

Frank

After modifying the meter widget I was successful at getting the meter in the form I was wanted. The modified widget will draw the rectangular meter correctly in quadrants 1 and 2 or quadrants 2 and 3 of the circle. It still does not draw the meter correctly in quadrants 1 and 4 or 3 and 4. I may go back and fix that in the future and keep it in my LVGL library as an enhanced meter widget. But for now I have what I need now for my project .

Frank


1 Like

How did you resolve?