refactoring

This commit is contained in:
Gabor Kiss-Vamosi
2021-02-07 22:39:54 +01:00
parent c43259814a
commit 956a367dbc
184 changed files with 207 additions and 4551 deletions

View File

@@ -1,40 +0,0 @@
/**
* @file lv_ex_get_started.h
*
*/
#ifndef LV_EX_GET_STARTED_H
#define LV_EX_GET_STARTED_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void lv_ex_get_started_1(void);
void lv_ex_get_started_2(void);
void lv_ex_get_started_3(void);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_EX_GET_STARTED_H*/

View File

@@ -1,28 +0,0 @@
#include "../../lvgl.h"
static void btn_event_cb(lv_obj_t * btn, lv_event_t event)
{
if(event == LV_EVENT_CLICKED) {
static uint8_t cnt = 0;
cnt++;
/*Get the first child of the button which is the label and change its text*/
lv_obj_t * label = lv_obj_get_child(btn, 0);
lv_label_set_text_fmt(label, "Button: %d", cnt);
}
}
/**
* Create a button with a label and react on Click event.
*/
void lv_ex_get_started_1(void)
{
lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL); /*Add a button the current screen*/
lv_obj_set_pos(btn, 10, 10); /*Set its position*/
lv_obj_set_size(btn, 120, 50); /*Set its size*/
lv_obj_add_event_cb(btn, btn_event_cb, NULL); /*Assign a callback to the button*/
lv_obj_t * label = lv_label_create(btn, NULL); /*Add a label to the button*/
lv_label_set_text(label, "Button"); /*Set the labels text*/
}

View File

@@ -1,83 +0,0 @@
//#include "../../lv_examples.h"
//
//
///**
// * Create styles from scratch for buttons.
// */
//void lv_ex_get_started_2(void)
//{
// static lv_style_t style_btn;
// static lv_style_t style_btn_red;
//
// /*Create a simple button style*/
// lv_style_init(&style_btn);
// lv_style_set_radius(&style_btn, LV_STATE_DEFAULT, 10);
// lv_style_set_bg_opa(&style_btn, LV_STATE_DEFAULT, LV_OPA_COVER);
// lv_style_set_bg_color(&style_btn, LV_STATE_DEFAULT, LV_COLOR_SILVER);
// lv_style_set_bg_grad_color(&style_btn, LV_STATE_DEFAULT, LV_COLOR_GRAY);
// lv_style_set_bg_grad_dir(&style_btn, LV_STATE_DEFAULT, LV_GRAD_DIR_VER);
//
// /*Swap the colors in pressed state*/
// lv_style_set_bg_color(&style_btn, LV_STATE_PRESSED, LV_COLOR_GRAY);
// lv_style_set_bg_grad_color(&style_btn, LV_STATE_PRESSED, LV_COLOR_SILVER);
//
// /*Add a border*/
// lv_style_set_border_color(&style_btn, LV_STATE_DEFAULT, LV_COLOR_WHITE);
// lv_style_set_border_opa(&style_btn, LV_STATE_DEFAULT, LV_OPA_70);
// lv_style_set_border_width(&style_btn, LV_STATE_DEFAULT, 2);
//
// /*Different border color in focused state*/
// lv_style_set_border_color(&style_btn, LV_STATE_FOCUSED, LV_COLOR_BLUE);
// lv_style_set_border_color(&style_btn, LV_STATE_FOCUSED | LV_STATE_PRESSED, LV_COLOR_NAVY);
//
// /*Set the text style*/
// lv_style_set_text_color(&style_btn, LV_STATE_DEFAULT, LV_COLOR_WHITE);
//
// /*Make the button smaller when pressed*/
// lv_style_set_transform_height(&style_btn, LV_STATE_PRESSED, -5);
// lv_style_set_transform_width(&style_btn, LV_STATE_PRESSED, -10);
//#if LV_USE_ANIMATION
// /*Add a transition to the size change*/
// static lv_anim_path_t path;
// lv_anim_path_init(&path);
// lv_anim_path_set_cb(&path, lv_anim_path_overshoot);
//
// lv_style_set_transition_prop_1(&style_btn, LV_STATE_DEFAULT, LV_STYLE_TRANSFORM_HEIGHT);
// lv_style_set_transition_prop_2(&style_btn, LV_STATE_DEFAULT, LV_STYLE_TRANSFORM_WIDTH);
// lv_style_set_transition_time(&style_btn, LV_STATE_DEFAULT, 300);
// lv_style_set_transition_path(&style_btn, LV_STATE_DEFAULT, &path);
//#endif
//
// /*Create a red style. Change only some colors.*/
// lv_style_init(&style_btn_red);
// lv_style_set_bg_color(&style_btn_red, LV_STATE_DEFAULT, LV_COLOR_RED);
// lv_style_set_bg_grad_color(&style_btn_red, LV_STATE_DEFAULT, LV_COLOR_MAROON);
// lv_style_set_bg_color(&style_btn_red, LV_STATE_PRESSED, LV_COLOR_MAROON);
// lv_style_set_bg_grad_color(&style_btn_red, LV_STATE_PRESSED, LV_COLOR_RED);
// lv_style_set_text_color(&style_btn_red, LV_STATE_DEFAULT, LV_COLOR_WHITE);
//#if LV_USE_BTN
// /*Create buttons and use the new styles*/
// lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL); /*Add a button the current screen*/
// lv_obj_set_pos(btn, 10, 10); /*Set its position*/
// lv_obj_set_size(btn, 120, 50); /*Set its size*/
// lv_obj_reset_style_list(btn, LV_BTN_PART_MAIN); /*Remove the styles coming from the theme*/
// lv_obj_add_style(btn, LV_BTN_PART_MAIN, &style_btn);
//
// lv_obj_t * label = lv_label_create(btn, NULL); /*Add a label to the button*/
// lv_label_set_text(label, "Button"); /*Set the labels text*/
//
// /*Create a new button*/
// lv_obj_t * btn2 = lv_btn_create(lv_scr_act(), btn);
// lv_obj_set_pos(btn2, 10, 80);
// lv_obj_set_size(btn2, 120, 50); /*Set its size*/
// lv_obj_reset_style_list(btn2, LV_BTN_PART_MAIN); /*Remove the styles coming from the theme*/
// lv_obj_add_style(btn2, LV_BTN_PART_MAIN, &style_btn);
// lv_obj_add_style(btn2, LV_BTN_PART_MAIN, &style_btn_red); /*Add the red style on top of the current */
// lv_obj_set_style_local_radius(btn2, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); /*Add a local style*/
//
// label = lv_label_create(btn2, NULL); /*Add a label to the button*/
// lv_label_set_text(label, "Button 2"); /*Set the labels text*/
//#endif
//}
//
//

View File

@@ -1,31 +0,0 @@
//#include "../../lv_examples.h"
//
//static lv_obj_t * label;
//
//static void slider_event_cb(lv_obj_t * slider, lv_event_t event)
//{
// if(event == LV_EVENT_VALUE_CHANGED) {
// /*Refresh the text*/
// lv_label_set_text_fmt(label, "%d", lv_slider_get_value(slider));
// lv_obj_align(label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 20); /*Align below the slider*/
// }
//}
//
///**
// * Create a slider and write its value on a label.
// */
//void lv_ex_get_started_3(void)
//{
// /* Create a slider in the center of the display */
// lv_obj_t * slider = lv_slider_create(lv_scr_act(), NULL);
// lv_obj_set_width(slider, 200); /*Set the width*/
// lv_obj_align(slider, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the center of the parent (screen)*/
// lv_obj_set_event_cb(slider, slider_event_cb); /*Assign an event function*/
//
// /* Create a label below the slider */
// label = lv_label_create(lv_scr_act(), NULL);
// lv_label_set_text(label, "0");
// lv_obj_align(label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 20); /*Align below the slider*/
//}
//
//

View File

@@ -1,37 +0,0 @@
/**
* @file lv_ex_flex.h
*
*/
#ifndef LV_EX_FLEX_H
#define LV_EX_FLEX_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_EX_FLEX_H*/

View File

