LVGL tips

Code tips and tricks for beginners
Post Reply
User avatar
cicciocb
Site Admin
Posts: 2947
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 609 times
Been thanked: 2100 times
Contact:

LVGL tips

Post by cicciocb »

Given that the implementation of the LVGL library introduces many features, I propose gathering useful tricks and tips here as we discover how to use them.
The goal is to gather everything in one place to make searching easier.
User avatar
cicciocb
Site Admin
Posts: 2947
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 609 times
Been thanked: 2100 times
Contact:

Message Box example

Post by cicciocb »

Hi,
I've just uploaded a little video showing how use the msgbox ojbect in LVGL.


The code is :

Code: [Local Link Removed for Guests]

lvgl.init WHITE, 0x003a57
lvgl.set_theme 0x107090, 0xff9900, 12, 0, 0 ' character 12, dark 0, mode 3
lvgl.remove_flag lvgl.screen, 0x20 'remove elasticity on scroll
lvgl.clean
img1 = lvgl.image "/greece.jpg"
but1 = lvgl.button "msgbox"
but2 = lvgl.button "msgbox custom", 160, 0
lvgl.add_event but1, 7, but1_pressed
lvgl.add_event but2, 7, but2_pressed

while 1
lvgl.refresh
wend

but1_pressed:
msgBox = lvgl.msgBox "This is Header", "This is content"
footer = lvgl.get_child msgbox, 2 'get the buttons zone
b_OK = lvgl.get_child footer, 0 ' extract the button OK
lvgl.add_Event b_OK, 7, b_OK_clicked 'add an event when OK clicked
return

but2_pressed:
msgBox = lvgl.msgBox "Entry Date", "Enter Data Validated"
header = lvgl.get_child msgbox, 0 'get the header zone
content = lvgl.get_child msgbox, 1 'get the content zone
footer = lvgl.get_child msgbox, 2 'get the buttons zone
b_OK = lvgl.get_child footer, 0 ' extract the button OK
b_cancel = lvgl.get_child footer, 1 ' extract the button cancel
lvgl.visible b_cancel, 0 'hide the button cancel
lvgl.add_Event b_OK, 7, b_OK_clicked 'add an event when OK clicked
t = lvgl.get_child b_ok,0 'get the first child (is a label)
lvgl.set_text t, "Tutto Bene" ' now change the text of the button OK
'now change the colors
''' HEADER '''
lvgl.set_bg_opa msgbox, 128 'set the box transparent
lvgl.set_text_color header, white 'set the text color to white
lvgl.set_bg_color header, red 'set the background color to red
lvgl.set_bg_opa header, 128 ' transparent at 50%
''' CONTENT '''
lvgl.set_text_color content, Yellow 'set the text color to yellow
lvgl.set_bg_color content, black 'set the background color to black
lvgl.set_bg_opa content, 128 ' transparent at 50%
''' FOOTER '''
lvgl.set_bg_color footer, black 'set the background color to black
lvgl.set_bg_opa footer, 128 ' transparent at 50%
return

b_OK_clicked:
LVGL.MSGBOX_CLOSE msgbox
return

User avatar
karlkloss
Posts: 244
Joined: Fri Aug 18, 2023 12:21 pm
Location: Local group
Has thanked: 37 times
Been thanked: 51 times

Re: LVGL tips

Post by karlkloss »

I made this picture to visualize the possible positions of LVGL Alignment Enums (lv_align_t):

grafik.png
grafik.png
grafik.png
You do not have the required permissions to view the files attached to this post.
User avatar
cicciocb
Site Admin
Posts: 2947
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 609 times
Been thanked: 2100 times
Contact:

Re: LVGL tips

Post by cicciocb »

How remove the KNOB (button) from an ARC objact

Code: [Local Link Removed for Guests]

arc = lvgl.arc
lvgl.set_bg_opa arc, 0, 0x030000 ' change the knob transparent
lvgl.remove_flag arc, 2 ' disable the object (no clickable)
Post Reply