Draw rectangle, circle, background

Hello, I simply want draw rectangle, circles and with a specific screen color background. What is currently the correct way to do this? I tried to do with canvas but the examples shows many errors like not defined variables etc.

Can somebody show me the simplest code possible to draw for example a red rectangle or circle on a white background, the rectangle should not be filled?

Thank you

Rectangle:
static lv_obj_t * my_rect = lv_obj_create(lv_scr_act());
lv_obj_set_size(my_rect , 500, 120);
lv_obj_set_pos(my_rect , 1, 162);
lv_obj_set_style_bg_color(my_rect , lv_palette_lighten(LV_PALETTE_GREY, 3));

Circle:
static lv_obj_t * my_Cir = lv_obj_create(lv_scr_act());
lv_obj_set_scrollbar_mode(my_Cir , LV_SCROLLBAR_MODE_OFF);
lv_obj_set_size(my_Cir , 42, 42);
lv_obj_set_pos(my_Cir , 270, 10);
lv_obj_set_style_bg_color(my_Cir , lv_palette_lighten(LV_PALETTE_BLUE), 0);
lv_obj_set_style_radius(my_Cir , LV_RADIUS_CIRCLE, 0);

thank you very much, looks good, but the function lv_palette_lighten looks not correct, we need here 3 values, what is “uint8_t lvl” ? What is the function of this third value, or where can I find the documentation of this?

  • Do you also have an example for polygon?

Sorry that takes style, not object. My mistake.

You could just use:
lv_obj_set_style_bg_color(my_rect , (lv_color_t)LV_COLOR_MAKE(R, G, B), 0);
Where R,G,B is any value 0-255.
So, (255,0,0) is red color.

yes ok, thank you.

Last question:

  • How can I easily use canvas functions without include lv_examples or something? The lv_canvas_draw functions and so on are not available… and the examples looks a little bit complicated.

I ask this, because it seems that without canvas, draw polygon is not possible…