@@ -1,43 +0,0 @@
//#include "../../lv_examples.h"
//
///**
// * A simple row and a column layout with flexbox
// */
//void lv_ex_flex_1(void)
//{
// /*Create a container with ROW flex direction*/
// lv_obj_t * cont_row = lv_obj_create(lv_scr_act(), NULL);
// lv_obj_set_size(cont_row, 300, 75);
// lv_obj_align(cont_row, NULL, LV_ALIGN_IN_TOP_MID, 0, 5);
// lv_obj_set_flex_dir(cont_row, LV_FLEX_DIR_ROW);
// lv_obj_set_flex_gap(cont_row, 10);
//
// /*Create a container with COLUMN flex direction*/
// lv_obj_t * cont_col = lv_obj_create(lv_scr_act(), NULL);
// lv_obj_set_size(cont_col, 200, 150);
// lv_obj_align(cont_col, cont_row, LV_ALIGN_OUT_BOTTOM_MID, 0, 5);
// lv_obj_set_flex_dir(cont_col, LV_FLEX_DIR_COLUMN);
// lv_obj_set_flex_gap(cont_col, 10);
//
// uint32_t i;
// for(i = 0; i < 10; i++) {
// /*Add items to the row*/
// lv_obj_t * obj1 = lv_obj_create(cont_row, NULL);
// lv_obj_set_size(obj1, 100, LV_COORD_PCT(100));
// lv_obj_set_flex_item(obj1, true);
//
// lv_obj_t * label1 = lv_label_create(obj1, NULL);
// lv_label_set_text_fmt(label1, "Item: %d", i);
// lv_obj_align(label1, NULL, LV_ALIGN_CENTER, 0, 0);
//
// /*Add items to the column*/
// lv_obj_t * obj2 = lv_obj_create(cont_col, NULL);
// lv_obj_set_size(obj2, LV_COORD_PCT(100), LV_SIZE_AUTO);
// lv_obj_set_flex_item(obj2, true);
//
// lv_obj_t * label3 = lv_label_create(obj2, NULL);
// lv_label_set_text_fmt(label3, "Item: %d", i);
// lv_obj_align(label3, NULL, LV_ALIGN_CENTER, 0, 0);
// }
//}
//

View File

@@ -1,24 +0,0 @@
//#include "../../lv_examples.h"
//
///**
// * Arrange items in column with wrap and place the row to get even space around them.
// */
//void lv_ex_flex_2(void)
//{
// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
// lv_obj_set_size(cont, 300, 220);
// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
// lv_obj_set_flex_dir(cont, LV_FLEX_DIR_COLUMN_WRAP);
// lv_obj_set_flex_place(cont, LV_FLEX_PLACE_START, LV_FLEX_PLACE_START);
//
// uint32_t i;
// for(i = 0; i < 3; i++) {
// lv_obj_t * obj = lv_obj_create(cont, NULL);
// lv_obj_set_flex_item_place(obj, LV_FLEX_PLACE_STRETCH);
// lv_obj_set_size(obj, 70, LV_SIZE_AUTO);
//
// lv_obj_t * label = lv_label_create(obj, NULL);
// lv_label_set_text_fmt(label, "%d", i);
// }
//}
//

View File

@@ -1,30 +0,0 @@
//#include "../../lv_examples.h"
//
///**
// * Arrange items in a row and demonstrate flex grow.
// */
//void lv_ex_flex_3(void)
//{
// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
// lv_obj_set_size(cont, 300, 220);
// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
// lv_obj_set_flex_dir(cont, LV_FLEX_DIR_ROW);
//
// lv_obj_t * obj;
// obj = lv_obj_create(cont, NULL);
// lv_obj_set_size(obj, 20, 20); /*Fix size*/
// lv_obj_set_flex_item(obj, true);
//
// obj = lv_obj_create(cont, NULL);
// lv_obj_set_size(obj, LV_FLEX_GROW(1), 30); /*1 portion from the free space*/
// lv_obj_set_flex_item(obj, true);
//
// obj = lv_obj_create(cont, NULL);
// lv_obj_set_size(obj, LV_FLEX_GROW(2), 40); /*2 portion from the free space*/
// lv_obj_set_flex_item(obj, true);
//
// obj = lv_obj_create(cont, NULL);
// lv_obj_set_size(obj, 20, 20); /*Fix size. It is flushed to the right by the "grow" items*/
// lv_obj_set_flex_item(obj, true);
//}
//

View File

@@ -1,24 +0,0 @@
//#include "../../lv_examples.h"
//
///**
// * Reverse the order of flex items
// */
//void lv_ex_flex_4(void)
//{
// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
// lv_obj_set_size(cont, 300, 220);
// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
// lv_obj_set_flex_dir(cont, LV_FLEX_DIR_COLUMN_WRAP_REVERSE);
// lv_obj_set_flex_gap(cont, 10);
//
// uint32_t i;
// for(i = 0; i < 20; i++) {
// lv_obj_t * obj = lv_obj_create(cont, NULL);
// lv_obj_set_size(obj, 100, LV_SIZE_AUTO);
// lv_obj_set_flex_item(obj, true);
//
// lv_obj_t * label = lv_label_create(obj, NULL);
// lv_label_set_text_fmt(label, "Item: %d", i);
// }
//}
//

View File

@@ -1,28 +0,0 @@
//#include "../../lv_examples.h"
//
///**
// * Demonstrate the effect of margin on flex item
// */
//void lv_ex_flex_5(void)
//{
// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
// lv_obj_set_size(cont, 300, 220);
// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
// lv_obj_set_flex_dir(cont, LV_FLEX_DIR_ROW_WRAP);
//
// uint32_t i;
// for(i = 0; i < 20; i++) {
// lv_obj_t * obj = lv_obj_create(cont, NULL);
// lv_obj_set_size(obj, 100, LV_SIZE_AUTO);
// lv_obj_set_flex_item(obj, true);
//
// /*Set margin on every side*/
// if(i == 4) {
// lv_obj_set_style_local_margin_all(obj, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 20);
// }
//
// lv_obj_t * label = lv_label_create(obj, NULL);
// lv_label_set_text_fmt(label, "Item:%d", i);
// }
//}
//

View File

@@ -1,25 +0,0 @@
//#include "../../lv_examples.h"
//
///**
// * RTL base direction changes order of the items.
// */
//void lv_ex_flex_6(void)
//{
// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
// lv_obj_set_base_dir(cont, LV_BIDI_DIR_RTL);
// lv_obj_set_size(cont, 300, 220);
// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
// lv_obj_set_flex_dir(cont, LV_FLEX_DIR_COLUMN_WRAP);
//
// uint32_t i;
// for(i = 0; i < 20; i++) {
// lv_obj_t * obj = lv_obj_create(cont, NULL);
// lv_obj_set_size(obj, 80, LV_SIZE_AUTO);
// lv_obj_set_flex_item(obj, true);
//
// lv_obj_t * label = lv_label_create(obj, NULL);
// lv_label_set_text_fmt(label, "%d", i);
// lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
// }
//}
//

View File

@@ -1,37 +0,0 @@
/**
* @file lv_ex_grid.h
*
*/
#ifndef LV_EX_GRID_H
#define LV_EX_GRID_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_EX_GRID_H*/

View File

@@ -1,39 +0,0 @@
//#include "../../lv_examples.h"
//
///**
// * A simple grid
// */
//void lv_ex_grid_1(void)
//{
// static lv_coord_t col_dsc[3] = {80, 80, 80};
// static lv_coord_t row_dsc[3] = {60, 60, 60};
//
// static lv_grid_t grid;
// lv_grid_init(&grid);
// lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3);
//
// /*Create a container with grid*/
// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
// lv_obj_set_size(cont, 300, 220);
// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
// lv_obj_set_grid(cont, &grid);
//
// lv_obj_t * label;
// lv_obj_t * obj;
//
// uint32_t i;
// for(i = 0; i < 9; i++) {
// uint8_t col = i % 3;
// uint8_t row = i / 3;
//
// obj = lv_obj_create(cont, NULL);
// /* Stretch the cell horizontally and vertically too
// * Set span to 1 to make the cell 1 column/row sized */
// lv_obj_set_grid_cell(obj, LV_GRID_CELL_STRETCH(col, 1), LV_GRID_CELL_STRETCH(row, 1));
//
// label = lv_label_create(obj, NULL);
// lv_label_set_text_fmt(label, "c%d, r%d", col, row);
// lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
// }
//}
//

View File

@@ -1,59 +0,0 @@
//#include "../../lv_examples.h"
//
///**
// * Demonstrate cell placement and span
// */
//void lv_ex_grid_2(void)
//{
// static lv_coord_t col_dsc[3] = {80, 80, 80};
// static lv_coord_t row_dsc[3] = {60, 60, 60};
//
// static lv_grid_t grid;
// lv_grid_init(&grid);
// lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3);
//
// /*Create a container with grid*/
// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
// lv_obj_set_size(cont, 300, 220);
// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
// lv_obj_set_grid(cont, &grid);
//
// lv_obj_t * label;
// lv_obj_t * obj;
//
// /*Cell to 0;0 and align to to the start (left/top) horizontally and vertically too */
// obj = lv_obj_create(cont, NULL);
// lv_obj_set_size(obj, LV_SIZE_AUTO, LV_SIZE_AUTO);
// lv_obj_set_grid_cell(obj, LV_GRID_CELL_START(0, 1), LV_GRID_CELL_START(0, 1));
// label = lv_label_create(obj, NULL);
// lv_label_set_text(label, "c0, r0");
//
// /*Cell to 1;0 and align to to the start (left) horizontally and center vertically too */
// obj = lv_obj_create(cont, NULL);
// lv_obj_set_size(obj, LV_SIZE_AUTO, LV_SIZE_AUTO);
// lv_obj_set_grid_cell(obj, LV_GRID_CELL_START(1, 1), LV_GRID_CELL_CENTER(0, 1));
// label = lv_label_create(obj, NULL);
// lv_label_set_text(label, "c1, r0");
//
// /*Cell to 2;0 and align to to the start (left) horizontally and end (bottom) vertically too */
// obj = lv_obj_create(cont, NULL);
// lv_obj_set_size(obj, LV_SIZE_AUTO, LV_SIZE_AUTO);
// lv_obj_set_grid_cell(obj, LV_GRID_CELL_START(2, 1), LV_GRID_CELL_END(0, 1));
// label = lv_label_create(obj, NULL);
// lv_label_set_text(label, "c2, r0");
//
// /*Cell to 1;1 but 2 column wide (span = 2).Set width and height to stretched. */
// obj = lv_obj_create(cont, NULL);
// lv_obj_set_size(obj, LV_SIZE_AUTO, LV_SIZE_AUTO);
// lv_obj_set_grid_cell(obj, LV_GRID_CELL_STRETCH(1, 2), LV_GRID_CELL_STRETCH(1, 1));
// label = lv_label_create(obj, NULL);
// lv_label_set_text(label, "c1-2, r1");
//
// /*Cell to 0;1 but 2 rows tall (span = 2).Set width and height to stretched. */
// obj = lv_obj_create(cont, NULL);
// lv_obj_set_size(obj, LV_SIZE_AUTO, LV_SIZE_AUTO);
// lv_obj_set_grid_cell(obj, LV_GRID_CELL_STRETCH(0, 1), LV_GRID_CELL_STRETCH(1, 2));
// label = lv_label_create(obj, NULL);
// lv_label_set_text(label, "c0\nr1-2");
//}
//

