Rotate label via code

Hello,

I am looking to achieve a “screen rotation” feature, via code. I can rotate images with “lv_img_set_angle(img, angle)”, but not a label.

Is there a way to rotate a label object?
Any ideas are much appreciated, as I would avoid building and maintaining 2 totally separate projects.

Thank you!
Marius

SLS now uses LVGL 8.2 but LVGL 8.3 can already rotate any widget. See here.

So you can update LVGL to v8.3.1 manually and add the rotation setting from code.

2 Likes

This is great, I will give it a go. Will come back with my findings.
Thank you very much for your help, I really appreciate it.

Marius

1 Like

Hello, I have managed to install 8.3.1 (verified with lvgl arduino example and indeed the version is good).
However, I have tried 2 methods of transforming the angle (rotating) of both labels and images, like so:

Method 1

static lv_style_t style;
lv_style_init(&style);
lv_style_set_transform_angle(&style, 300);
lv_obj_add_style(ui_myImage, &style, 0);

Method 2

lv_obj_set_style_transform_angle(ui_myLabel, 150, 0);

Nothing seems to work, the widgets/objects disappear.
I have also tried some copy/paste code from the docs, the obj is not rendering, doesn’t show up.

Any ideas? @kisvegabor

Thank you!
Marius

Probably you also need to enable LV_COLOR_SCREEN_TRANSP in lv_conf.h.

2 Likes

That was it! It’s written in the comments there that LV_COLOR_SCREEN_TRANSP = 1 is needed for transform actions - I didn’t notice.

I was able to rotate a label with:

lv_obj_set_style_transform_angle(ui_myLabel, 900, 0);

Thank you!
Marius

2 Likes

Great! Thank for the feedback!

1 Like