update asserts

This commit is contained in:
Gabor Kiss-Vamosi
2021-02-08 09:53:03 +01:00
parent 956a367dbc
commit 7bec13c2b9
173 changed files with 4906 additions and 696 deletions
+14
View File
@@ -0,0 +1,14 @@
#include "../../../lvgl.h"
#if LV_USE_ARC
void lv_example_arc_1(void)
{
/*Create an Arc*/
lv_obj_t * arc = lv_arc_create(lv_scr_act(), NULL);
lv_arc_set_end_angle(arc, 200);
lv_obj_set_size(arc, 150, 150);
lv_obj_align(arc, NULL, LV_ALIGN_CENTER, 0, 0);
}
#endif
+12
View File
@@ -0,0 +1,12 @@
# Create style for the Arcs
style = lv.style_t()
lv.style_copy(style, lv.style_plain)
style.line.color = lv.color_make(0,0,255) # Arc color
style.line.width = 8 # Arc width
# Create an Arc
arc = lv.arc(lv.scr_act())
arc.set_style(lv.arc.STYLE.MAIN, style) # Use the new style
arc.set_angles(90, 60)
arc.set_size(150, 150)
arc.align(None, lv.ALIGN.CENTER, 0, 0)
+38
View File
@@ -0,0 +1,38 @@
#include "../../../lvgl.h"
#if LV_USE_ARC
/**
* An `lv_task` to call periodically to set the angles of the arc
* @param t
*/
static void arc_loader(lv_timer_t * t)
{
static int16_t a = 270;
a+=5;
lv_arc_set_end_angle(t->user_data, a);
if(a >= 270 + 360) {
lv_timer_del(t);
return;
}
}
/**
* Create an arc which acts as a loader.
*/
void lv_example_arc_2(void)
{
/*Create an Arc*/
lv_obj_t * arc = lv_arc_create(lv_scr_act(), NULL);
lv_arc_set_bg_angles(arc, 0, 360);
lv_arc_set_angles(arc, 270, 270);
lv_obj_align(arc, NULL, LV_ALIGN_CENTER, 0, 0);
/* Create an `lv_task` to update the arc.
* Store the `arc` in the user data*/
lv_timer_create(arc_loader, 20, arc);
}
#endif
+43
View File
@@ -0,0 +1,43 @@
# Create an arc which acts as a loader.
class loader_arc(lv.arc):
def __init__(self, parent, color=lv.color_hex(0x000080),
width=8, style=lv.style_plain, rate=20):
super().__init__(parent)
self.a = 0
self.rate = rate
# Create style for the Arcs
self.style = lv.style_t()
lv.style_copy(self.style, style)
self.style.line.color = color
self.style.line.width = width
# Create an Arc
self.set_angles(180, 180);
self.set_style(self.STYLE.MAIN, self.style);
# Spin the Arc
self.spin()
def spin(self):
# Create an `lv_task` to update the arc.
lv.task_create(self.task_cb, self.rate, lv.TASK_PRIO.LOWEST, {})
# An `lv_task` to call periodically to set the angles of the arc
def task_cb(self, task):
self.a+=5;
if self.a >= 359: self.a = 359
if self.a < 180: self.set_angles(180-self.a, 180)
else: self.set_angles(540-self.a, 180)
if self.a == 359:
self.a = 0
lv.task_del(task)
# Create a loader arc
loader_arc = loader_arc(lv.scr_act())
loader_arc.align(None, lv.ALIGN.CENTER, 0, 0)
+12
View File
@@ -0,0 +1,12 @@
#include "../../../lvgl.h"
#if LV_USE_BAR
void lv_example_bar_1(void)
{
lv_obj_t * bar1 = lv_bar_create(lv_scr_act(), NULL);
lv_obj_set_size(bar1, 200, 20);
lv_obj_align(bar1, NULL, LV_ALIGN_CENTER, 0, 0);
lv_bar_set_value(bar1, 70, LV_ANIM_OFF);
}
#endif
+5
View File
@@ -0,0 +1,5 @@
bar1 = lv.bar(lv.scr_act())
bar1.set_size(200, 30)
bar1.align(None, lv.ALIGN.CENTER, 0, 0)
bar1.set_anim_time(1000)
bar1.set_value(100, lv.ANIM.ON)
+37
View File
@@ -0,0 +1,37 @@
#include "../../../lvgl.h"
#if LV_USE_BAR
static void set_temp(lv_obj_t * bar, int32_t temp)
{
lv_bar_set_value(bar, temp, LV_ANIM_ON);
static char buf[10]; /*Only the pointer t saved so must be static*/
lv_snprintf(buf, sizeof(buf), "%d°C", temp);
lv_obj_set_style_content_text(bar, LV_PART_INDICATOR, LV_STATE_DEFAULT, buf);
}
/**
* A temperature meter example
*/
void lv_example_bar_3(void)
{
static lv_style_t style_indic;
lv_style_init(&style_indic);
lv_style_set_bg_opa(&style_indic, LV_OPA_COVER);
lv_style_set_bg_color(&style_indic, LV_COLOR_RED);
lv_style_set_bg_grad_color(&style_indic, LV_COLOR_BLUE);
lv_style_set_bg_grad_dir(&style_indic, LV_GRAD_DIR_VER);
lv_style_set_content_align(&style_indic, LV_ALIGN_OUT_LEFT_TOP);
lv_style_set_content_ofs_x(&style_indic, -3);
lv_obj_t * bar = lv_bar_create(lv_scr_act(), NULL);
lv_obj_add_style(bar, LV_PART_INDICATOR, LV_STATE_DEFAULT, &style_indic);
lv_obj_set_size(bar, 20, 200);
lv_obj_align(bar, NULL, LV_ALIGN_CENTER, 0, 0);
lv_bar_set_range(bar, -20, 40);
set_temp(bar, 30);
}
#endif
+27
View File
@@ -0,0 +1,27 @@
#include "../../../lvgl.h"
#if LV_USE_BAR
/**
* Bar with stripe pattern and ranged value
*/
void lv_example_bar_4(void)
{
LV_IMG_DECLARE(img_skew_strip);
static lv_style_t style_indic;
lv_style_init(&style_indic);
lv_style_set_bg_img_src(&style_indic, &img_skew_strip);
lv_style_set_bg_img_tiled(&style_indic, true);
lv_style_set_bg_img_opa(&style_indic, LV_OPA_30);
lv_obj_t * bar = lv_bar_create(lv_scr_act(), NULL);
lv_obj_add_style(bar, LV_PART_INDICATOR, LV_STATE_DEFAULT, &style_indic);
lv_obj_set_size(bar, 260, 20);
lv_obj_align(bar, NULL, LV_ALIGN_CENTER, 0, 0);
lv_bar_set_type(bar, LV_BAR_TYPE_RANGE);
lv_bar_set_value(bar, 90, LV_ANIM_OFF);
lv_bar_set_start_value(bar, 20, LV_ANIM_OFF);
}
#endif
+30
View File
@@ -0,0 +1,30 @@
#include "../../../lvgl.h"
#if LV_USE_BAR
/**
* Bar with LTR and RTL base direction
*/
void lv_example_bar_5(void)
{
static lv_style_t style_bg;
lv_style_init(&style_bg);
lv_style_set_content_ofs_y(&style_bg, -3);
lv_style_set_content_align(&style_bg, LV_ALIGN_OUT_TOP_MID);
lv_obj_t * bar_ltr = lv_bar_create(lv_scr_act(), NULL);
lv_obj_set_size(bar_ltr, 200, 20);
lv_bar_set_value(bar_ltr, 70, LV_ANIM_OFF);
lv_obj_align(bar_ltr, NULL, LV_ALIGN_CENTER, 0, -30);
lv_obj_add_style(bar_ltr, LV_PART_MAIN, LV_STATE_DEFAULT, &style_bg);
lv_obj_set_style_content_text(bar_ltr, LV_PART_MAIN, LV_STATE_DEFAULT, "Left to Right base direction");
lv_obj_t * bar_rtl = lv_bar_create(lv_scr_act(), NULL);
lv_obj_set_base_dir(bar_rtl, LV_BIDI_DIR_RTL);
lv_obj_set_size(bar_rtl, 200, 20);
lv_bar_set_value(bar_rtl, 70, LV_ANIM_OFF);
lv_obj_align(bar_rtl, NULL, LV_ALIGN_CENTER, 0, 30);
lv_obj_add_style(bar_rtl, LV_PART_MAIN, LV_STATE_DEFAULT, &style_bg);
lv_obj_set_style_content_text(bar_rtl, LV_PART_MAIN, LV_STATE_DEFAULT, "Right to Left base direction");
}
#endif
+68
View File
@@ -0,0 +1,68 @@
#include "../../../lvgl.h"
#if LV_USE_BAR
static void event_cb(lv_obj_t * obj, lv_event_t e)
{
if(e == LV_EVENT_DRAW_POST_END) {
lv_bar_t * bar = (lv_bar_t *)obj;
lv_draw_label_dsc_t dsc;
lv_draw_label_dsc_init(&dsc);
dsc.font = LV_THEME_FONT_NORMAL;
char buf[8];
lv_snprintf(buf, sizeof(buf), "%d", lv_bar_get_value(obj));
lv_point_t txt_size;
lv_txt_get_size(&txt_size, buf, dsc.font, dsc.letter_space, dsc.line_space, LV_COORD_MAX, dsc.flag);
lv_area_t txt_area;
/*If the indicator is long enough put the text inside on the right*/
if(lv_area_get_width(&bar->indic_area) > txt_size.x + 20) {
txt_area.x2 = bar->indic_area.x2 - 5;
txt_area.x1 = txt_area.x2 - txt_size.x + 1;
dsc.color = LV_COLOR_WHITE;
}
/*If the indicator is still short put the text out of it on the right */
else {
txt_area.x1 = bar->indic_area.x2 + 5;
txt_area.x2 = txt_area.x1 + txt_size.x - 1;
dsc.color = LV_COLOR_BLACK;
}
txt_area.y1 = bar->indic_area.y1 + (lv_area_get_height(&bar->indic_area) - txt_size.y) / 2;
txt_area.y2 = txt_area.y1 + txt_size.y - 1;
const lv_area_t * clip_area = lv_event_get_param();
lv_draw_label(&txt_area, clip_area, &dsc, buf, NULL);
}
}
/**
* Custom drawer on bar to display the current value
*/
void lv_example_bar_6(void)
{
static lv_style_t style_bg;
lv_style_init(&style_bg);
lv_style_set_content_ofs_y(&style_bg, -3);
lv_style_set_content_align(&style_bg, LV_ALIGN_OUT_TOP_MID);
lv_obj_t * bar = lv_bar_create(lv_scr_act(), NULL);
lv_obj_add_event_cb(bar, event_cb, NULL);
lv_obj_set_size(bar, 200, 20);
lv_obj_align(bar, NULL, LV_ALIGN_CENTER, 0, 0);
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, bar);
lv_anim_set_values(&a, 0, 100);
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t) lv_bar_set_value);
lv_anim_set_time(&a, 2000);
lv_anim_set_playback_time(&a, 2000);
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
lv_anim_start(&a);
}
#endif
+35
View File
@@ -0,0 +1,35 @@
#include "../../../lvgl.h"
#include <stdio.h>
#if LV_USE_BTN
static void event_handler(lv_obj_t * obj, lv_event_t event)
{
if(event == LV_EVENT_CLICKED) {
printf("Clicked\n");
}
else if(event == LV_EVENT_VALUE_CHANGED) {
printf("Toggled\n");
}
}
void lv_example_btn_1(void)
{
lv_obj_t * label;
lv_obj_t * btn1 = lv_btn_create(lv_scr_act(), NULL);
lv_obj_add_event_cb(btn1, event_handler, NULL);
lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, -40);
label = lv_label_create(btn1, NULL);
lv_label_set_text(label, "Button");
lv_obj_t * btn2 = lv_btn_create(lv_scr_act(), NULL);
lv_obj_add_event_cb(btn2, event_handler, NULL);
lv_obj_align(btn2, NULL, LV_ALIGN_CENTER, 0, 40);
lv_obj_add_flag(btn2, LV_OBJ_FLAG_CHECKABLE);
lv_obj_set_height(btn2, LV_SIZE_CONTENT);
label = lv_label_create(btn2, NULL);
lv_label_set_text(label, "Toggle");
}
#endif
+21
View File
@@ -0,0 +1,21 @@
def event_handler(obj, event):
if event == lv.EVENT.CLICKED:
print("Clicked")
btn1 = lv.btn(lv.scr_act())
btn1.set_event_cb(event_handler)
btn1.align(None, lv.ALIGN.CENTER, 0, -40)
label = lv.label(btn1)
label.set_text("Button")
btn2 = lv.btn(lv.scr_act())
# callback can be lambda:
btn2.set_event_cb(lambda obj, event: print("Toggled") if event == lv.EVENT.VALUE_CHANGED else None)
btn2.align(None, lv.ALIGN.CENTER, 0, 40)
btn2.set_toggle(True)
btn2.toggle()
btn2.set_fit2(lv.FIT.NONE, lv.FIT.TIGHT)
label = lv.label(btn2)
label.set_text("Toggled")
+52
View File
@@ -0,0 +1,52 @@
#include "../../../lvgl.h"
#include <stdio.h>
#if LV_USE_BTN
/**
* Style a button from scratch
*/
void lv_example_btn_2(void)
{
static lv_style_t style;
static lv_style_t style_pr;
lv_style_init(&style);
lv_style_init(&style_pr);
/*Init the default style*/
lv_style_set_radius(&style, 3);
lv_style_set_bg_opa(&style, LV_OPA_70);
lv_style_set_bg_color(&style, LV_COLOR_BLUE);
lv_style_set_bg_grad_color(&style, LV_COLOR_AQUA);
lv_style_set_bg_grad_dir(&style, LV_GRAD_DIR_VER);
lv_style_set_border_opa(&style, LV_OPA_40);
lv_style_set_border_width(&style, 2);
lv_style_set_border_color(&style, LV_COLOR_GRAY);
lv_style_set_shadow_width(&style, 8);
lv_style_set_shadow_color(&style, LV_COLOR_GRAY);
lv_style_set_shadow_ofs_x(&style, 8);
lv_style_set_shadow_ofs_y(&style, 8);
lv_style_set_text_color(&style, LV_COLOR_WHITE);
/*Init the pressed style*/
lv_style_set_shadow_ofs_x(&style_pr, 4);
lv_style_set_shadow_ofs_y(&style_pr, 4);
lv_style_set_color_filter_cb(&style_pr, lv_color_darken); /*Darken every color*/
lv_style_set_color_filter_opa(&style_pr, LV_OPA_30);
lv_obj_t * btn1 = lv_btn_create(lv_scr_act(), NULL);
lv_obj_remove_style(btn1, LV_PART_ANY, LV_STATE_ANY, NULL);
lv_obj_add_style(btn1, LV_PART_MAIN, LV_STATE_DEFAULT, &style);
lv_obj_add_style(btn1, LV_PART_MAIN, LV_STATE_PRESSED, &style_pr);
lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_t * label = lv_label_create(btn1, NULL);
lv_label_set_text(label, "Button");
lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
}
#endif
@@ -0,0 +1,31 @@
#include "../../../lvgl.h"
#include <stdio.h>
#if LV_USE_BTNMATRIX
static void event_handler(lv_obj_t * obj, lv_event_t event)
{
if(event == LV_EVENT_VALUE_CHANGED) {
uint32_t id = lv_btnmatrix_get_active_btn(obj);
const char * txt = lv_btnmatrix_get_btn_text(obj, id);
printf("%s was pressed\n", txt);
}
}
static const char * btnm_map[] = {"1", "2", "3", "4", "5", "\n",
"6", "7", "8", "9", "0", "\n",
"Action1", "Action2", ""};
void lv_example_btnmatrix_1(void)
{
lv_obj_t * btnm1 = lv_btnmatrix_create(lv_scr_act(), NULL);
lv_btnmatrix_set_map(btnm1, btnm_map);
lv_btnmatrix_set_btn_width(btnm1, 10, 2); /*Make "Action1" twice as wide as "Action2"*/
lv_btnmatrix_set_btn_ctrl(btnm1, 10, LV_BTNMATRIX_CTRL_CHECKABLE);
lv_btnmatrix_set_btn_ctrl(btnm1, 11, LV_BTNMATRIX_CTRL_CHECKED);
lv_obj_align(btnm1, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_add_event_cb(btnm1, event_handler, NULL);
}
#endif
@@ -0,0 +1,14 @@
def event_handler(obj, event):
if event == lv.EVENT.VALUE_CHANGED:
txt = obj.get_active_btn_text()
print("%s was pressed" % txt)
btnm_map = ["1", "2", "3", "4", "5", "\n",
"6", "7", "8", "9", "0", "\n",
"Action1", "Action2", ""]
btnm1 = lv.btnm(lv.scr_act())
btnm1.set_map(btnm_map)
btnm1.set_btn_width(10, 2) # Make "Action1" twice as wide as "Action2"
btnm1.align(None, lv.ALIGN.CENTER, 0, 0)
btnm1.set_event_cb(event_handler)
@@ -0,0 +1,71 @@
#include "../../../lvgl.h"
#include <stdio.h>
#if LV_USE_BTNMATRIX
void event_cb(lv_obj_t * obj, lv_event_t e)
{
if(e == LV_EVENT_DRAW_PART_BEGIN) {
lv_obj_draw_hook_dsc_t * dsc = lv_event_get_param();
/*Change the draw descriptor the 2nd button */
if(dsc->id == 1) {
dsc->rect_dsc->radius = 0;
if(lv_btnmatrix_get_pressed_btn(obj) == dsc->id) dsc->rect_dsc->bg_color = LV_COLOR_NAVY;
else dsc->rect_dsc->bg_color = LV_COLOR_BLUE;
dsc->rect_dsc->shadow_width = 6;
dsc->rect_dsc->shadow_ofs_x = 3;
dsc->rect_dsc->shadow_ofs_y = 3;
dsc->label_dsc->color = LV_COLOR_WHITE;
}
/*Change the draw descriptor the 3rd button */
else if(dsc->id == 2) {
dsc->rect_dsc->radius = LV_RADIUS_CIRCLE;
if(lv_btnmatrix_get_pressed_btn(obj) == dsc->id) dsc->rect_dsc->bg_color = LV_COLOR_MAROON;
else dsc->rect_dsc->bg_color = LV_COLOR_RED;
dsc->label_dsc->color = LV_COLOR_WHITE;
}
else if(dsc->id == 3) {
dsc->label_dsc->opa = LV_OPA_TRANSP; /*Hide the text if any*/
}
}
if(e == LV_EVENT_DRAW_PART_END) {
lv_obj_draw_hook_dsc_t * dsc = lv_event_get_param();
/*Add custom content to the 4th button when the button itself was drawn*/
if(dsc->id == 3) {
LV_IMG_DECLARE(img_star);
lv_img_header_t header;
lv_res_t res = lv_img_decoder_get_info(&img_star, &header);
if(res != LV_RES_OK) return;
lv_area_t a;
a.x1 = dsc->draw_area->x1 + (lv_area_get_width(dsc->draw_area) - header.w) / 2;
a.x2 = a.x1 + header.w - 1;
a.y1 = dsc->draw_area->y1 + (lv_area_get_height(dsc->draw_area) - header.h) / 2;
a.y2 = a.y1 + header.h - 1;
lv_draw_img_dsc_t img_draw_dsc;
lv_draw_img_dsc_init(&img_draw_dsc);
img_draw_dsc.recolor = LV_COLOR_BLACK;
if(lv_btnmatrix_get_pressed_btn(obj) == dsc->id) img_draw_dsc.recolor_opa = LV_OPA_30;
lv_draw_img(&a, dsc->clip_area, &img_star, &img_draw_dsc);
}
}
}
/**
* Add custom drawer to the button matrix to c
*/
void lv_example_btnmatrix_2(void)
{
lv_obj_t * btnm = lv_btnmatrix_create(lv_scr_act(), NULL);
lv_obj_add_event_cb(btnm, event_cb, NULL);
lv_obj_align(btnm, NULL, LV_ALIGN_CENTER, 0, 0);
}
#endif
@@ -0,0 +1,71 @@
#include "../../../lvgl.h"
#include <stdio.h>
#if LV_USE_BTNMATRIX
static void event_cb(lv_obj_t * obj, lv_event_t e)
{
if(e == LV_EVENT_VALUE_CHANGED) {
uint32_t id = lv_btnmatrix_get_active_btn(obj);
bool prev = id == 0 ? true : false;
bool next = id == 6 ? true : false;
if(prev || next) {
/*Find the checked button*/
uint32_t i;
for(i = 1; i < 7; i++) {
if(lv_btnmatrix_has_btn_ctrl(obj, i, LV_BTNMATRIX_CTRL_CHECKED)) break;
}
if(prev && i > 1) i--;
else if(next && i < 5) i++;
lv_btnmatrix_set_btn_ctrl(obj, i, LV_BTNMATRIX_CTRL_CHECKED);
}
}
}
/**
* Make a button group
*/
void lv_example_btnmatrix_3(void)
{
static lv_style_t style_bg;
lv_style_init(&style_bg);
lv_style_set_pad_all(&style_bg, 0);
lv_style_set_pad_gap(&style_bg, 0);
lv_style_set_clip_corner(&style_bg, true);
lv_style_set_radius(&style_bg, LV_RADIUS_CIRCLE);
lv_style_set_border_width(&style_bg, 0);
static lv_style_t style_btn;
lv_style_init(&style_btn);
lv_style_set_radius(&style_btn, 0);
lv_style_set_border_width(&style_btn, 1);
lv_style_set_border_opa(&style_btn, LV_OPA_50);
lv_style_set_border_color(&style_btn, LV_COLOR_GRAY);
lv_style_set_border_side(&style_btn, LV_BORDER_SIDE_INTERNAL);
lv_style_set_radius(&style_btn, 0);
static const char * map[] = {LV_SYMBOL_LEFT, "1", "2", "3", "4", "5", LV_SYMBOL_RIGHT, ""};
lv_obj_t * btnm = lv_btnmatrix_create(lv_scr_act(), NULL);
lv_btnmatrix_set_map(btnm, map);
lv_obj_add_style(btnm, LV_PART_MAIN, LV_STATE_DEFAULT, &style_bg);
lv_obj_add_style(btnm, LV_PART_ITEMS, LV_STATE_DEFAULT, &style_btn);
lv_obj_add_event_cb(btnm, event_cb, NULL);
lv_obj_set_size(btnm, 225, 35);
/*Allow selecting on one number at time*/
lv_btnmatrix_set_btn_ctrl_all(btnm, LV_BTNMATRIX_CTRL_CHECKABLE);
lv_btnmatrix_clear_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKABLE);
lv_btnmatrix_clear_btn_ctrl(btnm, 6, LV_BTNMATRIX_CTRL_CHECKABLE);
lv_btnmatrix_set_one_checked(btnm, true);
lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKED);
lv_obj_align(btnm, NULL, LV_ALIGN_CENTER, 0, 0);
}
#endif
@@ -0,0 +1,55 @@
#include "../../../lvgl.h"
#include <stdio.h>
#if LV_USE_CALENDAR
static void event_handler(lv_obj_t * obj, lv_event_t event)
{
if(event == LV_EVENT_VALUE_CHANGED) {
lv_calendar_date_t date;
if(lv_calendar_get_pressed_date(obj, &date)) {
printf("Clicked date: %02d.%02d.%d\n", date.day, date.month, date.year);
}
}
}
void lv_example_calendar_1(void)
{
lv_obj_t * calendar = lv_calendar_create(lv_scr_act());
lv_obj_set_size(calendar, 180, 180);
lv_obj_align(calendar, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_add_event_cb(calendar, event_handler, NULL);
/*Set today's date*/
lv_calendar_date_t today;
today.year = 2021;
today.month = 02;
today.day = 23;
lv_calendar_set_today_date(calendar, &today);
lv_calendar_set_showed_date(calendar, &today);
/*Highlight a few days*/
static lv_calendar_date_t highlighted_days[3]; /*Only its pointer will be saved so should be static*/
highlighted_days[0].year = 2020;
highlighted_days[0].month = 10;
highlighted_days[0].day = 6;
highlighted_days[1].year = 2020;
highlighted_days[1].month = 10;
highlighted_days[1].day = 11;
highlighted_days[2].year = 2020;
highlighted_days[2].month = 11;
highlighted_days[2].day = 22;
lv_calendar_set_highlighted_dates(calendar, highlighted_days, 3);
#if LV_USE_CALENDAR_HEADER_ARROW
lv_obj_t * h = lv_calendar_header_arrow_create(lv_scr_act(), calendar, 25);
lv_obj_align(h, NULL, LV_ALIGN_IN_TOP_MID, 0, 5);
lv_obj_align(calendar, h, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
#endif
}
#endif
@@ -0,0 +1,53 @@
#include "../../../lvgl.h"
#if LV_USE_CANVAS
#define CANVAS_WIDTH 200
#define CANVAS_HEIGHT 150
void lv_example_canvas_1(void)
{
lv_draw_rect_dsc_t rect_dsc;
lv_draw_rect_dsc_init(&rect_dsc);
rect_dsc.radius = 10;
rect_dsc.bg_opa = LV_OPA_COVER;
rect_dsc.bg_grad_dir = LV_GRAD_DIR_HOR;
rect_dsc.bg_color = LV_COLOR_RED;
rect_dsc.bg_grad_color = LV_COLOR_BLUE;
rect_dsc.border_width = 2;
rect_dsc.border_opa = LV_OPA_90;
rect_dsc.border_color = LV_COLOR_WHITE;
rect_dsc.shadow_width = 5;
rect_dsc.shadow_ofs_x = 5;
rect_dsc.shadow_ofs_y = 5;
lv_draw_label_dsc_t label_dsc;
lv_draw_label_dsc_init(&label_dsc);
label_dsc.color = LV_COLOR_YELLOW;
static lv_color_t cbuf[LV_CANVAS_BUF_SIZE_TRUE_COLOR(CANVAS_WIDTH, CANVAS_HEIGHT)];
lv_obj_t * canvas = lv_canvas_create(lv_scr_act(), NULL);
lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_TRUE_COLOR);
lv_obj_align(canvas, NULL, LV_ALIGN_CENTER, 0, 0);
lv_canvas_fill_bg(canvas, LV_COLOR_SILVER, LV_OPA_COVER);
lv_canvas_draw_rect(canvas, 70, 60, 100, 70, &rect_dsc);
lv_canvas_draw_text(canvas, 40, 20, 100, &label_dsc, "Some text on text canvas");
/* Test the rotation. It requires an other buffer where the orignal image is stored.
* So copy the current image to buffer and rotate it to the canvas */
static lv_color_t cbuf_tmp[CANVAS_WIDTH * CANVAS_HEIGHT];
memcpy(cbuf_tmp, cbuf, sizeof(cbuf_tmp));
lv_img_dsc_t img;
img.data = (void *)cbuf_tmp;
img.header.cf = LV_IMG_CF_TRUE_COLOR;
img.header.w = CANVAS_WIDTH;
img.header.h = CANVAS_HEIGHT;
lv_canvas_fill_bg(canvas, LV_COLOR_SILVER, LV_OPA_COVER);
lv_canvas_transform(canvas, &img, 30, LV_IMG_ZOOM_NONE, 0, 0, CANVAS_WIDTH / 2, CANVAS_HEIGHT / 2, true);
}
#endif
@@ -0,0 +1,38 @@
CANVAS_WIDTH = 200
CANVAS_HEIGHT = 150
style = lv.style_t()
lv.style_copy(style, lv.style_plain)
style.body.main_color = lv.color_make(0xFF,0,0)
style.body.grad_color = lv.color_make(0x80,0,0)
style.body.radius = 4
style.body.border.width = 2
style.body.border.color = lv.color_make(0xFF,0xFF,0xFF)
style.body.shadow.color = lv.color_make(0xFF,0xFF,0xFF)
style.body.shadow.width = 4
style.line.width = 2
style.line.color = lv.color_make(0,0,0)
style.text.color = lv.color_make(0,0,0xFF)
# CF.TRUE_COLOR requires 4 bytes per pixel
cbuf = bytearray(CANVAS_WIDTH * CANVAS_HEIGHT * 4)
canvas = lv.canvas(lv.scr_act())
canvas.set_buffer(cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, lv.img.CF.TRUE_COLOR)
canvas.align(None, lv.ALIGN.CENTER, 0, 0)
canvas.fill_bg(lv.color_make(0xC0, 0xC0, 0xC0))
canvas.draw_rect(70, 60, 100, 70, style)
canvas.draw_text(40, 20, 100, style, "Some text on text canvas", lv.label.ALIGN.LEFT)
# Test the rotation. It requires an other buffer where the orignal image is stored.
# So copy the current image to buffer and rotate it to the canvas
img = lv.img_dsc_t()
img.data = cbuf[:]
img.header.cf = lv.img.CF.TRUE_COLOR
img.header.w = CANVAS_WIDTH
img.header.h = CANVAS_HEIGHT
canvas.fill_bg(lv.color_make(0xC0, 0xC0, 0xC0))
canvas.rotate(img, 30, 0, 0, CANVAS_WIDTH // 2, CANVAS_HEIGHT // 2)
@@ -0,0 +1,44 @@
#include "../../../lvgl.h"
#if LV_USE_CANVAS
#define CANVAS_WIDTH 50
#define CANVAS_HEIGHT 50
/**
* Create a transparent canvas with Chroma keying and indexed color format (palette).
*/
void lv_example_canvas_2(void)
{
/*Create a button to better see the transparency*/
lv_btn_create(lv_scr_act(), NULL);
/*Create a buffer for the canvas*/
static lv_color_t cbuf[LV_CANVAS_BUF_SIZE_INDEXED_1BIT(CANVAS_WIDTH, CANVAS_HEIGHT)];
/*Create a canvas and initialize its the palette*/
lv_obj_t * canvas = lv_canvas_create(lv_scr_act(), NULL);
lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_INDEXED_1BIT);
lv_canvas_set_palette(canvas, 0, LV_COLOR_CHROMA_KEY);
lv_canvas_set_palette(canvas, 1, LV_COLOR_RED);
/*Create colors with the indices of the palette*/
lv_color_t c0;
lv_color_t c1;
c0.full = 0;
c1.full = 1;
/*Red background (There is no dedicated alpha channel in indexed images so LV_OPA_COVER is ignored)*/
lv_canvas_fill_bg(canvas, c1, LV_OPA_COVER);
/*Create hole on the canvas*/
uint32_t x;
uint32_t y;
for( y = 10; y < 30; y++) {
for( x = 5; x < 20; x++) {
lv_canvas_set_px(canvas, x, y, c0);
}
}
}
#endif
@@ -0,0 +1,41 @@
# Create a transparent canvas with Chroma keying and indexed color format (palette).
CANVAS_WIDTH = 50
CANVAS_HEIGHT = 50
def bufsize(w, h, bits, indexed=False):
"""this function determines required buffer size
depending on the color depth"""
size = (w * bits // 8 + 1) * h
if indexed:
# + 4 bytes per palette color
size += 4 * (2**bits)
return size
# Create a button to better see the transparency
lv.btn(lv.scr_act())
# Create a buffer for the canvas
cbuf = bytearray(bufsize(CANVAS_WIDTH, CANVAS_HEIGHT, 1, indexed=True))
# Create a canvas and initialize its the palette
canvas = lv.canvas(lv.scr_act())
canvas.set_buffer(cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, lv.img.CF.INDEXED_1BIT)
# transparent color can be defined in lv_conf.h and set to pure green by default
canvas.set_palette(0, lv.color_make(0x00, 0xFF, 0x00))
canvas.set_palette(1, lv.color_make(0xFF, 0x00, 0x00))
# Create colors with the indices of the palette
c0 = lv.color_t()
c1 = lv.color_t()
c0.full = 0
c1.full = 1
# Transparent background
canvas.fill_bg(c1)
# Create hole on the canvas
for y in range(10,30):
for x in range(5, 20):
canvas.set_px(x, y, c0)
@@ -0,0 +1,44 @@
#include "../../../lvgl.h"
#if LV_USE_CHART
void lv_example_chart_1(void)
{
/*Create a chart*/
lv_obj_t * chart;
chart = lv_chart_create(lv_scr_act(), NULL);
lv_obj_set_size(chart, 200, 150);
lv_obj_align(chart, NULL, LV_ALIGN_CENTER, 0, 0);
lv_chart_set_type(chart, LV_CHART_TYPE_LINE); /*Show lines and points too*/
/*Add two data series*/
lv_chart_series_t * ser1 = lv_chart_add_series(chart, LV_COLOR_RED, LV_CHART_AXIS_PRIMARY_Y);
lv_chart_series_t * ser2 = lv_chart_add_series(chart, LV_COLOR_GREEN, LV_CHART_AXIS_SECONDARY_Y);
/*Set the next points on 'ser1'*/
lv_chart_set_next_value(chart, ser1, 10);
lv_chart_set_next_value(chart, ser1, 10);
lv_chart_set_next_value(chart, ser1, 10);
lv_chart_set_next_value(chart, ser1, 10);
lv_chart_set_next_value(chart, ser1, 10);
lv_chart_set_next_value(chart, ser1, 10);
lv_chart_set_next_value(chart, ser1, 10);
lv_chart_set_next_value(chart, ser1, 30);
lv_chart_set_next_value(chart, ser1, 70);
lv_chart_set_next_value(chart, ser1, 90);
/*Directly set points on 'ser2'*/
ser2->points[0] = 90;
ser2->points[1] = 70;
ser2->points[2] = 65;
ser2->points[3] = 65;
ser2->points[4] = 65;
ser2->points[5] = 65;
ser2->points[6] = 65;
ser2->points[7] = 65;
ser2->points[8] = 65;
ser2->points[9] = 65;
lv_chart_refresh(chart); /*Required after direct set*/
}
#endif
@@ -0,0 +1,19 @@
# Create a chart
chart = lv.chart(lv.scr_act())
chart.set_size(200, 150)
chart.align(None, lv.ALIGN.CENTER, 0, 0)
chart.set_type(lv.chart.TYPE.POINT | lv.chart.TYPE.LINE) # Show lines and points too
chart.set_series_opa(lv.OPA._70) # Opacity of the data series
chart.set_series_width(4) # Line width and point radious
chart.set_range(0, 100)
# Add two data series
ser1 = chart.add_series(lv.color_make(0xFF,0,0))
ser2 = chart.add_series(lv.color_make(0,0x80,0))
# Set points on 'dl1'
chart.set_points(ser1, [10, 10, 10, 10, 10, 10, 10, 30, 70, 90])
# Set points on 'dl2'
chart.set_points(ser2, [90, 70, 65, 65, 65, 65, 65, 65, 65, 65])
@@ -0,0 +1,82 @@
#include "../../../lvgl.h"
#if LV_USE_CHART
static lv_obj_t * chart1;
static lv_chart_series_t * ser1;
static lv_chart_series_t * ser2;
static void event_cb(lv_obj_t * obj, lv_event_t e)
{
/*Add the faded area before the lines are drawn */
if(e == LV_EVENT_DRAW_PART_BEGIN) {
lv_obj_draw_hook_dsc_t * hook_dsc = lv_event_get_param();
if(hook_dsc->part != LV_PART_ITEMS) return;
if(!hook_dsc->p1 || !hook_dsc->p2) return;
/*Add a line mask that keeps the area below the line*/
lv_draw_mask_line_param_t line_mask_param;
lv_draw_mask_line_points_init(&line_mask_param, hook_dsc->p1->x, hook_dsc->p1->y, hook_dsc->p2->x, hook_dsc->p2->y, LV_DRAW_MASK_LINE_SIDE_BOTTOM);
int16_t line_mask_id = lv_draw_mask_add(&line_mask_param, NULL);
/*Add a fade effect: transparent bottom covering top*/
lv_coord_t h = lv_obj_get_height(obj);
lv_draw_mask_fade_param_t fade_mask_param;
lv_draw_mask_fade_init(&fade_mask_param, &obj->coords, LV_OPA_COVER, obj->coords.y1 + h / 8, LV_OPA_TRANSP,obj->coords.y2);
int16_t fade_mask_id = lv_draw_mask_add(&fade_mask_param, NULL);
/*Draw a rectangle that will be affected by the mask*/
lv_draw_rect_dsc_t draw_rect_dsc;
lv_draw_rect_dsc_init(&draw_rect_dsc);
draw_rect_dsc.bg_opa = LV_OPA_20;
draw_rect_dsc.bg_color = hook_dsc->line_dsc->color;
lv_area_t a;
a.x1 = hook_dsc->p1->x;
a.x2 = hook_dsc->p2->x - 1;
a.y1 = LV_MIN(hook_dsc->p1->y, hook_dsc->p2->y);
a.y2 = obj->coords.y2;
lv_draw_rect(&a, hook_dsc->clip_area, &draw_rect_dsc);
/*Remove the masks*/
lv_draw_mask_remove_id(line_mask_id);
lv_draw_mask_remove_id(fade_mask_id);
}
}
static void add_data(lv_timer_t * timer)
{
static uint32_t cnt = 0;
lv_chart_set_next_value(chart1, ser1, lv_rand(20, 90));
if(cnt % 4 == 0) lv_chart_set_next_value(chart1, ser2, lv_rand(40, 60));
cnt++;
}
/**
* Add a faded area effect to the line chart
*/
void lv_example_chart_2(void)
{
/*Create a chart1*/
chart1 = lv_chart_create(lv_scr_act(), NULL);
lv_obj_set_size(chart1, 200, 150);
lv_obj_align(chart1, NULL, LV_ALIGN_CENTER, 0, 0);
lv_chart_set_type(chart1, LV_CHART_TYPE_LINE); /*Show lines and points too*/
lv_obj_add_event_cb(chart1, event_cb, NULL);
/*Add two data series*/
ser1 = lv_chart_add_series(chart1, LV_COLOR_RED, LV_CHART_AXIS_PRIMARY_Y);
ser2 = lv_chart_add_series(chart1, LV_COLOR_BLUE, LV_CHART_AXIS_SECONDARY_Y);
uint32_t i;
for(i = 0; i < 10; i++) {
lv_chart_set_next_value(chart1, ser1, lv_rand(20, 90));
lv_chart_set_next_value(chart1, ser2, lv_rand(30, 70));
}
lv_timer_create(add_data, 200, NULL);
}
#endif
@@ -0,0 +1,75 @@
#include "../../../lvgl.h"
#if LV_USE_CHART
static void event_cb(lv_obj_t * chart, lv_event_t e)
{
if(e == LV_EVENT_DRAW_PART_BEGIN) {
lv_obj_draw_hook_dsc_t * hook_dsc = lv_event_get_param();
if(hook_dsc->part == LV_PART_MARKER && hook_dsc->sub_part_id == LV_CHART_AXIS_X) {
const char * month[] = {"Jan", "Febr", "March", "Apr", "May", "Jun", "July", "Aug", "Sept", "Oct", "Nov", "Dec"};
lv_snprintf(hook_dsc->text, sizeof(hook_dsc->text), "%s", month[hook_dsc->id]);
}
}
}
/**
* Add ticks and labels to the axis and demonstrate scrolling
*/
void lv_example_chart_3(void)
{
/*Create a chart*/
lv_obj_t * chart;
chart = lv_chart_create(lv_scr_act(), NULL);
lv_obj_set_size(chart, 200, 150);
lv_obj_align(chart, NULL, LV_ALIGN_CENTER, 0, 0);
lv_chart_set_type(chart, LV_CHART_TYPE_BAR);
lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_Y, 0, 100);
lv_chart_set_range(chart, LV_CHART_AXIS_SECONDARY_Y, 0, 400);
lv_chart_set_point_count(chart, 12);
lv_obj_add_event_cb(chart, event_cb, NULL);
/*Add ticks and label to every axis*/
lv_chart_set_axis_tick(chart, LV_CHART_AXIS_X, 10, 5, 12, 3, true, 40);
lv_chart_set_axis_tick(chart, LV_CHART_AXIS_PRIMARY_Y, 10, 5, 6, 2, true, 50);
lv_chart_set_axis_tick(chart, LV_CHART_AXIS_SECONDARY_Y, 10, 5, 3, 4, true, 50);
/*Zoom in a little in X*/
lv_chart_set_zoom_x(chart, 800);
/*Add two data series*/
lv_chart_series_t * ser1 = lv_chart_add_series(chart, LV_COLOR_RED, LV_CHART_AXIS_PRIMARY_Y);
lv_chart_series_t * ser2 = lv_chart_add_series(chart, LV_COLOR_GREEN, LV_CHART_AXIS_SECONDARY_Y);
/*Set the next points on 'ser1'*/
lv_chart_set_next_value(chart, ser1, 31);
lv_chart_set_next_value(chart, ser1, 66);
lv_chart_set_next_value(chart, ser1, 10);
lv_chart_set_next_value(chart, ser1, 89);
lv_chart_set_next_value(chart, ser1, 63);
lv_chart_set_next_value(chart, ser1, 56);
lv_chart_set_next_value(chart, ser1, 32);
lv_chart_set_next_value(chart, ser1, 35);
lv_chart_set_next_value(chart, ser1, 57);
lv_chart_set_next_value(chart, ser1, 85);
lv_chart_set_next_value(chart, ser1, 22);
lv_chart_set_next_value(chart, ser1, 58);
lv_coord_t * ser2_array = lv_chart_get_array(chart, ser2);
/*Directly set points on 'ser2'*/
ser2_array[0] = 92;
ser2_array[1] = 71;
ser2_array[2] = 61;
ser2_array[3] = 15;
ser2_array[4] = 21;
ser2_array[5] = 35;
ser2_array[6] = 35;
ser2_array[7] = 58;
ser2_array[8] = 31;
ser2_array[9] = 53;
ser2_array[10] = 33;
ser2_array[11] = 73;
lv_chart_refresh(chart); /*Required after direct set*/
}
#endif
@@ -0,0 +1,80 @@
#include "../../../lvgl.h"
#if LV_USE_CHART
static void event_cb(lv_obj_t * chart, lv_event_t e)
{
if(e == LV_EVENT_VALUE_CHANGED) {
lv_obj_invalidate(chart);
}
if(e == LV_EVENT_REFR_EXT_DRAW_SIZE) {
lv_coord_t * s = lv_event_get_param();
*s = LV_MAX(*s, 20);
}
else if(e == LV_EVENT_DRAW_POST_END) {
int32_t id = lv_chart_get_pressed_point(chart);
if(id < 0) return;
printf("Selected point %d\n", id);
lv_chart_series_t * ser = lv_chart_get_series_next(chart, NULL);
while(ser) {
lv_point_t p;
lv_chart_get_point_pos_by_id(chart, ser, id, &p);
lv_coord_t * y_array = lv_chart_get_array(chart, ser);
lv_coord_t value = y_array[id];
char buf[16];
lv_snprintf(buf, sizeof(buf), "$%d", value);
lv_draw_rect_dsc_t draw_rect_dsc;
lv_draw_rect_dsc_init(&draw_rect_dsc);
draw_rect_dsc.bg_color = LV_COLOR_BLACK;
draw_rect_dsc.bg_opa = LV_OPA_50;
draw_rect_dsc.radius = 3;
draw_rect_dsc.content_text = buf;
draw_rect_dsc.content_color = LV_COLOR_WHITE;
lv_area_t a;
a.x1 = chart->coords.x1 + p.x - 20;
a.x2 = chart->coords.x1 + p.x + 20;
a.y1 = chart->coords.y1 + p.y - 30;
a.y2 = chart->coords.y1 + p.y - 10;
const lv_area_t * clip_area = lv_event_get_param();
lv_draw_rect(&a, clip_area, &draw_rect_dsc);
ser = lv_chart_get_series_next(chart, ser);
}
}
}
/**
* Add ticks and labels to the axis and demonstrate scrolling
*/
void lv_example_chart_4(void)
{
/*Create a chart*/
lv_obj_t * chart;
chart = lv_chart_create(lv_scr_act(), NULL);
lv_obj_set_size(chart, 200, 150);
lv_obj_align(chart, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_add_event_cb(chart, event_cb, NULL);
lv_obj_refresh_ext_draw_size(chart);
/*Zoom in a little in X*/
lv_chart_set_zoom_x(chart, 800);
/*Add two data series*/
lv_chart_series_t * ser1 = lv_chart_add_series(chart, LV_COLOR_RED, LV_CHART_AXIS_PRIMARY_Y);
lv_chart_series_t * ser2 = lv_chart_add_series(chart, LV_COLOR_GREEN, LV_CHART_AXIS_PRIMARY_Y);
uint32_t i;
for(i = 0; i < 10; i++) {
lv_chart_set_next_value(chart, ser1, lv_rand(60,90));
lv_chart_set_next_value(chart, ser2, lv_rand(10,40));
}
}
#endif
@@ -0,0 +1,44 @@
#include "../../../lvgl.h"
#include <stdio.h>
#if LV_USE_CHECKBOX
static void event_handler(lv_obj_t * obj, lv_event_t event)
{
if(event == LV_EVENT_VALUE_CHANGED) {
const char * txt = lv_checkbox_get_text(obj);
const char * state = lv_obj_get_state(obj) & LV_STATE_CHECKED ? "Checked" : "Unchecked";
printf("%s: %s\n", txt, state);
}
}
void lv_example_checkbox_1(void)
{
static lv_flex_t flex_center;
lv_flex_init(&flex_center);
lv_flex_set_flow(&flex_center, LV_FLEX_FLOW_COLUMN);
lv_flex_set_place(&flex_center, LV_FLEX_PLACE_CENTER, LV_FLEX_PLACE_START, LV_FLEX_PLACE_CENTER);
lv_obj_set_layout(lv_scr_act(), &flex_center);
lv_obj_t * cb;
cb = lv_checkbox_create(lv_scr_act(), NULL);
lv_checkbox_set_text(cb, "Apple");
lv_obj_add_event_cb(cb, event_handler, NULL);
cb = lv_checkbox_create(lv_scr_act(), NULL);
lv_checkbox_set_text(cb, "Banana");
lv_obj_add_state(cb, LV_STATE_CHECKED);
lv_obj_add_event_cb(cb, event_handler, NULL);
cb = lv_checkbox_create(lv_scr_act(), NULL);
lv_checkbox_set_text(cb, "Lemon");
lv_obj_add_state(cb, LV_STATE_DISABLED);
lv_obj_add_event_cb(cb, event_handler, NULL);
cb = lv_checkbox_create(lv_scr_act(), NULL);
lv_obj_add_state(cb, LV_STATE_CHECKED | LV_STATE_DISABLED);
lv_checkbox_set_text(cb, "Melon");
lv_obj_add_event_cb(cb, event_handler, NULL);
}
#endif
@@ -0,0 +1,8 @@
def event_handler(obj, event):
if event == lv.EVENT.VALUE_CHANGED:
print("State: %s" % ("Checked" if obj.is_checked() else "Unchecked"))
cb = lv.cb(lv.scr_act())
cb.set_text("I agree to terms and conditions.")
cb.align(None, lv.ALIGN.CENTER, 0, 0)
cb.set_event_cb(event_handler)
@@ -0,0 +1,13 @@
#include "../../../lvgl.h"
#if LV_USE_COLORWHEEL
void lv_example_colorwheel_1(void)
{
lv_obj_t * cw;
cw = lv_colorwheel_create(lv_scr_act(), true);
lv_obj_set_size(cw, 200, 200);
lv_obj_align(cw, NULL, LV_ALIGN_CENTER, 0, 0);
}
#endif
@@ -0,0 +1,35 @@
#include "../../../lvgl.h"
#include <stdio.h>
#if LV_USE_DROPDOWN
static void event_handler(lv_obj_t * obj, lv_event_t event)
{
if(event == LV_EVENT_VALUE_CHANGED) {
char buf[32];
lv_dropdown_get_selected_str(obj, buf, sizeof(buf));
printf("Option: %s\n", buf);
}
}
void lv_example_dropdown_1(void)
{
/*Create a normal drop down list*/
lv_obj_t * dd = lv_dropdown_create(lv_scr_act(), NULL);
lv_dropdown_set_options(dd, "Apple\n"
"Banana\n"
"Orange\n"
"Cherry\n"
"Grape\n"
"Raspberry\n"
"Melon\n"
"Orange\n"
"Lemon\n"
"Nuts");
lv_obj_align(dd, NULL, LV_ALIGN_IN_TOP_MID, 0, 20);
lv_obj_add_event_cb(dd, event_handler, NULL);
}
#endif
@@ -0,0 +1,21 @@
def event_handler(obj, event):
if event == lv.EVENT.VALUE_CHANGED:
option = " "*10 # should be large enough to store the option
obj.get_selected_str(option, len(option))
# .strip() removes trailing spaces
print("Option: \"%s\"" % option.strip())
# Create a drop down list
ddlist = lv.ddlist(lv.scr_act())
ddlist.set_options("\n".join([
"Apple",
"Banana",
"Orange",
"Melon",
"Grape",
"Raspberry"]))
ddlist.set_fix_width(150)
ddlist.set_draw_arrow(True)
ddlist.align(None, lv.ALIGN.IN_TOP_MID, 0, 20)
ddlist.set_event_cb(event_handler)
@@ -0,0 +1,42 @@
#include "../../../lvgl.h"
#include <stdio.h>
#if LV_USE_DROPDOWN
/**
* Create a drop down, up, left and right menus
*/
void lv_example_dropdown_2(void)
{
static const char * opts = "Apple\n"
"Banana\n"
"Orange\n"
"Melon\n"
"Grape\n"
"Raspberry";
lv_obj_t * dd;
dd = lv_dropdown_create(lv_scr_act(), NULL);
lv_dropdown_set_options_static(dd, opts);
lv_obj_align(dd, NULL, LV_ALIGN_IN_TOP_MID, 0, 10);
dd = lv_dropdown_create(lv_scr_act(), NULL);
lv_dropdown_set_options_static(dd, opts);
lv_dropdown_set_dir(dd, LV_DIR_BOTTOM);
lv_dropdown_set_symbol(dd, LV_SYMBOL_UP);
lv_obj_align(dd, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, -10);
dd = lv_dropdown_create(lv_scr_act(), NULL);
lv_dropdown_set_options_static(dd, opts);
lv_dropdown_set_dir(dd, LV_DIR_RIGHT);
lv_dropdown_set_symbol(dd, LV_SYMBOL_RIGHT);
lv_obj_align(dd, NULL, LV_ALIGN_IN_LEFT_MID, 10, 0);
dd = lv_dropdown_create(lv_scr_act(), NULL);
lv_dropdown_set_options_static(dd, opts);
lv_dropdown_set_dir(dd, LV_DIR_LEFT);
lv_dropdown_set_symbol(dd, LV_SYMBOL_LEFT);
lv_obj_align(dd, NULL, LV_ALIGN_IN_RIGHT_MID, -10, 0);
}
#endif
@@ -0,0 +1,23 @@
# Create a drop UP list by applying auto realign
# Create a drop down list
ddlist = lv.ddlist(lv.scr_act())
ddlist.set_options("\n".join([
"Apple",
"Banana",
"Orange",
"Melon",
"Grape",
"Raspberry"]))
ddlist.set_fix_width(150)
ddlist.set_fix_height(150)
ddlist.set_draw_arrow(True)
# Enable auto-realign when the size changes.
# It will keep the bottom of the ddlist fixed
ddlist.set_auto_realign(True)
# It will be called automatically when the size changes
ddlist.align(None, lv.ALIGN.IN_BOTTOM_MID, 0, -20)
@@ -0,0 +1,34 @@
#include "../../../lvgl.h"
#include <stdio.h>
#if LV_USE_DROPDOWN
/**
* Create a menu from a drop-down list and show some drop-down list features and styling
*/
void lv_example_dropdown_3(void)
{
/*Create a drop down list*/
lv_obj_t * dd = lv_dropdown_create(lv_scr_act(), NULL);
lv_obj_align(dd, NULL, LV_ALIGN_IN_TOP_RIGHT, -10, 10);
lv_dropdown_set_options(dd, "New\n"
"Open\n"
"Edit\n"
"Close\n"
"Preferences\n"
"Exit");
/*Set a fixed text to display on the button of the drop-down list*/
lv_dropdown_set_text(dd, "Menu");
/*Use a custom image as down icon*/
LV_IMG_DECLARE(img_caret_down)
lv_dropdown_set_symbol(dd, &img_caret_down);
/* Remove the style of the selected part on the list.
* In a menu we don't need to show the last clicked item*/
lv_obj_t * list = lv_dropdown_get_list(dd);
lv_obj_remove_style(list, LV_PART_SELECTED, LV_STATE_DEFAULT, NULL);
}
#endif
+21
View File
@@ -0,0 +1,21 @@
C
^
Image from variable and symbol
"""""""""""""""""""""""""""""""
.. lv_example:: lv_ex_widgets/lv_ex_img/lv_ex_img_1
:language: c
Image recoloring
""""""""""""""""
.. lv_example:: lv_ex_widgets/lv_ex_img/lv_ex_img_2
:language: c
MicroPython
^^^^^^^^^^^
No examples yet.
+18
View File
@@ -0,0 +1,18 @@
#include "../../../lvgl.h"
#if LV_USE_IMG
/* Find the image here: https://github.com/lvgl/lv_examples/tree/master/assets */
LV_IMG_DECLARE(img_cogwheel_argb);
void lv_example_img_1(void)
{
lv_obj_t * img1 = lv_img_create(lv_scr_act(), NULL);
lv_img_set_src(img1, &img_cogwheel_argb);
lv_obj_align(img1, NULL, LV_ALIGN_CENTER, 0, -20);
lv_obj_t * img2 = lv_img_create(lv_scr_act(), NULL);
lv_img_set_src(img2, LV_SYMBOL_OK "Accept");
lv_obj_align(img2, img1, LV_ALIGN_OUT_BOTTOM_MID, 0, 20);
}
#endif
+29
View File
@@ -0,0 +1,29 @@
from imagetools import get_png_info, open_png
# Register PNG image decoder
decoder = lv.img.decoder_create()
decoder.info_cb = get_png_info
decoder.open_cb = open_png
# Create a screen with a draggable image
with open('cogwheel.png','rb') as f:
png_data = f.read()
png_img_dsc = lv.img_dsc_t({
'data_size': len(png_data),
'data': png_data
})
scr = lv.scr_act()
# Create an image on the left using the decoder
# lv.img.cache_set_size(2)
img1 = lv.img(scr)
img1.align(scr, lv.ALIGN.CENTER, 0, -20)
img1.set_src(png_img_dsc)
img2 = lv.img(scr)
img2.set_src(lv.SYMBOL.OK + "Accept")
img2.align(img1, lv.ALIGN.OUT_BOTTOM_MID, 0, 20)
+64
View File
@@ -0,0 +1,64 @@
#include "../../../lvgl.h"
#if LV_USE_IMG
static lv_obj_t * create_slider(lv_color_t color);
static void slider_event_cb(lv_obj_t * slider, lv_event_t event);
static lv_obj_t * red_slider, * green_slider, * blue_slider, * intense_slider;
static lv_obj_t * img1;
/**
* Demonstrate runtime image re-coloring
*/
void lv_example_img_2(void)
{
/*Create 4 sliders to adjust RGB color and re-color intensity*/
red_slider = create_slider(LV_COLOR_RED);
green_slider = create_slider(LV_COLOR_LIME);
blue_slider = create_slider(LV_COLOR_BLUE);
intense_slider = create_slider(LV_COLOR_GRAY);
lv_slider_set_value(red_slider, LV_OPA_20, LV_ANIM_OFF);
lv_slider_set_value(green_slider, LV_OPA_90, LV_ANIM_OFF);
lv_slider_set_value(blue_slider, LV_OPA_60, LV_ANIM_OFF);
lv_slider_set_value(intense_slider, LV_OPA_50, LV_ANIM_OFF);
lv_obj_align(red_slider, NULL, LV_ALIGN_IN_LEFT_MID, 25, 0);
lv_obj_align(green_slider, red_slider, LV_ALIGN_OUT_RIGHT_MID, 25, 0);
lv_obj_align(blue_slider, green_slider, LV_ALIGN_OUT_RIGHT_MID, 25, 0);
lv_obj_align(intense_slider, blue_slider, LV_ALIGN_OUT_RIGHT_MID, 25, 0);
/* Now create the actual image */
LV_IMG_DECLARE(img_cogwheel_argb);
img1 = lv_img_create(lv_scr_act(), NULL);
lv_img_set_src(img1, &img_cogwheel_argb);
lv_obj_align(img1, NULL, LV_ALIGN_IN_RIGHT_MID, -20, 0);
lv_event_send(intense_slider, LV_EVENT_VALUE_CHANGED, NULL);
}
static void slider_event_cb(lv_obj_t * slider, lv_event_t event)
{
if(event == LV_EVENT_VALUE_CHANGED) {
/* Recolor the image based on the sliders' values */
lv_color_t color = lv_color_make(lv_slider_get_value(red_slider), lv_slider_get_value(green_slider), lv_slider_get_value(blue_slider));
lv_opa_t intense = lv_slider_get_value(intense_slider);
lv_obj_set_style_img_recolor_opa(img1, LV_PART_MAIN, LV_STATE_DEFAULT, intense);
lv_obj_set_style_img_recolor(img1, LV_PART_MAIN, LV_STATE_DEFAULT, color);
}
}
static lv_obj_t * create_slider(lv_color_t color)
{
lv_obj_t * slider = lv_slider_create(lv_scr_act(), NULL);
lv_slider_set_range(slider, 0, 255);
lv_obj_set_size(slider, 10, 200);
lv_obj_set_style_bg_color(slider, LV_PART_KNOB, LV_STATE_DEFAULT, color);
lv_obj_set_style_bg_color(slider, LV_PART_INDICATOR, LV_STATE_DEFAULT, lv_color_darken(color, LV_OPA_40));
lv_obj_add_event_cb(slider, slider_event_cb, NULL);
return slider;
}
#endif
+33
View File
@@ -0,0 +1,33 @@
#include "../../../lvgl.h"
#if LV_USE_IMG
LV_IMG_DECLARE(img_cogwheel_argb);
/**
* Show transformations (zoom and rotation) using a pivot point.
*/
void lv_example_img_3(void)
{
/* Now create the actual image */
lv_obj_t * img = lv_img_create(lv_scr_act(), NULL);
lv_img_set_src(img, &img_cogwheel_argb);
lv_obj_align(img, NULL, LV_ALIGN_CENTER, 50, 50);
lv_img_set_pivot(img, 0, 0); /*Rotate around the top left corner*/
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, img);
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_img_set_angle);
lv_anim_set_values(&a, 0, 3600);
lv_anim_set_time(&a, 5000);
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
lv_anim_start(&a);
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_img_set_zoom);
lv_anim_set_values(&a, 128, 256);
lv_anim_set_playback_time(&a, 3000);
lv_anim_start(&a);
}
#endif
+36
View File
@@ -0,0 +1,36 @@
#include "../../../lvgl.h"
#if LV_USE_IMG
LV_IMG_DECLARE(img_skew_strip);
/**
* Image styling and offset
*/
void lv_example_img_4(void)
{
static lv_style_t style;
lv_style_init(&style);
lv_style_set_bg_color(&style, LV_COLOR_YELLOW);
lv_style_set_bg_opa(&style, LV_OPA_COVER);
lv_style_set_img_recolor_opa(&style, LV_OPA_COVER);
lv_style_set_img_recolor(&style, LV_COLOR_BLACK);
lv_obj_t * img = lv_img_create(lv_scr_act(), NULL);
lv_obj_add_style(img, LV_PART_MAIN, LV_STATE_DEFAULT, &style);
lv_img_set_src(img, &img_skew_strip);
lv_obj_set_size(img, 150, 100);
lv_obj_align(img, NULL, LV_ALIGN_CENTER, 0, 0);
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, img);
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_img_set_offset_y);
lv_anim_set_values(&a, 0, 100);
lv_anim_set_time(&a, 3000);
lv_anim_set_playback_time(&a, 500);
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
lv_anim_start(&a);
}
#endif
@@ -0,0 +1,37 @@
#include "../../../lvgl.h"
#if LV_USE_KEYBOARD
static void ta_event_cb(lv_obj_t * ta, lv_event_t e)
{
lv_obj_t * kb = lv_event_get_user_data();
if(e == LV_EVENT_FOCUSED) {
lv_keyboard_set_textarea(kb, ta);
lv_obj_clear_flag(kb, LV_OBJ_FLAG_HIDDEN);
}
if(e == LV_EVENT_DEFOCUSED) {
lv_keyboard_set_textarea(kb, NULL);
lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN);
}
}
void lv_keyboard_example_1(void)
{
/*Create a keyboard to use it with an of the text areas*/
lv_obj_t *kb = lv_keyboard_create(lv_scr_act());
/*Create a text area. The keyboard will write here*/
lv_obj_t * ta;
ta = lv_textarea_create(lv_scr_act(), NULL);
lv_obj_align(ta, NULL, LV_ALIGN_IN_TOP_LEFT, 10, 10);
lv_obj_add_event_cb(ta, ta_event_cb, kb);
lv_textarea_set_placeholder_text(ta, "Hello");
ta = lv_textarea_create(lv_scr_act(), NULL);
lv_obj_align(ta, NULL, LV_ALIGN_IN_TOP_RIGHT, -10, 10);
lv_obj_add_event_cb(ta, ta_event_cb, kb);
lv_keyboard_set_textarea(kb, ta);
}
#endif
@@ -0,0 +1,26 @@
# Create styles for the keyboard
rel_style = lv.style_t()
pr_style = lv.style_t()
lv.style_copy(rel_style, lv.style_btn_rel)
rel_style.body.radius = 0
rel_style.body.border.width = 1
lv.style_copy(pr_style, lv.style_btn_pr)
pr_style.body.radius = 0
pr_style.body.border.width = 1
# Create a keyboard and apply the styles
kb = lv.kb(lv.scr_act())
kb.set_cursor_manage(True)
kb.set_style(lv.kb.STYLE.BG, lv.style_transp_tight)
kb.set_style(lv.kb.STYLE.BTN_REL, rel_style)
kb.set_style(lv.kb.STYLE.BTN_PR, pr_style)
# Create a text area. The keyboard will write here
ta = lv.ta(lv.scr_act())
ta.align(None, lv.ALIGN.IN_TOP_MID, 0, 10)
ta.set_text("")
# Assign the text area to the keyboard
kb.set_ta(ta)
@@ -0,0 +1,26 @@
#include "../../../lvgl.h"
#if LV_USE_LABEL
/**
* Show line wrap, re-color, line align and text scrolling.
*/
void lv_example_label_1(void)
{
lv_obj_t * label1 = lv_label_create(lv_scr_act(), NULL);
lv_label_set_long_mode(label1, LV_LABEL_LONG_WRAP); /*Break the long lines*/
lv_label_set_recolor(label1, true); /*Enable re-coloring by commands in the text*/
lv_label_set_text(label1, "#0000ff Re-color# #ff00ff words# #ff0000 of a# label, align the lines to the center"
"and wrap long text automatically.");
lv_obj_set_width(label1, 150); /*Set smaller width to make the lines wrap*/
lv_obj_set_style_text_align(label1, LV_PART_MAIN, LV_STATE_DEFAULT, LV_TEXT_ALIGN_CENTER);
lv_obj_align(label1, NULL, LV_ALIGN_CENTER, 0, -40);
lv_obj_t * label2 = lv_label_create(lv_scr_act(), NULL);
lv_label_set_long_mode(label2, LV_LABEL_LONG_SROLL_CIRC); /*Circular scroll*/
lv_obj_set_width(label2, 150);
lv_label_set_text(label2, "It is a circularly scrolling text. ");
lv_obj_align(label2, NULL, LV_ALIGN_CENTER, 0, 40);
}
#endif
@@ -0,0 +1,14 @@
label1 = lv.label(lv.scr_act())
label1.set_long_mode(lv.label.LONG.BREAK) # Break the long lines
label1.set_recolor(True) # Enable re-coloring by commands in the text
label1.set_align(lv.label.ALIGN.CENTER) # Center aligned lines
label1.set_text("#000080 Re-color# #0000ff words# #6666ff of a# label " +
"and wrap long text automatically.")
label1.set_width(150)
label1.align(None, lv.ALIGN.CENTER, 0, -30)
label2 = lv.label(lv.scr_act())
label2.set_long_mode(lv.label.LONG.SROLL_CIRC) # Circular scroll
label2.set_width(150)
label2.set_text("It is a circularly scrolling text. ")
label2.align(None, lv.ALIGN.CENTER, 0, 30)
@@ -0,0 +1,36 @@
#include "../../../lvgl.h"
#if LV_USE_LABEL
/**
* Create a fake text shadow
*/
void lv_example_label_2(void)
{
/* Create a style for the shadow*/
static lv_style_t style_shadow;
lv_style_init(&style_shadow);
lv_style_set_text_opa(&style_shadow, LV_OPA_30);
lv_style_set_text_color(&style_shadow, LV_COLOR_BLACK);
/*Create a label for the shadow first (it's in the background) */
lv_obj_t * shadow_label = lv_label_create(lv_scr_act(), NULL);
lv_obj_add_style(shadow_label, LV_PART_MAIN, LV_STATE_DEFAULT, &style_shadow);
/* Create the main label */
lv_obj_t * main_label = lv_label_create(lv_scr_act(), NULL);
lv_label_set_text(main_label, "A simple method to create\n"
"shadows on a text.\n"
"It even works with\n\n"
"newlines and spaces.");
/*Set the same text for the shadow label*/
lv_label_set_text(shadow_label, lv_label_get_text(main_label));
/* Position the main label */
lv_obj_align(main_label, NULL, LV_ALIGN_CENTER, 0, 0);
/* Shift the second label down and to the right by 2 pixel */
lv_obj_align(shadow_label, main_label, LV_ALIGN_IN_TOP_LEFT, 2, 2);
}
#endif
@@ -0,0 +1,24 @@
# Create a style for the shadow
label_style = lv.style_t()
lv.style_copy(label_style, lv.style_plain)
label_style.text.opa = lv.OPA._50
# Create a label for the shadow first (it's in the background)
shadow_label = lv.label(lv.scr_act())
shadow_label.set_style(lv.label.STYLE.MAIN, label_style)
# Create the main label
main_label = lv.label(lv.scr_act())
main_label.set_text("A simple method to create\n" +
"shadows on text\n" +
"It even works with\n\n" +
"newlines and spaces.")
# Set the same text for the shadow label
shadow_label.set_text(main_label.get_text())
# Position the main label
main_label.align(None, lv.ALIGN.CENTER, 0, 0)
# Shift the second label down and to the right by 1 pixel
shadow_label.align(main_label, lv.ALIGN.IN_TOP_LEFT, 1, 1)
+22
View File
@@ -0,0 +1,22 @@
#include "../../../lvgl.h"
#if LV_USE_LED
void lv_example_led_1(void)
{
/*Create a LED and switch it OFF*/
lv_obj_t * led1 = lv_led_create(lv_scr_act());
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());
lv_obj_align(led2, NULL, LV_ALIGN_CENTER, 0, 0);
lv_led_set_bright(led2, 150);
/*Copy the previous LED and switch it ON*/
lv_obj_t * led3 = lv_led_create(lv_scr_act());
lv_obj_align(led3, NULL, LV_ALIGN_CENTER, 80, 0);
lv_led_on(led3);
}
#endif
+27
View File
@@ -0,0 +1,27 @@
# Create a style for the LED
style_led = lv.style_t()
lv.style_copy(style_led, lv.style_pretty_color)
style_led.body.radius = 800 # large enough to draw a circle
style_led.body.main_color = lv.color_make(0xb5, 0x0f, 0x04)
style_led.body.grad_color = lv.color_make(0x50, 0x07, 0x02)
style_led.body.border.color = lv.color_make(0xfa, 0x0f, 0x00)
style_led.body.border.width = 3
style_led.body.border.opa = lv.OPA._30
style_led.body.shadow.color = lv.color_make(0xb5, 0x0f, 0x04)
style_led.body.shadow.width = 5
# Create a LED and switch it OFF
led1 = lv.led(lv.scr_act())
led1.set_style(lv.led.STYLE.MAIN, style_led)
led1.align(None, lv.ALIGN.CENTER, -80, 0)
led1.off()
# Copy the previous LED and set a brightness
led2 = lv.led(lv.scr_act(), led1)
led2.align(None, lv.ALIGN.CENTER, 0, 0)
led2.set_bright(190)
# Copy the previous LED and switch it ON
led3 = lv.led(lv.scr_act(), led1)
led3.align(None, lv.ALIGN.CENTER, 80, 0)
led3.on()
+24
View File
@@ -0,0 +1,24 @@
#include "../../../lvgl.h"
#if LV_USE_LINE
void lv_example_line_1(void)
{
/*Create an array for the points of the line*/
static lv_point_t line_points[] = { {5, 5}, {70, 70}, {120, 10}, {180, 60}, {240, 10} };
/*Create style*/
static lv_style_t style_line;
lv_style_init(&style_line);
lv_style_set_line_width(&style_line, 8);
lv_style_set_line_color(&style_line, LV_COLOR_BLUE);
lv_style_set_line_rounded(&style_line, true);
/*Create a line and apply the new style*/
lv_obj_t * line1;
line1 = lv_line_create(lv_scr_act(), NULL);
lv_line_set_points(line1, line_points, 5); /*Set the points*/
lv_obj_add_style(line1, LV_PART_MAIN, LV_STATE_DEFAULT, &style_line); /*Set the points*/
lv_obj_align(line1, NULL, LV_ALIGN_CENTER, 0, 0);
}
#endif

Some files were not shown because too many files have changed in this diff Show More