View File

@@ -1,45 +0,0 @@
//#include "../../lv_examples.h"
//
///**
// * Demonstrate grid's "free unit"
// */
//void lv_ex_grid_3(void)
//{
// /* Column 1: fix width 60 px
// * Column 2: 1 unit from the remaining free space
// * Column 3: 2 unit from the remaining free space */
// static lv_coord_t col_dsc[3] = {60, LV_GRID_FR(1), LV_GRID_FR(2)};
//
// /* Row 1: fix width 60 px
// * Row 2: 1 unit from the remaining free space
// * Row 3: fix width 60 px */
// static lv_coord_t row_dsc[3] = {60, LV_GRID_FR(1), 60};
//
// static lv_grid_t grid;
// lv_grid_init(&grid);
// lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3);
//
// /*Create a container with grid*/
// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
// lv_obj_set_size(cont, 300, 220);
// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
// lv_obj_set_grid(cont, &grid);
//
// lv_obj_t * label;
// lv_obj_t * obj;
// uint32_t i;
// for(i = 0; i < 9; i++) {
// uint8_t col = i % 3;
// uint8_t row = i / 3;
//
// obj = lv_obj_create(cont, NULL);
// /* Stretch the cell horizontally and vertically too
// * Set span to 1 to make the cell 1 column/row sized */
// lv_obj_set_grid_cell(obj, LV_GRID_CELL_STRETCH(col, 1), LV_GRID_CELL_STRETCH(row, 1));
//
// label = lv_label_create(obj, NULL);
// lv_label_set_text_fmt(label, "%d,%d", col, row);
// lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
// }
//}
//

View File

@@ -1,41 +0,0 @@
//#include "../../lv_examples.h"
//
///**
// * Demonstrate track placement
// */
//void lv_ex_grid_4(void)
//{
// static lv_coord_t col_dsc[3] = {60, 60, 60};
// static lv_coord_t row_dsc[3] = {50, 50, 50};
//
// static lv_grid_t grid;
// lv_grid_init(&grid);
// lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3);
//
// /*Add space between the columns and move the rows to the bottom (end)*/
// lv_grid_set_place(&grid, LV_GRID_SPACE_BETWEEN, LV_GRID_END);
//
// /*Create a container with grid*/
// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
// lv_obj_set_size(cont, 300, 220);
// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
// lv_obj_set_grid(cont, &grid);
//
// lv_obj_t * label;
// lv_obj_t * obj;
// uint32_t i;
// for(i = 0; i < 9; i++) {
// uint8_t col = i % 3;
// uint8_t row = i / 3;
//
// obj = lv_obj_create(cont, NULL);
// /* Stretch the cell horizontally and vertically too
// * Set span to 1 to make the cell 1 column/row sized */
// lv_obj_set_grid_cell(obj, LV_GRID_CELL_STRETCH(col, 1), LV_GRID_CELL_STRETCH(row, 1));
//
// label = lv_label_create(obj, NULL);
// lv_label_set_text_fmt(label, "%d,%d", col, row);
// lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
// }
//}
//

View File

@@ -1,41 +0,0 @@
//#include "../../lv_examples.h"
//
///**
// * Demonstrate margin in grid
// */
//void lv_ex_grid_5(void)
//{
//
// /*60x60 cells*/
// static lv_coord_t col_dsc[3] = {100, 60, 60};
// static lv_coord_t row_dsc[3] = {60, 60, 60};
//
// static lv_grid_t grid;
// lv_grid_init(&grid);
// lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3);
//
// /*Create a container with grid*/
// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
// lv_obj_set_size(cont, 300, 220);
// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
// lv_obj_set_grid(cont, &grid);
//
// lv_obj_t * label;
// lv_obj_t * obj;
// uint32_t i;
// for(i = 0; i < 9; i++) {
// uint8_t col = i % 3;
// uint8_t row = i / 3;
//
// obj = lv_obj_create(cont, NULL);
// lv_obj_set_grid_cell(obj, LV_GRID_CELL_START(col, 1), LV_GRID_CELL_START(row, 1));
// lv_obj_set_size(obj, 55, 55);
// if(i == 1) {
// lv_obj_set_style_local_margin_all(obj, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 5);
// }
// label = lv_label_create(obj, NULL);
// lv_label_set_text_fmt(label, "%d,%d", col, row);
// lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
// }
//}
//

View File

@@ -1,43 +0,0 @@
//#include "../../lv_examples.h"
//
///**
// * Demonstrate RTL direction on grid
// */
//void lv_ex_grid_6(void)
//{
//
// static lv_coord_t col_dsc[3] = {100, 60, 60};
// static lv_coord_t row_dsc[3] = {60, 60, 60};
//
// static lv_grid_t grid;
// lv_grid_init(&grid);
// lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3);
//
// /*Add space between the columns and move the rows to the bottom (end)*/
//
// /*Create a container with grid*/
// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
// lv_obj_set_size(cont, 300, 220);
// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
// lv_obj_set_base_dir(cont, LV_BIDI_DIR_RTL);
// lv_obj_set_grid(cont, &grid);
//
// lv_obj_t * label;
// lv_obj_t * obj;
// uint32_t i;
// for(i = 0; i < 3; i++) {
// uint8_t col = i % 3;
// uint8_t row = i / 3;
//
// obj = lv_obj_create(cont, NULL);
// /* Stretch the cell horizontally and vertically too
// * Set span to 1 to make the cell 1 column/row sized */
// lv_obj_set_grid_cell(obj, LV_GRID_CELL_STRETCH(col, 1), LV_GRID_CELL_START(row, 1));
// lv_obj_set_size(obj, 55, 55);
//
// label = lv_label_create(obj, NULL);
// lv_label_set_text_fmt(label, "%d,%d", col, row);
// lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
// }
//}
//

View File

@@ -1,48 +0,0 @@
/**
* @file lv_ex_widgets.h
*
*/
#ifndef LV_EX_STYLE_H
#define LV_EX_STYLE_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void lv_ex_style_1(void);
void lv_ex_style_2(void);
void lv_ex_style_3(void);
void lv_ex_style_4(void);
void lv_ex_style_5(void);
void lv_ex_style_6(void);
void lv_ex_style_7(void);
void lv_ex_style_8(void);
void lv_ex_style_9(void);
void lv_ex_style_10(void);
void lv_ex_style_11(void);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_EX_STYLE_H*/

View File

@@ -1,28 +0,0 @@
//#include "../../lv_examples.h"
//
///**
// * Using the background style properties
// */
//void lv_ex_style_1(void)
//{
// static lv_style_t style;
// lv_style_init(&style);
// lv_style_set_radius(&style, LV_STATE_DEFAULT, 5);
//
// /*Make a gradient*/
// lv_style_set_bg_opa(&style, LV_STATE_DEFAULT, LV_OPA_COVER);
// lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_SILVER);
// lv_style_set_bg_grad_color(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE);
// lv_style_set_bg_grad_dir(&style, LV_STATE_DEFAULT, LV_GRAD_DIR_VER);
//
// /*Shift the gradient to the bottom*/
// lv_style_set_bg_main_stop(&style, LV_STATE_DEFAULT, 128);
// lv_style_set_bg_grad_stop(&style, LV_STATE_DEFAULT, 192);
//
//
// /*Create an object with the new style*/
// lv_obj_t * obj = lv_obj_create(lv_scr_act(), NULL);
// lv_obj_add_style(obj, LV_OBJ_PART_MAIN, &style);
// lv_obj_align(obj, NULL, LV_ALIGN_CENTER, 0, 0);
//}
//

