STM32-LTDC, LCD-TFT, LVGL(MCU3) Lecture 59| Exercise implementation on simulator part-4

  • Post author:
  • Post category:Blog

 

How to apply borders to objects in LVGL?

 

In this article, we will discuss how to apply borders to objects. Explore techniques to set border colors and adjust border widths using LVGL. 

Here, there is a base object – Rectangle. The base object has a border. You can add this border, and you can control the width of the border. 

Figure 1. RGB demo
Figure 1. RGB demo

To achieve this, you can employ a similar API to the one you previously utilized. Take a look at the following code snippet:

lv_obj_set_style_border_color(rect, lv_color_black(), LV_PART_MAIN);

  • This line sets the border color of the rect object to black.
  • lv_color_black() returns an LVGL color object representing black.
  • The LV_PART_MAIN parameter specifies that the border color change should be applied to the main part of the object.

 

Now, let’s delve into controlling the border width:

lv_obj_set_style_border_width(rect, 5, LV_PART_MAIN);

  • This line sets the border width of the rect object to 5 pixels.
  • The LV_PART_MAIN parameter specifies that the border width change should be applied to the main part of the object.

 

Code

/* Create a base object to use it as rectangle */
lv_obj_t* rect = lv_obj_create(lv_scr_act());
lv_obj_set_size(rect, 300, 80);
lv_obj_align_to(rect, slider_b, LV_ALIGN_TOP_MID, 0, 30);
lv_obj_set_style_border_color(rect, lv_color_black(), LV_PART_MAIN);
lv_obj_set_style_border_width(rect, 5, LV_PART_MAIN);

 

Figure 2. Output- borders
Figure 2. Output

 

In the following article, we will add labels. Should you wish to experiment with label addition, navigate to the widget section, proceed to the core widget, and then explore the label section.

 

Get Microcontroller Embedded C Programming Full Course on Here.

FastBit Embedded Brain Academy Courses

https://fastbitlab.com/course1

 

FastBitLab

The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.

Leave a Reply