Change Led Style

Important: posts that do not use this template will be ignored or closed.

Before posting

  • Get familiar with Markdown to format and structure your post
  • Be sure to update lvgl from the latest version from the master branch.
  • Read the

Delete this section if you read and applied the mentioned points.

Description

according to documentation:

LEDs are rectangle (or circle) type objects. It’s brightness can be adjusted. With lower brightness, the colors of the LED become darker.

how to change the style of the led to rectangle?

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

STM32

What do you want to achieve?

What have you tried so far?

Code to reproduce

Add the relevant code snippets here.

The code block(s) should be between ```c and ``` tags:

/*You code here*/
void lv_ex_led_1(void)
{
    /*Create a LED and switch it OFF*/
    lv_obj_t * led1  = lv_led_create(lv_scr_act(), NULL);
    lv_obj_align(led1, NULL, LV_ALIGN_CENTER, -80, 0);
    lv_led_off(led1);

    /*Copy the previous LED and set a brightness*/
    lv_obj_t * led2  = lv_led_create(lv_scr_act(), led1);
    lv_obj_align(led2, NULL, LV_ALIGN_CENTER, 0, 0);
    lv_led_set_bright(led2, 190);

    /*Copy the previous LED and switch it ON*/
    lv_obj_t * led3  = lv_led_create(lv_scr_act(), led1);
    lv_obj_align(led3, NULL, LV_ALIGN_CENTER, 80, 0);
    lv_led_on(led3);
}

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

You change its radius to 0 to make it a rectangle.

Is it enough to call lv_obj_set_style_local_radius(led1, LV_LED_PART_MAIN, LV_STATE_DEFAULT, 0);?

Yes; that should work.

1 Like

Maybe it would be useful to add a rectangular LED in the example. I can send a PR if you agree.

Why not? More examples are always good. :slight_smile:

Thank you!

1 Like

Hello,

How can you change the led color? The implicit color is red, so i would like to add 2 more for green and blue colors.

Thanks!

You can change the bg_color, border_color, and shadow_color styles of the LED.

The theme might be a good reference implementation to work with, though you shouldn’t need to change every single property in that function, just the ones I mentioned above.

Thanks, it worked!