View File

@@ -1,35 +0,0 @@
//#include "../../lv_examples.h"
//
///**
// * Using the transitions style properties
// */
//void lv_ex_style_10(void)
//{
// static lv_style_t style;
// lv_style_init(&style);
//
// /*Set a background color and a radius*/
// lv_style_set_radius(&style, LV_STATE_DEFAULT, 5);
// lv_style_set_bg_opa(&style, LV_STATE_DEFAULT, LV_OPA_COVER);
// lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_SILVER);
//
// /*Set different background color in pressed state*/
// lv_style_set_bg_color(&style, LV_STATE_PRESSED, LV_COLOR_GRAY);
//
// /*Set different transition time in default and pressed state
// *fast press, slower revert to default*/
// lv_style_set_transition_time(&style, LV_STATE_DEFAULT, 500);
// lv_style_set_transition_time(&style, LV_STATE_PRESSED, 200);
//
// /*Small delay to make transition more visible*/
// lv_style_set_transition_delay(&style, LV_STATE_DEFAULT, 100);
//
// /*Add `bg_color` to transitioned properties*/
// lv_style_set_transition_prop_1(&style, LV_STATE_DEFAULT, LV_STYLE_BG_COLOR);
//
// /*Create an object with the new style*/
// lv_obj_t * obj = lv_obj_create(lv_scr_act(), NULL);
// lv_obj_add_style(obj, LV_OBJ_PART_MAIN, &style);
// lv_obj_align(obj, NULL, LV_ALIGN_CENTER, 0, 0);
//}
//

View File

@@ -1,36 +0,0 @@
//#include "../../lv_examples.h"
//
///**
// * Using the scale style properties
// */
//void lv_ex_style_11(void)
//{
// static lv_style_t style;
// lv_style_init(&style);
//
// /*Set a background color and a radius*/
// lv_style_set_radius(&style, LV_STATE_DEFAULT, 5);
// lv_style_set_bg_opa(&style, LV_STATE_DEFAULT, LV_OPA_COVER);
// lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_SILVER);
//
// /*Set some paddings*/
// lv_style_set_pad_top(&style, LV_STATE_DEFAULT, 20);
// lv_style_set_pad_left(&style, LV_STATE_DEFAULT, 5);
// lv_style_set_pad_right(&style, LV_STATE_DEFAULT, 5);
//
// lv_style_set_scale_end_color(&style, LV_STATE_DEFAULT, LV_COLOR_RED);
// lv_style_set_line_color(&style, LV_STATE_DEFAULT, LV_COLOR_WHITE);
// lv_style_set_scale_grad_color(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE);
// lv_style_set_line_width(&style, LV_STATE_DEFAULT, 2);
// lv_style_set_scale_end_line_width(&style, LV_STATE_DEFAULT, 4);
// lv_style_set_scale_end_border_width(&style, LV_STATE_DEFAULT, 4);
//
// /*Gauge has a needle but for simplicity its style is not initialized here*/
//#if LV_USE_GAUGE
// /*Create an object with the new style*/
// lv_obj_t * obj = lv_gauge_create(lv_scr_act(), NULL);
// lv_obj_add_style(obj, LV_GAUGE_PART_MAIN, &style);
// lv_obj_align(obj, NULL, LV_ALIGN_CENTER, 0, 0);
//#endif
//}
//

View File

@@ -1,27 +0,0 @@
//#include "../../lv_examples.h"
//
///**
// * Using the border style properties
// */
//void lv_ex_style_2(void)
//{
// static lv_style_t style;
// lv_style_init(&style);
//
// /*Set a background color and a radius*/
// lv_style_set_radius(&style, LV_STATE_DEFAULT, 20);
// lv_style_set_bg_opa(&style, LV_STATE_DEFAULT, LV_OPA_COVER);
// lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_SILVER);
//
// /*Add border to the bottom+right*/
// lv_style_set_border_color(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE);
// lv_style_set_border_width(&style, LV_STATE_DEFAULT, 5);
// lv_style_set_border_opa(&style, LV_STATE_DEFAULT, LV_OPA_50);
// lv_style_set_border_side(&style, LV_STATE_DEFAULT, LV_BORDER_SIDE_BOTTOM | LV_BORDER_SIDE_RIGHT);
//
// /*Create an object with the new style*/
// lv_obj_t * obj = lv_obj_create(lv_scr_act(), NULL);
// lv_obj_add_style(obj, LV_OBJ_PART_MAIN, &style);
// lv_obj_align(obj, NULL, LV_ALIGN_CENTER, 0, 0);
//}
//

View File

@@ -1,26 +0,0 @@
//#include "../../lv_examples.h"
//
///**
// * Using the outline style properties
// */
//void lv_ex_style_3(void)
//{
// static lv_style_t style;
// lv_style_init(&style);
//
// /*Set a background color and a radius*/
// lv_style_set_radius(&style, LV_STATE_DEFAULT, 5);
// lv_style_set_bg_opa(&style, LV_STATE_DEFAULT, LV_OPA_COVER);
// lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_SILVER);
//
// /*Add outline*/
// lv_style_set_outline_width(&style, LV_STATE_DEFAULT, 2);
// lv_style_set_outline_color(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE);
// lv_style_set_outline_pad(&style, LV_STATE_DEFAULT, 8);
//
// /*Create an object with the new style*/
// lv_obj_t * obj = lv_obj_create(lv_scr_act(), NULL);
// lv_obj_add_style(obj, LV_OBJ_PART_MAIN, &style);
// lv_obj_align(obj, NULL, LV_ALIGN_CENTER, 0, 0);
//}
//

View File

@@ -1,27 +0,0 @@
//#include "../../lv_examples.h"
//
///**
// * Using the Shadow style properties
// */
//void lv_ex_style_4(void)
//{
// static lv_style_t style;
// lv_style_init(&style);
//
// /*Set a background color and a radius*/
// lv_style_set_radius(&style, LV_STATE_DEFAULT, 5);
// lv_style_set_bg_opa(&style, LV_STATE_DEFAULT, LV_OPA_COVER);
// lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_SILVER);
//
// /*Add a shadow*/
// lv_style_set_shadow_width(&style, LV_STATE_DEFAULT, 8);
// lv_style_set_shadow_color(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE);
// lv_style_set_shadow_ofs_x(&style, LV_STATE_DEFAULT, 10);
// lv_style_set_shadow_ofs_y(&style, LV_STATE_DEFAULT, 20);
//
// /*Create an object with the new style*/
// lv_obj_t * obj = lv_obj_create(lv_scr_act(), NULL);
// lv_obj_add_style(obj, LV_OBJ_PART_MAIN, &style);
// lv_obj_align(obj, NULL, LV_ALIGN_CENTER, 0, 0);
//}
//

View File

@@ -1,27 +0,0 @@
//#include "../../lv_examples.h"
//
///**
// * Using the pattern style properties
// */
//void lv_ex_style_5(void)
//{
// static lv_style_t style;
// lv_style_init(&style);
//
// /*Set a background color and a radius*/
// lv_style_set_radius(&style, LV_STATE_DEFAULT, 5);
// lv_style_set_bg_opa(&style, LV_STATE_DEFAULT, LV_OPA_COVER);
// lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_SILVER);
//
// /*Add a repeating pattern*/
// lv_style_set_pattern_image(&style, LV_STATE_DEFAULT, LV_SYMBOL_OK);
// lv_style_set_pattern_recolor(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE);
// lv_style_set_pattern_opa(&style, LV_STATE_DEFAULT, LV_OPA_50);
// lv_style_set_pattern_repeat(&style, LV_STATE_DEFAULT, true);
//
// /*Create an object with the new style*/
// lv_obj_t * obj = lv_obj_create(lv_scr_act(), NULL);
// lv_obj_add_style(obj, LV_OBJ_PART_MAIN, &style);
// lv_obj_align(obj, NULL, LV_ALIGN_CENTER, 0, 0);
//}
//

View File

@@ -1,30 +0,0 @@
//#include "../../lv_examples.h"
//
///**
// * Using the value style properties
// */
//void lv_ex_style_6(void)
//{
// static lv_style_t style;
// lv_style_init(&style);
//
// /*Set a background color and a radius*/
// lv_style_set_radius(&style, LV_STATE_DEFAULT, 5);
// lv_style_set_bg_opa(&style, LV_STATE_DEFAULT, LV_OPA_COVER);
// lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_SILVER);
//
// /*Add a value text properties*/
// lv_style_set_value_color(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE);
// lv_style_set_value_align(&style, LV_STATE_DEFAULT, LV_ALIGN_IN_BOTTOM_RIGHT);
// lv_style_set_value_ofs_x(&style, LV_STATE_DEFAULT, 10);
// lv_style_set_value_ofs_y(&style, LV_STATE_DEFAULT, 10);
//
// /*Create an object with the new style*/
// lv_obj_t * obj = lv_obj_create(lv_scr_act(), NULL);
// lv_obj_add_style(obj, LV_OBJ_PART_MAIN, &style);
// lv_obj_align(obj, NULL, LV_ALIGN_CENTER, 0, 0);
//
// /*Add a value text to the local style. This way every object can have different text*/
// lv_obj_set_style_local_value_str(obj, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, "Text");
//}
//

