How to display a rotated line meter


I’d like to display a line meter arched over a 90 degrees angle but with a different orientation from the default “top” one.

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

Currently working on SDL2.

What do you want to achieve?

Using a clock as reference, I would like my meter to span from hours 9 to 12.

What have you tried so far?

The function lv_lmeter_set_scale allows me to specify an angle, but said angle is always centered on the topmost point of the circle. I would like to have it rotated 45 degrees left, for example.
I’m not sure wether this is possible with the current API (if it is I couldn’t find a reference). If not I guess it would be pretty simple to implement.

Code to reproduce

void lv_ex_lmeter_1(void)
    /*Create a style for the line meter*/
    static lv_style_t style_lmeter;
    lv_style_copy(&style_lmeter, &lv_style_pretty_color);
    style_lmeter.line.width = 2;
    style_lmeter.line.color = LV_COLOR_SILVER;
    style_lmeter.body.main_color = lv_color_hex(0x91bfed);         /*Light blue*/
    style_lmeter.body.grad_color = lv_color_hex(0x04386c);         /*Dark blue*/
    style_lmeter.body.padding.left = 16;                           /*Line length*/

    /*Create a line meter */
    lv_obj_t * lmeter;
    lmeter = lv_lmeter_create(lv_scr_act(), NULL);
    lv_lmeter_set_range(lmeter, 0, 100);                   /*Set the range*/
    lv_lmeter_set_value(lmeter, 80);                       /*Set the current value*/
    lv_lmeter_set_scale(lmeter, 90, 30);                  /*Set the angle and number of lines*/
    lv_lmeter_set_style(lmeter, LV_LMETER_STYLE_MAIN, &style_lmeter);           /*Apply the new style*/
    lv_obj_set_size(lmeter, 150, 150);
    lv_obj_align(lmeter, NULL, LV_ALIGN_CENTER, 0, 0);

Hi Mattia_Maldini,

I haven’t had the need to rotate anything yet, but after a quick search it looks like you could do this via a canvas. Unfortunately I do not have time to test this today, but I think this might accomplish what you need.

Hi tarvik,
That doesn’t quite cut it for me. I don’t think I can insert any random lv_object into a canvas and rotate it. If I cannot find a better solution I will indeed use a canvas and draw my own line meter from scratch; however I was hoping to use the widget that is already provided by the API.

It’s not supported right now by the line meter but it’d be possible to improve it.
If you can help with implementing this feature please open an issue on GitHub to discuss it.
Don’t worry if you don’t know LittlevGL in details yet, we kindly help you.