mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-26 11:07:34 +08:00
update asserts
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* @file lv_example_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_example_get_started_1(void);
|
||||
void lv_example_get_started_2(void);
|
||||
void lv_example_get_started_3(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_EX_GET_STARTED_H*/
|
||||
@@ -0,0 +1,28 @@
|
||||
#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_example_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*/
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
//#include "../../lv_examples.h"
|
||||
//
|
||||
//
|
||||
///**
|
||||
// * Create styles from scratch for buttons.
|
||||
// */
|
||||
//void lv_example_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
|
||||
//}
|
||||
//
|
||||
//
|
||||
@@ -0,0 +1,31 @@
|
||||
//#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_example_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*/
|
||||
//}
|
||||
//
|
||||
//
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* @file lv_example_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*/
|
||||
@@ -0,0 +1,43 @@
|
||||
//#include "../../lv_examples.h"
|
||||
//
|
||||
///**
|
||||
// * A simple row and a column layout with flexbox
|
||||
// */
|
||||
//void lv_example_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);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
@@ -0,0 +1,24 @@
|
||||
//#include "../../lv_examples.h"
|
||||
//
|
||||
///**
|
||||
// * Arrange items in column with wrap and place the row to get even space around them.
|
||||
// */
|
||||
//void lv_example_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);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
@@ -0,0 +1,30 @@
|
||||
//#include "../../lv_examples.h"
|
||||
//
|
||||
///**
|
||||
// * Arrange items in a row and demonstrate flex grow.
|
||||
// */
|
||||
//void lv_example_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);
|
||||
//}
|
||||
//
|
||||
@@ -0,0 +1,24 @@
|
||||
//#include "../../lv_examples.h"
|
||||
//
|
||||
///**
|
||||
// * Reverse the order of flex items
|
||||
// */
|
||||
//void lv_example_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);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
@@ -0,0 +1,28 @@
|
||||
//#include "../../lv_examples.h"
|
||||
//
|
||||
///**
|
||||
// * Demonstrate the effect of margin on flex item
|
||||
// */
|
||||
//void lv_example_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);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
@@ -0,0 +1,25 @@
|
||||
//#include "../../lv_examples.h"
|
||||
//
|
||||
///**
|
||||
// * RTL base direction changes order of the items.
|
||||
// */
|
||||
//void lv_example_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);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* @file lv_example_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*/
|
||||
@@ -0,0 +1,39 @@
|
||||
//#include "../../lv_examples.h"
|
||||
//
|
||||
///**
|
||||
// * A simple grid
|
||||
// */
|
||||
//void lv_example_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);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
@@ -0,0 +1,59 @@
|
||||
//#include "../../lv_examples.h"
|
||||
//
|
||||
///**
|
||||
// * Demonstrate cell placement and span
|
||||
// */
|
||||
//void lv_example_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");
|
||||
//}
|
||||
//
|
||||
@@ -0,0 +1,45 @@
|
||||
//#include "../../lv_examples.h"
|
||||
//
|
||||
///**
|
||||
// * Demonstrate grid's "free unit"
|
||||
// */
|
||||
//void lv_example_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);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
@@ -0,0 +1,41 @@
|
||||
//#include "../../lv_examples.h"
|
||||
//
|
||||
///**
|
||||
// * Demonstrate track placement
|
||||
// */
|
||||
//void lv_example_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);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
@@ -0,0 +1,41 @@
|
||||
//#include "../../lv_examples.h"
|
||||
//
|
||||
///**
|
||||
// * Demonstrate margin in grid
|
||||
// */
|
||||
//void lv_example_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);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
@@ -0,0 +1,43 @@
|
||||
//#include "../../lv_examples.h"
|
||||
//
|
||||
///**
|
||||
// * Demonstrate RTL direction on grid
|
||||
// */
|
||||
//void lv_example_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);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* @file lv_example_widgets.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_EX_STYLE_H
|
||||
#define LV_EX_STYLE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void lv_example_style_1(void);
|
||||
void lv_example_style_2(void);
|
||||
void lv_example_style_3(void);
|
||||
void lv_example_style_4(void);
|
||||
void lv_example_style_5(void);
|
||||
void lv_example_style_6(void);
|
||||
void lv_example_style_7(void);
|
||||
void lv_example_style_8(void);
|
||||
void lv_example_style_9(void);
|
||||
void lv_example_style_10(void);
|
||||
void lv_example_style_11(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_EX_STYLE_H*/
|
||||
@@ -0,0 +1,28 @@
|
||||
//#include "../../lv_examples.h"
|
||||
//
|
||||
///**
|
||||
// * Using the background style properties
|
||||
// */
|
||||
//void lv_example_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);
|
||||
//}
|
||||
//
|
||||
@@ -0,0 +1,35 @@
|
||||
//#include "../../lv_examples.h"
|
||||
//
|
||||
///**
|
||||
// * Using the transitions style properties
|
||||
// */
|
||||
//void lv_example_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);
|
||||
//}
|
||||
//
|
||||
@@ -0,0 +1,36 @@
|
||||
//#include "../../lv_examples.h"
|
||||
//
|
||||
///**
|
||||
// * Using the scale style properties
|
||||
// */
|
||||
//void lv_example_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
|
||||
//}
|
||||
//
|
||||
@@ -0,0 +1,27 @@
|
||||
//#include "../../lv_examples.h"
|
||||
//
|
||||
///**
|
||||
// * Using the border style properties
|
||||
// */
|
||||
//void lv_example_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);
|
||||
//}
|
||||
//
|
||||
@@ -0,0 +1,26 @@
|
||||
//#include "../../lv_examples.h"
|
||||
//
|
||||
///**
|
||||
// * Using the outline style properties
|
||||
// */
|
||||
//void lv_example_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);
|
||||
//}
|
||||
//
|
||||
@@ -0,0 +1,27 @@
|
||||
//#include "../../lv_examples.h"
|
||||
//
|
||||
///**
|
||||
// * Using the Shadow style properties
|
||||
// */
|
||||
//void lv_example_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);
|
||||
//}
|
||||
//
|
||||
@@ -0,0 +1,27 @@
|
||||
//#include "../../lv_examples.h"
|
||||
//
|
||||
///**
|
||||
// * Using the pattern style properties
|
||||
// */
|
||||
//void lv_example_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);
|
||||
//}
|
||||
//
|
||||
@@ -0,0 +1,30 @@
|
||||
//#include "../../lv_examples.h"
|
||||
//
|
||||
///**
|
||||
// * Using the value style properties
|
||||
// */
|
||||
//void lv_example_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");
|
||||
//}
|
||||
//
|
||||
@@ -0,0 +1,34 @@
|
||||
//#include "../../lv_examples.h"
|
||||
//
|
||||
///**
|
||||
// * Using the text style properties
|
||||
// */
|
||||
//void lv_example_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);
|
||||
//}
|
||||
//
|
||||
@@ -0,0 +1,24 @@
|
||||
//#include "../../lv_examples.h"
|
||||
//
|
||||
///**
|
||||
// * Using the line style properties
|
||||
// */
|
||||
//void lv_example_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
|
||||
//}
|
||||
@@ -0,0 +1,35 @@
|
||||
//#include "../../lv_examples.h"
|
||||
//
|
||||
///**
|
||||
// * Using the image style properties
|
||||
// */
|
||||
//void lv_example_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
|
||||
//}
|
||||
//
|
||||
@@ -0,0 +1,14 @@
|
||||
#include "../../../lvgl.h"
|
||||
|
||||
#if LV_USE_ARC
|
||||
|
||||
void lv_example_arc_1(void)
|
||||
{
|
||||
/*Create an Arc*/
|
||||
lv_obj_t * arc = lv_arc_create(lv_scr_act(), NULL);
|
||||
lv_arc_set_end_angle(arc, 200);
|
||||
lv_obj_set_size(arc, 150, 150);
|
||||
lv_obj_align(arc, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
# Create style for the Arcs
|
||||
style = lv.style_t()
|
||||
lv.style_copy(style, lv.style_plain)
|
||||
style.line.color = lv.color_make(0,0,255) # Arc color
|
||||
style.line.width = 8 # Arc width
|
||||
|
||||
# Create an Arc
|
||||
arc = lv.arc(lv.scr_act())
|
||||
arc.set_style(lv.arc.STYLE.MAIN, style) # Use the new style
|
||||
arc.set_angles(90, 60)
|
||||
arc.set_size(150, 150)
|
||||
arc.align(None, lv.ALIGN.CENTER, 0, 0)
|
||||
@@ -0,0 +1,38 @@
|
||||
#include "../../../lvgl.h"
|
||||
#if LV_USE_ARC
|
||||
|
||||
/**
|
||||
* An `lv_task` to call periodically to set the angles of the arc
|
||||
* @param t
|
||||
*/
|
||||
static void arc_loader(lv_timer_t * t)
|
||||
{
|
||||
static int16_t a = 270;
|
||||
|
||||
a+=5;
|
||||
|
||||
lv_arc_set_end_angle(t->user_data, a);
|
||||
|
||||
if(a >= 270 + 360) {
|
||||
lv_timer_del(t);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an arc which acts as a loader.
|
||||
*/
|
||||
void lv_example_arc_2(void)
|
||||
{
|
||||
/*Create an Arc*/
|
||||
lv_obj_t * arc = lv_arc_create(lv_scr_act(), NULL);
|
||||
lv_arc_set_bg_angles(arc, 0, 360);
|
||||
lv_arc_set_angles(arc, 270, 270);
|
||||
lv_obj_align(arc, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
|
||||
/* Create an `lv_task` to update the arc.
|
||||
* Store the `arc` in the user data*/
|
||||
lv_timer_create(arc_loader, 20, arc);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,43 @@
|
||||
# Create an arc which acts as a loader.
|
||||
class loader_arc(lv.arc):
|
||||
|
||||
def __init__(self, parent, color=lv.color_hex(0x000080),
|
||||
width=8, style=lv.style_plain, rate=20):
|
||||
super().__init__(parent)
|
||||
|
||||
self.a = 0
|
||||
self.rate = rate
|
||||
|
||||
# Create style for the Arcs
|
||||
self.style = lv.style_t()
|
||||
lv.style_copy(self.style, style)
|
||||
self.style.line.color = color
|
||||
self.style.line.width = width
|
||||
|
||||
# Create an Arc
|
||||
self.set_angles(180, 180);
|
||||
self.set_style(self.STYLE.MAIN, self.style);
|
||||
|
||||
# Spin the Arc
|
||||
self.spin()
|
||||
|
||||
def spin(self):
|
||||
# Create an `lv_task` to update the arc.
|
||||
lv.task_create(self.task_cb, self.rate, lv.TASK_PRIO.LOWEST, {})
|
||||
|
||||
|
||||
# An `lv_task` to call periodically to set the angles of the arc
|
||||
def task_cb(self, task):
|
||||
self.a+=5;
|
||||
if self.a >= 359: self.a = 359
|
||||
|
||||
if self.a < 180: self.set_angles(180-self.a, 180)
|
||||
else: self.set_angles(540-self.a, 180)
|
||||
|
||||
if self.a == 359:
|
||||
self.a = 0
|
||||
lv.task_del(task)
|
||||
|
||||
# Create a loader arc
|
||||
loader_arc = loader_arc(lv.scr_act())
|
||||
loader_arc.align(None, lv.ALIGN.CENTER, 0, 0)
|
||||
@@ -0,0 +1,12 @@
|
||||
#include "../../../lvgl.h"
|
||||
#if LV_USE_BAR
|
||||
|
||||
void lv_example_bar_1(void)
|
||||
{
|
||||
lv_obj_t * bar1 = lv_bar_create(lv_scr_act(), NULL);
|
||||
lv_obj_set_size(bar1, 200, 20);
|
||||
lv_obj_align(bar1, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_bar_set_value(bar1, 70, LV_ANIM_OFF);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,5 @@
|
||||
bar1 = lv.bar(lv.scr_act())
|
||||
bar1.set_size(200, 30)
|
||||
bar1.align(None, lv.ALIGN.CENTER, 0, 0)
|
||||
bar1.set_anim_time(1000)
|
||||
bar1.set_value(100, lv.ANIM.ON)
|
||||
@@ -0,0 +1,37 @@
|
||||
#include "../../../lvgl.h"
|
||||
#if LV_USE_BAR
|
||||
|
||||
static void set_temp(lv_obj_t * bar, int32_t temp)
|
||||
{
|
||||
lv_bar_set_value(bar, temp, LV_ANIM_ON);
|
||||
|
||||
static char buf[10]; /*Only the pointer t saved so must be static*/
|
||||
lv_snprintf(buf, sizeof(buf), "%d°C", temp);
|
||||
lv_obj_set_style_content_text(bar, LV_PART_INDICATOR, LV_STATE_DEFAULT, buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* A temperature meter example
|
||||
*/
|
||||
void lv_example_bar_3(void)
|
||||
{
|
||||
static lv_style_t style_indic;
|
||||
|
||||
lv_style_init(&style_indic);
|
||||
lv_style_set_bg_opa(&style_indic, LV_OPA_COVER);
|
||||
lv_style_set_bg_color(&style_indic, LV_COLOR_RED);
|
||||
lv_style_set_bg_grad_color(&style_indic, LV_COLOR_BLUE);
|
||||
lv_style_set_bg_grad_dir(&style_indic, LV_GRAD_DIR_VER);
|
||||
lv_style_set_content_align(&style_indic, LV_ALIGN_OUT_LEFT_TOP);
|
||||
lv_style_set_content_ofs_x(&style_indic, -3);
|
||||
|
||||
lv_obj_t * bar = lv_bar_create(lv_scr_act(), NULL);
|
||||
lv_obj_add_style(bar, LV_PART_INDICATOR, LV_STATE_DEFAULT, &style_indic);
|
||||
lv_obj_set_size(bar, 20, 200);
|
||||
lv_obj_align(bar, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_bar_set_range(bar, -20, 40);
|
||||
set_temp(bar, 30);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,27 @@
|
||||
#include "../../../lvgl.h"
|
||||
#if LV_USE_BAR
|
||||
|
||||
/**
|
||||
* Bar with stripe pattern and ranged value
|
||||
*/
|
||||
void lv_example_bar_4(void)
|
||||
{
|
||||
LV_IMG_DECLARE(img_skew_strip);
|
||||
static lv_style_t style_indic;
|
||||
|
||||
lv_style_init(&style_indic);
|
||||
lv_style_set_bg_img_src(&style_indic, &img_skew_strip);
|
||||
lv_style_set_bg_img_tiled(&style_indic, true);
|
||||
lv_style_set_bg_img_opa(&style_indic, LV_OPA_30);
|
||||
|
||||
lv_obj_t * bar = lv_bar_create(lv_scr_act(), NULL);
|
||||
lv_obj_add_style(bar, LV_PART_INDICATOR, LV_STATE_DEFAULT, &style_indic);
|
||||
|
||||
lv_obj_set_size(bar, 260, 20);
|
||||
lv_obj_align(bar, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_bar_set_type(bar, LV_BAR_TYPE_RANGE);
|
||||
lv_bar_set_value(bar, 90, LV_ANIM_OFF);
|
||||
lv_bar_set_start_value(bar, 20, LV_ANIM_OFF);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
#include "../../../lvgl.h"
|
||||
#if LV_USE_BAR
|
||||
|
||||
/**
|
||||
* Bar with LTR and RTL base direction
|
||||
*/
|
||||
void lv_example_bar_5(void)
|
||||
{
|
||||
static lv_style_t style_bg;
|
||||
lv_style_init(&style_bg);
|
||||
lv_style_set_content_ofs_y(&style_bg, -3);
|
||||
lv_style_set_content_align(&style_bg, LV_ALIGN_OUT_TOP_MID);
|
||||
|
||||
lv_obj_t * bar_ltr = lv_bar_create(lv_scr_act(), NULL);
|
||||
lv_obj_set_size(bar_ltr, 200, 20);
|
||||
lv_bar_set_value(bar_ltr, 70, LV_ANIM_OFF);
|
||||
lv_obj_align(bar_ltr, NULL, LV_ALIGN_CENTER, 0, -30);
|
||||
lv_obj_add_style(bar_ltr, LV_PART_MAIN, LV_STATE_DEFAULT, &style_bg);
|
||||
lv_obj_set_style_content_text(bar_ltr, LV_PART_MAIN, LV_STATE_DEFAULT, "Left to Right base direction");
|
||||
|
||||
lv_obj_t * bar_rtl = lv_bar_create(lv_scr_act(), NULL);
|
||||
lv_obj_set_base_dir(bar_rtl, LV_BIDI_DIR_RTL);
|
||||
lv_obj_set_size(bar_rtl, 200, 20);
|
||||
lv_bar_set_value(bar_rtl, 70, LV_ANIM_OFF);
|
||||
lv_obj_align(bar_rtl, NULL, LV_ALIGN_CENTER, 0, 30);
|
||||
lv_obj_add_style(bar_rtl, LV_PART_MAIN, LV_STATE_DEFAULT, &style_bg);
|
||||
lv_obj_set_style_content_text(bar_rtl, LV_PART_MAIN, LV_STATE_DEFAULT, "Right to Left base direction");
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,68 @@
|
||||
#include "../../../lvgl.h"
|
||||
#if LV_USE_BAR
|
||||
|
||||
static void event_cb(lv_obj_t * obj, lv_event_t e)
|
||||
{
|
||||
if(e == LV_EVENT_DRAW_POST_END) {
|
||||
lv_bar_t * bar = (lv_bar_t *)obj;
|
||||
|
||||
lv_draw_label_dsc_t dsc;
|
||||
lv_draw_label_dsc_init(&dsc);
|
||||
dsc.font = LV_THEME_FONT_NORMAL;
|
||||
|
||||
char buf[8];
|
||||
lv_snprintf(buf, sizeof(buf), "%d", lv_bar_get_value(obj));
|
||||
|
||||
lv_point_t txt_size;
|
||||
lv_txt_get_size(&txt_size, buf, dsc.font, dsc.letter_space, dsc.line_space, LV_COORD_MAX, dsc.flag);
|
||||
|
||||
lv_area_t txt_area;
|
||||
/*If the indicator is long enough put the text inside on the right*/
|
||||
if(lv_area_get_width(&bar->indic_area) > txt_size.x + 20) {
|
||||
txt_area.x2 = bar->indic_area.x2 - 5;
|
||||
txt_area.x1 = txt_area.x2 - txt_size.x + 1;
|
||||
dsc.color = LV_COLOR_WHITE;
|
||||
}
|
||||
/*If the indicator is still short put the text out of it on the right */
|
||||
else {
|
||||
txt_area.x1 = bar->indic_area.x2 + 5;
|
||||
txt_area.x2 = txt_area.x1 + txt_size.x - 1;
|
||||
dsc.color = LV_COLOR_BLACK;
|
||||
}
|
||||
|
||||
txt_area.y1 = bar->indic_area.y1 + (lv_area_get_height(&bar->indic_area) - txt_size.y) / 2;
|
||||
txt_area.y2 = txt_area.y1 + txt_size.y - 1;
|
||||
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
lv_draw_label(&txt_area, clip_area, &dsc, buf, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom drawer on bar to display the current value
|
||||
*/
|
||||
void lv_example_bar_6(void)
|
||||
{
|
||||
static lv_style_t style_bg;
|
||||
lv_style_init(&style_bg);
|
||||
lv_style_set_content_ofs_y(&style_bg, -3);
|
||||
lv_style_set_content_align(&style_bg, LV_ALIGN_OUT_TOP_MID);
|
||||
|
||||
lv_obj_t * bar = lv_bar_create(lv_scr_act(), NULL);
|
||||
lv_obj_add_event_cb(bar, event_cb, NULL);
|
||||
lv_obj_set_size(bar, 200, 20);
|
||||
lv_obj_align(bar, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
|
||||
lv_anim_t a;
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_var(&a, bar);
|
||||
lv_anim_set_values(&a, 0, 100);
|
||||
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t) lv_bar_set_value);
|
||||
lv_anim_set_time(&a, 2000);
|
||||
lv_anim_set_playback_time(&a, 2000);
|
||||
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
|
||||
lv_anim_start(&a);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,35 @@
|
||||
#include "../../../lvgl.h"
|
||||
#include <stdio.h>
|
||||
#if LV_USE_BTN
|
||||
|
||||
static void event_handler(lv_obj_t * obj, lv_event_t event)
|
||||
{
|
||||
if(event == LV_EVENT_CLICKED) {
|
||||
printf("Clicked\n");
|
||||
}
|
||||
else if(event == LV_EVENT_VALUE_CHANGED) {
|
||||
printf("Toggled\n");
|
||||
}
|
||||
}
|
||||
|
||||
void lv_example_btn_1(void)
|
||||
{
|
||||
lv_obj_t * label;
|
||||
|
||||
lv_obj_t * btn1 = lv_btn_create(lv_scr_act(), NULL);
|
||||
lv_obj_add_event_cb(btn1, event_handler, NULL);
|
||||
lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, -40);
|
||||
|
||||
label = lv_label_create(btn1, NULL);
|
||||
lv_label_set_text(label, "Button");
|
||||
|
||||
lv_obj_t * btn2 = lv_btn_create(lv_scr_act(), NULL);
|
||||
lv_obj_add_event_cb(btn2, event_handler, NULL);
|
||||
lv_obj_align(btn2, NULL, LV_ALIGN_CENTER, 0, 40);
|
||||
lv_obj_add_flag(btn2, LV_OBJ_FLAG_CHECKABLE);
|
||||
lv_obj_set_height(btn2, LV_SIZE_CONTENT);
|
||||
|
||||
label = lv_label_create(btn2, NULL);
|
||||
lv_label_set_text(label, "Toggle");
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,21 @@
|
||||
def event_handler(obj, event):
|
||||
if event == lv.EVENT.CLICKED:
|
||||
print("Clicked")
|
||||
|
||||
btn1 = lv.btn(lv.scr_act())
|
||||
btn1.set_event_cb(event_handler)
|
||||
btn1.align(None, lv.ALIGN.CENTER, 0, -40)
|
||||
|
||||
label = lv.label(btn1)
|
||||
label.set_text("Button")
|
||||
|
||||
btn2 = lv.btn(lv.scr_act())
|
||||
# callback can be lambda:
|
||||
btn2.set_event_cb(lambda obj, event: print("Toggled") if event == lv.EVENT.VALUE_CHANGED else None)
|
||||
btn2.align(None, lv.ALIGN.CENTER, 0, 40)
|
||||
btn2.set_toggle(True)
|
||||
btn2.toggle()
|
||||
btn2.set_fit2(lv.FIT.NONE, lv.FIT.TIGHT)
|
||||
|
||||
label = lv.label(btn2)
|
||||
label.set_text("Toggled")
|
||||
@@ -0,0 +1,52 @@
|
||||
#include "../../../lvgl.h"
|
||||
#include <stdio.h>
|
||||
#if LV_USE_BTN
|
||||
|
||||
/**
|
||||
* Style a button from scratch
|
||||
*/
|
||||
void lv_example_btn_2(void)
|
||||
{
|
||||
|
||||
static lv_style_t style;
|
||||
static lv_style_t style_pr;
|
||||
lv_style_init(&style);
|
||||
lv_style_init(&style_pr);
|
||||
|
||||
/*Init the default style*/
|
||||
lv_style_set_radius(&style, 3);
|
||||
|
||||
lv_style_set_bg_opa(&style, LV_OPA_70);
|
||||
lv_style_set_bg_color(&style, LV_COLOR_BLUE);
|
||||
lv_style_set_bg_grad_color(&style, LV_COLOR_AQUA);
|
||||
lv_style_set_bg_grad_dir(&style, LV_GRAD_DIR_VER);
|
||||
|
||||
lv_style_set_border_opa(&style, LV_OPA_40);
|
||||
lv_style_set_border_width(&style, 2);
|
||||
lv_style_set_border_color(&style, LV_COLOR_GRAY);
|
||||
|
||||
lv_style_set_shadow_width(&style, 8);
|
||||
lv_style_set_shadow_color(&style, LV_COLOR_GRAY);
|
||||
lv_style_set_shadow_ofs_x(&style, 8);
|
||||
lv_style_set_shadow_ofs_y(&style, 8);
|
||||
|
||||
lv_style_set_text_color(&style, LV_COLOR_WHITE);
|
||||
|
||||
/*Init the pressed style*/
|
||||
lv_style_set_shadow_ofs_x(&style_pr, 4);
|
||||
lv_style_set_shadow_ofs_y(&style_pr, 4);
|
||||
lv_style_set_color_filter_cb(&style_pr, lv_color_darken); /*Darken every color*/
|
||||
lv_style_set_color_filter_opa(&style_pr, LV_OPA_30);
|
||||
|
||||
lv_obj_t * btn1 = lv_btn_create(lv_scr_act(), NULL);
|
||||
lv_obj_remove_style(btn1, LV_PART_ANY, LV_STATE_ANY, NULL);
|
||||
lv_obj_add_style(btn1, LV_PART_MAIN, LV_STATE_DEFAULT, &style);
|
||||
lv_obj_add_style(btn1, LV_PART_MAIN, LV_STATE_PRESSED, &style_pr);
|
||||
lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
|
||||
lv_obj_t * label = lv_label_create(btn1, NULL);
|
||||
lv_label_set_text(label, "Button");
|
||||
lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,31 @@
|
||||
#include "../../../lvgl.h"
|
||||
#include <stdio.h>
|
||||
#if LV_USE_BTNMATRIX
|
||||
|
||||
static void event_handler(lv_obj_t * obj, lv_event_t event)
|
||||
{
|
||||
if(event == LV_EVENT_VALUE_CHANGED) {
|
||||
uint32_t id = lv_btnmatrix_get_active_btn(obj);
|
||||
const char * txt = lv_btnmatrix_get_btn_text(obj, id);
|
||||
|
||||
printf("%s was pressed\n", txt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static const char * btnm_map[] = {"1", "2", "3", "4", "5", "\n",
|
||||
"6", "7", "8", "9", "0", "\n",
|
||||
"Action1", "Action2", ""};
|
||||
|
||||
void lv_example_btnmatrix_1(void)
|
||||
{
|
||||
lv_obj_t * btnm1 = lv_btnmatrix_create(lv_scr_act(), NULL);
|
||||
lv_btnmatrix_set_map(btnm1, btnm_map);
|
||||
lv_btnmatrix_set_btn_width(btnm1, 10, 2); /*Make "Action1" twice as wide as "Action2"*/
|
||||
lv_btnmatrix_set_btn_ctrl(btnm1, 10, LV_BTNMATRIX_CTRL_CHECKABLE);
|
||||
lv_btnmatrix_set_btn_ctrl(btnm1, 11, LV_BTNMATRIX_CTRL_CHECKED);
|
||||
lv_obj_align(btnm1, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_obj_add_event_cb(btnm1, event_handler, NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,14 @@
|
||||
def event_handler(obj, event):
|
||||
if event == lv.EVENT.VALUE_CHANGED:
|
||||
txt = obj.get_active_btn_text()
|
||||
print("%s was pressed" % txt)
|
||||
|
||||
btnm_map = ["1", "2", "3", "4", "5", "\n",
|
||||
"6", "7", "8", "9", "0", "\n",
|
||||
"Action1", "Action2", ""]
|
||||
|
||||
btnm1 = lv.btnm(lv.scr_act())
|
||||
btnm1.set_map(btnm_map)
|
||||
btnm1.set_btn_width(10, 2) # Make "Action1" twice as wide as "Action2"
|
||||
btnm1.align(None, lv.ALIGN.CENTER, 0, 0)
|
||||
btnm1.set_event_cb(event_handler)
|
||||
@@ -0,0 +1,71 @@
|
||||
#include "../../../lvgl.h"
|
||||
#include <stdio.h>
|
||||
#if LV_USE_BTNMATRIX
|
||||
|
||||
|
||||
void event_cb(lv_obj_t * obj, lv_event_t e)
|
||||
{
|
||||
if(e == LV_EVENT_DRAW_PART_BEGIN) {
|
||||
lv_obj_draw_hook_dsc_t * dsc = lv_event_get_param();
|
||||
|
||||
/*Change the draw descriptor the 2nd button */
|
||||
if(dsc->id == 1) {
|
||||
dsc->rect_dsc->radius = 0;
|
||||
if(lv_btnmatrix_get_pressed_btn(obj) == dsc->id) dsc->rect_dsc->bg_color = LV_COLOR_NAVY;
|
||||
else dsc->rect_dsc->bg_color = LV_COLOR_BLUE;
|
||||
|
||||
dsc->rect_dsc->shadow_width = 6;
|
||||
dsc->rect_dsc->shadow_ofs_x = 3;
|
||||
dsc->rect_dsc->shadow_ofs_y = 3;
|
||||
dsc->label_dsc->color = LV_COLOR_WHITE;
|
||||
}
|
||||
/*Change the draw descriptor the 3rd button */
|
||||
else if(dsc->id == 2) {
|
||||
dsc->rect_dsc->radius = LV_RADIUS_CIRCLE;
|
||||
if(lv_btnmatrix_get_pressed_btn(obj) == dsc->id) dsc->rect_dsc->bg_color = LV_COLOR_MAROON;
|
||||
else dsc->rect_dsc->bg_color = LV_COLOR_RED;
|
||||
|
||||
dsc->label_dsc->color = LV_COLOR_WHITE;
|
||||
}
|
||||
else if(dsc->id == 3) {
|
||||
dsc->label_dsc->opa = LV_OPA_TRANSP; /*Hide the text if any*/
|
||||
|
||||
}
|
||||
}
|
||||
if(e == LV_EVENT_DRAW_PART_END) {
|
||||
lv_obj_draw_hook_dsc_t * dsc = lv_event_get_param();
|
||||
|
||||
/*Add custom content to the 4th button when the button itself was drawn*/
|
||||
if(dsc->id == 3) {
|
||||
LV_IMG_DECLARE(img_star);
|
||||
lv_img_header_t header;
|
||||
lv_res_t res = lv_img_decoder_get_info(&img_star, &header);
|
||||
if(res != LV_RES_OK) return;
|
||||
|
||||
lv_area_t a;
|
||||
a.x1 = dsc->draw_area->x1 + (lv_area_get_width(dsc->draw_area) - header.w) / 2;
|
||||
a.x2 = a.x1 + header.w - 1;
|
||||
a.y1 = dsc->draw_area->y1 + (lv_area_get_height(dsc->draw_area) - header.h) / 2;
|
||||
a.y2 = a.y1 + header.h - 1;
|
||||
|
||||
lv_draw_img_dsc_t img_draw_dsc;
|
||||
lv_draw_img_dsc_init(&img_draw_dsc);
|
||||
img_draw_dsc.recolor = LV_COLOR_BLACK;
|
||||
if(lv_btnmatrix_get_pressed_btn(obj) == dsc->id) img_draw_dsc.recolor_opa = LV_OPA_30;
|
||||
|
||||
lv_draw_img(&a, dsc->clip_area, &img_star, &img_draw_dsc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add custom drawer to the button matrix to c
|
||||
*/
|
||||
void lv_example_btnmatrix_2(void)
|
||||
{
|
||||
lv_obj_t * btnm = lv_btnmatrix_create(lv_scr_act(), NULL);
|
||||
lv_obj_add_event_cb(btnm, event_cb, NULL);
|
||||
lv_obj_align(btnm, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,71 @@
|
||||
#include "../../../lvgl.h"
|
||||
#include <stdio.h>
|
||||
#if LV_USE_BTNMATRIX
|
||||
|
||||
|
||||
static void event_cb(lv_obj_t * obj, lv_event_t e)
|
||||
{
|
||||
if(e == LV_EVENT_VALUE_CHANGED) {
|
||||
uint32_t id = lv_btnmatrix_get_active_btn(obj);
|
||||
bool prev = id == 0 ? true : false;
|
||||
bool next = id == 6 ? true : false;
|
||||
if(prev || next) {
|
||||
/*Find the checked button*/
|
||||
uint32_t i;
|
||||
for(i = 1; i < 7; i++) {
|
||||
if(lv_btnmatrix_has_btn_ctrl(obj, i, LV_BTNMATRIX_CTRL_CHECKED)) break;
|
||||
}
|
||||
|
||||
if(prev && i > 1) i--;
|
||||
else if(next && i < 5) i++;
|
||||
|
||||
lv_btnmatrix_set_btn_ctrl(obj, i, LV_BTNMATRIX_CTRL_CHECKED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a button group
|
||||
*/
|
||||
void lv_example_btnmatrix_3(void)
|
||||
{
|
||||
static lv_style_t style_bg;
|
||||
lv_style_init(&style_bg);
|
||||
lv_style_set_pad_all(&style_bg, 0);
|
||||
lv_style_set_pad_gap(&style_bg, 0);
|
||||
lv_style_set_clip_corner(&style_bg, true);
|
||||
lv_style_set_radius(&style_bg, LV_RADIUS_CIRCLE);
|
||||
lv_style_set_border_width(&style_bg, 0);
|
||||
|
||||
|
||||
static lv_style_t style_btn;
|
||||
lv_style_init(&style_btn);
|
||||
lv_style_set_radius(&style_btn, 0);
|
||||
lv_style_set_border_width(&style_btn, 1);
|
||||
lv_style_set_border_opa(&style_btn, LV_OPA_50);
|
||||
lv_style_set_border_color(&style_btn, LV_COLOR_GRAY);
|
||||
lv_style_set_border_side(&style_btn, LV_BORDER_SIDE_INTERNAL);
|
||||
lv_style_set_radius(&style_btn, 0);
|
||||
|
||||
static const char * map[] = {LV_SYMBOL_LEFT, "1", "2", "3", "4", "5", LV_SYMBOL_RIGHT, ""};
|
||||
|
||||
lv_obj_t * btnm = lv_btnmatrix_create(lv_scr_act(), NULL);
|
||||
lv_btnmatrix_set_map(btnm, map);
|
||||
lv_obj_add_style(btnm, LV_PART_MAIN, LV_STATE_DEFAULT, &style_bg);
|
||||
lv_obj_add_style(btnm, LV_PART_ITEMS, LV_STATE_DEFAULT, &style_btn);
|
||||
lv_obj_add_event_cb(btnm, event_cb, NULL);
|
||||
lv_obj_set_size(btnm, 225, 35);
|
||||
|
||||
/*Allow selecting on one number at time*/
|
||||
lv_btnmatrix_set_btn_ctrl_all(btnm, LV_BTNMATRIX_CTRL_CHECKABLE);
|
||||
lv_btnmatrix_clear_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKABLE);
|
||||
lv_btnmatrix_clear_btn_ctrl(btnm, 6, LV_BTNMATRIX_CTRL_CHECKABLE);
|
||||
|
||||
lv_btnmatrix_set_one_checked(btnm, true);
|
||||
lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKED);
|
||||
|
||||
lv_obj_align(btnm, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,55 @@
|
||||
#include "../../../lvgl.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#if LV_USE_CALENDAR
|
||||
|
||||
static void event_handler(lv_obj_t * obj, lv_event_t event)
|
||||
{
|
||||
if(event == LV_EVENT_VALUE_CHANGED) {
|
||||
lv_calendar_date_t date;
|
||||
if(lv_calendar_get_pressed_date(obj, &date)) {
|
||||
printf("Clicked date: %02d.%02d.%d\n", date.day, date.month, date.year);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void lv_example_calendar_1(void)
|
||||
{
|
||||
lv_obj_t * calendar = lv_calendar_create(lv_scr_act());
|
||||
lv_obj_set_size(calendar, 180, 180);
|
||||
lv_obj_align(calendar, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_obj_add_event_cb(calendar, event_handler, NULL);
|
||||
|
||||
/*Set today's date*/
|
||||
lv_calendar_date_t today;
|
||||
today.year = 2021;
|
||||
today.month = 02;
|
||||
today.day = 23;
|
||||
|
||||
lv_calendar_set_today_date(calendar, &today);
|
||||
lv_calendar_set_showed_date(calendar, &today);
|
||||
|
||||
/*Highlight a few days*/
|
||||
static lv_calendar_date_t highlighted_days[3]; /*Only its pointer will be saved so should be static*/
|
||||
highlighted_days[0].year = 2020;
|
||||
highlighted_days[0].month = 10;
|
||||
highlighted_days[0].day = 6;
|
||||
|
||||
highlighted_days[1].year = 2020;
|
||||
highlighted_days[1].month = 10;
|
||||
highlighted_days[1].day = 11;
|
||||
|
||||
highlighted_days[2].year = 2020;
|
||||
highlighted_days[2].month = 11;
|
||||
highlighted_days[2].day = 22;
|
||||
|
||||
lv_calendar_set_highlighted_dates(calendar, highlighted_days, 3);
|
||||
|
||||
#if LV_USE_CALENDAR_HEADER_ARROW
|
||||
lv_obj_t * h = lv_calendar_header_arrow_create(lv_scr_act(), calendar, 25);
|
||||
lv_obj_align(h, NULL, LV_ALIGN_IN_TOP_MID, 0, 5);
|
||||
lv_obj_align(calendar, h, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,53 @@
|
||||
#include "../../../lvgl.h"
|
||||
#if LV_USE_CANVAS
|
||||
|
||||
|
||||
#define CANVAS_WIDTH 200
|
||||
#define CANVAS_HEIGHT 150
|
||||
|
||||
void lv_example_canvas_1(void)
|
||||
{
|
||||
lv_draw_rect_dsc_t rect_dsc;
|
||||
lv_draw_rect_dsc_init(&rect_dsc);
|
||||
rect_dsc.radius = 10;
|
||||
rect_dsc.bg_opa = LV_OPA_COVER;
|
||||
rect_dsc.bg_grad_dir = LV_GRAD_DIR_HOR;
|
||||
rect_dsc.bg_color = LV_COLOR_RED;
|
||||
rect_dsc.bg_grad_color = LV_COLOR_BLUE;
|
||||
rect_dsc.border_width = 2;
|
||||
rect_dsc.border_opa = LV_OPA_90;
|
||||
rect_dsc.border_color = LV_COLOR_WHITE;
|
||||
rect_dsc.shadow_width = 5;
|
||||
rect_dsc.shadow_ofs_x = 5;
|
||||
rect_dsc.shadow_ofs_y = 5;
|
||||
|
||||
lv_draw_label_dsc_t label_dsc;
|
||||
lv_draw_label_dsc_init(&label_dsc);
|
||||
label_dsc.color = LV_COLOR_YELLOW;
|
||||
|
||||
static lv_color_t cbuf[LV_CANVAS_BUF_SIZE_TRUE_COLOR(CANVAS_WIDTH, CANVAS_HEIGHT)];
|
||||
|
||||
lv_obj_t * canvas = lv_canvas_create(lv_scr_act(), NULL);
|
||||
lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_TRUE_COLOR);
|
||||
lv_obj_align(canvas, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_canvas_fill_bg(canvas, LV_COLOR_SILVER, LV_OPA_COVER);
|
||||
|
||||
lv_canvas_draw_rect(canvas, 70, 60, 100, 70, &rect_dsc);
|
||||
|
||||
lv_canvas_draw_text(canvas, 40, 20, 100, &label_dsc, "Some text on text canvas");
|
||||
|
||||
/* Test the rotation. It requires an other buffer where the orignal image is stored.
|
||||
* So copy the current image to buffer and rotate it to the canvas */
|
||||
static lv_color_t cbuf_tmp[CANVAS_WIDTH * CANVAS_HEIGHT];
|
||||
memcpy(cbuf_tmp, cbuf, sizeof(cbuf_tmp));
|
||||
lv_img_dsc_t img;
|
||||
img.data = (void *)cbuf_tmp;
|
||||
img.header.cf = LV_IMG_CF_TRUE_COLOR;
|
||||
img.header.w = CANVAS_WIDTH;
|
||||
img.header.h = CANVAS_HEIGHT;
|
||||
|
||||
lv_canvas_fill_bg(canvas, LV_COLOR_SILVER, LV_OPA_COVER);
|
||||
lv_canvas_transform(canvas, &img, 30, LV_IMG_ZOOM_NONE, 0, 0, CANVAS_WIDTH / 2, CANVAS_HEIGHT / 2, true);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,38 @@
|
||||
CANVAS_WIDTH = 200
|
||||
CANVAS_HEIGHT = 150
|
||||
|
||||
style = lv.style_t()
|
||||
lv.style_copy(style, lv.style_plain)
|
||||
style.body.main_color = lv.color_make(0xFF,0,0)
|
||||
style.body.grad_color = lv.color_make(0x80,0,0)
|
||||
style.body.radius = 4
|
||||
style.body.border.width = 2
|
||||
style.body.border.color = lv.color_make(0xFF,0xFF,0xFF)
|
||||
style.body.shadow.color = lv.color_make(0xFF,0xFF,0xFF)
|
||||
style.body.shadow.width = 4
|
||||
style.line.width = 2
|
||||
style.line.color = lv.color_make(0,0,0)
|
||||
style.text.color = lv.color_make(0,0,0xFF)
|
||||
|
||||
# CF.TRUE_COLOR requires 4 bytes per pixel
|
||||
cbuf = bytearray(CANVAS_WIDTH * CANVAS_HEIGHT * 4)
|
||||
|
||||
canvas = lv.canvas(lv.scr_act())
|
||||
canvas.set_buffer(cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, lv.img.CF.TRUE_COLOR)
|
||||
canvas.align(None, lv.ALIGN.CENTER, 0, 0)
|
||||
canvas.fill_bg(lv.color_make(0xC0, 0xC0, 0xC0))
|
||||
|
||||
canvas.draw_rect(70, 60, 100, 70, style)
|
||||
|
||||
canvas.draw_text(40, 20, 100, style, "Some text on text canvas", lv.label.ALIGN.LEFT)
|
||||
|
||||
# Test the rotation. It requires an other buffer where the orignal image is stored.
|
||||
# So copy the current image to buffer and rotate it to the canvas
|
||||
img = lv.img_dsc_t()
|
||||
img.data = cbuf[:]
|
||||
img.header.cf = lv.img.CF.TRUE_COLOR
|
||||
img.header.w = CANVAS_WIDTH
|
||||
img.header.h = CANVAS_HEIGHT
|
||||
|
||||
canvas.fill_bg(lv.color_make(0xC0, 0xC0, 0xC0))
|
||||
canvas.rotate(img, 30, 0, 0, CANVAS_WIDTH // 2, CANVAS_HEIGHT // 2)
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user