View File

@@ -1,34 +0,0 @@
//#include "../../lv_examples.h"
//
///**
// * Using the text style properties
// */
//void lv_ex_style_7(void)
//{
// static lv_style_t style;
// lv_style_init(&style);
//
// lv_style_set_radius(&style, LV_STATE_DEFAULT, 5);
// lv_style_set_bg_opa(&style, LV_STATE_DEFAULT, LV_OPA_COVER);
// lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_SILVER);
// lv_style_set_border_width(&style, LV_STATE_DEFAULT, 2);
// lv_style_set_border_color(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE);
//
// lv_style_set_pad_top(&style, LV_STATE_DEFAULT, 10);
// lv_style_set_pad_bottom(&style, LV_STATE_DEFAULT, 10);
// lv_style_set_pad_left(&style, LV_STATE_DEFAULT, 10);
// lv_style_set_pad_right(&style, LV_STATE_DEFAULT, 10);
//
// lv_style_set_text_color(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE);
// lv_style_set_text_letter_space(&style, LV_STATE_DEFAULT, 5);
// lv_style_set_text_line_space(&style, LV_STATE_DEFAULT, 20);
// lv_style_set_text_decor(&style, LV_STATE_DEFAULT, LV_TEXT_DECOR_UNDERLINE);
//
// /*Create an object with the new style*/
// lv_obj_t * obj = lv_label_create(lv_scr_act(), NULL);
// lv_obj_add_style(obj, LV_LABEL_PART_MAIN, &style);
// lv_label_set_text(obj, "Text of\n"
// "a label");
// lv_obj_align(obj, NULL, LV_ALIGN_CENTER, 0, 0);
//}
//

View File

@@ -1,24 +0,0 @@
//#include "../../lv_examples.h"
//
///**
// * Using the line style properties
// */
//void lv_ex_style_8(void)
//{
// static lv_style_t style;
// lv_style_init(&style);
//
// lv_style_set_line_color(&style, LV_STATE_DEFAULT, LV_COLOR_GRAY);
// lv_style_set_line_width(&style, LV_STATE_DEFAULT, 6);
// lv_style_set_line_rounded(&style, LV_STATE_DEFAULT, true);
//#if LV_USE_LINE
// /*Create an object with the new style*/
// lv_obj_t * obj = lv_line_create(lv_scr_act(), NULL);
// lv_obj_add_style(obj, LV_LINE_PART_MAIN, &style);
//
// static lv_point_t p[] = {{10, 30}, {30, 50}, {100, 0}};
// lv_line_set_points(obj, p, 3);
//
// lv_obj_align(obj, NULL, LV_ALIGN_CENTER, 0, 0);
//#endif
//}

View File

@@ -1,35 +0,0 @@
//#include "../../lv_examples.h"
//
///**
// * Using the image style properties
// */
//void lv_ex_style_9(void)
//{
// static lv_style_t style;
// lv_style_init(&style);
//
// /*Set a background color and a radius*/
// lv_style_set_radius(&style, LV_STATE_DEFAULT, 5);
// lv_style_set_bg_opa(&style, LV_STATE_DEFAULT, LV_OPA_COVER);
// lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_SILVER);
// lv_style_set_border_width(&style, LV_STATE_DEFAULT, 2);
// lv_style_set_border_color(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE);
//
// lv_style_set_pad_top(&style, LV_STATE_DEFAULT, 10);
// lv_style_set_pad_bottom(&style, LV_STATE_DEFAULT, 10);
// lv_style_set_pad_left(&style, LV_STATE_DEFAULT, 10);
// lv_style_set_pad_right(&style, LV_STATE_DEFAULT, 10);
//
// lv_style_set_image_recolor(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE);
// lv_style_set_image_recolor_opa(&style, LV_STATE_DEFAULT, LV_OPA_50);
//
//#if LV_USE_IMG
// /*Create an object with the new style*/
// lv_obj_t * obj = lv_img_create(lv_scr_act(), NULL);
// lv_obj_add_style(obj, LV_IMG_PART_MAIN, &style);
// LV_IMG_DECLARE(img_cogwheel_argb);
// lv_img_set_src(obj, &img_cogwheel_argb);
// lv_obj_align(obj, NULL, LV_ALIGN_CENTER, 0, 0);
//#endif
//}
//

View File

@@ -1,14 +0,0 @@
#include "../../../lvgl.h"
#if LV_USE_ARC
void lv_ex_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

View File

@@ -1,12 +0,0 @@
# 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)

View File

@@ -1,38 +0,0 @@
#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_ex_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

View File

@@ -1,43 +0,0 @@
# 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)

View File

@@ -1,12 +0,0 @@
#include "../../../lvgl.h"
#if LV_USE_BAR
void lv_ex_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

View File

@@ -1,5 +0,0 @@
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)

View File

@@ -4,7 +4,7 @@
/**
* Example of styling the bar
*/
void lv_ex_bar_2(void)
void lv_example_bar_2(void)
{
static lv_style_t style_bg;
static lv_style_t style_indic;

View File

@@ -1,37 +0,0 @@
#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_ex_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

View File

@@ -1,27 +0,0 @@
#include "../../../lvgl.h"
#if LV_USE_BAR
/**
* Bar with stripe pattern and ranged value
*/
void lv_ex_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

View File

@@ -1,30 +0,0 @@
#include "../../../lvgl.h"
#if LV_USE_BAR
/**
* Bar with LTR and RTL base direction
*/
void lv_ex_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

View File

@@ -1,68 +0,0 @@
#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_ex_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

View File

@@ -1,35 +0,0 @@
#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_ex_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

View File

@@ -1,21 +0,0 @@
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")

View File

@@ -1,52 +0,0 @@
#include "../../../lvgl.h"
#include <stdio.h>
#if LV_USE_BTN
/**
* Style a button from scratch
*/
void lv_ex_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

View File

@@ -5,7 +5,7 @@
/**
* Create a style transition on a button to act like a gum when clicked
*/
void lv_ex_btn_3(void)
void lv_example_btn_3(void)
{
/*Properties to transition*/
static lv_style_prop_t props[] = {

View File

@@ -1,31 +0,0 @@
#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_ex_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

View File

@@ -1,14 +0,0 @@
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)

View File

@@ -1,71 +0,0 @@
#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_ex_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

View File

@@ -1,71 +0,0 @@
#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_ex_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

View File

@@ -1,55 +0,0 @@
#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_ex_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

View File

@@ -1,53 +0,0 @@
#include "../../../lvgl.h"
#if LV_USE_CANVAS
#define CANVAS_WIDTH 200
#define CANVAS_HEIGHT 150
void lv_ex_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

View File

@@ -1,38 +0,0 @@
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)

View File

@@ -1,44 +0,0 @@
#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_ex_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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

View File

@@ -1,41 +0,0 @@
# 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)

View File

@@ -1,44 +0,0 @@
#include "../../../lvgl.h"
#if LV_USE_CHART
void lv_ex_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

View File

@@ -1,19 +0,0 @@
# 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])

View File

@@ -1,82 +0,0 @@
#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_ex_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

View File

@@ -1,75 +0,0 @@
#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_ex_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

View File

@@ -1,80 +0,0 @@
#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_ex_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

View File

@@ -1,44 +0,0 @@
#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_ex_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

View File

@@ -1,8 +0,0 @@
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)

View File

@@ -1,13 +0,0 @@
#include "../../../lvgl.h"
#if LV_USE_COLORWHEEL
void lv_ex_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

View File

@@ -1,35 +0,0 @@
#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_ex_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

View File

@@ -1,21 +0,0 @@
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)

View File

@@ -1,42 +0,0 @@
#include "../../../lvgl.h"
#include <stdio.h>
#if LV_USE_DROPDOWN
/**
* Create a drop down, up, left and right menus
*/
void lv_ex_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

View File

@@ -1,23 +0,0 @@
# 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)

View File

@@ -1,34 +0,0 @@
#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_ex_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

View File

@@ -1,37 +0,0 @@
#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

View File

@@ -1,26 +0,0 @@
# 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)

View File

@@ -1,26 +0,0 @@
#include "../../../lvgl.h"
#if LV_USE_LABEL
/**
* Show line wrap, re-color, line align and text scrolling.
*/
void lv_ex_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

View File

@@ -1,14 +0,0 @@
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)

View File

@@ -1,36 +0,0 @@
#include "../../../lvgl.h"
#if LV_USE_LABEL
/**
* Create a fake text shadow
*/
void lv_ex_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

View File

@@ -1,24 +0,0 @@
# 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)

View File

@@ -1,22 +0,0 @@
#include "../../../lvgl.h"
#if LV_USE_LED
void lv_ex_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

View File

@@ -1,27 +0,0 @@
# 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()

View File

@@ -1,24 +0,0 @@
#include "../../../lvgl.h"
#if LV_USE_LINE
void lv_ex_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

