mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
add some extra components and examples
This commit is contained in:
parent
8a1af8646f
commit
2cae4a27c1
71
examples/widgets/btnmatrix/lv_btnmatrix_example_3.c
Normal file
71
examples/widgets/btnmatrix/lv_btnmatrix_example_3.c
Normal file
@ -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_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
|
@ -2,7 +2,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#if LV_USE_MSGBOX
|
#if LV_USE_MSGBOX
|
||||||
|
|
||||||
static void event_handler(lv_obj_t * obj, lv_event_t event)
|
static void event_cb(lv_obj_t * obj, lv_event_t event)
|
||||||
{
|
{
|
||||||
if(event == LV_EVENT_VALUE_CHANGED) {
|
if(event == LV_EVENT_VALUE_CHANGED) {
|
||||||
printf("Button: %s\n", lv_msgbox_get_active_btn_text(obj));
|
printf("Button: %s\n", lv_msgbox_get_active_btn_text(obj));
|
||||||
@ -11,15 +11,15 @@ static void event_handler(lv_obj_t * obj, lv_event_t event)
|
|||||||
|
|
||||||
void lv_ex_msgbox_1(void)
|
void lv_ex_msgbox_1(void)
|
||||||
{
|
{
|
||||||
static lv_style_t style;
|
// static lv_style_t style;
|
||||||
lv_style_init(&style);
|
// lv_style_init(&style);
|
||||||
lv_style_set_radius(&style, LV_STATE_DEFAULT, 30);
|
// lv_style_set_radius(&style, LV_STATE_DEFAULT, 30);
|
||||||
|
|
||||||
static const char * btns[] ={"Apply", "Close", ""};
|
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_t * mbox1 = lv_msgbox_create("Hello", "This is a message box with two buttons.", btns, true);
|
||||||
// lv_obj_set_width(mbox1, 300);
|
// lv_obj_set_width(mbox1, 300);
|
||||||
lv_obj_set_event_cb(mbox1, event_handler);
|
lv_obj_add_event_cb(mbox1, event_cb, NULL);
|
||||||
lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the corner*/
|
lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the corner*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,16 +30,18 @@ void lv_ex_spinbox_1(void)
|
|||||||
lv_obj_align(spinbox, NULL, LV_ALIGN_CENTER, 0, 0);
|
lv_obj_align(spinbox, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||||
|
|
||||||
lv_coord_t h = lv_obj_get_height(spinbox);
|
lv_coord_t h = lv_obj_get_height(spinbox);
|
||||||
|
|
||||||
lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL);
|
lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL);
|
||||||
lv_obj_set_size(btn, h, h);
|
lv_obj_set_size(btn, h, h);
|
||||||
lv_obj_align(btn, spinbox, LV_ALIGN_OUT_RIGHT_MID, 5, 0);
|
lv_obj_align(btn, spinbox, LV_ALIGN_OUT_RIGHT_MID, 5, 0);
|
||||||
lv_obj_set_style_local_value_str(btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_SYMBOL_PLUS);
|
lv_obj_set_style_content_text(btn, LV_PART_MAIN, LV_STATE_DEFAULT, LV_SYMBOL_PLUS);
|
||||||
lv_obj_set_event_cb(btn, lv_spinbox_increment_event_cb);
|
lv_obj_add_event_cb(btn, lv_spinbox_increment_event_cb, NULL);
|
||||||
|
|
||||||
btn = lv_btn_create(lv_scr_act(), btn);
|
btn = lv_btn_create(lv_scr_act(), NULL);
|
||||||
|
lv_obj_set_size(btn, h, h);
|
||||||
lv_obj_align(btn, spinbox, LV_ALIGN_OUT_LEFT_MID, -5, 0);
|
lv_obj_align(btn, spinbox, LV_ALIGN_OUT_LEFT_MID, -5, 0);
|
||||||
lv_obj_set_event_cb(btn, lv_spinbox_decrement_event_cb);
|
lv_obj_set_style_content_text(btn, LV_PART_MAIN, LV_STATE_DEFAULT, LV_SYMBOL_MINUS);
|
||||||
lv_obj_set_style_local_value_str(btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_SYMBOL_MINUS);
|
lv_obj_add_event_cb(btn, lv_spinbox_decrement_event_cb, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
void lv_ex_spinner_1(void)
|
void lv_ex_spinner_1(void)
|
||||||
{
|
{
|
||||||
/*Create a Preloader object*/
|
/*Create a Preloader object*/
|
||||||
lv_obj_t * spinner = lv_spinner_create(lv_scr_act(), 500, 60);
|
lv_obj_t * spinner = lv_spinner_create(lv_scr_act(), 1000, 60);
|
||||||
lv_obj_set_size(spinner, 100, 100);
|
lv_obj_set_size(spinner, 100, 100);
|
||||||
lv_obj_align(spinner, NULL, LV_ALIGN_CENTER, 0, 0);
|
lv_obj_align(spinner, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||||
}
|
}
|
||||||
|
@ -19,13 +19,16 @@ void lv_ex_tabview_1(void)
|
|||||||
"If the content\n"
|
"If the content\n"
|
||||||
"of a tab\n"
|
"of a tab\n"
|
||||||
"becomes too\n"
|
"becomes too\n"
|
||||||
"long then\n"
|
"longer\n"
|
||||||
"it will \n"
|
"than the\n"
|
||||||
|
"container\n"
|
||||||
|
"then it\n"
|
||||||
"automatically\n"
|
"automatically\n"
|
||||||
"become\n"
|
"becomes\n"
|
||||||
"scrollable.\n"
|
"scrollable.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
"\n"
|
||||||
"Can you see it?");
|
"Can you see it?");
|
||||||
|
|
||||||
label = lv_label_create(tab2, NULL);
|
label = lv_label_create(tab2, NULL);
|
||||||
|
4
lvgl.h
4
lvgl.h
@ -73,6 +73,10 @@ extern "C" {
|
|||||||
#include "src/extra/widgets/calendar/lv_calendar_header_arrow.h"
|
#include "src/extra/widgets/calendar/lv_calendar_header_arrow.h"
|
||||||
#include "src/extra/widgets/keyboard/lv_keyboard.h"
|
#include "src/extra/widgets/keyboard/lv_keyboard.h"
|
||||||
#include "src/extra/widgets/list/lv_list.h"
|
#include "src/extra/widgets/list/lv_list.h"
|
||||||
|
#include "src/extra/widgets/msgbox/lv_msgbox.h"
|
||||||
|
#include "src/extra/widgets/spinbox/lv_spinbox.h"
|
||||||
|
#include "src/extra/widgets/spinner/lv_spinner.h"
|
||||||
|
#include "src/extra/widgets/tabview/lv_tabview.h"
|
||||||
|
|
||||||
/* LAYOUTS */
|
/* LAYOUTS */
|
||||||
#include "src/extra/layouts/flex/lv_flex.h"
|
#include "src/extra/layouts/flex/lv_flex.h"
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
props = [
|
props = [
|
||||||
{'name': 'RADIUS', 'style_type': 'num', 'var_type': 'lv_coord_t' },
|
{'name': 'RADIUS', 'style_type': 'num', 'var_type': 'lv_coord_t' },
|
||||||
{'name': 'CLIP_CORNER', 'style_type': 'num', 'var_type': 'bool' },
|
{'name': 'CLIP_CORNER', 'style_type': 'num', 'var_type': 'bool' },
|
||||||
@ -68,7 +70,13 @@ props = [
|
|||||||
{'name': 'LINE_ROUNDED', 'style_type': 'num', 'var_type': 'lv_coord_t' },
|
{'name': 'LINE_ROUNDED', 'style_type': 'num', 'var_type': 'lv_coord_t' },
|
||||||
{'name': 'LINE_COLOR', 'style_type': 'color', 'var_type': 'lv_color_t' },
|
{'name': 'LINE_COLOR', 'style_type': 'color', 'var_type': 'lv_color_t' },
|
||||||
{'name': 'LINE_COLOR_FILTERED', 'style_type': 'color', 'var_type': 'lv_color_t' },
|
{'name': 'LINE_COLOR_FILTERED', 'style_type': 'color', 'var_type': 'lv_color_t' },
|
||||||
{'name': 'LINE_OPA', 'style_type': 'num', 'var_type': 'lv_opa_t' },
|
{'name': 'LINE_OPA', 'style_type': 'num', 'var_type': 'lv_opa_t' },
|
||||||
|
{'name': 'ARC_WIDTH', 'style_type': 'num', 'var_type': 'lv_coord_t' },
|
||||||
|
{'name': 'ARC_ROUNDED', 'style_type': 'num', 'var_type': 'lv_coord_t' },
|
||||||
|
{'name': 'ARC_COLOR', 'style_type': 'color', 'var_type': 'lv_color_t' },
|
||||||
|
{'name': 'ARC_COLOR_FILTERED', 'style_type': 'color', 'var_type': 'lv_color_t' },
|
||||||
|
{'name': 'ARC_OPA', 'style_type': 'num', 'var_type': 'lv_opa_t' },
|
||||||
|
{'name': 'ARC_IMG_SRC', 'style_type': 'ptr', 'var_type': 'const void *' },
|
||||||
{'name': 'CONTENT_TEXT', 'style_type': 'ptr', 'var_type': 'const char *' },
|
{'name': 'CONTENT_TEXT', 'style_type': 'ptr', 'var_type': 'const char *' },
|
||||||
{'name': 'CONTENT_ALIGN', 'style_type': 'num', 'var_type': 'lv_align_t' },
|
{'name': 'CONTENT_ALIGN', 'style_type': 'num', 'var_type': 'lv_align_t' },
|
||||||
{'name': 'CONTENT_OFS_X', 'style_type': 'num', 'var_type': 'lv_coord_t' },
|
{'name': 'CONTENT_OFS_X', 'style_type': 'num', 'var_type': 'lv_coord_t' },
|
||||||
@ -99,9 +107,23 @@ def local_style_set(i):
|
|||||||
print("")
|
print("")
|
||||||
|
|
||||||
|
|
||||||
|
for i in range(len(props)):
|
||||||
|
obj_style_get(i)
|
||||||
|
|
||||||
|
print("")
|
||||||
|
print("--------------------------------------------------------------------------------------------")
|
||||||
|
print("")
|
||||||
|
|
||||||
|
|
||||||
for i in range(len(props)):
|
for i in range(len(props)):
|
||||||
local_style_set(i)
|
local_style_set(i)
|
||||||
|
|
||||||
|
print("")
|
||||||
|
print("--------------------------------------------------------------------------------------------")
|
||||||
|
print("")
|
||||||
|
|
||||||
|
for i in range(len(props)):
|
||||||
|
style_set(i)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ static lv_obj_t * get_next_item(lv_obj_t * cont, bool rev, int32_t * item_id);
|
|||||||
const lv_flex_t lv_flex_inline = {
|
const lv_flex_t lv_flex_inline = {
|
||||||
.base.update_cb = flex_update,
|
.base.update_cb = flex_update,
|
||||||
.item_main_place = LV_FLEX_PLACE_START,
|
.item_main_place = LV_FLEX_PLACE_START,
|
||||||
.item_cross_place = LV_FLEX_PLACE_START,
|
.item_cross_place = LV_FLEX_PLACE_CENTER,
|
||||||
.track_cross_place = LV_FLEX_PLACE_START,
|
.track_cross_place = LV_FLEX_PLACE_START,
|
||||||
.dir = LV_FLEX_FLOW_ROW,
|
.dir = LV_FLEX_FLOW_ROW,
|
||||||
.wrap = 1
|
.wrap = 1
|
||||||
@ -77,6 +77,14 @@ const lv_flex_t lv_flex_stacked = {
|
|||||||
.dir = LV_FLEX_FLOW_COLUMN
|
.dir = LV_FLEX_FLOW_COLUMN
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const lv_flex_t lv_flex_queue = {
|
||||||
|
.base.update_cb = flex_update,
|
||||||
|
.item_main_place = LV_FLEX_PLACE_START,
|
||||||
|
.item_cross_place = LV_FLEX_PLACE_START,
|
||||||
|
.track_cross_place = LV_FLEX_PLACE_START,
|
||||||
|
.dir = LV_FLEX_FLOW_ROW
|
||||||
|
};
|
||||||
|
|
||||||
const lv_flex_t lv_flex_even = {
|
const lv_flex_t lv_flex_even = {
|
||||||
.base.update_cb = flex_update,
|
.base.update_cb = flex_update,
|
||||||
.item_main_place = LV_FLEX_PLACE_SPACE_EVENLY,
|
.item_main_place = LV_FLEX_PLACE_SPACE_EVENLY,
|
||||||
|
@ -104,7 +104,8 @@ void lv_obj_set_flex_grow(struct _lv_obj_t * obj, uint8_t grow);
|
|||||||
extern const lv_flex_t lv_flex_inline; /**< Just put the items next to each other with wrap*/
|
extern const lv_flex_t lv_flex_inline; /**< Just put the items next to each other with wrap*/
|
||||||
extern const lv_flex_t lv_flex_center_row; /**< Center in a row with wrap*/
|
extern const lv_flex_t lv_flex_center_row; /**< Center in a row with wrap*/
|
||||||
extern const lv_flex_t lv_flex_center_column; /**< Center in a column with wrap*/
|
extern const lv_flex_t lv_flex_center_column; /**< Center in a column with wrap*/
|
||||||
extern const lv_flex_t lv_flex_stacked; /**< Stack the items vertically*/
|
extern const lv_flex_t lv_flex_stacked; /**< Stack the items vertically without wrapping*/
|
||||||
|
extern const lv_flex_t lv_flex_queue; /**< Put the items next to each other without wrap*/
|
||||||
extern const lv_flex_t lv_flex_even; /**< Place the items evenly in row with wrapping and vertical centering*/
|
extern const lv_flex_t lv_flex_even; /**< Place the items evenly in row with wrapping and vertical centering*/
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
|
@ -152,7 +152,6 @@ typedef struct {
|
|||||||
#if LV_USE_LIST
|
#if LV_USE_LIST
|
||||||
lv_style_t list_bg, list_btn, list_item_grow, list_label;
|
lv_style_t list_bg, list_btn, list_item_grow, list_label;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} my_theme_styles_t;
|
} my_theme_styles_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -206,7 +205,6 @@ static void style_init(void)
|
|||||||
style_init_reset(&styles->transition_normal);
|
style_init_reset(&styles->transition_normal);
|
||||||
lv_style_set_transition(&styles->transition_normal, &trans_normal); /*Go back to default state with delay*/
|
lv_style_set_transition(&styles->transition_normal, &trans_normal); /*Go back to default state with delay*/
|
||||||
|
|
||||||
|
|
||||||
style_init_reset(&styles->scrollbar);
|
style_init_reset(&styles->scrollbar);
|
||||||
lv_style_set_bg_opa(&styles->scrollbar, LV_OPA_COVER);
|
lv_style_set_bg_opa(&styles->scrollbar, LV_OPA_COVER);
|
||||||
lv_style_set_bg_color(&styles->scrollbar, (IS_LIGHT ? lv_color_hex(0xcccfd1) : lv_color_hex(0x777f85)));
|
lv_style_set_bg_color(&styles->scrollbar, (IS_LIGHT ? lv_color_hex(0xcccfd1) : lv_color_hex(0x777f85)));
|
||||||
@ -268,7 +266,7 @@ static void style_init(void)
|
|||||||
|
|
||||||
style_init_reset(&styles->pressed);
|
style_init_reset(&styles->pressed);
|
||||||
lv_style_set_color_filter_cb(&styles->pressed, lv_color_darken);
|
lv_style_set_color_filter_cb(&styles->pressed, lv_color_darken);
|
||||||
lv_style_set_color_filter_opa(&styles->pressed, LV_OPA_20);
|
lv_style_set_color_filter_opa(&styles->pressed, 35);
|
||||||
|
|
||||||
style_init_reset(&styles->disabled);
|
style_init_reset(&styles->disabled);
|
||||||
lv_style_set_color_filter_cb(&styles->disabled, gray_filter);
|
lv_style_set_color_filter_cb(&styles->disabled, gray_filter);
|
||||||
@ -308,21 +306,26 @@ static void style_init(void)
|
|||||||
style_init_reset(&styles->bg_color_primary);
|
style_init_reset(&styles->bg_color_primary);
|
||||||
lv_style_set_bg_color(&styles->bg_color_primary, theme.color_primary);
|
lv_style_set_bg_color(&styles->bg_color_primary, theme.color_primary);
|
||||||
lv_style_set_text_color(&styles->bg_color_primary, LV_COLOR_WHITE);
|
lv_style_set_text_color(&styles->bg_color_primary, LV_COLOR_WHITE);
|
||||||
|
lv_style_set_content_color(&styles->bg_color_primary, LV_COLOR_WHITE);
|
||||||
lv_style_set_bg_opa(&styles->bg_color_primary, LV_OPA_COVER);
|
lv_style_set_bg_opa(&styles->bg_color_primary, LV_OPA_COVER);
|
||||||
|
|
||||||
style_init_reset(&styles->bg_color_secondary);
|
style_init_reset(&styles->bg_color_secondary);
|
||||||
lv_style_set_bg_color(&styles->bg_color_secondary, theme.color_secondary);
|
lv_style_set_bg_color(&styles->bg_color_secondary, theme.color_secondary);
|
||||||
lv_style_set_text_color(&styles->bg_color_secondary, LV_COLOR_WHITE);
|
lv_style_set_text_color(&styles->bg_color_secondary, LV_COLOR_WHITE);
|
||||||
|
lv_style_set_content_color(&styles->bg_color_secondary, LV_COLOR_WHITE);
|
||||||
lv_style_set_bg_opa(&styles->bg_color_secondary, LV_OPA_COVER);
|
lv_style_set_bg_opa(&styles->bg_color_secondary, LV_OPA_COVER);
|
||||||
|
|
||||||
style_init_reset(&styles->bg_color_gray);
|
style_init_reset(&styles->bg_color_gray);
|
||||||
lv_style_set_bg_color(&styles->bg_color_gray, COLOR_GRAY);
|
lv_style_set_bg_color(&styles->bg_color_gray, COLOR_GRAY);
|
||||||
lv_style_set_bg_opa(&styles->bg_color_gray, LV_OPA_COVER);
|
lv_style_set_bg_opa(&styles->bg_color_gray, LV_OPA_COVER);
|
||||||
lv_style_set_text_color(&styles->bg_color_gray, CARD_TEXT_COLOR);
|
lv_style_set_text_color(&styles->bg_color_gray, CARD_TEXT_COLOR);
|
||||||
|
lv_style_set_content_color(&styles->bg_color_gray, CARD_TEXT_COLOR);
|
||||||
|
|
||||||
style_init_reset(&styles->bg_color_white);
|
style_init_reset(&styles->bg_color_white);
|
||||||
lv_style_set_bg_color(&styles->bg_color_white, LV_COLOR_WHITE);
|
lv_style_set_bg_color(&styles->bg_color_white, LV_COLOR_WHITE);
|
||||||
lv_style_set_bg_opa(&styles->bg_color_white, LV_OPA_COVER);
|
lv_style_set_bg_opa(&styles->bg_color_white, LV_OPA_COVER);
|
||||||
|
lv_style_set_text_color(&styles->bg_color_white, CARD_TEXT_COLOR);
|
||||||
|
lv_style_set_content_color(&styles->bg_color_white, CARD_TEXT_COLOR);
|
||||||
|
|
||||||
style_init_reset(&styles->circle);
|
style_init_reset(&styles->circle);
|
||||||
lv_style_set_radius(&styles->circle, LV_RADIUS_CIRCLE);
|
lv_style_set_radius(&styles->circle, LV_RADIUS_CIRCLE);
|
||||||
@ -349,14 +352,12 @@ static void style_init(void)
|
|||||||
|
|
||||||
#if LV_USE_ARC
|
#if LV_USE_ARC
|
||||||
style_init_reset(&styles->arc_indic);
|
style_init_reset(&styles->arc_indic);
|
||||||
lv_style_set_line_color(&styles->arc_indic, COLOR_GRAY);
|
lv_style_set_arc_color(&styles->arc_indic, COLOR_GRAY);
|
||||||
lv_style_set_line_width(&styles->arc_indic, LV_DPX(15));
|
lv_style_set_arc_width(&styles->arc_indic, LV_DPX(15));
|
||||||
lv_style_set_line_rounded(&styles->arc_indic, true);
|
lv_style_set_arc_rounded(&styles->arc_indic, true);
|
||||||
|
|
||||||
style_init_reset(&styles->arc_indic_primary);
|
style_init_reset(&styles->arc_indic_primary);
|
||||||
lv_style_set_line_color(&styles->arc_indic_primary, theme.color_primary);
|
lv_style_set_arc_color(&styles->arc_indic_primary, theme.color_primary);
|
||||||
LV_IMG_DECLARE(asd);
|
|
||||||
lv_style_set_bg_img_src(&styles->arc_indic_primary, &asd);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LV_USE_DROPDOWN
|
#if LV_USE_DROPDOWN
|
||||||
@ -527,6 +528,15 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
|
|||||||
|
|
||||||
#if LV_USE_BTNMATRIX
|
#if LV_USE_BTNMATRIX
|
||||||
else if(lv_obj_check_type(obj, &lv_btnmatrix)) {
|
else if(lv_obj_check_type(obj, &lv_btnmatrix)) {
|
||||||
|
#if LV_USE_MSGBOX
|
||||||
|
if(lv_obj_check_type(lv_obj_get_parent(obj), &lv_msgbox)) {
|
||||||
|
lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->pad_gap);
|
||||||
|
lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_DEFAULT, &styles->btn);
|
||||||
|
lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_PRESSED, &styles->pressed);
|
||||||
|
lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_CHECKED, &styles->bg_color_primary);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->card);
|
lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->card);
|
||||||
lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_DEFAULT, &styles->btn);
|
lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_DEFAULT, &styles->btn);
|
||||||
lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_PRESSED, &styles->pressed);
|
lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_PRESSED, &styles->pressed);
|
||||||
@ -647,17 +657,16 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
|
|||||||
#if LV_USE_LABEL
|
#if LV_USE_LABEL
|
||||||
else if(lv_obj_check_type(obj, &lv_label)) {
|
else if(lv_obj_check_type(obj, &lv_label)) {
|
||||||
#if LV_USE_LIST
|
#if LV_USE_LIST
|
||||||
if(lv_obj_check_type(lv_obj_get_parent(obj), &lv_list)) {
|
if(lv_obj_check_type(lv_obj_get_parent(obj), &lv_list)) {
|
||||||
lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->bg_color_gray);
|
lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->bg_color_gray);
|
||||||
lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->list_item_grow);
|
lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->list_item_grow);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LV_USE_ARC
|
#if LV_USE_ARC
|
||||||
else if(lv_obj_check_type(obj, &lv_arc)) {
|
else if(lv_obj_check_type(obj, &lv_arc)) {
|
||||||
lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->card);
|
|
||||||
lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->arc_indic);
|
lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->arc_indic);
|
||||||
lv_obj_add_style(obj, LV_PART_INDICATOR, LV_STATE_DEFAULT, &styles->arc_indic);
|
lv_obj_add_style(obj, LV_PART_INDICATOR, LV_STATE_DEFAULT, &styles->arc_indic);
|
||||||
lv_obj_add_style(obj, LV_PART_INDICATOR, LV_STATE_DEFAULT, &styles->arc_indic_primary);
|
lv_obj_add_style(obj, LV_PART_INDICATOR, LV_STATE_DEFAULT, &styles->arc_indic_primary);
|
||||||
@ -700,23 +709,28 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
|
|||||||
lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_DEFAULT, &styles->bg_color_white);
|
lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_DEFAULT, &styles->bg_color_white);
|
||||||
lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_PRESSED, &styles->pressed);
|
lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_PRESSED, &styles->pressed);
|
||||||
lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_CHECKED, &styles->bg_color_gray);
|
lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_CHECKED, &styles->bg_color_gray);
|
||||||
// lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->card);
|
|
||||||
// lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->no_radius);
|
|
||||||
// lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->pad_small);
|
|
||||||
// lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_DEFAULT, &styles->btn);
|
|
||||||
// lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_PRESSED, &styles->pressed);
|
|
||||||
// lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_CHECKED, &styles->bg_color_primary);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if LV_USE_LIST
|
#if LV_USE_LIST
|
||||||
/*Add different buttons to the lists*/
|
else if(lv_obj_check_type(obj, &lv_list)) {
|
||||||
if(lv_obj_check_type(obj, &lv_list)) {
|
lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->card);
|
||||||
lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->card);
|
lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->list_bg);
|
||||||
lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->list_bg);
|
lv_obj_add_style(obj, LV_PART_SCROLLBAR, LV_STATE_DEFAULT, &styles->scrollbar);
|
||||||
lv_obj_add_style(obj, LV_PART_SCROLLBAR, LV_STATE_DEFAULT, &styles->scrollbar);
|
lv_obj_add_style(obj, LV_PART_SCROLLBAR, LV_STATE_SCROLLED, &styles->scrollbar_scrolled);
|
||||||
lv_obj_add_style(obj, LV_PART_SCROLLBAR, LV_STATE_SCROLLED, &styles->scrollbar_scrolled);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
#endif
|
||||||
|
#if LV_USE_MSGBOX
|
||||||
|
else if(lv_obj_check_type(obj, &lv_msgbox)) {
|
||||||
|
lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->card);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#if LV_USE_SPINBOX
|
||||||
|
else if(lv_obj_check_type(obj, &lv_spinbox)) {
|
||||||
|
lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->card);
|
||||||
|
lv_obj_add_style(obj, LV_PART_MARKER, LV_STATE_DEFAULT, &styles->bg_color_gray);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ static void msgbox_close_event_cb(lv_obj_t * btn, lv_event_t e);
|
|||||||
/**********************
|
/**********************
|
||||||
* STATIC VARIABLES
|
* STATIC VARIABLES
|
||||||
**********************/
|
**********************/
|
||||||
static bool inited = false;
|
const lv_obj_class_t lv_msgbox = {.base_class = &lv_obj};
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
@ -45,74 +45,54 @@ static bool inited = false;
|
|||||||
*/
|
*/
|
||||||
lv_obj_t * lv_msgbox_create(const char * title, const char * txt, const char * btn_txts[], bool add_close_btn)
|
lv_obj_t * lv_msgbox_create(const char * title, const char * txt, const char * btn_txts[], bool add_close_btn)
|
||||||
{
|
{
|
||||||
static lv_style_t style_title;
|
|
||||||
static lv_style_t style_btnm_bg;
|
|
||||||
if(!inited) {
|
|
||||||
lv_style_init(&style_title);
|
|
||||||
lv_style_set_text_font(&style_title, LV_STATE_DEFAULT, lv_theme_get_font_subtitle());
|
|
||||||
lv_style_set_margin_bottom(&style_title, LV_STATE_DEFAULT, LV_DPX(8));
|
|
||||||
|
|
||||||
lv_style_init(&style_btnm_bg);
|
|
||||||
lv_style_set_margin_top(&style_btnm_bg, LV_STATE_DEFAULT, LV_DPX(8));
|
|
||||||
|
|
||||||
inited = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
lv_obj_t * parent = lv_obj_create(lv_layer_top(), NULL);
|
lv_obj_t * parent = lv_obj_create(lv_layer_top(), NULL);
|
||||||
lv_obj_reset_style_list(parent, LV_OBJ_PART_MAIN);
|
|
||||||
lv_obj_set_size(parent, LV_COORD_PCT(100), LV_COORD_PCT(100));
|
lv_obj_set_size(parent, LV_COORD_PCT(100), LV_COORD_PCT(100));
|
||||||
|
lv_obj_remove_style(parent, LV_PART_ANY, LV_STATE_ANY, NULL);
|
||||||
|
|
||||||
lv_obj_t * mbox = lv_obj_create(parent, NULL);
|
lv_obj_t * mbox = lv_obj_create_from_class(&lv_msgbox, parent, NULL);
|
||||||
LV_ASSERT_MEM(mbox);
|
LV_ASSERT_MEM(mbox);
|
||||||
if(mbox == NULL) return NULL;
|
if(mbox == NULL) return NULL;
|
||||||
|
|
||||||
lv_coord_t w = lv_obj_get_width_fit(parent);
|
lv_coord_t w = lv_obj_get_width_fit(parent);
|
||||||
if(w > 2 * LV_DPI) w = 2 * LV_DPI;
|
if(w > 2 * LV_DPI_DEF) w = 2 * LV_DPI_DEF;
|
||||||
|
|
||||||
lv_obj_set_size(mbox, w, LV_SIZE_AUTO);
|
lv_obj_set_size(mbox, w, LV_SIZE_AUTO);
|
||||||
lv_obj_set_flex_dir(mbox, LV_FLEX_DIR_ROW_WRAP);
|
lv_obj_set_layout(mbox, &lv_flex_inline);
|
||||||
|
|
||||||
lv_obj_t * label;
|
lv_obj_t * label;
|
||||||
label = lv_label_create(mbox, NULL);
|
label = lv_label_create(mbox, NULL);
|
||||||
lv_label_set_text(label, title);
|
lv_label_set_text(label, title);
|
||||||
lv_label_set_long_mode(label, LV_LABEL_LONG_BREAK);
|
lv_label_set_long_mode(label, LV_LABEL_LONG_SROLL_CIRC);
|
||||||
lv_obj_set_width(label, add_close_btn ? LV_FLEX_GROW(1) : LV_COORD_PCT(100));
|
if(add_close_btn) lv_obj_set_flex_grow(label, 1);
|
||||||
lv_obj_set_flex_item(label, true);
|
else lv_obj_set_width(label, LV_COORD_PCT(100));
|
||||||
lv_obj_add_style(label, LV_LABEL_PART_MAIN, &style_title);
|
|
||||||
|
|
||||||
if(add_close_btn) {
|
if(add_close_btn) {
|
||||||
lv_obj_t * close_btn = lv_btn_create(mbox, NULL);
|
lv_obj_t * close_btn = lv_btn_create(mbox, NULL);
|
||||||
lv_obj_add_style(close_btn, LV_BTN_PART_MAIN, &style_title);
|
lv_obj_set_ext_click_area(close_btn, LV_DPX(10));
|
||||||
lv_obj_set_ext_click_area(close_btn, LV_DPX(10), LV_DPX(10), LV_DPX(10), LV_DPX(10));
|
lv_obj_add_event_cb(close_btn, msgbox_close_event_cb, NULL);
|
||||||
lv_obj_set_event_cb(close_btn, msgbox_close_event_cb);
|
|
||||||
label = lv_label_create(close_btn, NULL);
|
label = lv_label_create(close_btn, NULL);
|
||||||
lv_label_set_text(label, LV_SYMBOL_CLOSE);
|
lv_label_set_text(label, LV_SYMBOL_CLOSE);
|
||||||
lv_coord_t close_btn_size = LV_MAX(lv_obj_get_width(label), lv_obj_get_height(label)) + LV_DPX(10);
|
lv_coord_t close_btn_size = LV_MAX(lv_obj_get_width(label), lv_obj_get_height(label)) + LV_DPX(10);
|
||||||
lv_obj_set_size(close_btn, close_btn_size, close_btn_size);
|
lv_obj_set_size(close_btn, close_btn_size, close_btn_size);
|
||||||
lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
|
lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||||
lv_obj_set_flex_item_place(close_btn, LV_FLEX_PLACE_CENTER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
label = lv_label_create(mbox, NULL);
|
label = lv_label_create(mbox, NULL);
|
||||||
lv_label_set_text(label, txt);
|
lv_label_set_text(label, txt);
|
||||||
lv_label_set_long_mode(label, LV_LABEL_LONG_BREAK);
|
lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP);
|
||||||
lv_obj_set_width(label, LV_COORD_PCT(100));
|
lv_obj_set_width(label, LV_COORD_PCT(100));
|
||||||
lv_obj_set_flex_item(label, LV_FLEX_PLACE_START);
|
|
||||||
|
|
||||||
lv_obj_t * btns = lv_btnmatrix_create(mbox, NULL);
|
lv_obj_t * btns = lv_btnmatrix_create(mbox, NULL);
|
||||||
lv_btnmatrix_set_map(btns, btn_txts);
|
lv_btnmatrix_set_map(btns, btn_txts);
|
||||||
lv_obj_reset_style_list(btns, LV_BTNMATRIX_PART_MAIN);
|
|
||||||
lv_obj_add_style(btns, LV_BTNMATRIX_PART_MAIN, &style_btnm_bg);
|
|
||||||
lv_obj_set_flex_item(btns, LV_FLEX_PLACE_START);
|
|
||||||
|
|
||||||
uint32_t btn_cnt = 0;
|
uint32_t btn_cnt = 0;
|
||||||
while(btn_txts[btn_cnt][0] != '\0') {
|
while(btn_txts[btn_cnt][0] != '\0') {
|
||||||
btn_cnt++;
|
btn_cnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
const lv_font_t * font = lv_obj_get_style_text_font(btns, LV_BTNMATRIX_PART_BTN);
|
const lv_font_t * font = lv_obj_get_style_text_font(btns, LV_PART_ITEMS);
|
||||||
lv_coord_t btn_h = lv_font_get_line_height(font) + LV_DPI / 10;
|
lv_coord_t btn_h = lv_font_get_line_height(font) + LV_DPI_DEF / 10;
|
||||||
lv_obj_set_size(btns, btn_cnt * (2 * LV_DPI / 3), btn_h);
|
lv_obj_set_size(btns, btn_cnt * (2 * LV_DPI_DEF / 3), btn_h);
|
||||||
lv_obj_add_flag(btns, LV_OBJ_FLAG_EVENT_BUBBLE); /*To see the event directly on the message box*/
|
lv_obj_add_flag(btns, LV_OBJ_FLAG_EVENT_BUBBLE); /*To see the event directly on the message box*/
|
||||||
return mbox;
|
return mbox;
|
||||||
}
|
}
|
||||||
@ -120,30 +100,30 @@ lv_obj_t * lv_msgbox_create(const char * title, const char * txt, const char * b
|
|||||||
|
|
||||||
lv_obj_t * lv_msgbox_get_title(lv_obj_t * mbox)
|
lv_obj_t * lv_msgbox_get_title(lv_obj_t * mbox)
|
||||||
{
|
{
|
||||||
return lv_obj_get_child_by_id(mbox, 0);
|
return lv_obj_get_child(mbox, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
lv_obj_t * lv_msgbox_get_close_btn(lv_obj_t * mbox)
|
lv_obj_t * lv_msgbox_get_close_btn(lv_obj_t * mbox)
|
||||||
{
|
{
|
||||||
uint32_t cnt = lv_obj_count_children(mbox);
|
lv_obj_t * obj = lv_obj_get_child(mbox, 1);
|
||||||
if(cnt == 3) return NULL; /*No close button*/
|
if(lv_obj_check_type(obj, &lv_btn)) return obj;
|
||||||
else return lv_obj_get_child_by_id(mbox, 1);
|
else return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
lv_obj_t * lv_msgbox_get_text(lv_obj_t * mbox)
|
lv_obj_t * lv_msgbox_get_text(lv_obj_t * mbox)
|
||||||
{
|
{
|
||||||
return lv_obj_get_child_by_id(mbox, lv_obj_count_children(mbox) - 2);
|
return lv_obj_get_child(mbox, lv_obj_get_child_cnt(mbox) - 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
lv_obj_t * lv_msgbox_get_btns(lv_obj_t * mbox)
|
lv_obj_t * lv_msgbox_get_btns(lv_obj_t * mbox)
|
||||||
{
|
{
|
||||||
return lv_obj_get_child_by_id(mbox, lv_obj_count_children(mbox) - 1);
|
return lv_obj_get_child(mbox, lv_obj_get_child_cnt(mbox) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * lv_msgbox_get_active_btn_text(lv_obj_t * mbox)
|
const char * lv_msgbox_get_active_btn_text(lv_obj_t * mbox)
|
||||||
{
|
{
|
||||||
lv_obj_t * btnm = lv_msgbox_get_btns(mbox);
|
lv_obj_t * btnm = lv_msgbox_get_btns(mbox);
|
||||||
return lv_btnmatrix_get_active_btn_text(btnm);
|
return lv_btnmatrix_get_btn_text(btnm, lv_btnmatrix_get_active_btn(btnm));
|
||||||
}
|
}
|
||||||
|
|
||||||
void lv_msgbox_close(lv_obj_t * mbox)
|
void lv_msgbox_close(lv_obj_t * mbox)
|
||||||
|
@ -13,7 +13,7 @@ extern "C" {
|
|||||||
/*********************
|
/*********************
|
||||||
* INCLUDES
|
* INCLUDES
|
||||||
*********************/
|
*********************/
|
||||||
#include "../../../lv_core/lv_obj.h"
|
#include "../../../lvgl.h"
|
||||||
|
|
||||||
#if LV_USE_MSGBOX
|
#if LV_USE_MSGBOX
|
||||||
|
|
||||||
@ -33,6 +33,7 @@ extern "C" {
|
|||||||
/**********************
|
/**********************
|
||||||
* TYPEDEFS
|
* TYPEDEFS
|
||||||
**********************/
|
**********************/
|
||||||
|
extern const lv_obj_class_t lv_msgbox;
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* GLOBAL PROTOTYPES
|
* GLOBAL PROTOTYPES
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
/*********************
|
/*********************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
*********************/
|
*********************/
|
||||||
|
#define MY_CLASS &lv_spinbox
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* TYPEDEFS
|
* TYPEDEFS
|
||||||
@ -20,14 +21,22 @@
|
|||||||
/**********************
|
/**********************
|
||||||
* STATIC PROTOTYPES
|
* STATIC PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
static lv_res_t lv_spinbox_signal(lv_obj_t * spinbox, lv_signal_t sign, void * param);
|
|
||||||
static void lv_spinbox_updatevalue(lv_obj_t * spinbox);
|
static void lv_spinbox_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy);
|
||||||
|
static void lv_spinbox_destructor(lv_obj_t * obj);
|
||||||
|
static lv_res_t lv_spinbox_signal(lv_obj_t * obj, lv_signal_t sign, void * param);
|
||||||
|
static void lv_spinbox_updatevalue(lv_obj_t * obj);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC VARIABLES
|
* STATIC VARIABLES
|
||||||
**********************/
|
**********************/
|
||||||
static lv_signal_cb_t ancestor_signal;
|
const lv_obj_class_t lv_spinbox = {
|
||||||
|
.constructor_cb = lv_spinbox_constructor,
|
||||||
|
.destructor_cb = lv_spinbox_destructor,
|
||||||
|
.signal_cb = lv_spinbox_signal,
|
||||||
|
.instance_size = sizeof(lv_spinbox_t),
|
||||||
|
.base_class = &lv_textarea
|
||||||
|
};
|
||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
**********************/
|
**********************/
|
||||||
@ -44,45 +53,7 @@ static lv_signal_cb_t ancestor_signal;
|
|||||||
*/
|
*/
|
||||||
lv_obj_t * lv_spinbox_create(lv_obj_t * parent)
|
lv_obj_t * lv_spinbox_create(lv_obj_t * parent)
|
||||||
{
|
{
|
||||||
LV_LOG_TRACE("spinbox create started");
|
return lv_obj_create_from_class(&lv_spinbox, parent, NULL);
|
||||||
|
|
||||||
/*Create the ancestor of spinbox*/
|
|
||||||
lv_obj_t * spinbox = lv_textarea_create(parent, NULL);
|
|
||||||
LV_ASSERT_MEM(spinbox);
|
|
||||||
if(spinbox == NULL) return NULL;
|
|
||||||
|
|
||||||
/*Allocate the spinbox type specific extended data*/
|
|
||||||
lv_spinbox_ext_t * ext = lv_obj_allocate_ext_attr(spinbox, sizeof(lv_spinbox_ext_t));
|
|
||||||
LV_ASSERT_MEM(ext);
|
|
||||||
if(ext == NULL) {
|
|
||||||
lv_obj_del(spinbox);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(spinbox);
|
|
||||||
|
|
||||||
/*Initialize the allocated 'ext'*/
|
|
||||||
ext->value = 0;
|
|
||||||
ext->dec_point_pos = 0;
|
|
||||||
ext->digit_count = 5;
|
|
||||||
ext->step = 1;
|
|
||||||
ext->range_max = 99999;
|
|
||||||
ext->range_min = -99999;
|
|
||||||
ext->rollover = false;
|
|
||||||
|
|
||||||
|
|
||||||
/*The signal and draw functions are not copied so set them here*/
|
|
||||||
lv_obj_set_signal_cb(spinbox, lv_spinbox_signal);
|
|
||||||
|
|
||||||
lv_textarea_set_one_line(spinbox, true);
|
|
||||||
lv_textarea_set_cursor_click_pos(spinbox, true);
|
|
||||||
lv_obj_set_width(spinbox, LV_DPI);
|
|
||||||
|
|
||||||
lv_spinbox_updatevalue(spinbox);
|
|
||||||
|
|
||||||
LV_LOG_INFO("spinbox created");
|
|
||||||
|
|
||||||
return spinbox;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*=====================
|
/*=====================
|
||||||
@ -94,17 +65,16 @@ lv_obj_t * lv_spinbox_create(lv_obj_t * parent)
|
|||||||
* @param spinbox pointer to spinbox
|
* @param spinbox pointer to spinbox
|
||||||
* @param i value to be set
|
* @param i value to be set
|
||||||
*/
|
*/
|
||||||
void lv_spinbox_set_value(lv_obj_t * spinbox, int32_t i)
|
void lv_spinbox_set_value(lv_obj_t * obj, int32_t i)
|
||||||
{
|
{
|
||||||
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
|
lv_spinbox_t * spinbox = (lv_spinbox_t *) obj;
|
||||||
if(ext == NULL) return;
|
|
||||||
|
|
||||||
if(i > ext->range_max) i = ext->range_max;
|
if(i > spinbox->range_max) i = spinbox->range_max;
|
||||||
if(i < ext->range_min) i = ext->range_min;
|
if(i < spinbox->range_min) i = spinbox->range_min;
|
||||||
|
|
||||||
ext->value = i;
|
spinbox->value = i;
|
||||||
|
|
||||||
lv_spinbox_updatevalue(spinbox);
|
lv_spinbox_updatevalue(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -112,11 +82,11 @@ void lv_spinbox_set_value(lv_obj_t * spinbox, int32_t i)
|
|||||||
* @param spinbox pointer to spinbox
|
* @param spinbox pointer to spinbox
|
||||||
* @param b true or false to enable or disable (default)
|
* @param b true or false to enable or disable (default)
|
||||||
*/
|
*/
|
||||||
void lv_spinbox_set_rollover(lv_obj_t * spinbox, bool b)
|
void lv_spinbox_set_rollover(lv_obj_t * obj, bool b)
|
||||||
{
|
{
|
||||||
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
|
lv_spinbox_t * spinbox = (lv_spinbox_t *) obj;
|
||||||
|
|
||||||
ext->rollover = b;
|
spinbox->rollover = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -126,10 +96,9 @@ void lv_spinbox_set_rollover(lv_obj_t * spinbox, bool b)
|
|||||||
* @param separator_position number of digit before the decimal point. If 0, decimal point is not
|
* @param separator_position number of digit before the decimal point. If 0, decimal point is not
|
||||||
* shown
|
* shown
|
||||||
*/
|
*/
|
||||||
void lv_spinbox_set_digit_format(lv_obj_t * spinbox, uint8_t digit_count, uint8_t separator_position)
|
void lv_spinbox_set_digit_format(lv_obj_t * obj, uint8_t digit_count, uint8_t separator_position)
|
||||||
{
|
{
|
||||||
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
|
lv_spinbox_t * spinbox = (lv_spinbox_t *) obj;
|
||||||
if(ext == NULL) return;
|
|
||||||
|
|
||||||
if(digit_count > LV_SPINBOX_MAX_DIGIT_COUNT) digit_count = LV_SPINBOX_MAX_DIGIT_COUNT;
|
if(digit_count > LV_SPINBOX_MAX_DIGIT_COUNT) digit_count = LV_SPINBOX_MAX_DIGIT_COUNT;
|
||||||
|
|
||||||
@ -138,14 +107,14 @@ void lv_spinbox_set_digit_format(lv_obj_t * spinbox, uint8_t digit_count, uint8_
|
|||||||
|
|
||||||
if(digit_count < LV_SPINBOX_MAX_DIGIT_COUNT) {
|
if(digit_count < LV_SPINBOX_MAX_DIGIT_COUNT) {
|
||||||
int64_t max_val = lv_pow(10, digit_count);
|
int64_t max_val = lv_pow(10, digit_count);
|
||||||
if(ext->range_max > max_val - 1) ext->range_max = max_val - 1;
|
if(spinbox->range_max > max_val - 1) spinbox->range_max = max_val - 1;
|
||||||
if(ext->range_min < - max_val + 1) ext->range_min = - max_val + 1;
|
if(spinbox->range_min < - max_val + 1) spinbox->range_min = - max_val + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ext->digit_count = digit_count;
|
spinbox->digit_count = digit_count;
|
||||||
ext->dec_point_pos = separator_position;
|
spinbox->dec_point_pos = separator_position;
|
||||||
|
|
||||||
lv_spinbox_updatevalue(spinbox);
|
lv_spinbox_updatevalue(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -153,13 +122,12 @@ void lv_spinbox_set_digit_format(lv_obj_t * spinbox, uint8_t digit_count, uint8_
|
|||||||
* @param spinbox pointer to spinbox
|
* @param spinbox pointer to spinbox
|
||||||
* @param step steps on increment/decrement
|
* @param step steps on increment/decrement
|
||||||
*/
|
*/
|
||||||
void lv_spinbox_set_step(lv_obj_t * spinbox, uint32_t step)
|
void lv_spinbox_set_step(lv_obj_t * obj, uint32_t step)
|
||||||
{
|
{
|
||||||
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
|
lv_spinbox_t * spinbox = (lv_spinbox_t *) obj;
|
||||||
if(ext == NULL) return;
|
|
||||||
|
|
||||||
ext->step = step;
|
spinbox->step = step;
|
||||||
lv_spinbox_updatevalue(spinbox);
|
lv_spinbox_updatevalue(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -168,18 +136,17 @@ void lv_spinbox_set_step(lv_obj_t * spinbox, uint32_t step)
|
|||||||
* @param range_min maximum value, inclusive
|
* @param range_min maximum value, inclusive
|
||||||
* @param range_max minimum value, inclusive
|
* @param range_max minimum value, inclusive
|
||||||
*/
|
*/
|
||||||
void lv_spinbox_set_range(lv_obj_t * spinbox, int32_t range_min, int32_t range_max)
|
void lv_spinbox_set_range(lv_obj_t * obj, int32_t range_min, int32_t range_max)
|
||||||
{
|
{
|
||||||
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
|
lv_spinbox_t * spinbox = (lv_spinbox_t *) obj;
|
||||||
if(ext == NULL) return;
|
|
||||||
|
|
||||||
ext->range_max = range_max;
|
spinbox->range_max = range_max;
|
||||||
ext->range_min = range_min;
|
spinbox->range_min = range_min;
|
||||||
|
|
||||||
if(ext->value > ext->range_max) ext->value = ext->range_max;
|
if(spinbox->value > spinbox->range_max) spinbox->value = spinbox->range_max;
|
||||||
if(ext->value < ext->range_min) ext->value = ext->range_min;
|
if(spinbox->value < spinbox->range_min) spinbox->value = spinbox->range_min;
|
||||||
|
|
||||||
lv_spinbox_updatevalue(spinbox);
|
lv_spinbox_updatevalue(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*=====================
|
/*=====================
|
||||||
@ -191,11 +158,11 @@ void lv_spinbox_set_range(lv_obj_t * spinbox, int32_t range_min, int32_t range_m
|
|||||||
* @param spinbox pointer to spinbox
|
* @param spinbox pointer to spinbox
|
||||||
* @return value integer value of the spinbox
|
* @return value integer value of the spinbox
|
||||||
*/
|
*/
|
||||||
int32_t lv_spinbox_get_value(lv_obj_t * spinbox)
|
int32_t lv_spinbox_get_value(lv_obj_t * obj)
|
||||||
{
|
{
|
||||||
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
|
lv_spinbox_t * spinbox = (lv_spinbox_t *) obj;
|
||||||
|
|
||||||
return ext->value;
|
return spinbox->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*=====================
|
/*=====================
|
||||||
@ -206,209 +173,230 @@ int32_t lv_spinbox_get_value(lv_obj_t * spinbox)
|
|||||||
* Select next lower digit for edition
|
* Select next lower digit for edition
|
||||||
* @param spinbox pointer to spinbox
|
* @param spinbox pointer to spinbox
|
||||||
*/
|
*/
|
||||||
void lv_spinbox_step_next(lv_obj_t * spinbox)
|
void lv_spinbox_step_next(lv_obj_t * obj)
|
||||||
{
|
{
|
||||||
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
|
lv_spinbox_t * spinbox = (lv_spinbox_t *) obj;
|
||||||
|
|
||||||
int32_t new_step = ext->step / 10;
|
int32_t new_step = spinbox->step / 10;
|
||||||
if((new_step) > 0)
|
if((new_step) > 0)
|
||||||
ext->step = new_step;
|
spinbox->step = new_step;
|
||||||
else
|
else
|
||||||
ext->step = 1;
|
spinbox->step = 1;
|
||||||
|
|
||||||
lv_spinbox_updatevalue(spinbox);
|
lv_spinbox_updatevalue(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Select next higher digit for edition
|
* Select next higher digit for edition
|
||||||
* @param spinbox pointer to spinbox
|
* @param spinbox pointer to spinbox
|
||||||
*/
|
*/
|
||||||
void lv_spinbox_step_prev(lv_obj_t * spinbox)
|
void lv_spinbox_step_prev(lv_obj_t * obj)
|
||||||
{
|
{
|
||||||
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
|
lv_spinbox_t * spinbox = (lv_spinbox_t *) obj;
|
||||||
int32_t step_limit;
|
int32_t step_limit;
|
||||||
step_limit = LV_MAX(ext->range_max, (ext->range_min < 0 ? (-ext->range_min) : ext->range_min));
|
step_limit = LV_MAX(spinbox->range_max, (spinbox->range_min < 0 ? (-spinbox->range_min) : spinbox->range_min));
|
||||||
int32_t new_step = ext->step * 10;
|
int32_t new_step = spinbox->step * 10;
|
||||||
if(new_step <= step_limit) ext->step = new_step;
|
if(new_step <= step_limit) spinbox->step = new_step;
|
||||||
|
|
||||||
lv_spinbox_updatevalue(spinbox);
|
lv_spinbox_updatevalue(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get spinbox rollover function status
|
* Get spinbox rollover function status
|
||||||
* @param spinbox pointer to spinbox
|
* @param spinbox pointer to spinbox
|
||||||
*/
|
*/
|
||||||
bool lv_spinbox_get_rollover(lv_obj_t * spinbox)
|
bool lv_spinbox_get_rollover(lv_obj_t * obj)
|
||||||
{
|
{
|
||||||
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
|
lv_spinbox_t * spinbox = (lv_spinbox_t *) obj;
|
||||||
|
|
||||||
return ext->rollover;
|
return spinbox->rollover;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increment spinbox value by one step
|
* Increment spinbox value by one step
|
||||||
* @param spinbox pointer to spinbox
|
* @param spinbox pointer to spinbox
|
||||||
*/
|
*/
|
||||||
void lv_spinbox_increment(lv_obj_t * spinbox)
|
void lv_spinbox_increment(lv_obj_t * obj)
|
||||||
{
|
{
|
||||||
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
|
lv_spinbox_t * spinbox = (lv_spinbox_t *) obj;
|
||||||
|
|
||||||
if(ext->value + ext->step <= ext->range_max) {
|
if(spinbox->value + spinbox->step <= spinbox->range_max) {
|
||||||
/*Special mode when zero crossing*/
|
/*Special mode when zero crossing*/
|
||||||
if((ext->value + ext->step) > 0 && ext->value < 0) ext->value = -ext->value;
|
if((spinbox->value + spinbox->step) > 0 && spinbox->value < 0) spinbox->value = -spinbox->value;
|
||||||
ext->value += ext->step;
|
spinbox->value += spinbox->step;
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Rollover?
|
// Rollover?
|
||||||
if((ext->rollover) && (ext->value == ext->range_max))
|
if((spinbox->rollover) && (spinbox->value == spinbox->range_max))
|
||||||
ext->value = ext->range_min;
|
spinbox->value = spinbox->range_min;
|
||||||
else
|
else
|
||||||
ext->value = ext->range_max;
|
spinbox->value = spinbox->range_max;
|
||||||
}
|
}
|
||||||
|
|
||||||
lv_spinbox_updatevalue(spinbox);
|
lv_spinbox_updatevalue(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decrement spinbox value by one step
|
* Decrement spinbox value by one step
|
||||||
* @param spinbox pointer to spinbox
|
* @param spinbox pointer to spinbox
|
||||||
*/
|
*/
|
||||||
void lv_spinbox_decrement(lv_obj_t * spinbox)
|
void lv_spinbox_decrement(lv_obj_t * obj)
|
||||||
{
|
{
|
||||||
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
|
lv_spinbox_t * spinbox = (lv_spinbox_t *) obj;
|
||||||
|
|
||||||
if(ext->value - ext->step >= ext->range_min) {
|
if(spinbox->value - spinbox->step >= spinbox->range_min) {
|
||||||
/*Special mode when zero crossing*/
|
/*Special mode when zero crossing*/
|
||||||
if((ext->value - ext->step) < 0 && ext->value > 0) ext->value = -ext->value;
|
if((spinbox->value - spinbox->step) < 0 && spinbox->value > 0) spinbox->value = -spinbox->value;
|
||||||
ext->value -= ext->step;
|
spinbox->value -= spinbox->step;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Rollover?
|
/*Rollover?*/
|
||||||
if((ext->rollover) && (ext->value == ext->range_min))
|
if((spinbox->rollover) && (spinbox->value == spinbox->range_min))
|
||||||
ext->value = ext->range_max;
|
spinbox->value = spinbox->range_max;
|
||||||
else
|
else
|
||||||
ext->value = ext->range_min;
|
spinbox->value = spinbox->range_min;
|
||||||
}
|
}
|
||||||
|
|
||||||
lv_spinbox_updatevalue(spinbox);
|
lv_spinbox_updatevalue(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC FUNCTIONS
|
* STATIC FUNCTIONS
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
/**
|
static void lv_spinbox_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy)
|
||||||
* Signal function of the spinbox
|
{
|
||||||
* @param spinbox pointer to a spinbox object
|
LV_LOG_TRACE("spinbox create started");
|
||||||
* @param sign a signal type from lv_signal_t enum
|
|
||||||
* @param param pointer to a signal specific variable
|
lv_obj_construct_base(obj, parent, copy);
|
||||||
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
|
|
||||||
*/
|
|
||||||
static lv_res_t lv_spinbox_signal(lv_obj_t * spinbox, lv_signal_t sign, void * param)
|
lv_spinbox_t * spinbox = (lv_spinbox_t *) obj;
|
||||||
|
|
||||||
|
/*Initialize the allocated 'ext'*/
|
||||||
|
spinbox->value = 0;
|
||||||
|
spinbox->dec_point_pos = 0;
|
||||||
|
spinbox->digit_count = 5;
|
||||||
|
spinbox->step = 1;
|
||||||
|
spinbox->range_max = 99999;
|
||||||
|
spinbox->range_min = -99999;
|
||||||
|
spinbox->rollover = false;
|
||||||
|
|
||||||
|
lv_textarea_set_one_line(obj, true);
|
||||||
|
lv_textarea_set_cursor_click_pos(obj, true);
|
||||||
|
lv_obj_set_width(obj, LV_DPI_DEF);
|
||||||
|
|
||||||
|
lv_spinbox_updatevalue(obj);
|
||||||
|
|
||||||
|
LV_LOG_INFO("spinbox created");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void lv_spinbox_destructor(lv_obj_t * obj)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static lv_res_t lv_spinbox_signal(lv_obj_t * obj, lv_signal_t sign, void * param)
|
||||||
{
|
{
|
||||||
/* Include the ancient signal function */
|
/* Include the ancient signal function */
|
||||||
lv_res_t res = LV_RES_OK;
|
lv_res_t res = LV_RES_OK;
|
||||||
res = ancestor_signal(spinbox, sign, param);
|
res = lv_obj_signal_base(MY_CLASS, obj, sign, param);
|
||||||
if(res != LV_RES_OK) return res;
|
if(res != LV_RES_OK) return res;
|
||||||
|
|
||||||
|
lv_spinbox_t * spinbox = (lv_spinbox_t *) obj;
|
||||||
if(sign == LV_SIGNAL_RELEASED) {
|
if(sign == LV_SIGNAL_RELEASED) {
|
||||||
/*If released with an ENCODER then move to the next digit*/
|
/*If released with an ENCODER then move to the next digit*/
|
||||||
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
|
|
||||||
lv_indev_t * indev = lv_indev_get_act();
|
lv_indev_t * indev = lv_indev_get_act();
|
||||||
if(lv_indev_get_type(indev) == LV_INDEV_TYPE_ENCODER) {
|
if(lv_indev_get_type(indev) == LV_INDEV_TYPE_ENCODER) {
|
||||||
#if LV_USE_GROUP
|
if(lv_group_get_editing(lv_obj_get_group(obj))) {
|
||||||
if(lv_group_get_editing(lv_obj_get_group(spinbox))) {
|
if(spinbox->step > 1) {
|
||||||
if(ext->step > 1) {
|
lv_spinbox_step_next(obj);
|
||||||
lv_spinbox_step_next(spinbox);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/*Restart from the MSB*/
|
/*Restart from the MSB*/
|
||||||
ext->step = 1;
|
spinbox->step = 1;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
for(i = 0; i < ext->digit_count; i++) {
|
for(i = 0; i < spinbox->digit_count; i++) {
|
||||||
int32_t new_step = ext->step * 10;
|
int32_t new_step = spinbox->step * 10;
|
||||||
if(new_step >= ext->range_max) break;
|
if(new_step >= spinbox->range_max) break;
|
||||||
ext->step = new_step;
|
spinbox->step = new_step;
|
||||||
}
|
}
|
||||||
lv_spinbox_step_prev(spinbox);
|
lv_spinbox_step_prev(spinbox);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
/*The cursor has been positioned to a digit.
|
/*The cursor has been positioned to a digit.
|
||||||
* Set `step` accordingly*/
|
* Set `step` accordingly*/
|
||||||
else {
|
else {
|
||||||
const char * txt = lv_textarea_get_text(spinbox);
|
const char * txt = lv_textarea_get_text(obj);
|
||||||
size_t txt_len = strlen(txt);
|
size_t txt_len = strlen(txt);
|
||||||
|
|
||||||
if(txt[ext->ta.cursor.pos] == '.') {
|
if(txt[spinbox->ta.cursor.pos] == '.') {
|
||||||
lv_textarea_cursor_left(spinbox);
|
lv_textarea_cursor_left(obj);
|
||||||
}
|
}
|
||||||
else if(ext->ta.cursor.pos == (uint32_t)txt_len) {
|
else if(spinbox->ta.cursor.pos == (uint32_t)txt_len) {
|
||||||
lv_textarea_set_cursor_pos(spinbox, txt_len - 1);
|
lv_textarea_set_cursor_pos(obj, txt_len - 1);
|
||||||
}
|
}
|
||||||
else if(ext->ta.cursor.pos == 0 && ext->range_min < 0) {
|
else if(spinbox->ta.cursor.pos == 0 && spinbox->range_min < 0) {
|
||||||
lv_textarea_set_cursor_pos(spinbox, 1);
|
lv_textarea_set_cursor_pos(obj, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t len = ext->digit_count - 1;
|
size_t len = spinbox->digit_count - 1;
|
||||||
uint16_t cp = ext->ta.cursor.pos;
|
uint16_t cp = spinbox->ta.cursor.pos;
|
||||||
|
|
||||||
if(ext->ta.cursor.pos > ext->dec_point_pos && ext->dec_point_pos != 0) cp--;
|
if(spinbox->ta.cursor.pos > spinbox->dec_point_pos && spinbox->dec_point_pos != 0) cp--;
|
||||||
uint32_t pos = len - cp;
|
uint32_t pos = len - cp;
|
||||||
|
|
||||||
if(ext->range_min < 0) pos++;
|
if(spinbox->range_min < 0) pos++;
|
||||||
|
|
||||||
ext->step = 1;
|
spinbox->step = 1;
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
for(i = 0; i < pos; i++) ext->step *= 10;
|
for(i = 0; i < pos; i++) spinbox->step *= 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(sign == LV_SIGNAL_CONTROL) {
|
else if(sign == LV_SIGNAL_CONTROL) {
|
||||||
#if LV_USE_GROUP
|
|
||||||
lv_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act());
|
lv_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act());
|
||||||
|
|
||||||
uint32_t c = *((uint32_t *)param); /*uint32_t because can be UTF-8*/
|
uint32_t c = *((uint32_t *)param); /*uint32_t because can be UTF-8*/
|
||||||
if(c == LV_KEY_RIGHT) {
|
if(c == LV_KEY_RIGHT) {
|
||||||
if(indev_type == LV_INDEV_TYPE_ENCODER)
|
if(indev_type == LV_INDEV_TYPE_ENCODER)
|
||||||
lv_spinbox_increment(spinbox);
|
lv_spinbox_increment(obj);
|
||||||
else
|
else
|
||||||
lv_spinbox_step_next(spinbox);
|
lv_spinbox_step_next(obj);
|
||||||
}
|
}
|
||||||
else if(c == LV_KEY_LEFT) {
|
else if(c == LV_KEY_LEFT) {
|
||||||
if(indev_type == LV_INDEV_TYPE_ENCODER)
|
if(indev_type == LV_INDEV_TYPE_ENCODER)
|
||||||
lv_spinbox_decrement(spinbox);
|
lv_spinbox_decrement(spinbox);
|
||||||
else
|
else
|
||||||
lv_spinbox_step_prev(spinbox);
|
lv_spinbox_step_prev(obj);
|
||||||
}
|
}
|
||||||
else if(c == LV_KEY_UP) {
|
else if(c == LV_KEY_UP) {
|
||||||
lv_spinbox_increment(spinbox);
|
lv_spinbox_increment(obj);
|
||||||
}
|
}
|
||||||
else if(c == LV_KEY_DOWN) {
|
else if(c == LV_KEY_DOWN) {
|
||||||
lv_spinbox_decrement(spinbox);
|
lv_spinbox_decrement(obj);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
lv_textarea_add_char(spinbox, c);
|
lv_textarea_add_char(obj, c);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void lv_spinbox_updatevalue(lv_obj_t * spinbox)
|
static void lv_spinbox_updatevalue(lv_obj_t * obj)
|
||||||
{
|
{
|
||||||
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
|
lv_spinbox_t * spinbox = (lv_spinbox_t *) obj;
|
||||||
|
|
||||||
char buf[LV_SPINBOX_MAX_DIGIT_COUNT + 8];
|
char buf[LV_SPINBOX_MAX_DIGIT_COUNT + 8];
|
||||||
lv_memset_00(buf, sizeof(buf));
|
lv_memset_00(buf, sizeof(buf));
|
||||||
char * buf_p = buf;
|
char * buf_p = buf;
|
||||||
uint8_t cur_shift_left = 0;
|
uint8_t cur_shift_left = 0;
|
||||||
|
|
||||||
if(ext->range_min < 0) { // hide sign if there are only positive values
|
if(spinbox->range_min < 0) { // hide sign if there are only positive values
|
||||||
/*Add the sign*/
|
/*Add the sign*/
|
||||||
(*buf_p) = ext->value >= 0 ? '+' : '-';
|
(*buf_p) = spinbox->value >= 0 ? '+' : '-';
|
||||||
buf_p++;
|
buf_p++;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -419,10 +407,10 @@ static void lv_spinbox_updatevalue(lv_obj_t * spinbox)
|
|||||||
int32_t i;
|
int32_t i;
|
||||||
char digits[LV_SPINBOX_MAX_DIGIT_COUNT + 4];
|
char digits[LV_SPINBOX_MAX_DIGIT_COUNT + 4];
|
||||||
/*Convert the numbers to string (the sign is already handled so always covert positive number)*/
|
/*Convert the numbers to string (the sign is already handled so always covert positive number)*/
|
||||||
lv_snprintf(digits, sizeof(digits), "%d", LV_ABS(ext->value));
|
lv_snprintf(digits, sizeof(digits), "%d", LV_ABS(spinbox->value));
|
||||||
|
|
||||||
/*Add leading zeros*/
|
/*Add leading zeros*/
|
||||||
int lz_cnt = ext->digit_count - (int)strlen(digits);
|
int lz_cnt = spinbox->digit_count - (int)strlen(digits);
|
||||||
if(lz_cnt > 0) {
|
if(lz_cnt > 0) {
|
||||||
for(i = (uint16_t)strlen(digits); i >= 0; i--) {
|
for(i = (uint16_t)strlen(digits); i >= 0; i--) {
|
||||||
digits[i + lz_cnt] = digits[i];
|
digits[i + lz_cnt] = digits[i];
|
||||||
@ -433,7 +421,7 @@ static void lv_spinbox_updatevalue(lv_obj_t * spinbox)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t intDigits;
|
int32_t intDigits;
|
||||||
intDigits = (ext->dec_point_pos == 0) ? ext->digit_count : ext->dec_point_pos;
|
intDigits = (spinbox->dec_point_pos == 0) ? spinbox->digit_count : spinbox->dec_point_pos;
|
||||||
|
|
||||||
/*Add the decimal part*/
|
/*Add the decimal part*/
|
||||||
for(i = 0; i < intDigits && digits[i] != '\0'; i++) {
|
for(i = 0; i < intDigits && digits[i] != '\0'; i++) {
|
||||||
@ -441,23 +429,23 @@ static void lv_spinbox_updatevalue(lv_obj_t * spinbox)
|
|||||||
buf_p++;
|
buf_p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ext->dec_point_pos != 0) {
|
if(spinbox->dec_point_pos != 0) {
|
||||||
/*Insert the decimal point*/
|
/*Insert the decimal point*/
|
||||||
(*buf_p) = '.';
|
(*buf_p) = '.';
|
||||||
buf_p++;
|
buf_p++;
|
||||||
|
|
||||||
for(/*Leave i*/; i < ext->digit_count && digits[i] != '\0'; i++) {
|
for(/*Leave i*/; i < spinbox->digit_count && digits[i] != '\0'; i++) {
|
||||||
(*buf_p) = digits[i];
|
(*buf_p) = digits[i];
|
||||||
buf_p++;
|
buf_p++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Refresh the text*/
|
/*Refresh the text*/
|
||||||
lv_textarea_set_text(spinbox, (char *)buf);
|
lv_textarea_set_text(obj, (char *)buf);
|
||||||
|
|
||||||
/*Set the cursor position*/
|
/*Set the cursor position*/
|
||||||
int32_t step = ext->step;
|
int32_t step = spinbox->step;
|
||||||
uint8_t cur_pos = (uint8_t)ext->digit_count;
|
uint8_t cur_pos = (uint8_t)spinbox->digit_count;
|
||||||
while(step >= 10) {
|
while(step >= 10) {
|
||||||
step /= 10;
|
step /= 10;
|
||||||
cur_pos--;
|
cur_pos--;
|
||||||
|
@ -13,7 +13,7 @@ extern "C" {
|
|||||||
/*********************
|
/*********************
|
||||||
* INCLUDES
|
* INCLUDES
|
||||||
*********************/
|
*********************/
|
||||||
#include "../../../lv_core/lv_obj.h"
|
#include "../../../lvgl.h"
|
||||||
|
|
||||||
#if LV_USE_SPINBOX
|
#if LV_USE_SPINBOX
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ extern "C" {
|
|||||||
|
|
||||||
/*Data of spinbox*/
|
/*Data of spinbox*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
lv_textarea_ext_t ta; /*Ext. of ancestor*/
|
lv_textarea_t ta; /*Ext. of ancestor*/
|
||||||
/*New data for this type */
|
/*New data for this type */
|
||||||
int32_t value;
|
int32_t value;
|
||||||
int32_t range_max;
|
int32_t range_max;
|
||||||
@ -42,14 +42,9 @@ typedef struct {
|
|||||||
uint16_t digit_count : 4;
|
uint16_t digit_count : 4;
|
||||||
uint16_t dec_point_pos : 4; /*if 0, there is no separator and the number is an integer*/
|
uint16_t dec_point_pos : 4; /*if 0, there is no separator and the number is an integer*/
|
||||||
uint16_t rollover : 1; // Set to true for rollover functionality
|
uint16_t rollover : 1; // Set to true for rollover functionality
|
||||||
} lv_spinbox_ext_t;
|
} lv_spinbox_t;
|
||||||
|
|
||||||
enum {
|
extern const lv_obj_class_t lv_spinbox;
|
||||||
LV_SPINBOX_PART_MAIN = LV_TEXTAREA_PART_MAIN,
|
|
||||||
LV_SPINBOX_PART_CURSOR = LV_TEXTAREA_PART_CURSOR,
|
|
||||||
_LV_SPINBOX_PART_VIRTUAL_LAST = _LV_TEXTAREA_PART_VIRTUAL_LAST,
|
|
||||||
};
|
|
||||||
typedef uint8_t lv_spinbox_part_t;
|
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* GLOBAL PROTOTYPES
|
* GLOBAL PROTOTYPES
|
||||||
@ -72,14 +67,14 @@ lv_obj_t * lv_spinbox_create(lv_obj_t * parent);
|
|||||||
* @param spinbox pointer to spinbox
|
* @param spinbox pointer to spinbox
|
||||||
* @param b true or false to enable or disable (default)
|
* @param b true or false to enable or disable (default)
|
||||||
*/
|
*/
|
||||||
void lv_spinbox_set_rollover(lv_obj_t * spinbox, bool b);
|
void lv_spinbox_set_rollover(lv_obj_t * obj, bool b);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set spinbox value
|
* Set spinbox value
|
||||||
* @param spinbox pointer to spinbox
|
* @param spinbox pointer to spinbox
|
||||||
* @param i value to be set
|
* @param i value to be set
|
||||||
*/
|
*/
|
||||||
void lv_spinbox_set_value(lv_obj_t * spinbox, int32_t i);
|
void lv_spinbox_set_value(lv_obj_t * obj, int32_t i);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set spinbox digit format (digit count and decimal format)
|
* Set spinbox digit format (digit count and decimal format)
|
||||||
@ -88,14 +83,14 @@ void lv_spinbox_set_value(lv_obj_t * spinbox, int32_t i);
|
|||||||
* @param separator_position number of digit before the decimal point. If 0, decimal point is not
|
* @param separator_position number of digit before the decimal point. If 0, decimal point is not
|
||||||
* shown
|
* shown
|
||||||
*/
|
*/
|
||||||
void lv_spinbox_set_digit_format(lv_obj_t * spinbox, uint8_t digit_count, uint8_t separator_position);
|
void lv_spinbox_set_digit_format(lv_obj_t * obj, uint8_t digit_count, uint8_t separator_position);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set spinbox step
|
* Set spinbox step
|
||||||
* @param spinbox pointer to spinbox
|
* @param spinbox pointer to spinbox
|
||||||
* @param step steps on increment/decrement
|
* @param step steps on increment/decrement
|
||||||
*/
|
*/
|
||||||
void lv_spinbox_set_step(lv_obj_t * spinbox, uint32_t step);
|
void lv_spinbox_set_step(lv_obj_t * obj, uint32_t step);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set spinbox value range
|
* Set spinbox value range
|
||||||
@ -103,14 +98,14 @@ void lv_spinbox_set_step(lv_obj_t * spinbox, uint32_t step);
|
|||||||
* @param range_min maximum value, inclusive
|
* @param range_min maximum value, inclusive
|
||||||
* @param range_max minimum value, inclusive
|
* @param range_max minimum value, inclusive
|
||||||
*/
|
*/
|
||||||
void lv_spinbox_set_range(lv_obj_t * spinbox, int32_t range_min, int32_t range_max);
|
void lv_spinbox_set_range(lv_obj_t * obj, int32_t range_min, int32_t range_max);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set spinbox left padding in digits count (added between sign and first digit)
|
* Set spinbox left padding in digits count (added between sign and first digit)
|
||||||
* @param spinbox pointer to spinbox
|
* @param spinbox pointer to spinbox
|
||||||
* @param cb Callback function called on value change event
|
* @param cb Callback function called on value change event
|
||||||
*/
|
*/
|
||||||
void lv_spinbox_set_padding_left(lv_obj_t * spinbox, uint8_t padding);
|
void lv_spinbox_set_padding_left(lv_obj_t * obj, uint8_t padding);
|
||||||
|
|
||||||
/*=====================
|
/*=====================
|
||||||
* Getter functions
|
* Getter functions
|
||||||
@ -120,14 +115,14 @@ void lv_spinbox_set_padding_left(lv_obj_t * spinbox, uint8_t padding);
|
|||||||
* Get spinbox rollover function status
|
* Get spinbox rollover function status
|
||||||
* @param spinbox pointer to spinbox
|
* @param spinbox pointer to spinbox
|
||||||
*/
|
*/
|
||||||
bool lv_spinbox_get_rollover(lv_obj_t * spinbox);
|
bool lv_spinbox_get_rollover(lv_obj_t * obj);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the spinbox numeral value (user has to convert to float according to its digit format)
|
* Get the spinbox numeral value (user has to convert to float according to its digit format)
|
||||||
* @param spinbox pointer to spinbox
|
* @param spinbox pointer to spinbox
|
||||||
* @return value integer value of the spinbox
|
* @return value integer value of the spinbox
|
||||||
*/
|
*/
|
||||||
int32_t lv_spinbox_get_value(lv_obj_t * spinbox);
|
int32_t lv_spinbox_get_value(lv_obj_t * obj);
|
||||||
|
|
||||||
/*=====================
|
/*=====================
|
||||||
* Other functions
|
* Other functions
|
||||||
@ -137,25 +132,25 @@ int32_t lv_spinbox_get_value(lv_obj_t * spinbox);
|
|||||||
* Select next lower digit for edition by dividing the step by 10
|
* Select next lower digit for edition by dividing the step by 10
|
||||||
* @param spinbox pointer to spinbox
|
* @param spinbox pointer to spinbox
|
||||||
*/
|
*/
|
||||||
void lv_spinbox_step_next(lv_obj_t * spinbox);
|
void lv_spinbox_step_next(lv_obj_t * obj);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Select next higher digit for edition by multiplying the step by 10
|
* Select next higher digit for edition by multiplying the step by 10
|
||||||
* @param spinbox pointer to spinbox
|
* @param spinbox pointer to spinbox
|
||||||
*/
|
*/
|
||||||
void lv_spinbox_step_prev(lv_obj_t * spinbox);
|
void lv_spinbox_step_prev(lv_obj_t * obj);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increment spinbox value by one step
|
* Increment spinbox value by one step
|
||||||
* @param spinbox pointer to spinbox
|
* @param spinbox pointer to spinbox
|
||||||
*/
|
*/
|
||||||
void lv_spinbox_increment(lv_obj_t * spinbox);
|
void lv_spinbox_increment(lv_obj_t * obj);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decrement spinbox value by one step
|
* Decrement spinbox value by one step
|
||||||
* @param spinbox pointer to spinbox
|
* @param spinbox pointer to spinbox
|
||||||
*/
|
*/
|
||||||
void lv_spinbox_decrement(lv_obj_t * spinbox);
|
void lv_spinbox_decrement(lv_obj_t * obj);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
|
@ -48,25 +48,27 @@ lv_obj_t * lv_spinner_create(lv_obj_t * par, uint32_t time, uint32_t arc_length)
|
|||||||
LV_ASSERT_MEM(spinner);
|
LV_ASSERT_MEM(spinner);
|
||||||
if(spinner == NULL) return NULL;
|
if(spinner == NULL) return NULL;
|
||||||
|
|
||||||
lv_obj_set_size(spinner, LV_DPI, LV_DPI);
|
lv_obj_set_size(spinner, LV_DPI_DEF, LV_DPI_DEF);
|
||||||
|
|
||||||
lv_anim_path_t path;
|
lv_obj_remove_style(spinner, LV_PART_KNOB, LV_STATE_ANY, NULL);
|
||||||
lv_anim_path_init(&path);
|
|
||||||
lv_anim_path_set_cb(&path, lv_anim_path_ease_in_out);
|
|
||||||
|
|
||||||
lv_anim_t a;
|
lv_anim_path_t path;
|
||||||
lv_anim_init(&a);
|
lv_anim_path_init(&path);
|
||||||
lv_anim_set_var(&a, spinner);
|
lv_anim_path_set_cb(&path, lv_anim_path_ease_in_out);
|
||||||
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_spinner_angle_anim_cb);
|
|
||||||
lv_anim_set_path(&a, &path);
|
|
||||||
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
|
|
||||||
lv_anim_set_time(&a, time);
|
|
||||||
lv_anim_set_values(&a, 0, 360);
|
|
||||||
lv_anim_start(&a);
|
|
||||||
|
|
||||||
lv_arc_set_angles(spinner, 0, arc_length);
|
lv_anim_t a;
|
||||||
lv_arc_set_bg_angles(spinner, 0, 360);
|
lv_anim_init(&a);
|
||||||
lv_arc_set_rotation(spinner, 270 - arc_length / 2);
|
lv_anim_set_var(&a, spinner);
|
||||||
|
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_spinner_angle_anim_cb);
|
||||||
|
lv_anim_set_path(&a, &path);
|
||||||
|
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
|
||||||
|
lv_anim_set_time(&a, time);
|
||||||
|
lv_anim_set_values(&a, 0, 360);
|
||||||
|
lv_anim_start(&a);
|
||||||
|
|
||||||
|
lv_arc_set_bg_angles(spinner, 0, 360);
|
||||||
|
lv_arc_set_angles(spinner, 0, arc_length);
|
||||||
|
lv_arc_set_angle_ofs(spinner, 270 - arc_length / 2);
|
||||||
|
|
||||||
return spinner;
|
return spinner;
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ extern "C" {
|
|||||||
/*********************
|
/*********************
|
||||||
* INCLUDES
|
* INCLUDES
|
||||||
*********************/
|
*********************/
|
||||||
#include "../../../lv_core/lv_obj.h"
|
#include "../../../lvgl.h"
|
||||||
|
|
||||||
#if LV_USE_SPINNER
|
#if LV_USE_SPINNER
|
||||||
|
|
||||||
@ -22,10 +22,6 @@ extern "C" {
|
|||||||
#error "lv_spinner: lv_arc is required. Enable it in lv_conf.h (LV_USE_ARC 1) "
|
#error "lv_spinner: lv_arc is required. Enable it in lv_conf.h (LV_USE_ARC 1) "
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LV_USE_ANIMATION == 0
|
|
||||||
#error "lv_spinner: animations are required. Enable it in lv_conf.h (LV_USE_ANIMATION 1) "
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
*********************/
|
*********************/
|
||||||
|
@ -16,22 +16,24 @@
|
|||||||
/**********************
|
/**********************
|
||||||
* TYPEDEFS
|
* TYPEDEFS
|
||||||
**********************/
|
**********************/
|
||||||
typedef struct {
|
|
||||||
uint16_t tab_cnt;
|
|
||||||
uint16_t tab_cur;
|
|
||||||
}lv_tabview_ext_t;
|
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC PROTOTYPES
|
* STATIC PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
|
static void lv_tabview_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy);
|
||||||
static void btns_event_cb(lv_obj_t * btns, lv_event_t e);
|
static void btns_event_cb(lv_obj_t * btns, lv_event_t e);
|
||||||
static void cont_event_cb(lv_obj_t * cont, lv_event_t e);
|
static void cont_event_cb(lv_obj_t * cont, lv_event_t e);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC VARIABLES
|
* STATIC VARIABLES
|
||||||
**********************/
|
**********************/
|
||||||
static bool inited;
|
const lv_obj_class_t lv_tabview = {
|
||||||
static lv_style_t style_bg;
|
.constructor_cb = lv_tabview_constructor,
|
||||||
|
.base_class = &lv_obj,
|
||||||
|
.instance_size = sizeof(lv_tabview_t)};
|
||||||
|
|
||||||
|
static lv_dir_t tabpos_create;
|
||||||
|
static lv_coord_t tabsize_create;
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
@ -43,174 +45,166 @@ static lv_style_t style_bg;
|
|||||||
|
|
||||||
lv_obj_t * lv_tabview_create(lv_obj_t * parent, lv_dir_t tab_pos, lv_coord_t tab_size)
|
lv_obj_t * lv_tabview_create(lv_obj_t * parent, lv_dir_t tab_pos, lv_coord_t tab_size)
|
||||||
{
|
{
|
||||||
if(!inited) {
|
tabpos_create = tab_pos;
|
||||||
lv_style_init(&style_bg);
|
tabsize_create = tab_size;
|
||||||
lv_style_set_radius(&style_bg, LV_STATE_DEFAULT, 0);
|
return lv_obj_create_from_class(&lv_tabview, parent, NULL);
|
||||||
|
|
||||||
inited = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
lv_obj_t * tabview = lv_obj_create(parent, NULL);
|
|
||||||
lv_tabview_ext_t * ext = lv_obj_allocate_ext_attr(tabview, sizeof(lv_tabview_ext_t));
|
|
||||||
|
|
||||||
lv_memset_00(ext, sizeof(lv_tabview_ext_t));
|
|
||||||
lv_flex_dir_t flex_dir;
|
|
||||||
switch(tab_pos) {
|
|
||||||
case LV_DIR_TOP:
|
|
||||||
flex_dir = LV_FLEX_DIR_COLUMN;
|
|
||||||
break;
|
|
||||||
case LV_DIR_BOTTOM:
|
|
||||||
flex_dir = LV_FLEX_DIR_COLUMN_REVERSE;
|
|
||||||
break;
|
|
||||||
case LV_DIR_LEFT:
|
|
||||||
flex_dir = LV_FLEX_DIR_ROW;
|
|
||||||
break;
|
|
||||||
case LV_DIR_RIGHT:
|
|
||||||
flex_dir = LV_FLEX_DIR_ROW_REVERSE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
lv_obj_reset_style_list(tabview, LV_OBJ_PART_MAIN);
|
|
||||||
|
|
||||||
lv_obj_set_size(tabview, LV_COORD_PCT(100), LV_COORD_PCT(100));
|
|
||||||
lv_obj_set_flex_dir(tabview, flex_dir);
|
|
||||||
|
|
||||||
lv_obj_t * btnm;
|
|
||||||
lv_obj_t * cont;
|
|
||||||
|
|
||||||
|
|
||||||
btnm = lv_btnmatrix_create(tabview, NULL);
|
|
||||||
cont = lv_obj_create(tabview, NULL);
|
|
||||||
|
|
||||||
lv_btnmatrix_set_one_checked(btnm, true);
|
|
||||||
const char ** map = lv_mem_alloc(sizeof(const char *));
|
|
||||||
map[0] = "";
|
|
||||||
lv_btnmatrix_set_map(btnm, map);
|
|
||||||
lv_obj_add_style(btnm, LV_BTNMATRIX_PART_MAIN, &style_bg);
|
|
||||||
lv_obj_set_event_cb(btnm, btns_event_cb);
|
|
||||||
lv_obj_add_flag(btnm, LV_OBJ_FLAG_EVENT_BUBBLE);
|
|
||||||
|
|
||||||
lv_obj_set_event_cb(cont, cont_event_cb);
|
|
||||||
lv_obj_reset_style_list(cont, LV_OBJ_PART_MAIN);
|
|
||||||
lv_obj_set_scrollbar_mode(cont, LV_SCROLLBAR_MODE_OFF);
|
|
||||||
|
|
||||||
lv_obj_set_flex_item(btnm, LV_FLEX_PLACE_START);
|
|
||||||
lv_obj_set_flex_item(cont, LV_FLEX_PLACE_START);
|
|
||||||
|
|
||||||
switch(tab_pos) {
|
|
||||||
case LV_DIR_TOP:
|
|
||||||
case LV_DIR_LEFT:
|
|
||||||
lv_obj_set_size(btnm, LV_COORD_PCT(100), tab_size);
|
|
||||||
lv_obj_set_size(cont, LV_COORD_PCT(100), LV_FLEX_GROW(1));
|
|
||||||
break;
|
|
||||||
case LV_DIR_BOTTOM:
|
|
||||||
case LV_DIR_RIGHT:
|
|
||||||
lv_obj_set_size(btnm, LV_COORD_PCT(100), tab_size);
|
|
||||||
lv_obj_set_size(cont, LV_FLEX_GROW(1), LV_COORD_PCT(100));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
lv_obj_set_flex_dir(cont, LV_FLEX_DIR_ROW);
|
|
||||||
lv_obj_set_snap_align_x(cont, LV_SCROLL_SNAP_ALIGN_CENTER);
|
|
||||||
lv_obj_add_flag(cont, LV_OBJ_FLAG_SCROLL_STOP);
|
|
||||||
lv_obj_clear_flag(cont, LV_OBJ_FLAG_FOCUS_SCROLL);
|
|
||||||
|
|
||||||
return tabview;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lv_obj_t * lv_tabview_add_tab(lv_obj_t * tv, const char * name)
|
lv_obj_t * lv_tabview_add_tab(lv_obj_t * obj, const char * name)
|
||||||
{
|
{
|
||||||
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tv);
|
lv_tabview_t * tabview = (lv_tabview_t *) obj;
|
||||||
lv_obj_t * cont = lv_tabview_get_content(tv);
|
lv_obj_t * cont = lv_tabview_get_content(obj);
|
||||||
|
|
||||||
lv_obj_t * page = lv_obj_create(cont, NULL);
|
lv_obj_t * page = lv_obj_create(cont, NULL);
|
||||||
lv_obj_clear_flag(page, LV_OBJ_FLAG_CLICK_FOCUSABLE);
|
lv_obj_clear_flag(page, LV_OBJ_FLAG_CLICK_FOCUSABLE);
|
||||||
lv_obj_add_style(page, LV_BTNMATRIX_PART_MAIN, &style_bg);
|
uint32_t tab_id = lv_obj_get_child_cnt(cont);
|
||||||
uint32_t tab_id = lv_obj_count_children(cont);
|
|
||||||
|
|
||||||
lv_obj_set_flex_item(page, true);
|
|
||||||
lv_obj_set_size(page, LV_COORD_PCT(100), LV_COORD_PCT(100));
|
lv_obj_set_size(page, LV_COORD_PCT(100), LV_COORD_PCT(100));
|
||||||
|
|
||||||
lv_obj_t * btns = lv_tabview_get_tab_btns(tv);
|
lv_obj_t * btns = lv_tabview_get_tab_btns(obj);
|
||||||
|
|
||||||
const char ** old_map = lv_btnmatrix_get_map_array(btns);
|
const char ** old_map = lv_btnmatrix_get_map(btns);
|
||||||
const char ** new_map;
|
const char ** new_map;
|
||||||
|
|
||||||
/*top or bottom dir*/
|
/*top or bottom dir*/
|
||||||
if(lv_obj_get_flex_dir(tv) == LV_FLEX_DIR_COLUMN) {
|
// if(lv_obj_get_flex_dir(tv) == LV_FLEX_DIR_COLUMN) {
|
||||||
new_map = lv_mem_alloc((tab_id + 1) * sizeof(const char *));
|
new_map = lv_mem_alloc((tab_id + 1) * sizeof(const char *));
|
||||||
lv_memcpy_small(new_map, old_map, sizeof(const char *) * (tab_id - 1));
|
lv_memcpy_small(new_map, old_map, sizeof(const char *) * (tab_id - 1));
|
||||||
new_map[tab_id - 1] = lv_mem_alloc(strlen(name) + 1);
|
new_map[tab_id - 1] = lv_mem_alloc(strlen(name) + 1);
|
||||||
strcpy((char *)new_map[tab_id - 1], name);
|
strcpy((char *)new_map[tab_id - 1], name);
|
||||||
new_map[tab_id] = "";
|
new_map[tab_id] = "";
|
||||||
}
|
// }
|
||||||
/*left or right dir*/
|
// /*left or right dir*/
|
||||||
else {
|
// else {
|
||||||
new_map = lv_mem_alloc((tab_id * 2) * sizeof(const char *));
|
// new_map = lv_mem_alloc((tab_id * 2) * sizeof(const char *));
|
||||||
lv_memcpy_small(new_map, old_map, sizeof(const char *) * tab_id * 2);
|
// lv_memcpy_small(new_map, old_map, sizeof(const char *) * tab_id * 2);
|
||||||
if(ext->tab_cnt == 0) {
|
// if(ext->tab_cnt == 0) {
|
||||||
new_map[0] = lv_mem_alloc(strlen(name) + 1);
|
// new_map[0] = lv_mem_alloc(strlen(name) + 1);
|
||||||
strcpy((char *)new_map[0], name);
|
// strcpy((char *)new_map[0], name);
|
||||||
new_map[1] = "";
|
// new_map[1] = "";
|
||||||
} else {
|
// } else {
|
||||||
new_map[tab_id * 2 - 3] = "\n";
|
// new_map[tab_id * 2 - 3] = "\n";
|
||||||
new_map[tab_id * 2 - 2] = lv_mem_alloc(strlen(name) + 1);
|
// new_map[tab_id * 2 - 2] = lv_mem_alloc(strlen(name) + 1);
|
||||||
new_map[tab_id * 2 - 1] = "";
|
// new_map[tab_id * 2 - 1] = "";
|
||||||
strcpy((char *)new_map[(tab_id * 2) - 2], name);
|
// strcpy((char *)new_map[(tab_id * 2) - 2], name);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
lv_btnmatrix_set_map(btns, new_map);
|
lv_btnmatrix_set_map(btns, new_map);
|
||||||
lv_mem_free(old_map);
|
lv_mem_free(old_map);
|
||||||
|
|
||||||
lv_btnmatrix_set_btn_ctrl_all(btns, LV_BTNMATRIX_CTRL_CHECKABLE | LV_BTNMATRIX_CTRL_CLICK_TRIG | LV_BTNMATRIX_CTRL_NO_REPEAT);
|
lv_btnmatrix_set_btn_ctrl_all(btns, LV_BTNMATRIX_CTRL_CHECKABLE | LV_BTNMATRIX_CTRL_CLICK_TRIG | LV_BTNMATRIX_CTRL_NO_REPEAT);
|
||||||
|
|
||||||
ext->tab_cnt++;
|
tabview->tab_cnt++;
|
||||||
if(ext->tab_cnt == 1) {
|
if(tabview->tab_cnt == 1) {
|
||||||
lv_tabview_set_act(tv, 0);
|
lv_tabview_set_act(obj, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
lv_btnmatrix_set_btn_ctrl(btns, ext->tab_cur, LV_BTNMATRIX_CTRL_CHECKED);
|
lv_btnmatrix_set_btn_ctrl(btns, tabview->tab_cur, LV_BTNMATRIX_CTRL_CHECKED);
|
||||||
|
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lv_tabview_set_act(lv_obj_t * tv, uint32_t id)
|
void lv_tabview_set_act(lv_obj_t * obj, uint32_t id)
|
||||||
{
|
{
|
||||||
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tv);
|
lv_tabview_t * tabview = (lv_tabview_t *) obj;
|
||||||
if(id >= ext->tab_cnt) {
|
|
||||||
id = ext->tab_cnt - 1;
|
if(id >= tabview->tab_cnt) {
|
||||||
|
id = tabview->tab_cnt - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
lv_obj_t * cont = lv_tabview_get_content(tv);
|
lv_obj_t * cont = lv_tabview_get_content(obj);
|
||||||
lv_obj_t * tab = lv_obj_get_child(cont, NULL);
|
lv_obj_t * tab = lv_obj_get_child(cont, 0);
|
||||||
lv_obj_scroll_to_x(cont, id * lv_obj_get_width(tab), LV_ANIM_ON);
|
lv_coord_t gap = lv_obj_get_style_pad_column(cont, LV_PART_MAIN);
|
||||||
|
lv_obj_scroll_to_x(cont, id * (gap + lv_obj_get_width(tab)), LV_ANIM_ON);
|
||||||
|
|
||||||
lv_obj_t * btns = lv_tabview_get_tab_btns(tv);
|
lv_obj_t * btns = lv_tabview_get_tab_btns(obj);
|
||||||
lv_btnmatrix_set_btn_ctrl(btns, id, LV_BTNMATRIX_CTRL_CHECKED);
|
lv_btnmatrix_set_btn_ctrl(btns, id, LV_BTNMATRIX_CTRL_CHECKED);
|
||||||
ext->tab_cur = id;
|
tabview->tab_cur = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t lv_tabview_get_tab_act(lv_obj_t * tv)
|
uint16_t lv_tabview_get_tab_act(lv_obj_t * obj)
|
||||||
{
|
{
|
||||||
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tv);
|
lv_tabview_t * tabview = (lv_tabview_t *) obj;
|
||||||
return ext->tab_cur;
|
return tabview->tab_cur;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lv_obj_t * lv_tabview_get_content(lv_obj_t * tv)
|
lv_obj_t * lv_tabview_get_content(lv_obj_t * tv)
|
||||||
{
|
{
|
||||||
return lv_obj_get_child(tv, NULL);
|
return lv_obj_get_child(tv, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
lv_obj_t * lv_tabview_get_tab_btns(lv_obj_t * tv)
|
lv_obj_t * lv_tabview_get_tab_btns(lv_obj_t * tv)
|
||||||
{
|
{
|
||||||
return lv_obj_get_child_back(tv, NULL);
|
return lv_obj_get_child(tv, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC FUNCTIONS
|
* STATIC FUNCTIONS
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
|
static void lv_tabview_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy)
|
||||||
|
{
|
||||||
|
lv_obj_construct_base(obj, parent, copy);
|
||||||
|
lv_tabview_t * tabview = (lv_tabview_t *) obj;
|
||||||
|
|
||||||
|
// lv_flex_flow_t flex_dir;
|
||||||
|
// switch(tab_pos) {
|
||||||
|
// case LV_DIR_TOP:
|
||||||
|
// flex_dir = LV_FLEX_DIR_COLUMN;
|
||||||
|
// break;
|
||||||
|
// case LV_DIR_BOTTOM:
|
||||||
|
// flex_dir = LV_FLEX_DIR_COLUMN_REVERSE;
|
||||||
|
// break;
|
||||||
|
// case LV_DIR_LEFT:
|
||||||
|
// flex_dir = LV_FLEX_DIR_ROW;
|
||||||
|
// break;
|
||||||
|
// case LV_DIR_RIGHT:
|
||||||
|
// flex_dir = LV_FLEX_DIR_ROW_REVERSE;
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
|
||||||
|
lv_obj_set_size(obj, LV_COORD_PCT(100), LV_COORD_PCT(100));
|
||||||
|
lv_obj_set_layout(obj, &lv_flex_stacked);
|
||||||
|
|
||||||
|
lv_obj_t * btnm;
|
||||||
|
lv_obj_t * cont;
|
||||||
|
|
||||||
|
|
||||||
|
btnm = lv_btnmatrix_create(obj, NULL);
|
||||||
|
cont = lv_obj_create(obj, NULL);
|
||||||
|
|
||||||
|
lv_btnmatrix_set_one_checked(btnm, true);
|
||||||
|
const char ** map = lv_mem_alloc(sizeof(const char *));
|
||||||
|
map[0] = "";
|
||||||
|
lv_btnmatrix_set_map(btnm, map);
|
||||||
|
lv_obj_add_event_cb(btnm, btns_event_cb, NULL);
|
||||||
|
lv_obj_add_flag(btnm, LV_OBJ_FLAG_EVENT_BUBBLE);
|
||||||
|
|
||||||
|
lv_obj_add_event_cb(cont, cont_event_cb, NULL);
|
||||||
|
lv_obj_set_scrollbar_mode(cont, LV_SCROLLBAR_MODE_OFF);
|
||||||
|
|
||||||
|
switch(tabpos_create) {
|
||||||
|
case LV_DIR_TOP:
|
||||||
|
case LV_DIR_LEFT:
|
||||||
|
lv_obj_set_size(btnm, LV_COORD_PCT(100), tabsize_create);
|
||||||
|
lv_obj_set_width(cont, LV_COORD_PCT(100));
|
||||||
|
lv_obj_set_flex_grow(cont, 1);
|
||||||
|
break;
|
||||||
|
case LV_DIR_BOTTOM:
|
||||||
|
case LV_DIR_RIGHT:
|
||||||
|
lv_obj_set_size(btnm, LV_COORD_PCT(100), tabsize_create);
|
||||||
|
lv_obj_set_height(cont, LV_COORD_PCT(100));
|
||||||
|
lv_obj_set_flex_grow(cont, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
lv_obj_set_layout(cont, &lv_flex_queue);
|
||||||
|
lv_obj_set_snap_align_x(cont, LV_SCROLL_SNAP_ALIGN_CENTER);
|
||||||
|
lv_obj_add_flag(cont, LV_OBJ_FLAG_SCROLL_ONE);
|
||||||
|
lv_obj_clear_flag(cont, LV_OBJ_FLAG_SCROLL_ON_FOCUS);
|
||||||
|
}
|
||||||
|
|
||||||
static void btns_event_cb(lv_obj_t * btns, lv_event_t e)
|
static void btns_event_cb(lv_obj_t * btns, lv_event_t e)
|
||||||
{
|
{
|
||||||
if(e == LV_EVENT_VALUE_CHANGED) {
|
if(e == LV_EVENT_VALUE_CHANGED) {
|
||||||
|
@ -13,7 +13,7 @@ extern "C" {
|
|||||||
/*********************
|
/*********************
|
||||||
* INCLUDES
|
* INCLUDES
|
||||||
*********************/
|
*********************/
|
||||||
#include "../../../lv_core/lv_obj.h"
|
#include "../../../lvgl.h"
|
||||||
|
|
||||||
#if LV_USE_TABVIEW
|
#if LV_USE_TABVIEW
|
||||||
|
|
||||||
@ -25,6 +25,13 @@ extern "C" {
|
|||||||
* TYPEDEFS
|
* TYPEDEFS
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
lv_obj_t obj;
|
||||||
|
uint16_t tab_cnt;
|
||||||
|
uint16_t tab_cur;
|
||||||
|
}lv_tabview_t;
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* GLOBAL PROTOTYPES
|
* GLOBAL PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
|
@ -174,8 +174,8 @@ void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t part, lv_draw_rect_dsc_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(draw_dsc->bg_img_opa != LV_OPA_TRANSP) {
|
if(draw_dsc->bg_img_opa != LV_OPA_TRANSP) {
|
||||||
draw_dsc->bg_img_src = lv_obj_get_style_bg_img_src(obj, part);
|
draw_dsc->img_src = lv_obj_get_style_bg_img_src(obj, part);
|
||||||
if(draw_dsc->bg_img_src) {
|
if(draw_dsc->img_src) {
|
||||||
draw_dsc->bg_img_opa = lv_obj_get_style_bg_img_opa(obj, part);
|
draw_dsc->bg_img_opa = lv_obj_get_style_bg_img_opa(obj, part);
|
||||||
if(draw_dsc->bg_img_opa > LV_OPA_MIN) {
|
if(draw_dsc->bg_img_opa > LV_OPA_MIN) {
|
||||||
draw_dsc->bg_img_tiled = lv_obj_get_style_bg_img_tiled(obj, part);
|
draw_dsc->bg_img_tiled = lv_obj_get_style_bg_img_tiled(obj, part);
|
||||||
@ -201,13 +201,11 @@ void lv_obj_init_draw_label_dsc(lv_obj_t * obj, uint8_t part, lv_draw_label_dsc_
|
|||||||
draw_dsc->opa = lv_obj_get_style_text_opa(obj, part);
|
draw_dsc->opa = lv_obj_get_style_text_opa(obj, part);
|
||||||
if(draw_dsc->opa <= LV_OPA_MIN) return;
|
if(draw_dsc->opa <= LV_OPA_MIN) return;
|
||||||
|
|
||||||
#if LV_USE_OPA_SCALE
|
|
||||||
lv_opa_t opa = lv_obj_get_style_opa(obj, part);
|
lv_opa_t opa = lv_obj_get_style_opa(obj, part);
|
||||||
if(opa < LV_OPA_MAX) {
|
if(opa < LV_OPA_MAX) {
|
||||||
draw_dsc->opa = (uint16_t)((uint16_t)draw_dsc->opa * opa) >> 8;
|
draw_dsc->opa = (uint16_t)((uint16_t)draw_dsc->opa * opa) >> 8;
|
||||||
}
|
}
|
||||||
if(draw_dsc->opa <= LV_OPA_MIN) return;
|
if(draw_dsc->opa <= LV_OPA_MIN) return;
|
||||||
#endif
|
|
||||||
|
|
||||||
draw_dsc->color = lv_obj_get_style_text_color_filtered(obj, part);
|
draw_dsc->color = lv_obj_get_style_text_color_filtered(obj, part);
|
||||||
draw_dsc->letter_space = lv_obj_get_style_text_letter_space(obj, part);
|
draw_dsc->letter_space = lv_obj_get_style_text_letter_space(obj, part);
|
||||||
@ -235,13 +233,11 @@ void lv_obj_init_draw_img_dsc(lv_obj_t * obj, uint8_t part, lv_draw_img_dsc_t *
|
|||||||
draw_dsc->opa = lv_obj_get_style_img_opa(obj, part);
|
draw_dsc->opa = lv_obj_get_style_img_opa(obj, part);
|
||||||
if(draw_dsc->opa <= LV_OPA_MIN) return;
|
if(draw_dsc->opa <= LV_OPA_MIN) return;
|
||||||
|
|
||||||
#if LV_USE_OPA_SCALE
|
|
||||||
lv_opa_t opa_scale = lv_obj_get_style_opa(obj, part);
|
lv_opa_t opa_scale = lv_obj_get_style_opa(obj, part);
|
||||||
if(opa_scale < LV_OPA_MAX) {
|
if(opa_scale < LV_OPA_MAX) {
|
||||||
draw_dsc->opa = (uint16_t)((uint16_t)draw_dsc->opa * opa_scale) >> 8;
|
draw_dsc->opa = (uint16_t)((uint16_t)draw_dsc->opa * opa_scale) >> 8;
|
||||||
}
|
}
|
||||||
if(draw_dsc->opa <= LV_OPA_MIN) return;
|
if(draw_dsc->opa <= LV_OPA_MIN) return;
|
||||||
#endif
|
|
||||||
|
|
||||||
draw_dsc->angle = 0;
|
draw_dsc->angle = 0;
|
||||||
draw_dsc->zoom = LV_IMG_ZOOM_NONE;
|
draw_dsc->zoom = LV_IMG_ZOOM_NONE;
|
||||||
@ -265,13 +261,11 @@ void lv_obj_init_draw_line_dsc(lv_obj_t * obj, uint8_t part, lv_draw_line_dsc_t
|
|||||||
draw_dsc->opa = lv_obj_get_style_line_opa(obj, part);
|
draw_dsc->opa = lv_obj_get_style_line_opa(obj, part);
|
||||||
if(draw_dsc->opa <= LV_OPA_MIN) return;
|
if(draw_dsc->opa <= LV_OPA_MIN) return;
|
||||||
|
|
||||||
#if LV_USE_OPA_SCALE
|
|
||||||
lv_opa_t opa = lv_obj_get_style_opa(obj, part);
|
lv_opa_t opa = lv_obj_get_style_opa(obj, part);
|
||||||
if(opa < LV_OPA_MAX) {
|
if(opa < LV_OPA_MAX) {
|
||||||
draw_dsc->opa = (uint16_t)((uint16_t)draw_dsc->opa * opa) >> 8;
|
draw_dsc->opa = (uint16_t)((uint16_t)draw_dsc->opa * opa) >> 8;
|
||||||
}
|
}
|
||||||
if(draw_dsc->opa <= LV_OPA_MIN) return;
|
if(draw_dsc->opa <= LV_OPA_MIN) return;
|
||||||
#endif
|
|
||||||
|
|
||||||
draw_dsc->color = lv_obj_get_style_line_color(obj, part);
|
draw_dsc->color = lv_obj_get_style_line_color(obj, part);
|
||||||
|
|
||||||
@ -290,22 +284,20 @@ void lv_obj_init_draw_line_dsc(lv_obj_t * obj, uint8_t part, lv_draw_line_dsc_t
|
|||||||
|
|
||||||
void lv_obj_init_draw_arc_dsc(lv_obj_t * obj, uint8_t part, lv_draw_arc_dsc_t * draw_dsc)
|
void lv_obj_init_draw_arc_dsc(lv_obj_t * obj, uint8_t part, lv_draw_arc_dsc_t * draw_dsc)
|
||||||
{
|
{
|
||||||
draw_dsc->width = lv_obj_get_style_line_width(obj, part);
|
draw_dsc->width = lv_obj_get_style_arc_width(obj, part);
|
||||||
if(draw_dsc->width == 0) return;
|
if(draw_dsc->width == 0) return;
|
||||||
|
|
||||||
draw_dsc->opa = lv_obj_get_style_line_opa(obj, part);
|
draw_dsc->opa = lv_obj_get_style_arc_opa(obj, part);
|
||||||
if(draw_dsc->opa <= LV_OPA_MIN) return;
|
if(draw_dsc->opa <= LV_OPA_MIN) return;
|
||||||
|
|
||||||
#if LV_USE_OPA_SCALE
|
|
||||||
lv_opa_t opa = lv_obj_get_style_opa(obj, part);
|
lv_opa_t opa = lv_obj_get_style_opa(obj, part);
|
||||||
if(opa < LV_OPA_MAX) {
|
if(opa < LV_OPA_MAX) {
|
||||||
draw_dsc->opa = (uint16_t)((uint16_t)draw_dsc->opa * opa) >> 8;
|
draw_dsc->opa = (uint16_t)((uint16_t)draw_dsc->opa * opa) >> 8;
|
||||||
}
|
}
|
||||||
if(draw_dsc->opa <= LV_OPA_MIN) return;
|
if(draw_dsc->opa <= LV_OPA_MIN) return;
|
||||||
#endif
|
|
||||||
|
|
||||||
draw_dsc->color = lv_obj_get_style_line_color(obj, part);
|
draw_dsc->color = lv_obj_get_style_arc_color(obj, part);
|
||||||
draw_dsc->bg_img_src = lv_obj_get_style_bg_img_src(obj, part);
|
draw_dsc->img_src = lv_obj_get_style_arc_img_src(obj, part);
|
||||||
|
|
||||||
draw_dsc->rounded = lv_obj_get_style_line_rounded(obj, part);
|
draw_dsc->rounded = lv_obj_get_style_line_rounded(obj, part);
|
||||||
|
|
||||||
|
@ -95,13 +95,17 @@ void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h)
|
|||||||
|
|
||||||
/*If the width or height is set by a layout do not modify them*/
|
/*If the width or height is set by a layout do not modify them*/
|
||||||
if(obj->w_set == LV_SIZE_LAYOUT && obj->h_set == LV_SIZE_LAYOUT) return;
|
if(obj->w_set == LV_SIZE_LAYOUT && obj->h_set == LV_SIZE_LAYOUT) return;
|
||||||
|
|
||||||
if(obj->w_set == LV_SIZE_LAYOUT) w = lv_obj_get_width(obj);
|
if(obj->w_set == LV_SIZE_LAYOUT) w = lv_obj_get_width(obj);
|
||||||
if(obj->h_set == LV_SIZE_LAYOUT) h = lv_obj_get_height(obj);
|
if(obj->h_set == LV_SIZE_LAYOUT) h = lv_obj_get_height(obj);
|
||||||
|
|
||||||
obj->w_set = w;
|
obj->w_set = w;
|
||||||
obj->h_set = h;
|
obj->h_set = h;
|
||||||
|
|
||||||
|
/* If the width or height is set to special layout related value save them in w_set and h_set
|
||||||
|
* but use the current size on the object width*/
|
||||||
|
if(LV_COORD_IS_LAYOUT(w)) w = lv_obj_get_width(obj);
|
||||||
|
if(LV_COORD_IS_LAYOUT(h)) h = lv_obj_get_height(obj);
|
||||||
|
|
||||||
/*Calculate the required auto sizes*/
|
/*Calculate the required auto sizes*/
|
||||||
bool x_auto = obj->w_set == LV_SIZE_AUTO ? true : false;
|
bool x_auto = obj->w_set == LV_SIZE_AUTO ? true : false;
|
||||||
bool y_auto = obj->h_set == LV_SIZE_AUTO ? true : false;
|
bool y_auto = obj->h_set == LV_SIZE_AUTO ? true : false;
|
||||||
|
@ -64,22 +64,37 @@ void lv_obj_set_y(struct _lv_obj_t * obj, lv_coord_t y);
|
|||||||
/**
|
/**
|
||||||
* Set the size of an object.
|
* Set the size of an object.
|
||||||
* @param obj: pointer to an object
|
* @param obj: pointer to an object
|
||||||
* @param w: new width in pixels or `LV_SIZE_AUTO` to set the size to involve all children
|
* @param w: the new width
|
||||||
* @param h: new height in pixels or `LV_SIZE_AUTO` to set the size to involve all children
|
* @param h: the new height
|
||||||
|
* @note possible values are:
|
||||||
|
* pixel: simple set the size accordingly
|
||||||
|
* LV_SIZE_AUTO: to set the size to involve all children in the given direction
|
||||||
|
* LV_COORD_PCT(x): to set size to a percentage of the parent's content area size (the size without paddings).
|
||||||
|
* x should be [0..1000] range
|
||||||
*/
|
*/
|
||||||
void lv_obj_set_size(struct _lv_obj_t * obj, lv_coord_t w, lv_coord_t h);
|
void lv_obj_set_size(struct _lv_obj_t * obj, lv_coord_t w, lv_coord_t h);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the width of an object
|
* Set the width of an object
|
||||||
* @param obj: pointer to an object
|
* @param obj: pointer to an object
|
||||||
* @param w: new width in pixels or `LV_SIZE_AUTO` to set the size to involve all children
|
* @param w: the new width
|
||||||
|
* @note possible values are:
|
||||||
|
* pixel: simple set the size accordingly
|
||||||
|
* LV_SIZE_AUTO: to set the size to involve all children in the given direction
|
||||||
|
* LV_COORD_PCT(x): to set size to a percentage of the parent's content area size (the size without paddings).
|
||||||
|
* x should be [0..1000] range
|
||||||
*/
|
*/
|
||||||
void lv_obj_set_width(struct _lv_obj_t * obj, lv_coord_t w);
|
void lv_obj_set_width(struct _lv_obj_t * obj, lv_coord_t w);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the height of an object
|
* Set the height of an object
|
||||||
* @param obj: pointer to an object
|
* @param obj: pointer to an object
|
||||||
* @param h: new height in pixels or `LV_SIZE_AUTO` to set the size to involve all children
|
* @param h: the new height
|
||||||
|
* @note possible values are:
|
||||||
|
* pixel: simple set the size accordingly
|
||||||
|
* LV_SIZE_AUTO: to set the size to involve all children in the given direction
|
||||||
|
* LV_COORD_PCT(x): to set size to a percentage of the parent's content area size (the size without paddings).
|
||||||
|
* x should be [0..1000] range
|
||||||
*/
|
*/
|
||||||
void lv_obj_set_height(struct _lv_obj_t * obj, lv_coord_t h);
|
void lv_obj_set_height(struct _lv_obj_t * obj, lv_coord_t h);
|
||||||
|
|
||||||
|
@ -369,6 +369,24 @@ static inline lv_color_t lv_obj_get_style_line_color_filtered(const struct _lv_o
|
|||||||
static inline lv_opa_t lv_obj_get_style_line_opa(const struct _lv_obj_t * obj, uint32_t part) {
|
static inline lv_opa_t lv_obj_get_style_line_opa(const struct _lv_obj_t * obj, uint32_t part) {
|
||||||
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_LINE_OPA); return (lv_opa_t) v.num; }
|
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_LINE_OPA); return (lv_opa_t) v.num; }
|
||||||
|
|
||||||
|
static inline lv_coord_t lv_obj_get_style_arc_width(const struct _lv_obj_t * obj, uint32_t part) {
|
||||||
|
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ARC_WIDTH); return (lv_coord_t) v.num; }
|
||||||
|
|
||||||
|
static inline lv_coord_t lv_obj_get_style_arc_rounded(const struct _lv_obj_t * obj, uint32_t part) {
|
||||||
|
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ARC_ROUNDED); return (lv_coord_t) v.num; }
|
||||||
|
|
||||||
|
static inline lv_color_t lv_obj_get_style_arc_color(const struct _lv_obj_t * obj, uint32_t part) {
|
||||||
|
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ARC_COLOR); return (lv_color_t) v.color; }
|
||||||
|
|
||||||
|
static inline lv_color_t lv_obj_get_style_arc_color_filtered(const struct _lv_obj_t * obj, uint32_t part) {
|
||||||
|
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ARC_COLOR_FILTERED); return (lv_color_t) v.color; }
|
||||||
|
|
||||||
|
static inline lv_opa_t lv_obj_get_style_arc_opa(const struct _lv_obj_t * obj, uint32_t part) {
|
||||||
|
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ARC_OPA); return (lv_opa_t) v.num; }
|
||||||
|
|
||||||
|
static inline const void * lv_obj_get_style_arc_img_src(const struct _lv_obj_t * obj, uint32_t part) {
|
||||||
|
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ARC_IMG_SRC); return (const void *) v.ptr; }
|
||||||
|
|
||||||
static inline const char * lv_obj_get_style_content_text(const struct _lv_obj_t * obj, uint32_t part) {
|
static inline const char * lv_obj_get_style_content_text(const struct _lv_obj_t * obj, uint32_t part) {
|
||||||
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_CONTENT_TEXT); return (const char *) v.ptr; }
|
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_CONTENT_TEXT); return (const char *) v.ptr; }
|
||||||
|
|
||||||
@ -403,9 +421,10 @@ static inline lv_text_decor_t lv_obj_get_style_content_decor(const struct _lv_ob
|
|||||||
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_CONTENT_DECOR); return (lv_text_decor_t) v.num; }
|
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_CONTENT_DECOR); return (lv_text_decor_t) v.num; }
|
||||||
|
|
||||||
|
|
||||||
/*=====================
|
/*********************
|
||||||
* Local style set
|
* LOCAL STYLE SET
|
||||||
*====================*/
|
*********************/
|
||||||
|
|
||||||
static inline void lv_obj_set_style_radius(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_coord_t value) {
|
static inline void lv_obj_set_style_radius(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_coord_t value) {
|
||||||
lv_style_value_t v = {.num = value}; lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_RADIUS, v); }
|
lv_style_value_t v = {.num = value}; lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_RADIUS, v); }
|
||||||
|
|
||||||
@ -616,6 +635,24 @@ static inline void lv_obj_set_style_line_color_filtered(struct _lv_obj_t * obj,
|
|||||||
static inline void lv_obj_set_style_line_opa(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_opa_t value) {
|
static inline void lv_obj_set_style_line_opa(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_opa_t value) {
|
||||||
lv_style_value_t v = {.num = value}; lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_LINE_OPA, v); }
|
lv_style_value_t v = {.num = value}; lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_LINE_OPA, v); }
|
||||||
|
|
||||||
|
static inline void lv_obj_set_style_arc_width(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_coord_t value) {
|
||||||
|
lv_style_value_t v = {.num = value}; lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_ARC_WIDTH, v); }
|
||||||
|
|
||||||
|
static inline void lv_obj_set_style_arc_rounded(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_coord_t value) {
|
||||||
|
lv_style_value_t v = {.num = value}; lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_ARC_ROUNDED, v); }
|
||||||
|
|
||||||
|
static inline void lv_obj_set_style_arc_color(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_color_t value) {
|
||||||
|
lv_style_value_t v = {.color = value}; lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_ARC_COLOR, v); }
|
||||||
|
|
||||||
|
static inline void lv_obj_set_style_arc_color_filtered(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_color_t value) {
|
||||||
|
lv_style_value_t v = {.color = value}; lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_ARC_COLOR_FILTERED, v); }
|
||||||
|
|
||||||
|
static inline void lv_obj_set_style_arc_opa(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_opa_t value) {
|
||||||
|
lv_style_value_t v = {.num = value}; lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_ARC_OPA, v); }
|
||||||
|
|
||||||
|
static inline void lv_obj_set_style_arc_img_src(struct _lv_obj_t * obj, uint32_t part, uint32_t state, const void * value) {
|
||||||
|
lv_style_value_t v = {.ptr = value}; lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_ARC_IMG_SRC, v); }
|
||||||
|
|
||||||
static inline void lv_obj_set_style_content_text(struct _lv_obj_t * obj, uint32_t part, uint32_t state, const char * value) {
|
static inline void lv_obj_set_style_content_text(struct _lv_obj_t * obj, uint32_t part, uint32_t state, const char * value) {
|
||||||
lv_style_value_t v = {.ptr = value}; lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_CONTENT_TEXT, v); }
|
lv_style_value_t v = {.ptr = value}; lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_CONTENT_TEXT, v); }
|
||||||
|
|
||||||
|
@ -91,9 +91,9 @@ void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, uin
|
|||||||
lv_draw_rect_dsc_t cir_dsc;
|
lv_draw_rect_dsc_t cir_dsc;
|
||||||
lv_draw_rect_dsc_init(&cir_dsc);
|
lv_draw_rect_dsc_init(&cir_dsc);
|
||||||
cir_dsc.blend_mode = dsc->blend_mode;
|
cir_dsc.blend_mode = dsc->blend_mode;
|
||||||
if(dsc->bg_img_src) {
|
if(dsc->img_src) {
|
||||||
cir_dsc.bg_opa = LV_OPA_TRANSP;
|
cir_dsc.bg_opa = LV_OPA_TRANSP;
|
||||||
cir_dsc.bg_img_src = dsc->bg_img_src;
|
cir_dsc.bg_img_src = dsc->img_src;
|
||||||
cir_dsc.bg_img_opa = dsc->opa;
|
cir_dsc.bg_img_opa = dsc->opa;
|
||||||
} else {
|
} else {
|
||||||
cir_dsc.bg_opa = dsc->opa;
|
cir_dsc.bg_opa = dsc->opa;
|
||||||
@ -115,6 +115,11 @@ void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, uin
|
|||||||
|
|
||||||
/*Draw a full ring*/
|
/*Draw a full ring*/
|
||||||
if(start_angle + 360 == end_angle || start_angle == end_angle + 360) {
|
if(start_angle + 360 == end_angle || start_angle == end_angle + 360) {
|
||||||
|
cir_dsc.border_width = dsc->width;
|
||||||
|
cir_dsc.border_color = dsc->color;
|
||||||
|
cir_dsc.border_opa = dsc->opa;
|
||||||
|
cir_dsc.bg_opa = LV_OPA_TRANSP;
|
||||||
|
cir_dsc.radius = LV_RADIUS_CIRCLE;
|
||||||
lv_draw_rect(&area_out, clip_area, &cir_dsc);
|
lv_draw_rect(&area_out, clip_area, &cir_dsc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ extern "C" {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
lv_color_t color;
|
lv_color_t color;
|
||||||
lv_coord_t width;
|
lv_coord_t width;
|
||||||
const void * bg_img_src;
|
const void * img_src;
|
||||||
lv_opa_t opa;
|
lv_opa_t opa;
|
||||||
lv_blend_mode_t blend_mode : 2;
|
lv_blend_mode_t blend_mode : 2;
|
||||||
uint8_t rounded : 1;
|
uint8_t rounded : 1;
|
||||||
|
@ -468,12 +468,7 @@ LV_ATTRIBUTE_FAST_MEM static void draw_border(const lv_area_t * coords, const lv
|
|||||||
fill_area.y1 = disp_area->y1 + draw_area.y1;
|
fill_area.y1 = disp_area->y1 + draw_area.y1;
|
||||||
fill_area.y2 = fill_area.y1;
|
fill_area.y2 = fill_area.y1;
|
||||||
|
|
||||||
uint32_t buf_ofs = 0;
|
|
||||||
if(dsc->border_side == LV_BORDER_SIDE_LEFT) fill_area.x2 = coords->x1 + corner_size;
|
if(dsc->border_side == LV_BORDER_SIDE_LEFT) fill_area.x2 = coords->x1 + corner_size;
|
||||||
else if(dsc->border_side == LV_BORDER_SIDE_RIGHT) {
|
|
||||||
fill_area.x1 = coords->x2 - corner_size;
|
|
||||||
buf_ofs = fill_area.x1 - coords->x1;
|
|
||||||
}
|
|
||||||
|
|
||||||
volatile bool top_only = false;
|
volatile bool top_only = false;
|
||||||
volatile bool bottom_only = false;
|
volatile bool bottom_only = false;
|
||||||
@ -492,7 +487,7 @@ LV_ATTRIBUTE_FAST_MEM static void draw_border(const lv_area_t * coords, const lv
|
|||||||
(bottom_only && fill_area.y1 >= coords->y2 - corner_size)) {
|
(bottom_only && fill_area.y1 >= coords->y2 - corner_size)) {
|
||||||
lv_memset_ff(mask_buf, draw_area_w);
|
lv_memset_ff(mask_buf, draw_area_w);
|
||||||
mask_res = lv_draw_mask_apply(mask_buf, vdb->area.x1 + draw_area.x1, vdb->area.y1 + h, draw_area_w);
|
mask_res = lv_draw_mask_apply(mask_buf, vdb->area.x1 + draw_area.x1, vdb->area.y1 + h, draw_area_w);
|
||||||
_lv_blend_fill(clip, &fill_area, color, mask_buf + buf_ofs, mask_res, opa, blend_mode);
|
_lv_blend_fill(clip, &fill_area, color, mask_buf, mask_res, opa, blend_mode);
|
||||||
}
|
}
|
||||||
fill_area.y1++;
|
fill_area.y1++;
|
||||||
fill_area.y2++;
|
fill_area.y2++;
|
||||||
|
@ -411,7 +411,7 @@ extern const lv_anim_path_t lv_anim_path_def;
|
|||||||
* MACROS
|
* MACROS
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
#endif /*LV_USE_ANIMATION == 0*/
|
#endif /*LV_ANIM_H*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* extern "C" */
|
} /* extern "C" */
|
||||||
|
@ -40,6 +40,12 @@
|
|||||||
|
|
||||||
void lv_style_init(lv_style_t * style)
|
void lv_style_init(lv_style_t * style)
|
||||||
{
|
{
|
||||||
|
#if LV_USE_ASSERT_STYLE
|
||||||
|
if(style->sentinel == LV_DEBUG_STYLE_SENTINEL_VALUE && style->allocated && style->props_and_values != NULL) {
|
||||||
|
LV_LOG_WARN("Style might be already inited. (Potential memory leak)")
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
lv_memset_00(style, sizeof(lv_style_t));
|
lv_memset_00(style, sizeof(lv_style_t));
|
||||||
#if LV_USE_ASSERT_STYLE
|
#if LV_USE_ASSERT_STYLE
|
||||||
style->sentinel = LV_DEBUG_STYLE_SENTINEL_VALUE;
|
style->sentinel = LV_DEBUG_STYLE_SENTINEL_VALUE;
|
||||||
@ -215,9 +221,10 @@ lv_style_value_t lv_style_prop_get_default(lv_style_prop_t prop)
|
|||||||
case LV_STYLE_TEXT_OPA:
|
case LV_STYLE_TEXT_OPA:
|
||||||
case LV_STYLE_IMG_OPA:
|
case LV_STYLE_IMG_OPA:
|
||||||
case LV_STYLE_BG_IMG_OPA:
|
case LV_STYLE_BG_IMG_OPA:
|
||||||
case LV_STYLE_LINE_OPA:
|
|
||||||
case LV_STYLE_OUTLINE_OPA:
|
case LV_STYLE_OUTLINE_OPA:
|
||||||
case LV_STYLE_SHADOW_OPA:
|
case LV_STYLE_SHADOW_OPA:
|
||||||
|
case LV_STYLE_LINE_OPA:
|
||||||
|
case LV_STYLE_ARC_OPA:
|
||||||
case LV_STYLE_CONTENT_OPA:
|
case LV_STYLE_CONTENT_OPA:
|
||||||
value.num = LV_OPA_COVER;
|
value.num = LV_OPA_COVER;
|
||||||
break;
|
break;
|
||||||
|
@ -193,19 +193,26 @@ typedef enum {
|
|||||||
LV_STYLE_LINE_COLOR_FILTERED = 104 | LV_STYLE_PROP_FILTER,
|
LV_STYLE_LINE_COLOR_FILTERED = 104 | LV_STYLE_PROP_FILTER,
|
||||||
LV_STYLE_LINE_OPA = 105,
|
LV_STYLE_LINE_OPA = 105,
|
||||||
|
|
||||||
LV_STYLE_CONTENT_TEXT = 110 | LV_STYLE_PROP_EXT_DRAW,
|
LV_STYLE_ARC_WIDTH = 110 | LV_STYLE_PROP_EXT_DRAW,
|
||||||
LV_STYLE_CONTENT_ALIGN = 111 | LV_STYLE_PROP_EXT_DRAW,
|
LV_STYLE_ARC_ROUNDED = 111,
|
||||||
LV_STYLE_CONTENT_OFS_X = 112 | LV_STYLE_PROP_EXT_DRAW,
|
LV_STYLE_ARC_COLOR = 112,
|
||||||
LV_STYLE_CONTENT_OFS_Y = 113 | LV_STYLE_PROP_EXT_DRAW,
|
LV_STYLE_ARC_COLOR_FILTERED = 112 | LV_STYLE_PROP_FILTER,
|
||||||
LV_STYLE_CONTENT_FONT = 114 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT,
|
LV_STYLE_ARC_OPA = 113,
|
||||||
LV_STYLE_CONTENT_COLOR = 115 | LV_STYLE_PROP_INHERIT,
|
LV_STYLE_ARC_IMG_SRC = 114,
|
||||||
LV_STYLE_CONTENT_COLOR_FILTERED = 115 | LV_STYLE_PROP_INHERIT | LV_STYLE_PROP_FILTER,
|
|
||||||
LV_STYLE_CONTENT_OPA = 116 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT,
|
|
||||||
LV_STYLE_CONTENT_LETTER_SPACE = 117 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT,
|
|
||||||
LV_STYLE_CONTENT_LINE_SPACE = 118 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT,
|
|
||||||
LV_STYLE_CONTENT_DECOR = 119 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT,
|
|
||||||
|
|
||||||
_LV_STYLE_LAST_BUILT_IN_PROP = 128,
|
LV_STYLE_CONTENT_TEXT = 120 | LV_STYLE_PROP_EXT_DRAW,
|
||||||
|
LV_STYLE_CONTENT_ALIGN = 121 | LV_STYLE_PROP_EXT_DRAW,
|
||||||
|
LV_STYLE_CONTENT_OFS_X = 122 | LV_STYLE_PROP_EXT_DRAW,
|
||||||
|
LV_STYLE_CONTENT_OFS_Y = 123 | LV_STYLE_PROP_EXT_DRAW,
|
||||||
|
LV_STYLE_CONTENT_FONT = 124 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT,
|
||||||
|
LV_STYLE_CONTENT_COLOR = 125 | LV_STYLE_PROP_INHERIT,
|
||||||
|
LV_STYLE_CONTENT_COLOR_FILTERED = 125 | LV_STYLE_PROP_INHERIT | LV_STYLE_PROP_FILTER,
|
||||||
|
LV_STYLE_CONTENT_OPA = 126 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT,
|
||||||
|
LV_STYLE_CONTENT_LETTER_SPACE = 127 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT,
|
||||||
|
LV_STYLE_CONTENT_LINE_SPACE = 128 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT,
|
||||||
|
LV_STYLE_CONTENT_DECOR = 129 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT,
|
||||||
|
|
||||||
|
_LV_STYLE_LAST_BUILT_IN_PROP = 140,
|
||||||
|
|
||||||
LV_STYLE_PROP_ALL = 0xFFFF
|
LV_STYLE_PROP_ALL = 0xFFFF
|
||||||
}lv_style_prop_t;
|
}lv_style_prop_t;
|
||||||
@ -562,6 +569,24 @@ static inline void lv_style_set_line_color_filtered(lv_style_t * style, lv_color
|
|||||||
static inline void lv_style_set_line_opa(lv_style_t * style, lv_opa_t value) {
|
static inline void lv_style_set_line_opa(lv_style_t * style, lv_opa_t value) {
|
||||||
lv_style_value_t v = {.num = value}; lv_style_set_prop(style, LV_STYLE_LINE_OPA, v); }
|
lv_style_value_t v = {.num = value}; lv_style_set_prop(style, LV_STYLE_LINE_OPA, v); }
|
||||||
|
|
||||||
|
static inline void lv_style_set_arc_width(lv_style_t * style, lv_coord_t value) {
|
||||||
|
lv_style_value_t v = {.num = value}; lv_style_set_prop(style, LV_STYLE_ARC_WIDTH, v); }
|
||||||
|
|
||||||
|
static inline void lv_style_set_arc_rounded(lv_style_t * style, lv_coord_t value) {
|
||||||
|
lv_style_value_t v = {.num = value}; lv_style_set_prop(style, LV_STYLE_ARC_ROUNDED, v); }
|
||||||
|
|
||||||
|
static inline void lv_style_set_arc_color(lv_style_t * style, lv_color_t value) {
|
||||||
|
lv_style_value_t v = {.color = value}; lv_style_set_prop(style, LV_STYLE_ARC_COLOR, v); }
|
||||||
|
|
||||||
|
static inline void lv_style_set_arc_color_filtered(lv_style_t * style, lv_color_t value) {
|
||||||
|
lv_style_value_t v = {.color = value}; lv_style_set_prop(style, LV_STYLE_ARC_COLOR_FILTERED, v); }
|
||||||
|
|
||||||
|
static inline void lv_style_set_arc_opa(lv_style_t * style, lv_opa_t value) {
|
||||||
|
lv_style_value_t v = {.num = value}; lv_style_set_prop(style, LV_STYLE_ARC_OPA, v); }
|
||||||
|
|
||||||
|
static inline void lv_style_set_arc_img_src(lv_style_t * style, const void * value) {
|
||||||
|
lv_style_value_t v = {.ptr = value}; lv_style_set_prop(style, LV_STYLE_ARC_IMG_SRC, v); }
|
||||||
|
|
||||||
static inline void lv_style_set_content_text(lv_style_t * style, const char * value) {
|
static inline void lv_style_set_content_text(lv_style_t * style, const char * value) {
|
||||||
lv_style_value_t v = {.ptr = value}; lv_style_set_prop(style, LV_STYLE_CONTENT_TEXT, v); }
|
lv_style_value_t v = {.ptr = value}; lv_style_set_prop(style, LV_STYLE_CONTENT_TEXT, v); }
|
||||||
|
|
||||||
|
@ -163,8 +163,8 @@ void lv_arc_set_angles(lv_obj_t * obj, uint16_t start, uint16_t end)
|
|||||||
|
|
||||||
inv_arc_area(obj,arc->indic_angle_start,arc->indic_angle_end, LV_PART_INDICATOR);
|
inv_arc_area(obj,arc->indic_angle_start,arc->indic_angle_end, LV_PART_INDICATOR);
|
||||||
|
|
||||||
arc->indic_angle_start = start;
|
arc->indic_angle_start = start;
|
||||||
arc->indic_angle_end = end;
|
arc->indic_angle_end = end;
|
||||||
|
|
||||||
inv_arc_area(obj,arc->indic_angle_start,arc->indic_angle_end, LV_PART_INDICATOR);
|
inv_arc_area(obj,arc->indic_angle_start,arc->indic_angle_end, LV_PART_INDICATOR);
|
||||||
}
|
}
|
||||||
@ -375,25 +375,6 @@ void lv_arc_set_chg_rate(lv_obj_t * obj, uint16_t rate)
|
|||||||
arc->chg_rate = rate;
|
arc->chg_rate = rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set whether the arc is adjustable.
|
|
||||||
* @param arc pointer to a arc object
|
|
||||||
* @param adjustable whether the arc has a knob that can be dragged
|
|
||||||
*/
|
|
||||||
void lv_arc_set_adjustable(lv_obj_t * obj, bool adjustable)
|
|
||||||
{
|
|
||||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
|
||||||
lv_arc_t * arc = (lv_arc_t *)obj;
|
|
||||||
|
|
||||||
if(arc->adjustable == adjustable)
|
|
||||||
return;
|
|
||||||
|
|
||||||
arc->adjustable = adjustable;
|
|
||||||
if(!adjustable)
|
|
||||||
arc->dragging = false;
|
|
||||||
lv_obj_invalidate(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*=====================
|
/*=====================
|
||||||
* Getter functions
|
* Getter functions
|
||||||
*====================*/
|
*====================*/
|
||||||
@ -487,17 +468,6 @@ lv_arc_type_t lv_arc_get_type(const lv_obj_t * obj)
|
|||||||
return ((lv_arc_t*) obj)->type;
|
return ((lv_arc_t*) obj)->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get whether the arc is adjustable.
|
|
||||||
* @param arc pointer to a arc object
|
|
||||||
* @return whether the arc has a knob that can be dragged
|
|
||||||
*/
|
|
||||||
bool lv_arc_get_adjustable(lv_obj_t * obj)
|
|
||||||
{
|
|
||||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
|
||||||
return ((lv_arc_t*) obj)->adjustable;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*=====================
|
/*=====================
|
||||||
* Other functions
|
* Other functions
|
||||||
*====================*/
|
*====================*/
|
||||||
@ -533,7 +503,6 @@ static void lv_arc_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t
|
|||||||
arc->min_value = 0;
|
arc->min_value = 0;
|
||||||
arc->max_value = 100;
|
arc->max_value = 100;
|
||||||
arc->dragging = false;
|
arc->dragging = false;
|
||||||
arc->adjustable = false;
|
|
||||||
arc->chg_rate = 540;
|
arc->chg_rate = 540;
|
||||||
arc->last_tick = lv_tick_get();
|
arc->last_tick = lv_tick_get();
|
||||||
arc->last_angle =arc->indic_angle_end;
|
arc->last_angle =arc->indic_angle_end;
|
||||||
@ -558,7 +527,6 @@ static void lv_arc_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t
|
|||||||
arc->min_value = copy_arc->min_value;
|
arc->min_value = copy_arc->min_value;
|
||||||
arc->max_value = copy_arc->max_value;
|
arc->max_value = copy_arc->max_value;
|
||||||
arc->dragging = copy_arc->dragging;
|
arc->dragging = copy_arc->dragging;
|
||||||
arc->adjustable = copy_arc->adjustable;
|
|
||||||
arc->chg_rate = copy_arc->chg_rate;
|
arc->chg_rate = copy_arc->chg_rate;
|
||||||
arc->last_tick = copy_arc->last_tick;
|
arc->last_tick = copy_arc->last_tick;
|
||||||
arc->last_angle = copy_arc->last_angle;
|
arc->last_angle = copy_arc->last_angle;
|
||||||
@ -580,16 +548,6 @@ static void lv_arc_destructor(lv_obj_t * obj)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle the drawing related tasks of the arcs
|
|
||||||
* @param arc pointer to an object
|
|
||||||
* @param clip_area the object will be drawn only in this area
|
|
||||||
* @param mode LV_DRAW_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
|
||||||
* (return 'true' if yes)
|
|
||||||
* LV_DRAW_DRAW: draw the object (always return 'true')
|
|
||||||
* LV_DRAW_DRAW_POST: drawing after every children are drawn
|
|
||||||
* @param return an element of `lv_draw_res_t`
|
|
||||||
*/
|
|
||||||
static lv_draw_res_t lv_arc_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode)
|
static lv_draw_res_t lv_arc_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode)
|
||||||
{
|
{
|
||||||
/*Return false if the object is not covers the mask_p area*/
|
/*Return false if the object is not covers the mask_p area*/
|
||||||
@ -633,16 +591,14 @@ static lv_draw_res_t lv_arc_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv
|
|||||||
&arc_dsc);
|
&arc_dsc);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(arc->adjustable) {
|
lv_area_t knob_area;
|
||||||
lv_area_t knob_area;
|
get_knob_area(obj, ¢er, arc_r, &knob_area);
|
||||||
get_knob_area(obj, ¢er, arc_r, &knob_area);
|
|
||||||
|
|
||||||
lv_draw_rect_dsc_t knob_rect_dsc;
|
lv_draw_rect_dsc_t knob_rect_dsc;
|
||||||
lv_draw_rect_dsc_init(&knob_rect_dsc);
|
lv_draw_rect_dsc_init(&knob_rect_dsc);
|
||||||
lv_obj_init_draw_rect_dsc(obj, LV_PART_KNOB, &knob_rect_dsc);
|
lv_obj_init_draw_rect_dsc(obj, LV_PART_KNOB, &knob_rect_dsc);
|
||||||
|
|
||||||
lv_draw_rect(&knob_area, clip_area, &knob_rect_dsc);
|
lv_draw_rect(&knob_area, clip_area, &knob_rect_dsc);
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
/*Post draw when the children are drawn*/
|
/*Post draw when the children are drawn*/
|
||||||
@ -653,13 +609,6 @@ static lv_draw_res_t lv_arc_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv
|
|||||||
return LV_DRAW_RES_OK;
|
return LV_DRAW_RES_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Signal function of the arc
|
|
||||||
* @param arc pointer to a arc object
|
|
||||||
* @param sign a signal type from lv_signal_t enum
|
|
||||||
* @param param pointer to a signal specific variable
|
|
||||||
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
|
|
||||||
*/
|
|
||||||
static lv_res_t lv_arc_signal(lv_obj_t * obj, lv_signal_t sign, void * param)
|
static lv_res_t lv_arc_signal(lv_obj_t * obj, lv_signal_t sign, void * param)
|
||||||
{
|
{
|
||||||
lv_res_t res;
|
lv_res_t res;
|
||||||
@ -670,9 +619,6 @@ static lv_res_t lv_arc_signal(lv_obj_t * obj, lv_signal_t sign, void * param)
|
|||||||
|
|
||||||
lv_arc_t * arc = (lv_arc_t *)obj;
|
lv_arc_t * arc = (lv_arc_t *)obj;
|
||||||
if(sign == LV_SIGNAL_PRESSING) {
|
if(sign == LV_SIGNAL_PRESSING) {
|
||||||
/* Only adjustable arcs can be dragged */
|
|
||||||
if(!arc->adjustable) return res;
|
|
||||||
|
|
||||||
lv_indev_t * indev = lv_indev_get_act();
|
lv_indev_t * indev = lv_indev_get_act();
|
||||||
if(indev == NULL) return res;
|
if(indev == NULL) return res;
|
||||||
|
|
||||||
@ -693,7 +639,7 @@ static lv_res_t lv_arc_signal(lv_obj_t * obj, lv_signal_t sign, void * param)
|
|||||||
|
|
||||||
/*Enter dragging mode if pressed out of the knob*/
|
/*Enter dragging mode if pressed out of the knob*/
|
||||||
if(arc->dragging == false) {
|
if(arc->dragging == false) {
|
||||||
lv_coord_t indic_width = lv_obj_get_style_line_width(obj, LV_PART_INDICATOR);
|
lv_coord_t indic_width = lv_obj_get_style_arc_width(obj, LV_PART_INDICATOR);
|
||||||
r -= indic_width;
|
r -= indic_width;
|
||||||
r -= r / 2; /*Add some more sensitive area*/
|
r -= r / 2; /*Add some more sensitive area*/
|
||||||
if(p.x * p.x + p.y * p.y > r * r) {
|
if(p.x * p.x + p.y * p.y > r * r) {
|
||||||
@ -789,8 +735,6 @@ static lv_res_t lv_arc_signal(lv_obj_t * obj, lv_signal_t sign, void * param)
|
|||||||
|
|
||||||
}
|
}
|
||||||
else if(sign == LV_SIGNAL_CONTROL) {
|
else if(sign == LV_SIGNAL_CONTROL) {
|
||||||
if(!arc->adjustable) return res;
|
|
||||||
|
|
||||||
char c = *((char *)param);
|
char c = *((char *)param);
|
||||||
|
|
||||||
int16_t old_value =arc->value;
|
int16_t old_value =arc->value;
|
||||||
@ -834,8 +778,8 @@ static void inv_arc_area(lv_obj_t * obj, uint16_t start_angle, uint16_t end_angl
|
|||||||
lv_coord_t rout = (LV_MIN(lv_obj_get_width(obj) - left - right, lv_obj_get_height(obj) - top - bottom)) / 2;
|
lv_coord_t rout = (LV_MIN(lv_obj_get_width(obj) - left - right, lv_obj_get_height(obj) - top - bottom)) / 2;
|
||||||
lv_coord_t x = obj->coords.x1 + rout + left;
|
lv_coord_t x = obj->coords.x1 + rout + left;
|
||||||
lv_coord_t y = obj->coords.y1 + rout + top;
|
lv_coord_t y = obj->coords.y1 + rout + top;
|
||||||
lv_coord_t w = lv_obj_get_style_line_width(obj, part);
|
lv_coord_t w = lv_obj_get_style_arc_width(obj, part);
|
||||||
lv_coord_t rounded = lv_obj_get_style_line_rounded(obj, part);
|
lv_coord_t rounded = lv_obj_get_style_arc_rounded(obj, part);
|
||||||
lv_coord_t rin = rout - w;
|
lv_coord_t rin = rout - w;
|
||||||
lv_coord_t extra_area = 0;
|
lv_coord_t extra_area = 0;
|
||||||
|
|
||||||
@ -852,7 +796,6 @@ static void inv_arc_area(lv_obj_t * obj, uint16_t start_angle, uint16_t end_angl
|
|||||||
knob_extra_size += LV_MAX4(knob_left, knob_right, knob_top, knob_bottom);
|
knob_extra_size += LV_MAX4(knob_left, knob_right, knob_top, knob_bottom);
|
||||||
|
|
||||||
extra_area = LV_MAX(extra_area, w / 2 + 2 + knob_extra_size);
|
extra_area = LV_MAX(extra_area, w / 2 + 2 + knob_extra_size);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lv_area_t inv_area;
|
lv_area_t inv_area;
|
||||||
@ -949,7 +892,7 @@ static void get_center(lv_obj_t * obj, lv_point_t * center, lv_coord_t * arc_r)
|
|||||||
center->x = obj->coords.x1 + r + left_bg;
|
center->x = obj->coords.x1 + r + left_bg;
|
||||||
center->y = obj->coords.y1 + r + top_bg;
|
center->y = obj->coords.y1 + r + top_bg;
|
||||||
|
|
||||||
lv_coord_t indic_width = lv_obj_get_style_line_width(obj, LV_PART_INDICATOR);
|
lv_coord_t indic_width = lv_obj_get_style_arc_width(obj, LV_PART_INDICATOR);
|
||||||
r -= indic_width;
|
r -= indic_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -958,7 +901,7 @@ static void get_knob_area(lv_obj_t * obj, const lv_point_t * center, lv_coord_t
|
|||||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||||
lv_arc_t * arc = (lv_arc_t *)obj;
|
lv_arc_t * arc = (lv_arc_t *)obj;
|
||||||
|
|
||||||
lv_coord_t indic_width = lv_obj_get_style_line_width(obj, LV_PART_INDICATOR);
|
lv_coord_t indic_width = lv_obj_get_style_arc_width(obj, LV_PART_INDICATOR);
|
||||||
lv_coord_t indic_width_half = indic_width / 2;
|
lv_coord_t indic_width_half = indic_width / 2;
|
||||||
r -= indic_width_half;
|
r -= indic_width_half;
|
||||||
|
|
||||||
|
@ -46,7 +46,6 @@ typedef struct {
|
|||||||
int16_t max_value; /*Maximum value of the arc*/
|
int16_t max_value; /*Maximum value of the arc*/
|
||||||
uint16_t dragging : 1;
|
uint16_t dragging : 1;
|
||||||
uint16_t type : 2;
|
uint16_t type : 2;
|
||||||
uint16_t adjustable : 1;
|
|
||||||
uint16_t min_close : 1; /*1: the last pressed angle was closer to minimum end*/
|
uint16_t min_close : 1; /*1: the last pressed angle was closer to minimum end*/
|
||||||
uint16_t chg_rate; /*Drag angle rate of change of the arc (degrees/sec)*/
|
uint16_t chg_rate; /*Drag angle rate of change of the arc (degrees/sec)*/
|
||||||
uint32_t last_tick; /*Last dragging event timestamp of the arc*/
|
uint32_t last_tick; /*Last dragging event timestamp of the arc*/
|
||||||
|
@ -528,10 +528,11 @@ static lv_draw_res_t lv_btnmatrix_draw(lv_obj_t * obj, const lv_area_t * clip_ar
|
|||||||
hook_dsc.id = btn_i;
|
hook_dsc.id = btn_i;
|
||||||
lv_event_send(obj,LV_EVENT_DRAW_PART_BEGIN, &hook_dsc);
|
lv_event_send(obj,LV_EVENT_DRAW_PART_BEGIN, &hook_dsc);
|
||||||
|
|
||||||
/*Remove borders on the edges if `LV_BORDER_SIDE_INTERNAL`*/
|
// /*Remove borders on the edges if `LV_BORDER_SIDE_INTERNAL`*/
|
||||||
if(draw_rect_dsc_act.border_side & LV_BORDER_SIDE_INTERNAL) {
|
if(draw_rect_dsc_act.border_side & LV_BORDER_SIDE_INTERNAL) {
|
||||||
|
draw_rect_dsc_act.border_side = LV_BORDER_SIDE_FULL;
|
||||||
if(btn_area.x1 == obj->coords.x1 + pleft) draw_rect_dsc_act.border_side &= ~LV_BORDER_SIDE_LEFT;
|
if(btn_area.x1 == obj->coords.x1 + pleft) draw_rect_dsc_act.border_side &= ~LV_BORDER_SIDE_LEFT;
|
||||||
if(btn_area.y2 == obj->coords.x2 - pright) draw_rect_dsc_act.border_side &= ~LV_BORDER_SIDE_RIGHT;
|
if(btn_area.x2 == obj->coords.x2 - pright) draw_rect_dsc_act.border_side &= ~LV_BORDER_SIDE_RIGHT;
|
||||||
if(btn_area.y1 == obj->coords.y1 + ptop) draw_rect_dsc_act.border_side &= ~LV_BORDER_SIDE_TOP;
|
if(btn_area.y1 == obj->coords.y1 + ptop) draw_rect_dsc_act.border_side &= ~LV_BORDER_SIDE_TOP;
|
||||||
if(btn_area.y2 == obj->coords.y2 - pbottom) draw_rect_dsc_act.border_side &= ~LV_BORDER_SIDE_BOTTOM;
|
if(btn_area.y2 == obj->coords.y2 - pbottom) draw_rect_dsc_act.border_side &= ~LV_BORDER_SIDE_BOTTOM;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user