
#include "BasicWidget.h"
#include "lvgl/lvgl.h"
void hello_world(void)
{
lv_obj_t* screen = lv_screen_active();
lv_obj_t* label = lv_label_create(screen);
lv_label_set_text(label, "hello world!");
}
#include "BasicWidget.h"
#include "lvgl/lvgl.h"
void basic_widget(void)
{
lv_obj_t* screen = lv_screen_active();
lv_obj_t* obj = lv_obj_create(screen);
lv_obj_set_width(obj, 100);
lv_obj_set_height(obj, 100);
lv_obj_set_x(obj, 100);
lv_obj_set_y(obj, 100);
lv_obj_t* label = lv_label_create(obj);
lv_label_set_text(label, "HI!");
lv_obj_set_y(label, 50);
}
void loading_screens(void)
{
lv_obj_t* screen = lv_screen_active();
lv_obj_t* obj = lv_obj_create(screen);
lv_obj_set_width(obj,100 );
lv_obj_set_height(obj,100);
lv_obj_set_x(obj, 100);
lv_obj_set_y(obj, 100);
lv_obj_t* screen2 = lv_obj_create(NULL);
lv_obj_t* label = lv_label_create(screen2);
lv_label_set_text(label, "HI!");
lv_obj_set_y(label,50);
lv_screen_load(screen2);
}
#include "BasicWidget.h"
#include "lvgl/lvgl.h"
void basic_label(void)
{
lv_obj_t* label = lv_label_create(lv_screen_active());
lv_label_set_text(label, "hello world!");
lv_obj_t* label2 = lv_label_create(lv_screen_active());
lv_obj_set_y(label2, 20);
lv_label_set_text_fmt(label2, "this is lable %d which is a %s string", 2, "formated");
lv_obj_set_width(label2, 100);
lv_obj_set_style_text_align(label2, LV_TEXT_ALIGN_CENTER, 0);
lv_obj_t* label3 = lv_label_create(lv_screen_active());
lv_label_set_text(label3, "Lorem ipsum dolor sit amet consectetur adipisicing elit.");
lv_obj_set_y(label3, 120);
lv_obj_set_width(label3, 140);
lv_obj_set_height(label3, 20);
lv_label_set_long_mode(label3, LV_LABEL_LONG_CLIP);
}
#include "BasicWidget.h"
#include "lvgl/lvgl.h"
void basic_led(void)
{
lv_obj_t* led = lv_led_create(lv_screen_active());
lv_led_off(led);
lv_obj_t* led2 = lv_led_create(lv_screen_active());
lv_led_set_color(led2, lv_palette_main(LV_PALETTE_LIME));
lv_obj_set_y(led2, 40);
lv_obj_t* led3 = lv_led_create(lv_screen_active());
lv_led_set_color(led3, lv_palette_main(LV_PALETTE_LIME));
lv_led_set_brightness(led3, 200);
lv_obj_set_y(led3, 80);
}
#include "BasicWidget.h"
#include "lvgl/lvgl.h"
void basic_line(void)
{
static lv_point_precise_t points[] = { {100,0},{0,100},{200,100},{100,0} };
static lv_style_t line_style;
lv_style_init(&line_style);
lv_style_set_line_width(&line_style, 12);
lv_style_set_line_color(&line_style, lv_palette_main(LV_PALETTE_INDIGO));
lv_style_set_line_rounded(&line_style, true);
lv_obj_t* line = lv_line_create(lv_screen_active());
lv_line_set_points(line, points, 4);
lv_obj_add_style(line, &line_style, 0);
lv_obj_center(line);
}
#include "BasicWidget.h"
#include "lvgl/lvgl.h"
void basic_bar(void)
{
lv_obj_t* bar = lv_bar_create(lv_screen_active());
lv_bar_set_value(bar, 50,LV_ANIM_ON);
}
#include "BasicWidget.h"
#include "lvgl/lvgl.h"
void basic_widget(void)
{
lv_obj_t* screen = lv_screen_active();
lv_obj_t* obj = lv_obj_create(screen);
lv_obj_set_width(obj, 100);
lv_obj_set_height(obj, 100);
lv_obj_set_x(obj, 100);
lv_obj_set_y(obj, 100);
lv_obj_t* label = lv_label_create(obj);
lv_label_set_text(label, "HI!");
lv_obj_set_y(label, 50);
}
#include "lvgl/lvgl.h"
#include "BasicEvent.h"
void on_clicked(lv_event_t* e)
{
int code = lv_event_get_code(e)
if (code == LV_EVENT_CLICKED)
{
lv_obj_t* led = (lv_obj_t*)e->user_data;
lv_led_toggle(led);
lv_log("CLICKED!\n");
}
if (code == LV_EVENT_VALUE_CHANGED)
{
lv_obj_t* btn2 = lv_event_get_target_obj(e);
lv_state_t state = lv_obj_get_state(btn2);
if (state == (LV_STATE_CHECKED | LV_STATE_FOCUSED))
{
lv_log("CHECKED!\n");
}
else
{
lv_log("UNCHECKED!\n");
}
}
}
void basic_button(void)
{
lv_obj_t* led = lv_led_create(lv_screen_active());
lv_led_off(led);
lv_obj_center(led);
lv_obj_t* btn = lv_button_create(lv_screen_active());
lv_obj_add_event_cb(btn, on_clicked, LV_EVENT_ALL, led);
lv_obj_t* btn_lbl = lv_label_create(btn);
lv_label_set_text(btn_lbl, "click me");
lv_obj_t* btn2 = lv_button_create(lv_screen_active());
lv_obj_add_flag(btn2, LV_OBJ_FLAG_CHECKABLE);
lv_obj_add_event_cb(btn2, on_clicked, LV_EVENT_ALL, led);
lv_obj_set_y(btn2, 50);
lv_obj_t* btn_lbl2 = lv_label_create(btn2);
lv_label_set_text(btn_lbl2, "click me");
}
#include "lvgl/lvgl.h"
#include "BasicEvent.h"
void on_drop_down(lv_event_t* e)
{
if (lv_event_get_code(e) == LV_EVENT_VALUE_CHANGED)
{
lv_obj_t* dd = lv_event_get_target_obj(e);
char result[10];
lv_dropdown_get_selected_str(dd, result, sizeof(result));
lv_log("selected %s \n", result);
}
}
static const char* fruit_options =
"Apple\n"
"Banana\n"
"Pear";
void basic_dropdown(void)
{
lv_obj_t* dd = lv_dropdown_create(lv_screen_active());
lv_obj_add_event_cb(dd, on_drop_down, LV_EVENT_ALL, NULL);
lv_dropdown_set_options_static(dd, fruit_options);
lv_dropdown_set_dir(dd, LV_DIR_RIGHT);
}
#include "lvgl/lvgl.h"
#include "BasicEvent.h"
void on_text_changed(lv_event_t* e)
{
lv_obj_t* text_input = lv_event_get_target_obj(e);
lv_obj_t* kb = (lv_obj_t*)lv_event_get_user_data(e);
int code = lv_event_get_code(e)
if (code == LV_EVENT_VALUE_CHANGED)
{
lv_log("text is: %s\n", lv_textarea_get_text(text_input));
}
if (code == LV_EVENT_FOCUSED)
{
lv_keyboard_set_textarea(kb, text_input);
lv_obj_remove_flag(kb, LV_OBJ_FLAG_HIDDEN);
}
if (code == LV_EVENT_DEFOCUSED)
{
lv_keyboard_set_textarea(kb, NULL);
lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN);
}
}
void basic_keyboard(void)
{
lv_obj_t* kb = lv_keyboard_create(lv_screen_active());
lv_obj_t* text_input = lv_textarea_create(lv_screen_active());
lv_obj_add_event_cb(text_input, on_text_changed, LV_EVENT_ALL, kb);
lv_textarea_set_placeholder_text(text_input, "First Name");
lv_textarea_set_one_line(text_input, true);
lv_keyboard_set_textarea(kb, text_input);
lv_obj_t* sw = lv_switch_create(lv_screen_active());
lv_obj_set_x(sw,300 );
lv_obj_set_style_text_font(kb, &lv_font_dejavu_16_persian_hebrew, 0);
lv_obj_set_style_text_font(text_input, &lv_font_dejavu_16_persian_hebrew, 0);
}
#include "lvgl/lvgl.h"
#include "BasicWidget.h"
void on_checked(lv_event_t* e)
{
if (lv_event_get_code(e) == LV_EVENT_VALUE_CHANGED)
{
lv_obj_t* chk = lv_event_get_target_obj(e);
lv_state_t state = lv_obj_get_state(chk);
if (state & LV_STATE_CHECKED)
{
lv_log("checked\n");
}
else
{
lv_log("unchecked\n");
}
}
}
void basic_checkbox(void)
{
lv_obj_t* chk = lv_checkbox_create(lv_screen_active());
lv_checkbox_set_text(chk, "check me");
lv_obj_add_state(chk, LV_STATE_CHECKED);
lv_obj_add_event_cb(chk, on_checked, LV_EVENT_ALL, NULL);
}
#include "lvgl/lvgl.h"
#include "BasicWidget.h"
static void slider_event_cb(lv_event_t* e)
{
lv_obj_t* slider = lv_event_get_target_obj(e);
lv_obj_t* slider_label = (lv_obj_t*)lv_event_get_user_data(e);
lv_label_set_text_fmt(slider_label, "value is %d%%", lv_slider_get_value(slider));
}
void basic_slider(void)
{
lv_obj_t* slider_label = lv_label_create(lv_screen_active());
lv_label_set_text(slider_label, "0%");
lv_obj_set_y(slider_label, 50);
lv_obj_t* slider = lv_slider_create(lv_screen_active());
lv_obj_center(slider);
lv_obj_add_event_cb(slider, slider_event_cb, LV_EVENT_VALUE_CHANGED, slider_label);
}
#include "lvgl/lvgl.h"
#include "BasicWidget.h"
void on_switch(lv_event_t* e)
{
if (lv_event_get_code(e) == LV_EVENT_VALUE_CHANGED)
{
lv_obj_t* sw = lv_event_get_target_obj(e);
if (lv_obj_has_state(sw, LV_STATE_CHECKED)) {
lv_log("checked\n");
}
else {
lv_log("unchecked\n");
}
}
}
void basic_switch(void)
{
lv_obj_t* sw = lv_switch_create(lv_screen_active());
lv_obj_add_state(sw, LV_STATE_CHECKED);
lv_obj_add_event_cb(sw, on_switch, LV_EVENT_ALL, NULL);
}
#include "lvgl/lvgl.h"
void style_theory(void)
{
static lv_style_t style;
lv_style_init(&style);
lv_style_set_x(&style, 50);
lv_style_set_y(&style, 50);
lv_style_set_size(&style, 150, 150);
lv_style_set_border_width(&style, 10);
lv_style_set_border_color(&style, lv_palette_main(LV_PALETTE_PURPLE));
lv_style_set_pad_top(&style, 100);
lv_style_set_pad_left(&style, 0);
lv_style_set_radius(&style, 50);
lv_style_set_outline_width(&style, 15);
lv_style_set_outline_color(&style,lv_palette_main(LV_PALETTE_CYAN));
lv_style_set_outline_pad(&style, 20);
lv_obj_t* obj = lv_obj_create(lv_screen_active());
lv_obj_t* lbl = lv_label_create(obj);
lv_label_set_text(lbl, "hello world!");
lv_obj_set_align(lbl, LV_ALIGN_CENTER);
lv_obj_t* obj2 = lv_obj_create(lv_screen_active());
lv_obj_add_style(obj, &style, 0);
lv_obj_add_style(obj2, &style, 0);
lv_obj_set_x(obj2, 200);
}
#include "lvgl/lvgl.h"
void style_theory(void)
{
static lv_style_t style;
lv_style_init(&style);
lv_style_set_x(&style, 50);
lv_style_set_y(&style, 50);
lv_style_set_size(&style, 150, 150);
lv_style_set_border_width(&style, 10);
lv_style_set_border_color(&style, lv_palette_main(LV_PALETTE_PURPLE));
lv_style_set_pad_top(&style, 100);
lv_style_set_pad_left(&style, 0);
lv_style_set_radius(&style, 50);
lv_style_set_outline_width(&style, 15);
lv_style_set_outline_color(&style,lv_palette_main(LV_PALETTE_CYAN));
lv_style_set_outline_pad(&style, 20);
lv_obj_t* obj = lv_obj_create(lv_screen_active());
lv_obj_t* lbl = lv_label_create(obj);
lv_label_set_text(lbl, "hello world!");
lv_obj_set_align(lbl, LV_ALIGN_CENTER);
lv_obj_t* obj2 = lv_obj_create(lv_screen_active());
lv_obj_add_style(obj, &style, 0);
lv_obj_add_style(obj2, &style, 0);
lv_obj_set_x(obj2, 200);
}
#include "lvgl/lvgl.h"
void style_states(void)
{
static lv_style_t style1;
lv_style_init(&style1);
lv_style_set_bg_color(&style1, lv_color_make(0, 255, 0));
lv_style_set_border_width(&style1, 5);
lv_style_set_border_color(&style1, lv_color_make(255, 0, 0));
static lv_style_t style2;
lv_style_init(&style2);
lv_style_set_bg_color(&style2, lv_color_hex(0x8027d9));
lv_obj_t* obj = lv_obj_create(lv_screen_active());
lv_obj_add_style(obj, &style1, LV_STATE_DEFAULT);
lv_obj_add_style(obj, &style2, LV_STATE_PRESSED);
}
#include "lvgl/lvgl.h"
void style_transitions(void)
{
static lv_style_t style1;
lv_style_init(&style1);
lv_style_set_bg_color(&style1, lv_color_make(0, 255, 0));
lv_style_set_border_width(&style1, 5);
lv_style_set_border_color(&style1, lv_color_make(255, 0, 0));
lv_style_set_shadow_color(&style1, lv_palette_main(LV_PALETTE_GREY));
lv_style_set_shadow_width(&style1, 4);
lv_style_set_shadow_ofs_x(&style1, 12);
lv_style_set_shadow_ofs_y(&style1, 12);
lv_style_set_shadow_opa(&style1, 100);
static lv_style_t style2;
lv_style_init(&style2);
lv_style_set_bg_color(&style2, lv_color_hex(0x8027d9));
lv_style_set_shadow_ofs_x(&style2, 4);
lv_style_set_shadow_ofs_y(&style2, 4);
lv_obj_t* obj = lv_obj_create(lv_screen_active());
lv_obj_add_style(obj, &style1, LV_STATE_DEFAULT);
lv_obj_add_style(obj, &style2, LV_STATE_PRESSED);
static lv_style_prop_t trans_props[] = { LV_STYLE_BG_COLOR,LV_STYLE_SHADOW_OFFSET_X,
LV_STYLE_SHADOW_OFFSET_Y, 0 };
static lv_style_transition_dsc_t trans1;
lv_style_transition_dsc_init(&trans1, trans_props, lv_anim_path_ease_in, 100, 50, NULL);
lv_style_set_transition(&style1, &trans1);
}
#include "lvgl/lvgl.h"
void translation(void)
{
static lv_style_t style_press;
lv_style_init(&style_press);
lv_style_set_translate_y(&style_press, -20);
lv_obj_t* btn1 = lv_btn_create(lv_screen_active());
lv_label_set_text(lv_label_create(btn1),"click me");
lv_obj_center(btn1);
lv_obj_add_style(btn1, &style_press, LV_STATE_PRESSED);
}
#include "lvgl/lvgl.h"
void transformation(void)
{
static lv_style_t style;
lv_style_init(&style);
lv_style_set_transform_rotation(&style, 3600);
lv_style_set_transform_pivot_x(&style, lv_pct(50));
lv_style_set_transform_pivot_y(&style, lv_pct(50));
lv_style_set_transform_scale(&style, 100);
lv_obj_t* obj = lv_obj_create(lv_screen_active());
lv_obj_center(obj);
lv_obj_add_style(obj, &style, LV_STATE_PRESSED);
static lv_style_prop_t tans_proprops[] = {
LV_STYLE_TRANSFORM_ROTATION,
LV_STYLE_TRANSFORM_SCALE_X,
LV_STYLE_TRANSFORM_SCALE_Y,
0
};
static lv_style_transition_dsc_t trans;
lv_style_transition_dsc_init(&trans, tans_proprops, lv_anim_path_ease_in_out, 300, 10, NULL);
lv_style_set_transition(&style, &trans);
}
#include "lvgl/lvgl.h"
static lv_style_t style;
void global_vs_local_styles(void)
{
lv_style_init(&style);
lv_style_set_bg_color(&style, lv_palette_main(LV_PALETTE_BLUE));
lv_obj_t* obj = lv_obj_create(lv_screen_active());
lv_obj_set_style_bg_color(obj, lv_palette_main(LV_PALETTE_GREEN), LV_STATE_DEFAULT);
lv_obj_center(obj);
lv_obj_add_style(obj, &style, LV_STATE_PRESSED);
}
#include "lvgl/lvgl.h"
void customizing_widgets(void)
{
static lv_style_t main;
lv_style_init(&main);
lv_style_set_bg_color(&main, lv_palette_main(LV_PALETTE_YELLOW));
lv_style_set_radius(&main, 0);
static lv_style_t indicator;
lv_style_init(&indicator);
lv_style_set_bg_color(&indicator, lv_palette_main(LV_PALETTE_RED));
lv_style_set_radius(&indicator, 0);
static lv_style_t knob;
lv_style_init(&knob);
lv_style_set_bg_color(&knob, lv_palette_main(LV_PALETTE_PURPLE));
lv_style_set_radius(&knob, 0);
lv_obj_t* sw = lv_switch_create(lv_screen_active());
lv_obj_add_style(sw, &main, LV_PART_MAIN);
lv_obj_add_style(sw, &indicator, LV_PART_INDICATOR | LV_STATE_CHECKED);
lv_obj_add_style(sw, &knob, LV_PART_KNOB);
}
#include "lvgl/lvgl.h"
void custom_theme(void)
{
lv_display_t* display = lv_display_get_default();
lv_theme_t* theme = lv_theme_default_init(display, lv_palette_main(LV_PALETTE_DEEP_PURPLE),
lv_palette_main(LV_PALETTE_LIGHT_GREEN), true, lv_font_default());
lv_display_set_theme(display, theme);
lv_obj_t* screen = lv_screen_active();
lv_obj_set_flex_align(screen,LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_obj_t* btn = lv_btn_create(screen);
lv_label_set_text(lv_label_create(btn), "click me!");
lv_switch_create(screen);
lv_slider_create(screen);
lv_obj_create(screen);
}
#include "lvgl/lvgl.h"
static lv_style_t style_btn;
void new_theme_apply_cb(lv_theme_t* lv_theme, lv_obj_t* obj)
{
LV_UNUSED(lv_theme);
if (lv_obj_check_type(obj, &lv_button_class)) {
lv_obj_add_style(obj, &style_btn,0);
}
}
void lv_theme_init_and_set(void)
{
lv_style_init(&style_btn);
lv_style_set_bg_color(&style_btn, lv_palette_main(LV_PALETTE_CYAN));
lv_style_set_border_color(&style_btn, lv_palette_darken(LV_PALETTE_CYAN,3));
lv_style_set_border_width(&style_btn, 3);
lv_theme_t * current_theme = lv_display_get_theme(NULL);
static lv_theme_t new_theme;
lv_theme_set_parent(&new_theme, current_theme);
lv_theme_set_apply_cb(&new_theme, new_theme_apply_cb);
lv_display_set_theme(NULL, &new_theme);
}
void custom_theme_2(void)
{
lv_obj_t* btn = lv_button_create(lv_screen_active());
lv_obj_align(btn, LV_ALIGN_TOP_MID, 0, 20);
lv_obj_t* label = lv_label_create(btn);
lv_label_set_text(label, "Original theme");
lv_theme_init_and_set();
btn = lv_button_create(lv_screen_active());
lv_obj_align(btn, LV_ALIGN_BOTTOM_MID, 0, -20);
label = lv_label_create(btn);
lv_label_set_text(label, "New theme");
}
#ifndef BASIC_IMAGES_H
#define BASIC_IMAGES_H
#ifdef __cplusplus
extern "C" {
#endif
void draw_image(void);
void image_compare(void);
void resize_image(void);
void image_background(void);
void load_jpg(void);
void basic_canvas(void);
LV_IMAGE_DECLARE(soldering_565);
LV_IMAGE_DECLARE(soldering_888);
LV_IMAGE_DECLARE(soldering_888a);
LV_IMAGE_DECLARE(chip565);
LV_IMAGE_DECLARE(chip565A8);
LV_IMAGE_DECLARE(chip888A);
#ifdef __cplusplus
}
#endif
#endif
#include "lvgl/lvgl.h"
#include "BasicImage.h"
void image_compare(void)
{
lv_obj_t* screen = lv_screen_active();
lv_obj_t* img = lv_image_create(screen);
lv_img_set_src(img, &soldering_565);
}
#include "lvgl/lvgl.h"
#include "BasicImage.h"
void draw_image(void)
{
lv_obj_t* screen = lv_screen_active();
lv_obj_set_flex_flow(screen, LV_FLEX_FLOW_ROW);
lv_obj_t* img565 = lv_image_create(screen);
lv_img_set_src(img565, &soldering_565);
lv_obj_t* img888 = lv_image_create(screen);
lv_img_set_src(img888, &soldering_888);
lv_obj_t* img888a = lv_image_create(screen);
lv_img_set_src(img888a, &soldering_888a);
lv_obj_t* img_chp565 = lv_image_create(screen);
lv_img_set_src(img_chp565, &chip565);
lv_obj_t* img_chp565a8 = lv_image_create(screen);
lv_img_set_src(img_chp565a8, &chip565A8);
lv_obj_t* img_chp888a = lv_image_create(screen);
lv_img_set_src(img_chp888a, &chip888A);
}
#include "lvgl/lvgl.h"
#include "BasicImage.h"
void resize_image(void)
{
lv_obj_t* screen = lv_screen_active();
//lv_obj_t* img888 = lv_image_create(screen);
//lv_img_set_src(img888, &soldering_888);
//lv_obj_set_width(img888, lv_obj_get_content_width(screen));
//lv_obj_set_height(img888, lv_obj_get_content_height(screen));
////lv_image_set_inner_align(img888, LV_IMAGE_ALIGN_TILE);
//lv_image_set_scale(img888, 350);
lv_obj_t* img_chip_888a = lv_image_create(screen);
lv_img_set_src(img_chip_888a, &chip888A);
lv_obj_set_width(img_chip_888a,200);
lv_obj_set_height(img_chip_888a, 200);
lv_image_set_scale(img_chip_888a, 80);
}
#include "lvgl/lvgl.h"
#include "BasicImage.h"
void image_background(void)
{
lv_obj_t* screen = lv_screen_active();
lv_obj_t* img888 = lv_image_create(screen);
lv_img_set_src(img888, &soldering_888);
lv_obj_set_width(img888, lv_obj_get_content_width(screen));
lv_obj_set_height(img888, lv_obj_get_content_height(screen));
lv_image_set_scale(img888, 350);
lv_obj_set_style_image_recolor(img888, lv_color_make(255, 255, 255), 0);
lv_obj_set_style_image_recolor_opa(img888, 220, 0);
lv_obj_t* img_chip_888a = lv_image_create(screen);
lv_img_set_src(img_chip_888a, &chip888A);
lv_obj_set_width(img_chip_888a, 200);
lv_obj_set_height(img_chip_888a, 200);
lv_image_set_scale(img_chip_888a, 80);
lv_obj_t* caption = lv_label_create(screen);
lv_label_set_text(caption, "This is a chip");
lv_obj_align_to(caption, img_chip_888a, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
}
#include "lvgl/lvgl.h"
#include "BasicImage.h"
void load_jpg(void)
{
lv_obj_t* screen = lv_screen_active();
lv_obj_t* img = lv_image_create(screen);
lv_img_set_src(img, "A:/mountain_landscape.jpg");
}
#include "lvgl/lvgl.h"
#include "BasicImage.h"
void basic_canvas(void)
{
LV_DRAW_BUF_DEFINE(draw_buf, 100, 100, LV_COLOR_FORMAT_ARGB8888);
lv_obj_t* canvas = lv_canvas_create(lv_screen_active());
lv_canvas_set_draw_buf(canvas, &draw_buf);
lv_obj_center(canvas);
lv_canvas_fill_bg(canvas, lv_color_hex3(0xeee), LV_OPA_COVER);
lv_layer_t layer;
lv_canvas_init_layer(canvas, &layer);
lv_draw_rect_dsc_t rect;
lv_draw_rect_dsc_init(&rect);
rect.bg_color = lv_palette_main(LV_PALETTE_RED);
rect.border_color = lv_palette_main(LV_PALETTE_BLUE);
rect.border_width = 3;
rect.radius = 4;
lv_area_t coords = { .x1 = 10, .y1 = 10, .x2 = 40, .y2 = 30 };
lv_draw_rect(&layer, &rect, &coords);
lv_draw_arc_dsc_t arc;
lv_draw_arc_dsc_init(&arc);
arc.center.x = 70;
arc.center.y = 20;
arc.radius = 15;
arc.width = 6;
arc.start_angle = 0;
arc.end_angle = 270;
arc.color = lv_palette_main(LV_PALETTE_PURPLE);
lv_draw_arc(&layer, &arc);
lv_draw_line_dsc_t line_dsc;
lv_draw_line_dsc_init(&line_dsc);
line_dsc.color = lv_palette_main(LV_PALETTE_CYAN);
line_dsc.width = 3;
line_dsc.p1.x = 50;
line_dsc.p1.y = 50;
line_dsc.p2.x = 100;
line_dsc.p2.y = 100;
lv_draw_line(&layer, &line_dsc);
lv_canvas_finish_layer(canvas, &layer);
}
#include "lvgl/lvgl.h"
void basic_fonts(void)
{
static lv_style_t style;
lv_style_init(&style);
lv_style_set_text_font(&style, &lv_font_montserrat_24);
lv_obj_t* label = lv_label_create(lv_screen_active());
lv_label_set_text(label, "Hello world!");
lv_obj_add_style(label, &style, 0);
lv_obj_t* label2 = lv_label_create(lv_screen_active());
lv_label_set_text(label2, "Hello world small");
lv_obj_set_style_text_font(label2, &lv_font_montserrat_14,0);
lv_obj_set_y(label2, 30);
lv_obj_t* label3 = lv_label_create(lv_screen_active());
lv_label_set_text(label3, "Hello world very small");
lv_obj_set_style_text_font(label3, &lv_font_montserrat_8, 0);
lv_obj_set_y(label3, 60);
lv_obj_t* label4 = lv_label_create(lv_screen_active());
lv_label_set_text(label4, "Hello world very big");
lv_obj_set_style_text_font(label4, &lv_font_montserrat_48, 0);
lv_obj_set_y(label4, 120);
lv_obj_t* label5 = lv_label_create(lv_screen_active());
lv_label_set_text(label5, "مرحبا بالعالم");
lv_obj_set_style_text_font(label5, &lv_font_dejavu_16_persian_hebrew, 0);
lv_obj_set_style_base_dir(label5, LV_BASE_DIR_RTL,0);
lv_obj_set_y(label5, 200);
lv_obj_t* label6 = lv_label_create(lv_screen_active());
lv_label_set_text(label6, "שלום עולם");
lv_obj_set_style_text_font(label6, &lv_font_dejavu_16_persian_hebrew, 0);
lv_obj_set_style_base_dir(label6, LV_BASE_DIR_RTL, 0);
lv_obj_set_y(label6, 250);
lv_obj_t* label7 = lv_label_create(lv_screen_active());
lv_label_set_text(label7, "你好世界");
lv_obj_set_style_text_font(label7, &lv_font_simsun_16_cjk, 0);
lv_obj_set_y(label7, 300);
}
#include "lvgl/lvgl.h"
#include "BasicFonts.h"
void custom_fonts(void)
{
static lv_style_t style;
lv_style_init(&style);
lv_style_set_text_font(&style, &Dancing_script_32);
lv_obj_t* label = lv_label_create(lv_screen_active());
lv_label_set_text(label, "Hello World");
lv_obj_add_style(label, &style,0);
}
#include "lvgl/lvgl.h"
#include "BasicFonts.h"
void symbols_built_in(void)
{
lv_obj_t* label = lv_label_create(lv_screen_active());
lv_obj_set_style_text_font(label, &lv_font_montserrat_48, 0);
lv_label_set_text(label, "This is a scissars " LV_SYMBOL_CUT " " LV_SYMBOL_SD_CARD);
#include "lvgl/lvgl.h"
#include "BasicFonts.h"
#include <stdio.h>
// https://lvgl.io/tools/fontconverter
#define SYMBOL_CLOUD 0Xf0c2
#define SYMBOL_RAIN 0Xf73d
#define SYMBOL_BOLT 0Xf0e7
char* utf8_encode(char* out, uint32_t utf);
void symbols_custom(void)
{
char buffer[5] = { 0 };
lv_obj_t* spans = lv_spangroup_create(lv_screen_active());
lv_obj_set_width(spans, 400);
lv_obj_set_height(spans, 400);
lv_obj_center(spans);
lv_spangroup_set_align(spans, LV_TEXT_ALIGN_LEFT);
lv_spangroup_set_overflow(spans, LV_SPAN_OVERFLOW_CLIP);
lv_spangroup_set_mode(spans, LV_SPAN_MODE_BREAK);
lv_span_t* span = lv_spangroup_new_span(spans);
lv_span_set_text(span, "It will be cloudy ");
lv_style_set_text_font(&span->style, &lv_font_montserrat_24);
span = lv_spangroup_new_span(spans);
lv_span_set_text(span, utf8_encode(buffer, SYMBOL_CLOUD));
lv_style_set_text_font(&span->style, &fa_solid_16);
lv_style_set_text_color(&span->style, lv_palette_main(LV_PALETTE_PINK));
span = lv_spangroup_new_span(spans);
lv_span_set_text(span, " and rainy ");
lv_style_set_text_font(&span->style, &lv_font_montserrat_24);
span = lv_spangroup_new_span(spans);
lv_span_set_text(span, utf8_encode(buffer, SYMBOL_RAIN));
lv_style_set_text_font(&span->style, &fa_solid_16);
lv_style_set_text_color(&span->style, lv_palette_main(LV_PALETTE_PINK));
span = lv_spangroup_new_span(spans);
lv_span_set_text(span, "\nwith a chance of thunder");
lv_style_set_text_font(&span->style, &lv_font_montserrat_24);
span = lv_spangroup_new_span(spans);
lv_span_set_text(span, utf8_encode(buffer, SYMBOL_BOLT));
lv_style_set_text_font(&span->style, &fa_solid_16);
lv_style_set_text_color(&span->style, lv_palette_main(LV_PALETTE_PINK));
lv_spangroup_refr_mode(spans);
}
char* utf8_encode(char* out, uint32_t utf)
{
if (utf <= 0x7F) {
// Plain ASCII
out[0] = (char)utf;
out[1] = 0;
return out;
}
else if (utf <= 0x07FF) {
// 2-byte unicode
out[0] = (char)(((utf >> 6) & 0x1F) | 0xC0);
out[1] = (char)(((utf >> 0) & 0x3F) | 0x80);
out[2] = 0;
return out;
}
else if (utf <= 0xFFFF) {
// 3-byte unicode
out[0] = (char)(((utf >> 12) & 0x0F) | 0xE0);
out[1] = (char)(((utf >> 6) & 0x3F) | 0x80);
out[2] = (char)(((utf >> 0) & 0x3F) | 0x80);
out[3] = 0;
return out;
}
else if (utf <= 0x10FFFF) {
// 4-byte unicode
out[0] = (char)(((utf >> 18) & 0x07) | 0xF0);
out[1] = (char)(((utf >> 12) & 0x3F) | 0x80);
out[2] = (char)(((utf >> 6) & 0x3F) | 0x80);
out[3] = (char)(((utf >> 0) & 0x3F) | 0x80);
out[4] = 0;
return out;
}
else {
// error - use replacement character
out[0] = (char)0xEF;
out[1] = (char)0xBF;
out[2] = (char)0xBD;
out[3] = 0;
return NULL;
}
}
#include "lvgl/lvgl.h"
#include "BasicAnimaitons.h"
void basic_animations(void)
{
lv_obj_t* header = lv_label_create(lv_screen_active());
lv_label_set_text(header, "Welcome to Animations");
lv_anim_t animation;
lv_anim_init(&animation);
lv_anim_set_exec_cb(&animation, (lv_anim_exec_xcb_t)lv_obj_set_x);
lv_anim_set_values(&animation, -200, (lv_obj_get_content_width(lv_screen_active()) / 2)
- lv_obj_get_self_width(header) / 2);
lv_anim_set_var(&animation, header);
lv_anim_set_duration(&animation, 1500);
lv_anim_set_delay(&animation, 600);
lv_anim_set_path_cb(&animation, lv_anim_path_ease_in);
lv_anim_start(&animation);
}
#include "lvgl/lvgl.h"
#include "BasicAnimaitons.h"
static void animation_cb(lv_obj_t* obj, int32_t value)
{
lv_obj_set_style_text_color(obj, lv_color_hsv_to_rgb(275, value, 100), 0);
}
void basic_with_cb(void)
{
lv_obj_t* header = lv_label_create(lv_screen_active());
lv_label_set_text(header, "Welcome to Animations");
lv_anim_t animation;
lv_anim_init(&animation);
lv_anim_set_exec_cb(&animation, (lv_anim_exec_xcb_t) animation_cb);
lv_anim_set_values(&animation, 0, 100);
lv_anim_set_var(&animation, header);
lv_anim_set_duration(&animation, 1500);
lv_anim_set_delay(&animation, 1000);
lv_anim_set_path_cb(&animation, lv_anim_path_ease_in);
lv_anim_start(&animation);
lv_anim_set_exec_cb(&animation, (lv_anim_exec_xcb_t)lv_obj_set_x);
lv_anim_set_values(&animation, -200, (lv_obj_get_content_width(lv_screen_active()) / 2)
- lv_obj_get_self_width(header) / 2);
lv_anim_start(&animation);
}
#include "lvgl/lvgl.h"
static void set_anim_pos(lv_anim_t* anim, int32_t v)
{
lv_obj_align((lv_obj_t *)anim->var, LV_ALIGN_TOP_MID, 0, v);
}
static void on_slider_change(lv_event_t* e)
{
lv_obj_t* slider = lv_event_get_current_target_obj(e);
lv_anim_timeline_t* anim_timeline = (lv_anim_timeline_t*)lv_event_get_user_data(e);
int32_t preogress = lv_slider_get_value(slider);
lv_anim_timeline_set_progress(anim_timeline, preogress);
}
void timeline_animation(void)
{
lv_obj_t* screen = lv_screen_active();
lv_obj_t* paragraph1 = lv_label_create(screen);
lv_obj_set_width(paragraph1, 600);
lv_label_set_text(paragraph1, "30+ built-in widgets, 100+ style properties, web inspired layout managers, and a typography system supporting many languages."
"All these features fit in a very small memory footprint.For example, LVGL and this demo required only : ");
lv_obj_t* paragraph2 = lv_label_create(screen);
lv_obj_set_width(paragraph2, 600);
lv_label_set_text(paragraph2, "30+ built-in widgets, 100+ style properties, web inspired layout managers, and a typography system supporting many languages."
"All these features fit in a very small memory footprint.For example, LVGL and this demo required only : ");
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, paragraph1);
lv_anim_set_values(&a, 600, 50);
lv_anim_set_custom_exec_cb(&a, set_anim_pos);
lv_anim_set_path_cb(&a, lv_anim_path_linear);
lv_anim_set_duration(&a, 800);
lv_anim_t b;
lv_anim_init(&b);
lv_anim_set_var(&b, paragraph2);
lv_anim_set_values(&b, 600, 200);
lv_anim_set_custom_exec_cb(&b, set_anim_pos);
lv_anim_set_path_cb(&b, lv_anim_path_linear);
lv_anim_set_duration(&b, 800);
lv_anim_timeline_t * anim_timeline = lv_anim_timeline_create();
lv_anim_timeline_add(anim_timeline, 0, &a);
lv_anim_timeline_add(anim_timeline, 400, &b);
lv_anim_timeline_start(anim_timeline);
lv_obj_t* slider = lv_slider_create(screen);
lv_slider_set_range(slider, 0, LV_ANIM_TIMELINE_PROGRESS_MAX);
lv_obj_add_event_cb(slider, on_slider_change, LV_EVENT_VALUE_CHANGED, anim_timeline);
}
#include "lvgl/lvgl.h"
static int time = 0;
void on_toggle(lv_event_t* e) {
lv_timer_t* timer = (lv_timer_t*)lv_event_get_user_data(e);
lv_obj_t* toggle_btn = lv_event_get_current_target_obj(e);
lv_obj_t* label = lv_obj_get_child(toggle_btn, 0);
if (lv_obj_get_state(toggle_btn) & LV_STATE_CHECKED) {
lv_label_set_text(label, "resume");
lv_timer_pause(timer);
}
else {
lv_label_set_text(label, "pause");
lv_timer_resume(timer);
}
}
void on_timer(lv_timer_t* timer)
{
lv_obj_t* stop_watch = (lv_obj_t*) timer->user_data;
lv_label_set_text_fmt(stop_watch, "%03d", time++);
}
void basic_timer(void){
lv_obj_t* stop_watch = lv_label_create(lv_screen_active());
lv_label_set_text_fmt(stop_watch, "%03d", time);
lv_obj_center(stop_watch);
lv_timer_t* timer = lv_timer_create(on_timer, 1, stop_watch);
lv_obj_t* toggle_btn = lv_button_create(lv_screen_active());
lv_label_set_text(lv_label_create(toggle_btn), "pause");
lv_obj_add_flag(toggle_btn, LV_OBJ_FLAG_CHECKABLE);
lv_obj_add_event_cb(toggle_btn, on_toggle, LV_EVENT_CLICKED, timer);
}
#include "lvgl/lvgl.h"
void draw_chart(void)
{
lv_obj_t* wrapper = lv_obj_create(lv_screen_active());
lv_obj_remove_style_all(wrapper);
lv_obj_set_size(wrapper, lv_pct(100), lv_pct(100));
lv_obj_set_flex_flow(wrapper, LV_FLEX_FLOW_COLUMN);
lv_obj_set_flex_align(wrapper, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_obj_t* chart = lv_chart_create(wrapper);
lv_obj_set_size(chart, lv_pct(95), lv_pct(50));
lv_chart_set_type(chart, LV_CHART_TYPE_SCATTER);
lv_chart_set_point_count(chart, 12);
lv_obj_set_style_line_width(chart, 0, LV_PART_ITEMS);
lv_chart_series_t* ser = lv_chart_add_series(chart, lv_color_hex(0x00ffff), LV_CHART_AXIS_PRIMARY_Y);
for (int i = 0; i < 12; i++){
lv_chart_set_next_value2(chart, ser, lv_rand(0,100), lv_rand(0, 100));
}
lv_chart_series_t* ser1 = lv_chart_add_series(chart, lv_color_hex(0xffcc00), LV_CHART_AXIS_PRIMARY_Y);
for (int i = 0; i < 12; i++) {
lv_chart_set_next_value2(chart, ser1, lv_rand(0, 100), lv_rand(0, 100));
}
lv_obj_t* x_scale = lv_scale_create(wrapper);
lv_obj_set_size(x_scale, lv_pct(95), lv_pct(50));
lv_scale_set_range(x_scale, 0, 12);
static const char* months[13] = { "Jan", "Feb", "Mar", "Apr","May", "Jun", "Jul", "Aug", "Sep",
"Oct", "Nov", "Dec", NULL };
lv_scale_set_text_src(x_scale, months);
lv_scale_set_total_tick_count(x_scale, 45);
lv_scale_set_major_tick_every(x_scale, 4);
lv_obj_set_style_length(x_scale, 10, LV_PART_INDICATOR);
lv_obj_set_style_length(x_scale, 5, LV_PART_ITEMS);
lv_obj_set_style_pad_hor(x_scale, lv_chart_get_first_point_center_offset(chart), 0);
}
We offer a comprehensive online course in mastering LVGL, developed with the team at LVGL .io, to give you a head start in learning to use this powerful tool.
Who this course is for
Embedded systems engineers
Entrepreneurs
Perfect for programmers looking to understand each LVGL function
Learning outcomes
Set up fundamentals: Install the relevant simulator and GitHub libraries
Walk through the basics: Code line-by-line. with underlying logic to ensure understanding.
Professional appearance: Build graphical user interfaces optimized for small screens
Port your project to chip: See your designs on your display, and debug any issues
Requirements and materials
Some experience coding in C or C++
A computer, microcontroller and screen of your choice, with appropriate cables is all you need to get started.
You’ll also receive code snippets to enhance your learning experience
Course format
Enjoy videos with supplemental code snippets.
Participate at your own pace, with recordings available for later review
LVGL (Light and Versatile Graphics Library) is the most popular, free and open-source graphics library for creating Graphical User Interfaces (GUIs) with very small resource requirements. This makes it perfect for devices such as 16, 32 and 64-bit micro controllers (including the PIC, ESP32, STM32 and high-end Arduinos).
LVGL will work on any screen of any size including very cheap and small TFT (Thin Film Transistor) colour screens, making it ideal for projects with space constraints including watch faces, thermostats, coffee machines, etc.
LVGL has many ‘widgets’ built in, enabling developers to build powerful applications with good looking UI’s that include button, dropdowns, charts, images and many more. This allows applications to have dashboards, forms and other UI’s that support advanced layouts, animations, custom themes, etc. It has built in interactivity for buttons, touch screens, mice, keypads, and keyboards making it easy for users to interact with your User Interface.
These features allow you to create applications that look slick and feel responsive.
LVGL is written in C/C++ however, the community has also put together bindings for python, Rust, JavaScript, and Zig
LVGL is free and opensource under the MIT license. This makes LVGL ideal for both commercial and hobby applications.
We cover how the library works, setting up a simulator as well as usage on a variety of chips including the Arduino and the ESP32