View File

@@ -1,19 +0,0 @@
# Create an array for the points of the line
line_points = [ {"x":5, "y":5},
{"x":70, "y":70},
{"x":120, "y":10},
{"x":180, "y":60},
{"x":240, "y":10}]
# Create new style (thick dark blue)
style_line = lv.style_t()
lv.style_copy(style_line, lv.style_plain)
style_line.line.color = lv.color_make(0x00, 0x3b, 0x75)
style_line.line.width = 3
style_line.line.rounded = 1
# Copy the previous line and apply the new style
line1 = lv.line(lv.scr_act())
line1.set_points(line_points, len(line_points)) # Set the points
line1.set_style(lv.line.STYLE.MAIN, style_line)
line1.align(None, lv.ALIGN.CENTER, 0, 0)

View File

@@ -1,25 +0,0 @@
def event_handler(obj, event):
if event == lv.EVENT.CLICKED:
print("Clicked: %s" % lv.list.get_btn_text(obj))
# Create a list
list1 = lv.list(lv.scr_act())
list1.set_size(160, 200)
list1.align(None, lv.ALIGN.CENTER, 0, 0)
# Add buttons to the list
list_btn = list1.add_btn(lv.SYMBOL.FILE, "New")
list_btn.set_event_cb(event_handler)
list_btn = list1.add_btn(lv.SYMBOL.DIRECTORY, "Open")
list_btn.set_event_cb(event_handler)
list_btn = list1.add_btn(lv.SYMBOL.CLOSE, "Delete")
list_btn.set_event_cb(event_handler)
list_btn = list1.add_btn(lv.SYMBOL.EDIT, "Edit")
list_btn.set_event_cb(event_handler)
list_btn = list1.add_btn(lv.SYMBOL.SAVE, "Save")
list_btn.set_event_cb(event_handler)

View File

@@ -1,34 +0,0 @@
#include "../../../lvgl.h"
#include <stdio.h>
#if LV_USE_LIST
static void event_handler(lv_obj_t * obj, lv_event_t event)
{
if(event == LV_EVENT_CLICKED) {
printf("Clicked: %s\n", lv_list_get_btn_text(obj));
}
}
void lv_list_example_1(void)
{
/*Create a list*/
lv_obj_t * list1 = lv_list_create(lv_scr_act());
lv_obj_align(list1, NULL, LV_ALIGN_CENTER, 0, 0);
/*Add buttons to the list*/
lv_list_add_text(list1, "File");
lv_list_add_btn(list1, LV_SYMBOL_FILE, "New", event_handler);
lv_list_add_btn(list1, LV_SYMBOL_DIRECTORY, "Open", event_handler);
lv_list_add_btn(list1, LV_SYMBOL_SAVE, "Save", event_handler);
lv_list_add_btn(list1, LV_SYMBOL_CLOSE, "Delete", event_handler);
lv_list_add_btn(list1, LV_SYMBOL_EDIT, "Edit", event_handler);
lv_list_add_text(list1, "Connectivity");
lv_list_add_btn(list1, LV_SYMBOL_BLUETOOTH, "Bluetooth", event_handler);
lv_list_add_btn(list1, LV_SYMBOL_GPS, "Navigation", event_handler);
lv_list_add_btn(list1, LV_SYMBOL_USB, "USB", event_handler);
lv_list_add_btn(list1, LV_SYMBOL_BATTERY_FULL, "Battery", event_handler);
lv_list_add_text(list1, "Exit");
lv_list_add_btn(list1, LV_SYMBOL_OK, "Apply", event_handler);
lv_list_add_btn(list1, LV_SYMBOL_CLOSE, "Close", event_handler);
}
#endif

View File

@@ -1,21 +0,0 @@
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.

View File

@@ -1,18 +0,0 @@
#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_ex_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

View File

@@ -1,29 +0,0 @@
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)

View File

@@ -1,64 +0,0 @@
#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_ex_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

View File

@@ -1,33 +0,0 @@
#include "../../../lvgl.h"
#if LV_USE_IMG
LV_IMG_DECLARE(img_cogwheel_argb);
/**
* Show transformations (zoom and rotation) using a pivot point.
*/
void lv_ex_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

View File

@@ -1,36 +0,0 @@
#include "../../../lvgl.h"
#if LV_USE_IMG
LV_IMG_DECLARE(img_skew_strip);
/**
* Image styling and offset
*/
void lv_ex_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

View File

@@ -1,77 +0,0 @@
/**
* @file lv_ex_widgets.h
*
*/
#ifndef LV_EX_WIDGETS_H
#define LV_EX_WIDGETS_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void lv_ex_arc_1(void);
void lv_ex_arc_2(void);
void lv_ex_bar_1(void);
void lv_ex_btn_1(void);
void lv_ex_btn_2(void);
void lv_ex_btnmatrix_1(void);
void lv_ex_calendar_1(void);
void lv_ex_canvas_1(void);
void lv_ex_canvas_2(void);
void lv_ex_checkbox_1(void);
void lv_ex_chart_1(void);
void lv_ex_chart_2(void);
void lv_ex_dropdown_1(void);
void lv_ex_dropdown_2(void);
void lv_ex_gauge_1(void);
void lv_ex_gauge_2(void);
void lv_ex_img_1(void);
void lv_ex_img_2(void);
void lv_ex_img_3(void);
void lv_ex_imgbtn_1(void);
void lv_ex_keyboard_1(void);
void lv_ex_label_1(void);
void lv_ex_label_2(void);
void lv_ex_label_3(void);
void lv_ex_led_1(void);
void lv_ex_line_1(void);
void lv_ex_list_1(void);
void lv_ex_linemeter_1(void);
void lv_ex_msgbox_1(void);
void lv_ex_msgbox_2(void);
void lv_ex_obj_1(void);
void lv_ex_spinner_1(void);
void lv_ex_roller_1(void);
void lv_ex_slider_1(void);
void lv_ex_slider_2(void);
void lv_ex_switch_1(void);
void lv_ex_textarea_1(void);
void lv_ex_objmask_1(void);
void lv_ex_objmask_2(void);
void lv_ex_table_1(void);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_EX_WIDGETS_H*/

View File

@@ -1,54 +0,0 @@
#include "../../../lvgl.h"
#include <stdio.h>
#if LV_USE_METER
static lv_obj_t * meter;
static void set_value(lv_meter_indicator_t * indic, int32_t v)
{
lv_meter_set_indicator_value(meter, indic, v);
}
/**
* A simple meter
*/
void lv_ex_meter_1(void)
{
meter = lv_meter_create(lv_scr_act(), NULL);
lv_obj_align(meter, NULL, LV_ALIGN_CENTER, 0, 0);
/*Add a scale first*/
lv_meter_scale_t * scale = lv_meter_add_scale(meter);
lv_meter_set_scale_ticks(meter, scale, 51, 2, 10, LV_COLOR_GRAY);
lv_meter_set_scale_major_ticks(meter, scale, 10, 4, 15, LV_COLOR_BLACK, 10);
lv_meter_indicator_t * indic;
/*Add a red arc to the end */
indic = lv_meter_add_arc(meter, scale, 3, LV_COLOR_RED, 1);
lv_meter_set_indicator_start_value(meter, indic, 80);
lv_meter_set_indicator_end_value(meter, indic, 100);
/*Make the tick lines red at the end of the scale*/
indic = lv_meter_add_scale_lines(meter, scale, LV_COLOR_RED, LV_COLOR_RED, false, 0);
lv_meter_set_indicator_start_value(meter, indic, 80);
lv_meter_set_indicator_end_value(meter, indic, 100);
/*Add a needle line indicator*/
indic = lv_meter_add_needle_line(meter, scale, 4, LV_COLOR_GRAY, -10);
/*Create an animation to set the value*/
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t) set_value);
lv_anim_set_var(&a, indic);
lv_anim_set_values(&a, 0, 100);
lv_anim_set_time(&a, 2000);
lv_anim_set_repeat_delay(&a, 100);
lv_anim_set_playback_time(&a, 500);
lv_anim_set_playback_delay(&a, 100);
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
lv_anim_start(&a);
}
#endif

View File

