# Rotate label via code

**URL:** <http://forum.squareline.io/t/rotate-label-via-code/442>\
**Category:** How to\
**Created:** [September 18, 2022, 6:25pm UTC](http://forum.squareline.io/t/rotate-label-via-code/442 "2022-09-18T18:25:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mariuselz](http://forum.squareline.io/letter_avatar_proxy/v4/letter/m/a8b319/32.png) [@mariuselz](http://forum.squareline.io/u/mariuselz)\
**Post date:** [September 18, 2022, 6:25pm UTC](http://forum.squareline.io/t/rotate-label-via-code/442/1 "2022-09-18T18:25:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kisvegabor](http://forum.squareline.io/user_avatar/forum.squareline.io/kisvegabor/32/537_2.png) [@kisvegabor](http://forum.squareline.io/u/kisvegabor)\
**Post date:** [September 19, 2022, 8:49am UTC](http://forum.squareline.io/t/rotate-label-via-code/442/2 "2022-09-19T08:49:46Z")

</div>

SLS now uses LVGL 8.2 but LVGL 8.3 can already rotate any widget. See [here](https://docs.lvgl.io/master/overview/style.html#opacity-blend-modes-and-transformations).

So you can update LVGL to [v8.3.1](https://github.com/lvgl/lvgl/tree/release/v8.3) manually and add the rotation setting from code.

---

<div class="post-metadata">

**Author:** ![mariuselz](http://forum.squareline.io/letter_avatar_proxy/v4/letter/m/a8b319/32.png) [@mariuselz](http://forum.squareline.io/u/mariuselz)\
**Post date:** [September 19, 2022, 9:06am UTC](http://forum.squareline.io/t/rotate-label-via-code/442/3 "2022-09-19T09:06:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mariuselz](http://forum.squareline.io/letter_avatar_proxy/v4/letter/m/a8b319/32.png) [@mariuselz](http://forum.squareline.io/u/mariuselz)\
**Post date:** [September 19, 2022, 4:05pm UTC](http://forum.squareline.io/t/rotate-label-via-code/442/4 "2022-09-19T16:05:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kisvegabor](http://forum.squareline.io/user_avatar/forum.squareline.io/kisvegabor/32/537_2.png) [@kisvegabor](http://forum.squareline.io/u/kisvegabor)\
**Post date:** [September 19, 2022, 9:16pm UTC](http://forum.squareline.io/t/rotate-label-via-code/442/5 "2022-09-19T21:16:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mariuselz](http://forum.squareline.io/letter_avatar_proxy/v4/letter/m/a8b319/32.png) [@mariuselz](http://forum.squareline.io/u/mariuselz)\
**Post date:** [September 20, 2022, 9:44am UTC](http://forum.squareline.io/t/rotate-label-via-code/442/6 "2022-09-20T09:44:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kisvegabor](http://forum.squareline.io/user_avatar/forum.squareline.io/kisvegabor/32/537_2.png) [@kisvegabor](http://forum.squareline.io/u/kisvegabor)\
**Post date:** [September 20, 2022, 10:58am UTC](http://forum.squareline.io/t/rotate-label-via-code/442/7 "2022-09-20T10:58:52Z")

</div>

Great! Thank for the feedback!