@@ -1,60 +0,0 @@
#include "../../../lvgl.h"
#include <stdio.h>
#if LV_USE_METER
static lv_obj_t * meter;
static void set_value(lv_meter_indicator_t * indic, int32_t v)
{
lv_meter_set_indicator_end_value(meter, indic, v);
}
/**
* A meter with multiple arcs
*/
void lv_ex_meter_2(void)
{
meter = lv_meter_create(lv_scr_act(), NULL);
lv_obj_align(meter, NULL, LV_ALIGN_CENTER, 0, 0);
/*Remove the circle from the middle*/
lv_obj_remove_style(meter, LV_PART_INDICATOR, LV_STATE_ANY, NULL);
/*Add a scale first*/
lv_meter_scale_t * scale = lv_meter_add_scale(meter);
lv_meter_set_scale_ticks(meter, scale, 11, 2, 10, LV_COLOR_GRAY);
lv_meter_set_scale_major_ticks(meter, scale, 1, 2, 30, lv_color_hex3(0xeee), 10);
lv_meter_set_scale_range(meter, scale, 0, 100, 270, 90);
/*Add a three arc indicator */
lv_meter_indicator_t * indic1 = lv_meter_add_arc(meter, scale, 10, LV_COLOR_RED, 0);
lv_meter_indicator_t * indic2 = lv_meter_add_arc(meter, scale, 10, LV_COLOR_GREEN, -10);
lv_meter_indicator_t * indic3 = lv_meter_add_arc(meter, scale, 10, LV_COLOR_BLUE, -20);
/*Create an animation to set the value*/
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t) set_value);
lv_anim_set_values(&a, 0, 100);
lv_anim_set_repeat_delay(&a, 100);
lv_anim_set_playback_delay(&a, 100);
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
lv_anim_set_time(&a, 2000);
lv_anim_set_playback_time(&a, 500);
lv_anim_set_var(&a, indic1);
lv_anim_start(&a);
lv_anim_set_time(&a, 1000);
lv_anim_set_playback_time(&a, 1000);
lv_anim_set_var(&a, indic2);
lv_anim_start(&a);
lv_anim_set_time(&a, 1000);
lv_anim_set_playback_time(&a, 2000);
lv_anim_set_var(&a, indic3);
lv_anim_start(&a);
}
#endif

View File

@@ -1,55 +0,0 @@
#include "../../../lvgl.h"
#include <stdio.h>
#if LV_USE_METER
static lv_obj_t * meter;
static void set_value(lv_meter_indicator_t * indic, int32_t v)
{
lv_meter_set_indicator_end_value(meter, indic, v);
}
/**
* A clock from a meter
*/
void lv_ex_meter_3(void)
{
meter = lv_meter_create(lv_scr_act(), NULL);
lv_obj_align(meter, NULL, LV_ALIGN_CENTER, 0, 0);
/*Create a scale for the minutes*/
/*61 ticks in a 360 degrees range (the last and the first line overlaps)*/
lv_meter_scale_t * scale_min = lv_meter_add_scale(meter);
lv_meter_set_scale_ticks(meter, scale_min, 61, 1, 10, LV_COLOR_GRAY);
lv_meter_set_scale_range(meter, scale_min, 0, 60, 360, 270);
/*Create an other scale for the hours. It's only visual and contains only major ticks*/
lv_meter_scale_t * scale_hour = lv_meter_add_scale(meter);
lv_meter_set_scale_ticks(meter, scale_hour, 12, 0, 0, LV_COLOR_GRAY); /*12 ticks*/
lv_meter_set_scale_major_ticks(meter, scale_hour, 1, 2, 20, LV_COLOR_BLACK, 10); /*Every tick is major*/
lv_meter_set_scale_range(meter, scale_hour, 1, 12, 330, 300); /*[1..12] values in an almost full circle*/
LV_IMG_DECLARE(img_hand)
/*Add a the hands from images */
lv_meter_indicator_t * indic_min = lv_meter_add_needle_img(meter, scale_min, &img_hand, 5, 5);
lv_meter_indicator_t * indic_hour = lv_meter_add_needle_img(meter, scale_min, &img_hand, 5, 5);
/*Create an animation to set the value*/
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t) set_value);
lv_anim_set_values(&a, 0, 60);
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
lv_anim_set_time(&a, 2000); /*2 sec for 1 turn of the minute hand (1 hour)*/
lv_anim_set_var(&a, indic_min);
lv_anim_start(&a);
lv_anim_set_var(&a, indic_hour);
lv_anim_set_time(&a, 24000); /*24 sec for 1 turn of the hour hand*/
lv_anim_set_values(&a, 0, 60);
lv_anim_start(&a);
}
#endif

View File

@@ -1,37 +0,0 @@
#include "../../../lvgl.h"
#include <stdio.h>
#if LV_USE_METER
/**
* Create a pie chart
*/
void lv_ex_meter_4(void)
{
lv_obj_t * meter = lv_meter_create(lv_scr_act(), NULL);
lv_obj_align(meter, NULL, LV_ALIGN_CENTER, 0, 0);
/*Remove the background and the circle from the middle*/
lv_obj_remove_style(meter, LV_PART_MAIN, LV_STATE_ANY, NULL);
lv_obj_remove_style(meter, LV_PART_INDICATOR, LV_STATE_ANY, NULL);
/*Add a scale first with no ticks.*/
lv_meter_scale_t * scale = lv_meter_add_scale(meter);
lv_meter_set_scale_ticks(meter, scale, 0, 0, 0, LV_COLOR_BLACK);
lv_meter_set_scale_range(meter, scale, 0, 100, 360, 0);
/*Add a three arc indicator */
lv_coord_t indic_w = lv_obj_get_width(meter) / 2;
lv_meter_indicator_t * indic1 = lv_meter_add_arc(meter, scale, indic_w, LV_COLOR_ORANGE, 0);
lv_meter_set_indicator_start_value(meter, indic1, 0);
lv_meter_set_indicator_end_value(meter, indic1, 40);
lv_meter_indicator_t * indic2 = lv_meter_add_arc(meter, scale, indic_w, LV_COLOR_GREEN, 0);
lv_meter_set_indicator_start_value(meter, indic2, 40); /*Start from the previous*/
lv_meter_set_indicator_end_value(meter, indic2, 80);
lv_meter_indicator_t * indic3 = lv_meter_add_arc(meter, scale, indic_w, LV_COLOR_BLUE, 0);
lv_meter_set_indicator_start_value(meter, indic3, 80); /*Start from the previous*/
lv_meter_set_indicator_end_value(meter, indic3, 100);
}
#endif

View File

@@ -1,26 +0,0 @@
#include "../../../lvgl.h"
#include <stdio.h>
#if LV_USE_MSGBOX
static void event_cb(lv_obj_t * obj, lv_event_t event)
{
if(event == LV_EVENT_VALUE_CHANGED) {
printf("Button: %s\n", lv_msgbox_get_active_btn_text(obj));
}
}
void lv_ex_msgbox_1(void)
{
// static lv_style_t style;
// lv_style_init(&style);
// lv_style_set_radius(&style, LV_STATE_DEFAULT, 30);
static const char * btns[] ={"Apply", "Close", ""};
lv_obj_t * mbox1 = lv_msgbox_create("Hello", "This is a message box with two buttons.", btns, true);
// lv_obj_set_width(mbox1, 300);
lv_obj_add_event_cb(mbox1, event_cb, NULL);
lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the corner*/
}
#endif

View File

@@ -1,12 +0,0 @@
def event_handler(obj, event):
if event == lv.EVENT.VALUE_CHANGED:
print("Button: %s" % lv.mbox.get_active_btn_text(obj))
btns = ["Apply", "Close", ""]
mbox1 = lv.mbox(lv.scr_act())
mbox1.set_text("A message box with two buttons.");
mbox1.add_btns(btns)
mbox1.set_width(200)
mbox1.set_event_cb(event_handler)
mbox1.align(None, lv.ALIGN.CENTER, 0, 0) # Align to the corner

View File

@@ -1,94 +0,0 @@
//#include "../../../lvgl.h"
//#if LV_USE_MSGBOX
//
//static void mbox_event_cb(lv_obj_t *obj, lv_event_t evt);
//static void btn_event_cb(lv_obj_t *btn, lv_event_t evt);
//static void opa_anim(void * bg, lv_anim_value_t v);
//
//static lv_obj_t *mbox, *info;
//static lv_style_t style_modal;
//
//static const char welcome_info[] = "Welcome to the modal message box demo!\n"
// "Press the button to display a message box.";
//
//static const char in_msg_info[] = "Notice that you cannot touch "
// "the button again while the message box is open.";
//
//void lv_ex_msgbox_2(void)
//{
// lv_style_init(&style_modal);
// lv_style_set_bg_color(&style_modal, LV_STATE_DEFAULT, LV_COLOR_BLACK);
//
// /* Create a button, then set its position and event callback */
// lv_obj_t *btn = lv_btn_create(lv_scr_act(), NULL);
// lv_obj_set_size(btn, 200, 60);
// lv_obj_set_event_cb(btn, btn_event_cb);
// lv_obj_align(btn, NULL, LV_ALIGN_IN_TOP_LEFT, 20, 20);
//
// /* Create a label on the button */
// lv_obj_t *label = lv_label_create(btn, NULL);
// lv_label_set_text(label, "Display a message box!");
//
// /* Create an informative label on the screen */
// info = lv_label_create(lv_scr_act(), NULL);
// lv_label_set_text(info, welcome_info);
// lv_label_set_long_mode(info, LV_LABEL_LONG_BREAK); /* Make sure text will wrap */
// lv_obj_set_width(info, LV_HOR_RES - 10);
// lv_obj_align(info, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 5, -5);
//
//}
//
//static void mbox_event_cb(lv_obj_t *obj, lv_event_t evt)
//{
// if(evt == LV_EVENT_DELETE && obj == mbox) {
// /* Delete the parent modal background */
// lv_obj_del_async(lv_obj_get_parent(mbox));
// mbox = NULL; /* happens before object is actually deleted! */
// lv_label_set_text(info, welcome_info);
// } else if(evt == LV_EVENT_VALUE_CHANGED) {
// /* A button was clicked */
// lv_msgbox_start_auto_close(mbox, 0);
// }
//}
//
//static void btn_event_cb(lv_obj_t *btn, lv_event_t evt)
//{
// if(evt == LV_EVENT_CLICKED) {
// /* Create a full-screen background */
//
// /* Create a base object for the modal background */
// lv_obj_t *obj = lv_obj_create(lv_scr_act(), NULL);
// lv_obj_reset_style_list(obj, LV_OBJ_PART_MAIN);
// lv_obj_add_style(obj, LV_OBJ_PART_MAIN, &style_modal);
// lv_obj_set_pos(obj, 0, 0);
// lv_obj_set_size(obj, LV_HOR_RES, LV_VER_RES);
//
// static const char * btns2[] = {"Ok", "Cancel", ""};
//
// /* Create the message box as a child of the modal background */
// mbox = lv_msgbox_create(obj, NULL);
// lv_msgbox_add_btns(mbox, btns2);
// lv_msgbox_set_text(mbox, "Hello world!");
// lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0);
// lv_obj_set_event_cb(mbox, mbox_event_cb);
//
// /* Fade the message box in with an animation */
// lv_anim_t a;
// lv_anim_init(&a);
// lv_anim_set_var(&a, obj);
// lv_anim_set_time(&a, 500);
// lv_anim_set_values(&a, LV_OPA_TRANSP, LV_OPA_50);
// lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)opa_anim);
// lv_anim_start(&a);
//
// lv_label_set_text(info, in_msg_info);
// lv_obj_align(info, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 5, -5);
// }
//}
//
//static void opa_anim(void * bg, lv_anim_value_t v)
//{
// lv_obj_set_style_local_bg_opa(bg, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, v);
//}
//
//#endif

View File

@@ -1,86 +0,0 @@
welcome_info = "Welcome to the modal message box demo!\nPress the button to display a message box."
in_msg_info = "Notice that you cannot touch the button again while the message box is open."
class Modal(lv.mbox):
"""mbox with semi-transparent background"""
def __init__(self, parent, *args, **kwargs):
# Create a full-screen background
modal_style = lv.style_t()
lv.style_copy(modal_style, lv.style_plain_color)
# Set the background's style
modal_style.body.main_color = modal_style.body.grad_color = lv.color_make(0,0,0)
modal_style.body.opa = lv.OPA._50
# Create a base object for the modal background
self.bg = lv.obj(parent)
self.bg.set_style(modal_style)
self.bg.set_pos(0, 0)
self.bg.set_size(parent.get_width(), parent.get_height())
self.bg.set_opa_scale_enable(True) # Enable opacity scaling for the animation
super().__init__(self.bg, *args, **kwargs)
self.align(None, lv.ALIGN.CENTER, 0, 0)
# Fade the message box in with an animation
a = lv.anim_t()
lv.anim_init(a)
lv.anim_set_time(a, 500, 0)
lv.anim_set_values(a, lv.OPA.TRANSP, lv.OPA.COVER)
lv.anim_set_exec_cb(a, self.bg, lv.obj.set_opa_scale)
lv.anim_create(a)
super().set_event_cb(self.default_callback)
def set_event_cb(self, callback):
self.callback = callback
def get_event_cb(self):
return self.callback
def default_callback(self, obj, evt):
if evt == lv.EVENT.DELETE:# and obj == self:
# Delete the parent modal background
self.get_parent().del_async()
elif evt == lv.EVENT.VALUE_CHANGED:
# A button was clicked
self.start_auto_close(0)
# Call user-defined callback
if self.callback is not None:
self.callback(obj, evt)
def mbox_event_cb(obj, evt):
if evt == lv.EVENT.DELETE:
info.set_text(welcome_info)
def btn_event_cb(btn, evt):
if evt == lv.EVENT.CLICKED:
btns2 = ["Ok", "Cancel", ""]
# Create the message box as a child of the modal background
mbox = Modal(lv.scr_act())
mbox.add_btns(btns2)
mbox.set_text("Hello world!")
mbox.set_event_cb(mbox_event_cb)
info.set_text(in_msg_info)
info.align(None, lv.ALIGN.IN_BOTTOM_LEFT, 5, -5)
# Get active screen
scr = lv.scr_act()
# Create a button, then set its position and event callback
btn = lv.btn(scr)
btn.set_size(200, 60)
btn.set_event_cb(btn_event_cb)
btn.align(None, lv.ALIGN.IN_TOP_LEFT, 20, 20)
# Create a label on the button
label = lv.label(btn)
label.set_text("Display a message box!")
# Create an informative label on the screen
info = lv.label(scr)
info.set_text(welcome_info)
info.set_long_mode(lv.label.LONG.BREAK) # Make sure text will wrap
info.set_width(scr.get_width() - 10)
info.align(None, lv.ALIGN.IN_BOTTOM_LEFT, 5, -5)

View File

@@ -1,21 +0,0 @@
//#include "../../../lvgl.h"
//
//void lv_ex_obj_1(void)
//{
// lv_obj_t * obj1;
// obj1 = lv_obj_create(lv_scr_act(), NULL);
// lv_obj_set_size(obj1, 100, 50);
// lv_obj_align(obj1, NULL, LV_ALIGN_CENTER, -60, -30);
//
// static lv_style_t style_shadow;
// lv_style_init(&style_shadow);
// lv_style_set_shadow_width(&style_shadow, LV_STATE_DEFAULT, 10);
// lv_style_set_shadow_spread(&style_shadow, LV_STATE_DEFAULT, 5);
// lv_style_set_shadow_color(&style_shadow, LV_STATE_DEFAULT, LV_COLOR_BLUE);
//
// /*Copy the previous object (drag is already enabled)*/
// lv_obj_t * obj3;
// obj3 = lv_obj_create(lv_scr_act(), NULL);
// lv_obj_add_style(obj3, LV_OBJ_PART_MAIN, &style_shadow);
// lv_obj_align(obj3, NULL, LV_ALIGN_CENTER, 60, 30);
//}

View File

@@ -1,20 +0,0 @@
obj1 = lv.obj(lv.scr_act())
obj1.set_size(100, 50)
obj1.set_style(lv.style_plain_color)
obj1.align(None, lv.ALIGN.CENTER, -60, -30)
# Copy the previous object and enable drag
obj2 = lv.obj(lv.scr_act(), obj1)
obj2.set_style(lv.style_pretty_color)
obj2.align(None, lv.ALIGN.CENTER, 0, 0)
obj2.set_drag(True)
style_shadow = lv.style_t()
lv.style_copy(style_shadow, lv.style_pretty)
style_shadow.body.shadow.width = 6
style_shadow.body.radius = 800 # large enough to make it round
# Copy the previous object (drag is already enabled)
obj3 = lv.obj(lv.scr_act(), obj2)
obj3.set_style(style_shadow)
obj3.align(None, lv.ALIGN.CENTER, 60, 30)

View File

@@ -1,40 +0,0 @@
#include "../../../lvgl.h"
#include <stdio.h>
#if LV_USE_ROLLER
static void event_handler(lv_obj_t * obj, lv_event_t event)
{
if(event == LV_EVENT_VALUE_CHANGED) {
char buf[32];
lv_roller_get_selected_str(obj, buf, sizeof(buf));
printf("Selected month: %s\n", buf);
}
}
/**
* An infinite roller with the name of the months
*/
void lv_ex_roller_1(void)
{
lv_obj_t *roller1 = lv_roller_create(lv_scr_act(), NULL);
lv_roller_set_options(roller1,
"January\n"
"February\n"
"March\n"
"April\n"
"May\n"
"June\n"
"July\n"
"August\n"
"September\n"
"October\n"
"November\n"
"December",
LV_ROLLER_MODE_INFINITE);
lv_roller_set_visible_row_count(roller1, 4);
lv_obj_align(roller1, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_add_event_cb(roller1, event_handler, NULL);
}
#endif

View File

@@ -1,24 +0,0 @@
def event_handler(obj, event):
if event == lv.EVENT.VALUE_CHANGED:
option = " "*10
obj.get_selected_str(option, len(option))
print("Selected month: %s" % option.strip())
roller1 = lv.roller(lv.scr_act())
roller1.set_options("\n".join([
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"]), lv.roller.MODE.INIFINITE)
roller1.set_visible_row_count(4)
roller1.align(None, lv.ALIGN.CENTER, 0, 0)
roller1.set_event_cb(event_handler)

View File

@@ -14,7 +14,7 @@ static void event_handler(lv_obj_t * obj, lv_event_t event)
/**
* Roller with various alignments and larger text in the selected area
*/
void lv_ex_roller_2(void)
void lv_example_roller_2(void)
{
/*A style to make the selected option larger*/
static lv_style_t style_sel;

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