1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

add table and btnmatrix

This commit is contained in:
Gabor Kiss-Vamosi 2021-01-05 13:01:07 +01:00
parent 9c55d77617
commit a42d3942c6
19 changed files with 931 additions and 1204 deletions

View File

@ -221,7 +221,7 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy)
return lv_obj_create_from_class(&lv_obj, parent, copy);
}
lv_obj_t * lv_obj_create_from_class(lv_obj_class_t * class, lv_obj_t * parent, const lv_obj_t * copy)
lv_obj_t * lv_obj_create_from_class(const lv_obj_class_t * class, lv_obj_t * parent, const lv_obj_t * copy)
{
lv_obj_t * obj = lv_mem_alloc(sizeof(lv_obj_t));
_lv_memset_00(obj, sizeof(lv_obj_t));
@ -1301,7 +1301,7 @@ lv_obj_t * _lv_obj_get_focused_obj(const lv_obj_t * obj)
* @param obj pointer to an object which type should be get
* @param buf pointer to an `lv_obj_type_t` buffer to store the types
*/
bool lv_obj_check_type(const lv_obj_t * obj, void * class_p)
bool lv_obj_check_type(const lv_obj_t * obj, const void * class_p)
{
return obj->class_p == class_p ? true : false;
}

View File

@ -162,6 +162,7 @@ enum {
LV_STATE_PRESSED = 0x10,
LV_STATE_SCROLLED = 0x20,
LV_STATE_DISABLED = 0x40,
LV_STATE_USER = 0x80, /** Free to use by the user */
};
typedef uint8_t lv_state_t;
@ -176,15 +177,27 @@ enum {
LV_OBJ_FLAG_SCROLL_MOMENTUM = (1 << 6),
LV_OBJ_FLAG_SCROLL_STOP = (1 << 7),
LV_OBJ_FLAG_SCROLL_CHAIN = (1 << 8), /** Allow propagating the scroll to a parent */
LV_OBJ_FLAG_SNAPABLE = (1 << 9),
LV_OBJ_FLAG_PRESS_LOCK = (1 << 10),
LV_OBJ_FLAG_EVENT_BUBBLE = (1 << 11),
LV_OBJ_FLAG_GESTURE_BUBBLE = (1 << 12),
LV_OBJ_FLAG_FOCUS_BUBBLE = (1 << 13),
LV_OBJ_FLAG_SCROLL_ON_FOCUS = (1 << 14), /** Automatically scroll the focused object's ancestors to make the focused object visible*/
LV_OBJ_FLAG_SCROLL_ON_FOCUS = (1 << 9), /** Automatically scroll the focused object's ancestors to make the focused object visible*/
LV_OBJ_FLAG_SNAPABLE = (1 << 10),
LV_OBJ_FLAG_PRESS_LOCK = (1 << 11),
LV_OBJ_FLAG_EVENT_BUBBLE = (1 << 12),
LV_OBJ_FLAG_GESTURE_BUBBLE = (1 << 13),
LV_OBJ_FLAG_FOCUS_BUBBLE = (1 << 14),
LV_OBJ_FLAG_ADV_HITTEST = (1 << 15),
LV_OBJ_FLAG_LAYOUT_1 = (1 << 16), /** Custom flag, free to use by layouts*/
LV_OBJ_FLAG_LAYOUT_2 = (1 << 17), /** Custom flag, free to use by layouts*/
LV_OBJ_FLAG_LAYOUT_3 = (1 << 18), /** Custom flag, free to use by layouts*/
LV_OBJ_FLAG_LAYOUT_4 = (1 << 19), /** Custom flag, free to use by layouts*/
LV_OBJ_FLAG_WIDGET_1 = (1 << 20), /** Custom flag, free to use by widget*/
LV_OBJ_FLAG_WIDGET_2 = (1 << 21), /** Custom flag, free to use by widget*/
LV_OBJ_FLAG_WIDGET_3 = (1 << 22), /** Custom flag, free to use by widget*/
LV_OBJ_FLAG_WIDGET_4 = (1 << 23), /** Custom flag, free to use by widget*/
LV_OBJ_FLAG_USER_1 = (1 << 24), /** Custom flag, free to use by user*/
LV_OBJ_FLAG_USER_2 = (1 << 25), /** Custom flag, free to use by user*/
LV_OBJ_FLAG_USER_3 = (1 << 26), /** Custom flag, free to use by user*/
LV_OBJ_FLAG_USER_4 = (1 << 27), /** Custom flag, free to use by user*/
};
typedef uint16_t lv_obj_flag_t;
typedef uint32_t lv_obj_flag_t;
#include "lv_obj_pos.h"
@ -253,10 +266,27 @@ enum {
LV_PART_CONTENT,
LV_PART_INDICATOR,
LV_PART_KNOB,
LV_PART_HIGHLIGHT,
LV_PART_PLACEHOLDER,
LV_PART_CURSOR,
LV_PART_HIGHLIGHT,
LV_PART_MARKER,
LV_PART_ITEM,
LV_PART_CUSTOM_1,
LV_PART_CUSTOM_2,
LV_PART_CUSTOM_3,
LV_PART_CUSTOM_4,
LV_PART_CUSTOM_5,
LV_PART_CUSTOM_6,
LV_PART_CUSTOM_7,
LV_PART_CUSTOM_8,
LV_PART_CUSTOM_9,
LV_PART_CUSTOM_10,
LV_PART_CUSTOM_11,
LV_PART_CUSTOM_12,
LV_PART_CUSTOM_13,
LV_PART_CUSTOM_14,
LV_PART_CUSTOM_15,
LV_PART_CUSTOM_16,
};
typedef uint8_t lv_part_t;
@ -301,7 +331,7 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy);
void lv_obj_create_finish(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy);
lv_obj_t * lv_obj_create_from_class(lv_obj_class_t * class, lv_obj_t * parent, const lv_obj_t * copy);
lv_obj_t * lv_obj_create_from_class(const lv_obj_class_t * class, lv_obj_t * parent, const lv_obj_t * copy);
/**
* Delete 'obj' and all of its children
@ -683,7 +713,7 @@ bool lv_obj_hit_test(lv_obj_t * obj, lv_point_t * point);
*/
void * lv_obj_get_ext_attr(const lv_obj_t * obj);
bool lv_obj_check_type(const lv_obj_t * obj, void * class_p);
bool lv_obj_check_type(const lv_obj_t * obj, const void * class_p);
#if LV_USE_USER_DATA
/**

View File

@ -124,6 +124,9 @@ void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h)
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);
obj->w_set = w;
obj->h_set = h;
/*Calculate the required auto sizes*/
bool x_auto = obj->w_set == LV_SIZE_AUTO ? true : false;
bool y_auto = obj->h_set == LV_SIZE_AUTO ? true : false;

View File

@ -646,7 +646,7 @@ static inline void lv_style_set_pad_all(lv_style_t * style, lv_coord_t value)
lv_style_set_pad_right(style, value);
}
//static inline void lv_style_set_pad_ver(lv_style_t * style, lv_style_int_t value)
//static inline void lv_style_set_pad_ver(lv_style_t * style, lv_coord_t value)
//{
// lv_style_set_pad_top(style, state, value);
// lv_style_set_pad_bottom(style, state, value);
@ -654,7 +654,7 @@ static inline void lv_style_set_pad_all(lv_style_t * style, lv_coord_t value)
//
//static inline void lv_obj_set_style_margin_all(lv_obj_t * obj, uint8_t part, lv_state_t state,
// lv_style_int_t value)
// lv_coord_t value)
//{
// lv_obj_set_style_local_margin_top(obj, part, state, value);
// lv_obj_set_style_local_margin_bottom(obj, part, state, value);
@ -663,7 +663,7 @@ static inline void lv_style_set_pad_all(lv_style_t * style, lv_coord_t value)
//}
//
//
//static inline void lv_style_set_margin_all(lv_style_t * style, lv_state_t state, lv_style_int_t value)
//static inline void lv_style_set_margin_all(lv_style_t * style, lv_state_t state, lv_coord_t value)
//{
// lv_style_set_margin_top(style, state, value);
// lv_style_set_margin_bottom(style, state, value);
@ -673,14 +673,14 @@ static inline void lv_style_set_pad_all(lv_style_t * style, lv_coord_t value)
//
//
//static inline void lv_obj_set_style_local_margin_hor(lv_obj_t * obj, uint8_t part, lv_state_t state,
// lv_style_int_t value)
// lv_coord_t value)
//{
// lv_obj_set_style_local_margin_left(obj, part, state, value);
// lv_obj_set_style_local_margin_right(obj, part, state, value);
//}
//
//
//static inline void lv_style_set_margin_hor(lv_style_t * style, lv_state_t state, lv_style_int_t value)
//static inline void lv_style_set_margin_hor(lv_style_t * style, lv_state_t state, lv_coord_t value)
//{
// lv_style_set_margin_left(style, state, value);
// lv_style_set_margin_right(style, state, value);
@ -688,14 +688,14 @@ static inline void lv_style_set_pad_all(lv_style_t * style, lv_coord_t value)
//
//
//static inline void lv_obj_set_style_local_margin_ver(lv_obj_t * obj, uint8_t part, lv_state_t state,
// lv_style_int_t value)
// lv_coord_t value)
//{
// lv_obj_set_style_local_margin_top(obj, part, state, value);
// lv_obj_set_style_local_margin_bottom(obj, part, state, value);
//}
//
//
//static inline void lv_style_set_margin_ver(lv_style_t * style, lv_state_t state, lv_style_int_t value)
//static inline void lv_style_set_margin_ver(lv_style_t * style, lv_state_t state, lv_coord_t value)
//{
// lv_style_set_margin_top(style, state, value);
// lv_style_set_margin_bottom(style, state, value);

View File

@ -61,7 +61,7 @@
#define COLOR_BG_TEXT_DIS (IS_LIGHT ? lv_color_hex3(0xaaa) : lv_color_hex3(0x999))
/*SECONDARY BACKGROUND*/
#define COLOR_GRAY (IS_LIGHT ? lv_color_hex(0xd4d7d9) : lv_color_hex(0x45494d))
#define COLOR_GRAY (IS_LIGHT ? lv_color_hex(0xd4d7d9) : lv_color_hex(0x45494d))
#define COLOR_BG_SEC_BORDER (IS_LIGHT ? lv_color_hex(0xdfe7ed) : lv_color_hex(0x404040))
#define COLOR_BG_SEC_TEXT (IS_LIGHT ? lv_color_hex(0x31404f) : lv_color_hex(0xa5a8ad))
#define COLOR_BG_SEC_TEXT_DIS (IS_LIGHT ? lv_color_hex(0xaaaaaa) : lv_color_hex(0xa5a8ad))
@ -82,18 +82,17 @@ typedef struct {
lv_style_t scrollbar_scrolled;
lv_style_t card;
lv_style_t btn;
lv_style_t btn_disabled;
lv_style_t btn_color;
lv_style_t btn_color_checked;
/*Utility*/
lv_style_t bg_color_primary;
lv_style_t bg_color_secondary;
lv_style_t bg_color_gray;
lv_style_t bg_color_white;
lv_style_t pressed;
lv_style_t disabled;
lv_style_t pad_zero;
lv_style_t pad_small;
lv_style_t pad_gap;
lv_style_t pad_small_negative;
lv_style_t focus_border;
lv_style_t focus_outline;
@ -253,22 +252,12 @@ static void basic_init(void)
style_init_reset(&styles->btn);
lv_style_set_radius(&styles->btn, RADIUS_DEFAULT);
lv_style_set_bg_opa(&styles->btn, LV_OPA_COVER);
lv_style_set_bg_color(&styles->btn, CARD_COLOR);
lv_style_set_border_color(&styles->btn, CARD_BORDER_COLOR);
lv_style_set_border_width(&styles->btn, BORDER_WIDTH);
lv_style_set_bg_color(&styles->btn, COLOR_GRAY);
lv_style_set_text_color(&styles->btn, CARD_TEXT_COLOR);
lv_style_set_pad_hor(&styles->btn, LV_DPX(40));
lv_style_set_pad_ver(&styles->btn, LV_DPX(15));
style_init_reset(&styles->btn_color);
lv_style_set_border_width(&styles->btn_color, 0);
lv_style_set_bg_color(&styles->btn_color, BTN_COLOR);
lv_style_set_text_color(&styles->btn_color, LV_COLOR_WHITE);
style_init_reset(&styles->btn_color_checked);
lv_style_set_bg_color(&styles->btn_color_checked, BTN_CHK_PR_COLOR);
style_init_reset(&styles->pressed);
lv_style_set_color_filter_cb(&styles->pressed, lv_color_darken);
lv_style_set_color_filter_opa(&styles->pressed, LV_OPA_20);
@ -281,8 +270,11 @@ static void basic_init(void)
lv_style_set_clip_corner(&styles->clip_corner, true);
style_init_reset(&styles->pad_small);
lv_coord_t pad_small_value = LV_DPX(10);
lv_style_set_pad_all(&styles->pad_small, pad_small_value);
lv_style_set_pad_all(&styles->pad_small, LV_DPX(10));
style_init_reset(&styles->pad_gap);
lv_style_set_pad_row(&styles->pad_gap, LV_DPX(10));
lv_style_set_pad_column(&styles->pad_gap, LV_DPX(10));
style_init_reset(&styles->pad_small_negative);
lv_style_set_pad_all(&styles->pad_small_negative, - LV_DPX(4));
@ -295,6 +287,11 @@ static void basic_init(void)
lv_style_set_text_color(&styles->bg_color_primary, LV_COLOR_WHITE);
lv_style_set_bg_opa(&styles->bg_color_primary, LV_OPA_COVER);
style_init_reset(&styles->bg_color_secondary);
lv_style_set_bg_color(&styles->bg_color_primary, theme.color_secondary);
lv_style_set_text_color(&styles->bg_color_primary, LV_COLOR_WHITE);
lv_style_set_bg_opa(&styles->bg_color_primary, LV_OPA_COVER);
style_init_reset(&styles->bg_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);
@ -350,14 +347,6 @@ static void basic_init(void)
}
static void btnmatrix_init(void)
{
#if LV_USE_BTNMATRIX != 0
style_init_reset(&styles->btnmatrix_btn);
lv_style_set_margin_all(&styles->btnmatrix_btn, LV_STATE_DEFAULT, LV_DPX(10));
#endif
}
static void line_init(void)
@ -501,20 +490,20 @@ static void textarea_init(void)
//}
static void table_init(void)
{
#if LV_USE_TABLE != 0
style_init_reset(&styles->table_cell);
lv_style_set_border_color(&styles->table_cell, LV_STATE_DEFAULT, CARD_BORDER_COLOR);
lv_style_set_border_width(&styles->table_cell, LV_STATE_DEFAULT, 1);
lv_style_set_border_side(&styles->table_cell, LV_STATE_DEFAULT, LV_BORDER_SIDE_TOP | LV_BORDER_SIDE_BOTTOM);
lv_style_set_pad_left(&styles->table_cell, LV_STATE_DEFAULT, PAD_DEF);
lv_style_set_pad_right(&styles->table_cell, LV_STATE_DEFAULT, PAD_DEF);
lv_style_set_pad_top(&styles->table_cell, LV_STATE_DEFAULT, PAD_DEF);
lv_style_set_pad_bottom(&styles->table_cell, LV_STATE_DEFAULT, PAD_DEF);
#endif
}
//static void table_init(void)
//{
//#if LV_USE_TABLE != 0
// style_init_reset(&styles->table_cell);
// lv_style_set_border_color(&styles->table_cell, LV_STATE_DEFAULT, CARD_BORDER_COLOR);
// lv_style_set_border_width(&styles->table_cell, LV_STATE_DEFAULT, 1);
// lv_style_set_border_side(&styles->table_cell, LV_STATE_DEFAULT, LV_BORDER_SIDE_TOP | LV_BORDER_SIDE_BOTTOM);
// lv_style_set_pad_left(&styles->table_cell, LV_STATE_DEFAULT, PAD_DEF);
// lv_style_set_pad_right(&styles->table_cell, LV_STATE_DEFAULT, PAD_DEF);
// lv_style_set_pad_top(&styles->table_cell, LV_STATE_DEFAULT, PAD_DEF);
// lv_style_set_pad_bottom(&styles->table_cell, LV_STATE_DEFAULT, PAD_DEF);
//
//#endif
//}
/**********************
@ -554,7 +543,6 @@ lv_theme_t * lv_theme_default_init(lv_color_t color_primary, lv_color_t color_se
theme.flags = flags;
basic_init();
btnmatrix_init();
line_init();
linemeter_init();
gauge_init();
@ -562,7 +550,6 @@ lv_theme_t * lv_theme_default_init(lv_color_t color_primary, lv_color_t color_se
spinner_init();
chart_init();
textarea_init();
table_init();
theme.apply_cb = theme_apply;
@ -593,15 +580,26 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
#if LV_USE_BTN
else if(lv_obj_check_type(obj, &lv_btn)) {
lv_obj_add_style_no_refresh(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->btn);
lv_obj_add_style_no_refresh(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->btn_color);
lv_obj_add_style_no_refresh(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->bg_color_primary);
lv_obj_add_style_no_refresh(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->transition_delayed);
lv_obj_add_style_no_refresh(obj, LV_PART_MAIN, LV_STATE_PRESSED, &styles->pressed);
lv_obj_add_style_no_refresh(obj, LV_PART_MAIN, LV_STATE_PRESSED, &styles->transition_normal);
lv_obj_add_style_no_refresh(obj, LV_PART_MAIN, LV_STATE_PRESSED, &styles->grow);
lv_obj_add_style_no_refresh(obj, LV_PART_MAIN, LV_STATE_CHECKED, &styles->btn_color_checked);
lv_obj_add_style_no_refresh(obj, LV_PART_MAIN, LV_STATE_CHECKED, &styles->bg_color_secondary);
}
#endif
#if LV_USE_BTNMATRIX
else if(lv_obj_check_type(obj, &lv_btnmatrix)) {
lv_obj_add_style_no_refresh(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->card);
lv_obj_add_style_no_refresh(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->pad_gap);
lv_obj_add_style_no_refresh(obj, LV_PART_ITEM, LV_STATE_DEFAULT, &styles->btn);
lv_obj_add_style_no_refresh(obj, LV_PART_ITEM, LV_STATE_PRESSED, &styles->pressed);
lv_obj_add_style_no_refresh(obj, LV_PART_ITEM, LV_STATE_PRESSED, &styles->grow);
lv_obj_add_style_no_refresh(obj, LV_PART_ITEM, LV_STATE_DEFAULT, &styles->transition_delayed);
lv_obj_add_style_no_refresh(obj, LV_PART_ITEM, LV_STATE_PRESSED, &styles->transition_normal);
}
#endif
#if LV_USE_BAR
else if(lv_obj_check_type(obj, &lv_bar)) {
lv_obj_add_style_no_refresh(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->bg_color_gray);
@ -626,6 +624,15 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
}
#endif
#if LV_USE_TABLE
else if(lv_obj_check_type(obj, &lv_table)) {
lv_obj_add_style_no_refresh(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->card);
lv_obj_add_style_no_refresh(obj, LV_PART_SCROLLBAR, LV_STATE_DEFAULT, &styles->scrollbar);
lv_obj_add_style_no_refresh(obj, LV_PART_SCROLLBAR, LV_STATE_SCROLLED, &styles->scrollbar_scrolled);
lv_obj_add_style_no_refresh(obj, LV_PART_ITEM, LV_STATE_DEFAULT, &styles->card);
}
#endif
#if LV_USE_CHECKBOX
else if(lv_obj_check_type(obj, &lv_checkbox)) {
lv_obj_add_style_no_refresh(obj, LV_PART_MARKER, LV_STATE_DEFAULT, &styles->cb_marker);
@ -682,23 +689,23 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
}
#endif
#if LV_USE_BTNMATRIX
case LV_THEME_BTNMATRIX:
list = _lv_obj_get_style_list(obj, LV_BTNMATRIX_PART_MAIN);
_lv_style_list_add_style(list, &styles->card);
_lv_style_list_add_style(list, &styles->pad_small);
list = _lv_obj_get_style_list(obj, LV_BTNMATRIX_PART_BTN);
_lv_style_list_add_style(list, &styles->card);
_lv_style_list_add_style(list, &styles->bg_click);
_lv_style_list_add_style(list, &styles->btnmatrix_btn);
list = _lv_obj_get_style_list(obj, LV_BTNMATRIX_PART_BTN_2);
_lv_style_list_add_style(list, &styles->card);
_lv_style_list_add_style(list, &styles->bg_click);
_lv_style_list_add_style(list, &styles->btnmatrix_btn);
break;
#endif
//#if LV_USE_BTNMATRIX
//case LV_THEME_BTNMATRIX:
// list = _lv_obj_get_style_list(obj, LV_BTNMATRIX_PART_MAIN);
// _lv_style_list_add_style(list, &styles->card);
// _lv_style_list_add_style(list, &styles->pad_small);
//
// list = _lv_obj_get_style_list(obj, LV_BTNMATRIX_PART_BTN);
// _lv_style_list_add_style(list, &styles->card);
// _lv_style_list_add_style(list, &styles->bg_click);
// _lv_style_list_add_style(list, &styles->btnmatrix_btn);
//
// list = _lv_obj_get_style_list(obj, LV_BTNMATRIX_PART_BTN_2);
// _lv_style_list_add_style(list, &styles->card);
// _lv_style_list_add_style(list, &styles->bg_click);
// _lv_style_list_add_style(list, &styles->btnmatrix_btn);
// break;
//#endif
#if LV_USE_IMG
case LV_THEME_IMAGE:
@ -773,22 +780,6 @@ case LV_THEME_OBJMASK:
// _lv_style_list_add_style(list, &styles->chart_series);
// break;
//#endif
#if LV_USE_TABLE
case LV_THEME_TABLE: {
list = _lv_obj_get_style_list(obj, LV_TABLE_PART_BG);
_lv_style_list_add_style(list, &styles->card);
int idx = 1; /* start value should be 1, not zero, since cell styles
start at 1 due to presence of LV_TABLE_PART_BG=0
in the enum (lv_table.h) */
/* declaring idx outside loop to work with older compilers */
for(; idx <= LV_TABLE_CELL_STYLE_CNT; idx ++) {
list = _lv_obj_get_style_list(obj, idx);
_lv_style_list_add_style(list, &styles->table_cell);
}
break;
}
#endif
#if LV_USE_TEXTAREA
case LV_THEME_TEXTAREA:

View File

@ -817,8 +817,8 @@ static void inv_arc_area(lv_obj_t * obj, uint16_t start_angle, uint16_t end_angl
lv_coord_t rout = (LV_MATH_MIN(lv_obj_get_width(obj) - left - right, lv_obj_get_height(obj) - top - bottom)) / 2;
lv_coord_t x = arc->coords.x1 + rout + left;
lv_coord_t y = arc->coords.y1 + rout + top;
lv_style_int_t w = lv_obj_get_style_line_width(obj, part);
lv_style_int_t rounded = lv_obj_get_style_line_rounded(obj, part);
lv_coord_t w = lv_obj_get_style_line_width(obj, part);
lv_coord_t rounded = lv_obj_get_style_line_rounded(obj, part);
lv_coord_t rin = rout - w;
lv_coord_t extra_area = 0;

File diff suppressed because it is too large Load Diff

View File

@ -42,10 +42,11 @@ enum {
LV_BTNMATRIX_CTRL_CHECKABLE = 0x0040, /**< Button *can* be toggled. */
LV_BTNMATRIX_CTRL_CHECKED = 0x0080, /**< Button is currently toggled (e.g. checked). */
LV_BTNMATRIX_CTRL_CLICK_TRIG = 0x0100, /**< 1: Send LV_EVENT_VALUE_CHANGE on CLICK, 0: Send LV_EVENT_VALUE_CHANGE on PRESS*/
LV_BTNMATRIX_CTRL_TYPE_2 = 0x0200, /**< Render the button with `LV_BTNMATRIX_PART_BTN2` style*/
};
typedef uint16_t lv_btnmatrix_ctrl_t;
typedef bool (*lv_btnmatrix_btn_drawer_cb_t)(lv_obj_t * btnm, uint32_t btn_id, const lv_area_t * draw_area, const lv_area_t * clip_area);
/*Data of button matrix*/
typedef struct {
/*No inherited ext.*/ /*Ext. of ancestor*/
@ -53,6 +54,7 @@ typedef struct {
const char ** map_p; /*Pointer to the current map*/
lv_area_t * button_areas; /*Array of areas of buttons*/
lv_btnmatrix_ctrl_t * ctrl_bits; /*Array of control bytes*/
lv_btnmatrix_btn_drawer_cb_t custom_drawer_cb;
uint16_t btn_cnt; /*Number of button in 'map_p'(Handled by the library)*/
uint16_t btn_id_pr; /*Index of the currently pressed button or LV_BTNMATRIX_BTN_NONE*/
uint16_t btn_id_focused; /*Index of the currently focused button or LV_BTNMATRIX_BTN_NONE*/
@ -62,12 +64,8 @@ typedef struct {
uint8_t align : 2; /*Align type from 'lv_label_align_t'*/
} lv_btnmatrix_ext_t;
enum {
LV_BTNMATRIX_PART_MAIN,
LV_BTNMATRIX_PART_BTN,
LV_BTNMATRIX_PART_BTN_2,
};
typedef uint8_t lv_btnmatrix_part_t;
extern const lv_obj_class_t lv_btnmatrix;
/**********************
* GLOBAL PROTOTYPES

View File

@ -199,10 +199,10 @@ void lv_gauge_set_value(lv_obj_t * gauge, uint8_t needle_id, int32_t value)
// lv_obj_invalidate(gauge);
lv_style_int_t pad = lv_obj_get_style_pad_left(gauge, LV_GAUGE_PART_NEEDLE);
lv_style_int_t left = lv_obj_get_style_pad_left(gauge, LV_GAUGE_PART_MAIN);
lv_style_int_t right = lv_obj_get_style_pad_right(gauge, LV_GAUGE_PART_MAIN);
lv_style_int_t top = lv_obj_get_style_pad_top(gauge, LV_GAUGE_PART_MAIN);
lv_coord_t pad = lv_obj_get_style_pad_left(gauge, LV_GAUGE_PART_NEEDLE);
lv_coord_t left = lv_obj_get_style_pad_left(gauge, LV_GAUGE_PART_MAIN);
lv_coord_t right = lv_obj_get_style_pad_right(gauge, LV_GAUGE_PART_MAIN);
lv_coord_t top = lv_obj_get_style_pad_top(gauge, LV_GAUGE_PART_MAIN);
lv_coord_t r = (lv_obj_get_width(gauge) - left - right) / 2 - pad;
lv_coord_t x_ofs = gauge->coords.x1 + r + left + pad;
lv_coord_t y_ofs = gauge->coords.y1 + r + top + pad;
@ -509,11 +509,11 @@ static lv_style_list_t * lv_gauge_get_style(lv_obj_t * gauge, uint8_t part)
static void lv_gauge_draw_labels(lv_obj_t * gauge, const lv_area_t * mask)
{
lv_gauge_ext_t * ext = lv_obj_get_ext_attr(gauge);
lv_style_int_t scale_width = lv_obj_get_style_scale_width(gauge, LV_GAUGE_PART_MAJOR);
lv_style_int_t left = lv_obj_get_style_pad_left(gauge, LV_GAUGE_PART_MAIN);
lv_style_int_t right = lv_obj_get_style_pad_right(gauge, LV_GAUGE_PART_MAIN);
lv_style_int_t top = lv_obj_get_style_pad_top(gauge, LV_GAUGE_PART_MAIN);
lv_style_int_t txt_pad = left;
lv_coord_t scale_width = lv_obj_get_style_scale_width(gauge, LV_GAUGE_PART_MAJOR);
lv_coord_t left = lv_obj_get_style_pad_left(gauge, LV_GAUGE_PART_MAIN);
lv_coord_t right = lv_obj_get_style_pad_right(gauge, LV_GAUGE_PART_MAIN);
lv_coord_t top = lv_obj_get_style_pad_top(gauge, LV_GAUGE_PART_MAIN);
lv_coord_t txt_pad = left;
lv_coord_t r = (lv_obj_get_width(gauge) - left - right) / 2 - scale_width - txt_pad;
lv_coord_t x_ofs = gauge->coords.x1 + r + left + scale_width + txt_pad;
lv_coord_t y_ofs = gauge->coords.y1 + r + top + scale_width + txt_pad;
@ -569,10 +569,10 @@ static void lv_gauge_draw_needle(lv_obj_t * gauge, const lv_area_t * clip_area)
{
lv_gauge_ext_t * ext = lv_obj_get_ext_attr(gauge);
lv_style_int_t pad = lv_obj_get_style_pad_left(gauge, LV_GAUGE_PART_NEEDLE);
lv_style_int_t left = lv_obj_get_style_pad_left(gauge, LV_GAUGE_PART_MAIN);
lv_style_int_t right = lv_obj_get_style_pad_right(gauge, LV_GAUGE_PART_MAIN);
lv_style_int_t top = lv_obj_get_style_pad_top(gauge, LV_GAUGE_PART_MAIN);
lv_coord_t pad = lv_obj_get_style_pad_left(gauge, LV_GAUGE_PART_NEEDLE);
lv_coord_t left = lv_obj_get_style_pad_left(gauge, LV_GAUGE_PART_MAIN);
lv_coord_t right = lv_obj_get_style_pad_right(gauge, LV_GAUGE_PART_MAIN);
lv_coord_t top = lv_obj_get_style_pad_top(gauge, LV_GAUGE_PART_MAIN);
lv_coord_t r = (lv_obj_get_width(gauge) - left - right) / 2 - pad;
lv_coord_t x_ofs = gauge->coords.x1 + r + left + pad;
@ -638,7 +638,7 @@ static void lv_gauge_draw_needle(lv_obj_t * gauge, const lv_area_t * clip_area)
lv_draw_rect_dsc_t mid_dsc;
lv_draw_rect_dsc_init(&mid_dsc);
lv_obj_init_draw_rect_dsc(gauge, LV_GAUGE_PART_NEEDLE, &mid_dsc);
lv_style_int_t size = lv_obj_get_style_size(gauge, LV_GAUGE_PART_NEEDLE) / 2;
lv_coord_t size = lv_obj_get_style_size(gauge, LV_GAUGE_PART_NEEDLE) / 2;
lv_area_t nm_cord;
nm_cord.x1 = x_ofs - size;
nm_cord.y1 = y_ofs - size;

View File

@ -202,8 +202,8 @@ void lv_img_set_src(lv_obj_t * img, const void * src_img)
if(src_type == LV_IMG_SRC_SYMBOL) {
/*`lv_img_dsc_get_info` couldn't set the with and height of a font so set it here*/
const lv_font_t * font = lv_obj_get_style_text_font(img, LV_IMG_PART_MAIN);
lv_style_int_t letter_space = lv_obj_get_style_text_letter_space(img, LV_IMG_PART_MAIN);
lv_style_int_t line_space = lv_obj_get_style_text_line_space(img, LV_IMG_PART_MAIN);
lv_coord_t letter_space = lv_obj_get_style_text_letter_space(img, LV_IMG_PART_MAIN);
lv_coord_t line_space = lv_obj_get_style_text_line_space(img, LV_IMG_PART_MAIN);
lv_point_t size;
_lv_txt_get_size(&size, src_img, font, letter_space, line_space,
LV_COORD_MAX, LV_TXT_FLAG_NONE);
@ -274,10 +274,10 @@ void lv_img_set_pivot(lv_obj_t * img, lv_coord_t x, lv_coord_t y)
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
if(ext->pivot.x == x && ext->pivot.y == y) return;
lv_style_int_t transf_zoom = lv_obj_get_style_transform_zoom(img, LV_IMG_PART_MAIN);
lv_coord_t transf_zoom = lv_obj_get_style_transform_zoom(img, LV_IMG_PART_MAIN);
transf_zoom = (transf_zoom * ext->zoom) >> 8;
lv_style_int_t transf_angle = lv_obj_get_style_transform_angle(img, LV_IMG_PART_MAIN);
lv_coord_t transf_angle = lv_obj_get_style_transform_angle(img, LV_IMG_PART_MAIN);
transf_angle += ext->angle;
lv_coord_t w = lv_obj_get_width(img);
@ -315,10 +315,10 @@ void lv_img_set_angle(lv_obj_t * img, int16_t angle)
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
if(angle == ext->angle) return;
lv_style_int_t transf_zoom = lv_obj_get_style_transform_zoom(img, LV_IMG_PART_MAIN);
lv_coord_t transf_zoom = lv_obj_get_style_transform_zoom(img, LV_IMG_PART_MAIN);
transf_zoom = (transf_zoom * ext->zoom) >> 8;
lv_style_int_t transf_angle = lv_obj_get_style_transform_angle(img, LV_IMG_PART_MAIN);
lv_coord_t transf_angle = lv_obj_get_style_transform_angle(img, LV_IMG_PART_MAIN);
lv_coord_t w = lv_obj_get_width(img);
lv_coord_t h = lv_obj_get_height(img);
@ -358,9 +358,9 @@ void lv_img_set_zoom(lv_obj_t * img, uint16_t zoom)
if(zoom == 0) zoom = 1;
lv_style_int_t transf_zoom = lv_obj_get_style_transform_zoom(img, LV_IMG_PART_MAIN);
lv_coord_t transf_zoom = lv_obj_get_style_transform_zoom(img, LV_IMG_PART_MAIN);
lv_style_int_t transf_angle = lv_obj_get_style_transform_angle(img, LV_IMG_PART_MAIN);
lv_coord_t transf_angle = lv_obj_get_style_transform_angle(img, LV_IMG_PART_MAIN);
transf_angle += ext->angle;
lv_coord_t w = lv_obj_get_width(img);
@ -755,10 +755,10 @@ static lv_res_t lv_img_signal(lv_obj_t * img, lv_signal_t sign, void * param)
else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) {
lv_coord_t * s = param;
lv_style_int_t transf_zoom = lv_obj_get_style_transform_zoom(img, LV_IMG_PART_MAIN);
lv_coord_t transf_zoom = lv_obj_get_style_transform_zoom(img, LV_IMG_PART_MAIN);
transf_zoom = (transf_zoom * ext->zoom) >> 8;
lv_style_int_t transf_angle = lv_obj_get_style_transform_angle(img, LV_IMG_PART_MAIN);
lv_coord_t transf_angle = lv_obj_get_style_transform_angle(img, LV_IMG_PART_MAIN);
transf_angle += ext->angle;
/*If the image has angle provide enough room for the rotated corners */
@ -775,10 +775,10 @@ static lv_res_t lv_img_signal(lv_obj_t * img, lv_signal_t sign, void * param)
}
/*Handle the padding of the background*/
lv_style_int_t left = lv_obj_get_style_pad_left(img, LV_IMG_PART_MAIN);
lv_style_int_t right = lv_obj_get_style_pad_right(img, LV_IMG_PART_MAIN);
lv_style_int_t top = lv_obj_get_style_pad_top(img, LV_IMG_PART_MAIN);
lv_style_int_t bottom = lv_obj_get_style_pad_bottom(img, LV_IMG_PART_MAIN);
lv_coord_t left = lv_obj_get_style_pad_left(img, LV_IMG_PART_MAIN);
lv_coord_t right = lv_obj_get_style_pad_right(img, LV_IMG_PART_MAIN);
lv_coord_t top = lv_obj_get_style_pad_top(img, LV_IMG_PART_MAIN);
lv_coord_t bottom = lv_obj_get_style_pad_bottom(img, LV_IMG_PART_MAIN);
*s = LV_MATH_MAX(*s, left);
*s = LV_MATH_MAX(*s, right);
@ -787,10 +787,10 @@ static lv_res_t lv_img_signal(lv_obj_t * img, lv_signal_t sign, void * param)
}
else if(sign == LV_SIGNAL_HIT_TEST) {
lv_hit_test_info_t * info = param;
lv_style_int_t zoom = lv_obj_get_style_transform_zoom(img, LV_IMG_PART_MAIN);
lv_coord_t zoom = lv_obj_get_style_transform_zoom(img, LV_IMG_PART_MAIN);
zoom = (zoom * ext->zoom) >> 8;
lv_style_int_t angle = lv_obj_get_style_transform_angle(img, LV_IMG_PART_MAIN);
lv_coord_t angle = lv_obj_get_style_transform_angle(img, LV_IMG_PART_MAIN);
angle += ext->angle;
/* If the object is exactly image sized (not cropped, not mosaic) and transformed

View File

@ -460,10 +460,10 @@ static lv_res_t lv_imgbtn_signal(lv_obj_t * imgbtn, lv_signal_t sign, void * par
}
else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) {
/*Handle the padding of the background*/
lv_style_int_t left = lv_obj_get_style_pad_left(imgbtn, LV_IMGBTN_PART_MAIN);
lv_style_int_t right = lv_obj_get_style_pad_right(imgbtn, LV_IMGBTN_PART_MAIN);
lv_style_int_t top = lv_obj_get_style_pad_top(imgbtn, LV_IMGBTN_PART_MAIN);
lv_style_int_t bottom = lv_obj_get_style_pad_bottom(imgbtn, LV_IMGBTN_PART_MAIN);
lv_coord_t left = lv_obj_get_style_pad_left(imgbtn, LV_IMGBTN_PART_MAIN);
lv_coord_t right = lv_obj_get_style_pad_right(imgbtn, LV_IMGBTN_PART_MAIN);
lv_coord_t top = lv_obj_get_style_pad_top(imgbtn, LV_IMGBTN_PART_MAIN);
lv_coord_t bottom = lv_obj_get_style_pad_bottom(imgbtn, LV_IMGBTN_PART_MAIN);
lv_coord_t * s = param;
*s = LV_MATH_MAX(*s, left);

View File

@ -39,10 +39,8 @@
/**********************
* STATIC PROTOTYPES
**********************/
lv_label_class_t lv_label;
static void lv_label_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy);
static void lv_label_destructor(void * obj);
static void lv_label_destructor(lv_obj_t * obj);
static lv_res_t lv_label_signal(lv_obj_t * label, lv_signal_t sign, void * param);
static lv_design_res_t lv_label_design(lv_obj_t * label, const lv_area_t * clip_area, lv_design_mode_t mode);
static void lv_label_revert_dots(lv_obj_t * label);
@ -60,6 +58,13 @@ static void get_txt_coords(const lv_obj_t * label, lv_area_t * area);
/**********************
* STATIC VARIABLES
**********************/
const lv_obj_class_t lv_label = {
.constructor = lv_label_constructor,
.destructor = lv_label_destructor,
.signal_cb = lv_label_signal,
.design_cb = lv_label_design,
.ext_size = sizeof(lv_label_ext_t),
};
/**********************
* MACROS
@ -78,20 +83,7 @@ static void get_txt_coords(const lv_obj_t * label, lv_area_t * area);
*/
lv_obj_t * lv_label_create(lv_obj_t * parent, const lv_obj_t * copy)
{
if(!lv_label._inited) {
LV_CLASS_INIT(lv_label, lv_obj);
lv_label.constructor = lv_label_constructor;
lv_label.destructor = lv_label_destructor;
lv_label.design_cb = lv_label_design;
lv_label.signal_cb = lv_label_signal;
}
lv_obj_t * obj = lv_class_new(&lv_label);
lv_label.constructor(obj, parent, copy);
lv_obj_create_finish(obj, parent, copy);
return obj;
return lv_obj_create_from_class(&lv_label, parent, copy);
}
/*=====================
@ -106,62 +98,62 @@ lv_obj_t * lv_label_create(lv_obj_t * parent, const lv_obj_t * copy)
void lv_label_set_text(lv_obj_t * obj, const char * text)
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_label_t * label = (lv_label_t *) obj;
lv_label_ext_t * ext = obj->ext_attr;
lv_obj_invalidate(obj);
/*If text is NULL then just refresh with the current text */
if(text == NULL) text = label->text;
if(text == NULL) text = ext->text;
LV_ASSERT_STR(text);
if(label->text == text && label->static_txt == 0) {
if(ext->text == text && ext->static_txt == 0) {
/*If set its own text then reallocate it (maybe its size changed)*/
#if LV_USE_ARABIC_PERSIAN_CHARS
/*Get the size of the text and process it*/
size_t len = _lv_txt_ap_calc_bytes_cnt(text);
label->text = lv_mem_realloc(label->text, len);
LV_ASSERT_MEM(label->text);
if(label->text == NULL) return;
ext->text = lv_mem_realloc(ext->text, len);
LV_ASSERT_MEM(ext->text);
if(ext->text == NULL) return;
_lv_txt_ap_proc(label->text, label->text);
_lv_txt_ap_proc(ext->text, ext->text);
#else
label->text = lv_mem_realloc(label->text, strlen(label->text) + 1);
ext->text = lv_mem_realloc(ext->text, strlen(ext->text) + 1);
#endif
LV_ASSERT_MEM(label->text);
if(label->text == NULL) return;
LV_ASSERT_MEM(ext->text);
if(ext->text == NULL) return;
}
else {
/*Free the old text*/
if(label->text != NULL && label->static_txt == 0) {
lv_mem_free(label->text);
label->text = NULL;
if(ext->text != NULL && ext->static_txt == 0) {
lv_mem_free(ext->text);
ext->text = NULL;
}
#if LV_USE_ARABIC_PERSIAN_CHARS
/*Get the size of the text and process it*/
size_t len = _lv_txt_ap_calc_bytes_cnt(text);
label->text = lv_mem_alloc(len);
LV_ASSERT_MEM(label->text);
if(label->text == NULL) return;
ext->text = lv_mem_alloc(len);
LV_ASSERT_MEM(ext->text);
if(ext->text == NULL) return;
_lv_txt_ap_proc(text, label->text);
_lv_txt_ap_proc(text, ext->text);
#else
/*Get the size of the text*/
size_t len = strlen(text) + 1;
/*Allocate space for the new text*/
label->text = lv_mem_alloc(len);
LV_ASSERT_MEM(label->text);
if(label->text == NULL) return;
strcpy(label->text, text);
ext->text = lv_mem_alloc(len);
LV_ASSERT_MEM(ext->text);
if(ext->text == NULL) return;
strcpy(ext->text, text);
#endif
/*Now the text is dynamically allocated*/
label->static_txt = 0;
ext->static_txt = 0;
}
lv_label_refr_text(obj);
@ -178,7 +170,7 @@ void lv_label_set_text_fmt(lv_obj_t * obj, const char * fmt, ...)
LV_ASSERT_STR(fmt);
lv_obj_invalidate(obj);
lv_label_t * label = (lv_label_t *) obj;
lv_label_ext_t * ext = obj->ext_attr;
/*If text is NULL then refresh */
if(fmt == NULL) {
@ -186,16 +178,16 @@ void lv_label_set_text_fmt(lv_obj_t * obj, const char * fmt, ...)
return;
}
if(label->text != NULL && label->static_txt == 0) {
lv_mem_free(label->text);
label->text = NULL;
if(ext->text != NULL && ext->static_txt == 0) {
lv_mem_free(ext->text);
ext->text = NULL;
}
va_list args;
va_start(args, fmt);
label->text = _lv_txt_set_text_vfmt(fmt, args);
ext->text = _lv_txt_set_text_vfmt(fmt, args);
va_end(args);
label->static_txt = 0; /*Now the text is dynamically allocated*/
ext->static_txt = 0; /*Now the text is dynamically allocated*/
lv_label_refr_text(obj);
}
@ -209,16 +201,16 @@ void lv_label_set_text_fmt(lv_obj_t * obj, const char * fmt, ...)
void lv_label_set_text_static(lv_obj_t * obj, const char * text)
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_label_t * label = (lv_label_t *) obj;
lv_label_ext_t * ext = obj->ext_attr;
if(label->static_txt == 0 && label->text != NULL) {
lv_mem_free(label->text);
label->text = NULL;
if(ext->static_txt == 0 && ext->text != NULL) {
lv_mem_free(ext->text);
ext->text = NULL;
}
if(text != NULL) {
label->static_txt = 1;
label->text = (char *)text;
ext->static_txt = 1;
ext->text = (char *)text;
}
lv_label_refr_text(obj);
@ -235,7 +227,7 @@ void lv_label_set_long_mode(lv_obj_t * obj, lv_label_long_mode_t long_mode)
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_label_t * label = (lv_label_t *) obj;
lv_label_ext_t * ext = obj->ext_attr;
#if LV_USE_ANIMATION
/*Delete the old animation (if exists)*/
@ -244,20 +236,20 @@ void lv_label_set_long_mode(lv_obj_t * obj, lv_label_long_mode_t long_mode)
lv_anim_del(obj, (lv_anim_exec_xcb_t)lv_label_set_offset_x);
lv_anim_del(obj, (lv_anim_exec_xcb_t)lv_label_set_offset_y);
#endif
label->offset.x = 0;
label->offset.y = 0;
ext->offset.x = 0;
ext->offset.y = 0;
if(long_mode == LV_LABEL_LONG_SROLL || long_mode == LV_LABEL_LONG_SROLL_CIRC || long_mode == LV_LABEL_LONG_CLIP)
label->expand = 1;
ext->expand = 1;
else
label->expand = 0;
ext->expand = 0;
/*Restore the character under the dots*/
if(label->long_mode == LV_LABEL_LONG_DOT && label->dot_end != LV_LABEL_DOT_END_INV) {
if(ext->long_mode == LV_LABEL_LONG_DOT && ext->dot_end != LV_LABEL_DOT_END_INV) {
lv_label_revert_dots(obj);
}
label->long_mode = long_mode;
ext->long_mode = long_mode;
lv_label_refr_text(obj);
}
@ -270,10 +262,10 @@ void lv_label_set_align(lv_obj_t * obj, lv_label_align_t align)
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_label_t * label = (lv_label_t *) obj;
if(label->align == align) return;
lv_label_ext_t * ext = obj->ext_attr;
if(ext->align == align) return;
label->align = align;
ext->align = align;
/*Enough to invalidate because alignment is only drawing related (lv_refr_label_text() not required)*/
lv_obj_invalidate(obj);
@ -288,10 +280,10 @@ void lv_label_set_recolor(lv_obj_t * obj, bool en)
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_label_t * label = (lv_label_t *) obj;
if(label->recolor == en) return;
lv_label_ext_t * ext = obj->ext_attr;
if(ext->recolor == en) return;
label->recolor = en == false ? 0 : 1;
ext->recolor = en == false ? 0 : 1;
/*Refresh the text because the potential color codes in text needs to be hidden or revealed*/
lv_label_refr_text(obj);
@ -307,12 +299,12 @@ void lv_label_set_anim_speed(lv_obj_t * obj, uint16_t anim_speed)
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
#if LV_USE_ANIMATION
lv_label_t * label = (lv_label_t *) obj;
if(label->anim_speed == anim_speed) return;
lv_label_ext_t * ext = obj->ext_attr;
if(ext->anim_speed == anim_speed) return;
label->anim_speed = anim_speed;
ext->anim_speed = anim_speed;
if(label->long_mode == LV_LABEL_LONG_SROLL || label->long_mode == LV_LABEL_LONG_SROLL_CIRC) {
if(ext->long_mode == LV_LABEL_LONG_SROLL || ext->long_mode == LV_LABEL_LONG_SROLL_CIRC) {
lv_label_refr_text(obj);
}
#else
@ -326,8 +318,8 @@ void lv_label_set_text_sel_start(lv_obj_t * obj, uint32_t index)
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
#if LV_LABEL_TEXT_SEL
lv_label_t * label = (lv_label_t *) obj;
label->sel_start = index;
lv_label_ext_t * ext = obj->ext_attr;
ext->sel_start = index;
lv_obj_invalidate(obj);
#else
(void)obj; /*Unused*/
@ -340,8 +332,8 @@ void lv_label_set_text_sel_end(lv_obj_t * obj, uint32_t index)
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
#if LV_LABEL_TEXT_SEL
lv_label_t * label = (lv_label_t *) obj;
label->sel_end = index;
lv_label_ext_t * ext = obj->ext_attr;
ext->sel_end = index;
lv_obj_invalidate(obj);
#else
(void)obj; /*Unused*/
@ -361,8 +353,8 @@ void lv_label_set_text_sel_end(lv_obj_t * obj, uint32_t index)
char * lv_label_get_text(const lv_obj_t * obj)
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_label_t * label = (lv_label_t *) obj;
return label->text;
lv_label_ext_t * ext = obj->ext_attr;
return ext->text;
}
/**
@ -373,8 +365,8 @@ char * lv_label_get_text(const lv_obj_t * obj)
lv_label_long_mode_t lv_label_get_long_mode(const lv_obj_t * obj)
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_label_t * label = (lv_label_t *) obj;
return label->long_mode;
lv_label_ext_t * ext = obj->ext_attr;
return ext->long_mode;
}
/**
@ -386,13 +378,13 @@ lv_label_align_t lv_label_get_align(const lv_obj_t * obj)
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_label_t * label = (lv_label_t *) obj;
lv_label_align_t align = label->align;
lv_label_ext_t * ext = obj->ext_attr;
lv_label_align_t align = ext->align;
if(align == LV_LABEL_ALIGN_AUTO) {
#if LV_USE_BIDI
lv_bidi_dir_t base_dir = lv_obj_get_base_dir(label);
if(base_dir == LV_BIDI_DIR_AUTO) base_dir = _lv_bidi_detect_base_dir(label->text);
if(base_dir == LV_BIDI_DIR_AUTO) base_dir = _lv_bidi_detect_base_dir(ext->text);
if(base_dir == LV_BIDI_DIR_LTR) align = LV_LABEL_ALIGN_LEFT;
else if(base_dir == LV_BIDI_DIR_RTL) align = LV_LABEL_ALIGN_RIGHT;
@ -413,8 +405,8 @@ bool lv_label_get_recolor(const lv_obj_t * obj)
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_label_t * label = (lv_label_t *) obj;
return label->recolor == 0 ? false : true;
lv_label_ext_t * ext = obj->ext_attr;
return ext->recolor == 0 ? false : true;
}
/**
@ -427,8 +419,8 @@ uint16_t lv_label_get_anim_speed(const lv_obj_t * obj)
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
#if LV_USE_ANIMATION
lv_label_t * label = (lv_label_t *) obj;
return label->anim_speed;
lv_label_ext_t * ext = obj->ext_attr;
return ext->anim_speed;
#else
(void)label; /*Unused*/
return 0;
@ -469,7 +461,7 @@ void lv_label_get_letter_pos(const lv_obj_t * obj, uint32_t char_id, lv_point_t
lv_area_t txt_coords;
get_txt_coords(obj, &txt_coords);
lv_label_t * label = (lv_label_t *) obj;
lv_label_ext_t * ext = obj->ext_attr;
uint32_t line_start = 0;
uint32_t new_line_start = 0;
lv_coord_t max_w = lv_area_get_width(&txt_coords);
@ -480,9 +472,9 @@ void lv_label_get_letter_pos(const lv_obj_t * obj, uint32_t char_id, lv_point_t
lv_coord_t y = 0;
lv_txt_flag_t flag = LV_TXT_FLAG_NONE;
if(label->recolor != 0) flag |= LV_TXT_FLAG_RECOLOR;
if(label->expand != 0) flag |= LV_TXT_FLAG_EXPAND;
if(label->long_mode == LV_LABEL_LONG_EXPAND) flag |= LV_TXT_FLAG_FIT;
if(ext->recolor != 0) flag |= LV_TXT_FLAG_RECOLOR;
if(ext->expand != 0) flag |= LV_TXT_FLAG_EXPAND;
if(ext->long_mode == LV_LABEL_LONG_EXPAND) flag |= LV_TXT_FLAG_FIT;
if(align == LV_LABEL_ALIGN_CENTER) flag |= LV_TXT_FLAG_CENTER;
if(align == LV_LABEL_ALIGN_RIGHT) flag |= LV_TXT_FLAG_RIGHT;
@ -568,7 +560,7 @@ uint32_t lv_label_get_letter_on(const lv_obj_t * obj, lv_point_t * pos_in)
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
LV_ASSERT_NULL(pos_in);
lv_label_t * label = (lv_label_t *) obj;
lv_label_ext_t * ext = obj->ext_attr;
lv_point_t pos;
pos.x = pos_in->x - lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
@ -589,9 +581,9 @@ uint32_t lv_label_get_letter_on(const lv_obj_t * obj, lv_point_t * pos_in)
uint32_t logical_pos;
char * bidi_txt;
if(label->recolor != 0) flag |= LV_TXT_FLAG_RECOLOR;
if(label->expand != 0) flag |= LV_TXT_FLAG_EXPAND;
if(label->long_mode == LV_LABEL_LONG_EXPAND) flag |= LV_TXT_FLAG_FIT;
if(ext->recolor != 0) flag |= LV_TXT_FLAG_RECOLOR;
if(ext->expand != 0) flag |= LV_TXT_FLAG_EXPAND;
if(ext->long_mode == LV_LABEL_LONG_EXPAND) flag |= LV_TXT_FLAG_FIT;
lv_label_align_t align = lv_label_get_align(obj);
if(align == LV_LABEL_ALIGN_CENTER) flag |= LV_TXT_FLAG_CENTER;
@ -700,8 +692,8 @@ uint32_t lv_label_get_text_sel_start(const lv_obj_t * obj)
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
#if LV_LABEL_TEXT_SEL
lv_label_t * label = (lv_label_t *) obj;
return label->sel_start;
lv_label_ext_t * ext = obj->ext_attr;
return ext->sel_start;
#else
(void)obj; /*Unused*/
@ -719,8 +711,8 @@ uint32_t lv_label_get_text_sel_end(const lv_obj_t * obj)
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
#if LV_LABEL_TEXT_SEL
lv_label_t * label = (lv_label_t *) obj;
return label->sel_end;
lv_label_ext_t * ext = obj->ext_attr;
return ext->sel_end;
#else
(void)obj; /*Unused*/
return LV_LABEL_TEXT_SEL_OFF;
@ -753,9 +745,9 @@ uint32_t lv_label_get_text_sel_end(const lv_obj_t * obj)
// lv_txt_flag_t flag = LV_TXT_FLAG_NONE;
// lv_label_align_t align = lv_label_get_align(label);
//
// if(label->recolor != 0) flag |= LV_TXT_FLAG_RECOLOR;
// if(label->expand != 0) flag |= LV_TXT_FLAG_EXPAND;
// if(label->long_mode == LV_LABEL_LONG_EXPAND) flag |= LV_TXT_FLAG_FIT;
// if(ext->recolor != 0) flag |= LV_TXT_FLAG_RECOLOR;
// if(ext->expand != 0) flag |= LV_TXT_FLAG_EXPAND;
// if(ext->long_mode == LV_LABEL_LONG_EXPAND) flag |= LV_TXT_FLAG_FIT;
// if(align == LV_LABEL_ALIGN_CENTER) flag |= LV_TXT_FLAG_CENTER;
//
// /*Search the line of the index letter */;
@ -835,23 +827,23 @@ void lv_label_ins_text(lv_obj_t * obj, uint32_t pos, const char * txt)
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
LV_ASSERT_STR(txt);
lv_label_t * label = (lv_label_t *) obj;
lv_label_ext_t * ext = obj->ext_attr;
/*Can not append to static text*/
if(label->static_txt != 0) return;
if(ext->static_txt != 0) return;
lv_obj_invalidate(obj);
/*Allocate space for the new text*/
size_t old_len = strlen(label->text);
size_t old_len = strlen(ext->text);
size_t ins_len = strlen(txt);
size_t new_len = ins_len + old_len;
label->text = lv_mem_realloc(label->text, new_len + 1);
LV_ASSERT_MEM(label->text);
if(label->text == NULL) return;
ext->text = lv_mem_realloc(ext->text, new_len + 1);
LV_ASSERT_MEM(ext->text);
if(ext->text == NULL) return;
if(pos == LV_LABEL_POS_LAST) {
pos = _lv_txt_get_encoded_length(label->text);
pos = _lv_txt_get_encoded_length(ext->text);
}
#if LV_USE_BIDI
@ -860,11 +852,11 @@ void lv_label_ins_text(lv_obj_t * obj, uint32_t pos, const char * txt)
if(bidi_buf == NULL) return;
_lv_bidi_process(txt, bidi_buf, lv_obj_get_base_dir(label));
_lv_txt_ins(label->text, pos, bidi_buf);
_lv_txt_ins(ext->text, pos, bidi_buf);
_lv_mem_buf_release(bidi_buf);
#else
_lv_txt_ins(label->text, pos, txt);
_lv_txt_ins(ext->text, pos, txt);
#endif
lv_label_set_text(obj, NULL);
}
@ -879,10 +871,10 @@ void lv_label_ins_text(lv_obj_t * obj, uint32_t pos, const char * txt)
void lv_label_cut_text(lv_obj_t * obj, uint32_t pos, uint32_t cnt)
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_label_t * label = (lv_label_t *) obj;
lv_label_ext_t * ext = obj->ext_attr;
/*Can not append to static text*/
if(label->static_txt != 0) return;
if(ext->static_txt != 0) return;
lv_obj_invalidate(obj);
@ -900,10 +892,10 @@ void lv_label_cut_text(lv_obj_t * obj, uint32_t pos, uint32_t cnt)
*/
void lv_label_refr_text(lv_obj_t * obj)
{
lv_label_t * label = (lv_label_t *) obj;
if(label->text == NULL) return;
lv_label_ext_t * ext = obj->ext_attr;
if(ext->text == NULL) return;
#if LV_LABEL_LONG_TXT_HINT
label->hint.line_start = -1; /*The hint is invalid if the text changes*/
ext->hint.line_start = -1; /*The hint is invalid if the text changes*/
#endif
lv_area_t txt_coords;
@ -916,26 +908,26 @@ void lv_label_refr_text(lv_obj_t * obj)
/*Calc. the height and longest line*/
lv_point_t size;
lv_txt_flag_t flag = LV_TXT_FLAG_NONE;
if(label->recolor != 0) flag |= LV_TXT_FLAG_RECOLOR;
if(label->expand != 0) flag |= LV_TXT_FLAG_EXPAND;
if(label->long_mode == LV_LABEL_LONG_EXPAND) flag |= LV_TXT_FLAG_FIT;
_lv_txt_get_size(&size, label->text, font, letter_space, line_space, max_w, flag);
if(ext->recolor != 0) flag |= LV_TXT_FLAG_RECOLOR;
if(ext->expand != 0) flag |= LV_TXT_FLAG_EXPAND;
if(ext->long_mode == LV_LABEL_LONG_EXPAND) flag |= LV_TXT_FLAG_FIT;
_lv_txt_get_size(&size, ext->text, font, letter_space, line_space, max_w, flag);
/*Set the full size in expand mode*/
if(label->long_mode == LV_LABEL_LONG_EXPAND) {
if(ext->long_mode == LV_LABEL_LONG_EXPAND) {
size.x += lv_obj_get_style_pad_left(obj, LV_PART_MAIN) + lv_obj_get_style_pad_right(obj, LV_PART_MAIN);
size.y += lv_obj_get_style_pad_top(obj, LV_PART_MAIN) + lv_obj_get_style_pad_bottom(obj, LV_PART_MAIN);
lv_obj_set_size(obj, size.x, size.y);
}
/*In roll mode keep the size but start offset animations*/
else if(label->long_mode == LV_LABEL_LONG_SROLL) {
else if(ext->long_mode == LV_LABEL_LONG_SROLL) {
#if LV_USE_ANIMATION
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, label);
lv_anim_set_var(&a, obj);
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
lv_anim_set_playback_delay(&a, (((lv_font_get_glyph_width(font, ' ', ' ') + letter_space) * 1000) /
label->anim_speed) *
ext->anim_speed) *
LV_LABEL_WAIT_CHAR_COUNT);
lv_anim_set_repeat_delay(&a, a.playback_delay);
@ -943,10 +935,10 @@ void lv_label_refr_text(lv_obj_t * obj)
if(size.x > lv_area_get_width(&txt_coords)) {
lv_anim_set_values(&a, 0, lv_area_get_width(&txt_coords) - size.x);
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_label_set_offset_x);
lv_anim_set_time(&a, lv_anim_speed_to_time(label->anim_speed, a.start, a.end));
lv_anim_set_time(&a, lv_anim_speed_to_time(ext->anim_speed, a.start, a.end));
lv_anim_set_playback_time(&a, a.time);
lv_anim_t * anim_cur = lv_anim_get(label, (lv_anim_exec_xcb_t)lv_label_set_offset_x);
lv_anim_t * anim_cur = lv_anim_get(obj, (lv_anim_exec_xcb_t)lv_label_set_offset_x);
int32_t act_time = 0;
bool playback_now = false;
if(anim_cur) {
@ -971,17 +963,17 @@ void lv_label_refr_text(lv_obj_t * obj)
}
else {
/*Delete the offset animation if not required*/
lv_anim_del(label, (lv_anim_exec_xcb_t)lv_label_set_offset_x);
label->offset.x = 0;
lv_anim_del(obj, (lv_anim_exec_xcb_t)lv_label_set_offset_x);
ext->offset.x = 0;
}
if(size.y > lv_area_get_height(&txt_coords) && hor_anim == false) {
lv_anim_set_values(&a, 0, lv_area_get_height(&txt_coords) - size.y - (lv_font_get_line_height(font)));
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_label_set_offset_y);
lv_anim_set_time(&a, lv_anim_speed_to_time(label->anim_speed, a.start, a.end));
lv_anim_set_time(&a, lv_anim_speed_to_time(ext->anim_speed, a.start, a.end));
lv_anim_set_playback_time(&a, a.time);
lv_anim_t * anim_cur = lv_anim_get(label, (lv_anim_exec_xcb_t)lv_label_set_offset_y);
lv_anim_t * anim_cur = lv_anim_get(obj, (lv_anim_exec_xcb_t)lv_label_set_offset_y);
int32_t act_time = 0;
bool playback_now = false;
if(anim_cur) {
@ -1005,26 +997,26 @@ void lv_label_refr_text(lv_obj_t * obj)
}
else {
/*Delete the offset animation if not required*/
lv_anim_del(label, (lv_anim_exec_xcb_t)lv_label_set_offset_y);
label->offset.y = 0;
lv_anim_del(obj, (lv_anim_exec_xcb_t)lv_label_set_offset_y);
ext->offset.y = 0;
}
#endif
}
/*In roll inf. mode keep the size but start offset animations*/
else if(label->long_mode == LV_LABEL_LONG_SROLL_CIRC) {
else if(ext->long_mode == LV_LABEL_LONG_SROLL_CIRC) {
#if LV_USE_ANIMATION
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, label);
lv_anim_set_var(&a, obj);
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
bool hor_anim = false;
if(size.x > lv_area_get_width(&txt_coords)) {
lv_anim_set_values(&a, 0, -size.x - lv_font_get_glyph_width(font, ' ', ' ') * LV_LABEL_WAIT_CHAR_COUNT);
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_label_set_offset_x);
lv_anim_set_time(&a, lv_anim_speed_to_time(label->anim_speed, a.start, a.end));
lv_anim_set_time(&a, lv_anim_speed_to_time(ext->anim_speed, a.start, a.end));
lv_anim_t * anim_cur = lv_anim_get(label, (lv_anim_exec_xcb_t)lv_label_set_offset_x);
lv_anim_t * anim_cur = lv_anim_get(obj, (lv_anim_exec_xcb_t)lv_label_set_offset_x);
int32_t act_time = anim_cur ? anim_cur->act_time : 0;
if(act_time < a.time) {
a.act_time = act_time; /*To keep the old position*/
@ -1036,16 +1028,16 @@ void lv_label_refr_text(lv_obj_t * obj)
}
else {
/*Delete the offset animation if not required*/
lv_anim_del(label, (lv_anim_exec_xcb_t)lv_label_set_offset_x);
label->offset.x = 0;
lv_anim_del(obj, (lv_anim_exec_xcb_t)lv_label_set_offset_x);
ext->offset.x = 0;
}
if(size.y > lv_area_get_height(&txt_coords) && hor_anim == false) {
lv_anim_set_values(&a, 0, -size.y - (lv_font_get_line_height(font)));
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_label_set_offset_y);
lv_anim_set_time(&a, lv_anim_speed_to_time(label->anim_speed, a.start, a.end));
lv_anim_set_time(&a, lv_anim_speed_to_time(ext->anim_speed, a.start, a.end));
lv_anim_t * anim_cur = lv_anim_get(label, (lv_anim_exec_xcb_t)lv_label_set_offset_y);
lv_anim_t * anim_cur = lv_anim_get(obj, (lv_anim_exec_xcb_t)lv_label_set_offset_y);
int32_t act_time = anim_cur ? anim_cur->act_time : 0;
if(act_time < a.time) {
a.act_time = act_time; /*To keep the old position*/
@ -1056,17 +1048,17 @@ void lv_label_refr_text(lv_obj_t * obj)
}
else {
/*Delete the offset animation if not required*/
lv_anim_del(label, (lv_anim_exec_xcb_t)lv_label_set_offset_y);
label->offset.y = 0;
lv_anim_del(obj, (lv_anim_exec_xcb_t)lv_label_set_offset_y);
ext->offset.y = 0;
}
#endif
}
else if(label->long_mode == LV_LABEL_LONG_DOT) {
else if(ext->long_mode == LV_LABEL_LONG_DOT) {
if(size.y <= lv_area_get_height(&txt_coords)) { /*No dots are required, the text is short enough*/
label->dot_end = LV_LABEL_DOT_END_INV;
ext->dot_end = LV_LABEL_DOT_END_INV;
}
else if(_lv_txt_get_encoded_length(label->text) <= LV_LABEL_DOT_NUM) { /*Don't turn to dots all the characters*/
label->dot_end = LV_LABEL_DOT_END_INV;
else if(_lv_txt_get_encoded_length(ext->text) <= LV_LABEL_DOT_NUM) { /*Don't turn to dots all the characters*/
ext->dot_end = LV_LABEL_DOT_END_INV;
}
else {
lv_point_t p;
@ -1090,10 +1082,10 @@ void lv_label_refr_text(lv_obj_t * obj)
/*Be sure there is space for the dots*/
size_t txt_len = strlen(label->text);
uint32_t byte_id = _lv_txt_encoded_get_byte_id(label->text, letter_id);
size_t txt_len = strlen(ext->text);
uint32_t byte_id = _lv_txt_encoded_get_byte_id(ext->text, letter_id);
while(byte_id + LV_LABEL_DOT_NUM > txt_len) {
_lv_txt_encoded_prev(label->text, &byte_id);
_lv_txt_encoded_prev(ext->text, &byte_id);
letter_id--;
}
@ -1102,26 +1094,26 @@ void lv_label_refr_text(lv_obj_t * obj)
uint32_t i;
uint8_t len = 0;
for(i = 0; i <= LV_LABEL_DOT_NUM; i++) {
len += _lv_txt_encoded_size(&label->text[byte_id]);
_lv_txt_encoded_next(label->text, &byte_id);
len += _lv_txt_encoded_size(&ext->text[byte_id]);
_lv_txt_encoded_next(ext->text, &byte_id);
}
if(lv_label_set_dot_tmp(obj, &label->text[byte_id_ori], len)) {
if(lv_label_set_dot_tmp(obj, &ext->text[byte_id_ori], len)) {
for(i = 0; i < LV_LABEL_DOT_NUM; i++) {
label->text[byte_id_ori + i] = '.';
ext->text[byte_id_ori + i] = '.';
}
label->text[byte_id_ori + LV_LABEL_DOT_NUM] = '\0';
label->dot_end = letter_id + LV_LABEL_DOT_NUM;
ext->text[byte_id_ori + LV_LABEL_DOT_NUM] = '\0';
ext->dot_end = letter_id + LV_LABEL_DOT_NUM;
}
}
}
/*In break mode only the height can change*/
else if(label->long_mode == LV_LABEL_LONG_WRAP) {
else if(ext->long_mode == LV_LABEL_LONG_WRAP) {
size.y += lv_obj_get_style_pad_top(obj, LV_PART_MAIN) + lv_obj_get_style_pad_bottom(obj, LV_PART_MAIN);
lv_obj_set_height(obj, size.y);
}
/*Do not set the size in Clip mode*/
else if(label->long_mode == LV_LABEL_LONG_CLIP) {
else if(ext->long_mode == LV_LABEL_LONG_CLIP) {
/*Do nothing*/
}
@ -1138,34 +1130,34 @@ static void lv_label_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj
LV_LOG_TRACE("label create started");
LV_CLASS_CONSTRUCTOR_BEGIN(obj, lv_label)
lv_label.base_p->constructor(obj, parent, copy);
lv_obj.constructor(obj, parent, copy);
lv_label_t * label = (lv_label_t *) obj;
lv_label_ext_t * ext = obj->ext_attr;
label->text = NULL;
label->static_txt = 0;
label->recolor = 0;
label->align = LV_LABEL_ALIGN_AUTO;
label->dot_end = LV_LABEL_DOT_END_INV;
label->long_mode = LV_LABEL_LONG_EXPAND;
ext->text = NULL;
ext->static_txt = 0;
ext->recolor = 0;
ext->align = LV_LABEL_ALIGN_AUTO;
ext->dot_end = LV_LABEL_DOT_END_INV;
ext->long_mode = LV_LABEL_LONG_EXPAND;
#if LV_USE_ANIMATION
label->anim_speed = LV_LABEL_DEF_SCROLL_SPEED;
ext->anim_speed = LV_LABEL_DEF_SCROLL_SPEED;
#endif
label->offset.x = 0;
label->offset.y = 0;
ext->offset.x = 0;
ext->offset.y = 0;
#if LV_LABEL_LONG_TXT_HINT
label->hint.line_start = -1;
label->hint.coord_y = 0;
label->hint.y = 0;
ext->hint.line_start = -1;
ext->hint.coord_y = 0;
ext->hint.y = 0;
#endif
#if LV_LABEL_TEXT_SEL
label->sel_start = LV_DRAW_LABEL_NO_TXT_SEL;
label->sel_end = LV_DRAW_LABEL_NO_TXT_SEL;
ext->sel_start = LV_DRAW_LABEL_NO_TXT_SEL;
ext->sel_end = LV_DRAW_LABEL_NO_TXT_SEL;
#endif
label->dot.tmp_ptr = NULL;
label->dot_tmp_alloc = 0;
ext->dot.tmp_ptr = NULL;
ext->dot_tmp_alloc = 0;
lv_obj_clear_flag(obj, LV_OBJ_FLAG_CLICKABLE);
lv_label_set_long_mode(obj, LV_LABEL_LONG_EXPAND);
@ -1176,10 +1168,10 @@ static void lv_label_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj
LV_LOG_INFO("label created");
}
static void lv_label_destructor(void * obj)
static void lv_label_destructor(lv_obj_t * obj)
{
// lv_label_dot_tmp_free(label->dot_...);
// lv_label_dot_tmp_free(label->text);
// lv_label_dot_tmp_free(ext->dot_...);
// lv_label_dot_tmp_free(ext->text);
// lv_bar_t * bar = obj;
//
@ -1211,7 +1203,7 @@ static lv_design_res_t lv_label_design(lv_obj_t * obj, const lv_area_t * clip_ar
lv_obj.design_cb(obj, clip_area, mode);
lv_label_t * label = (lv_label_t *) obj;
lv_label_ext_t * ext = obj->ext_attr;
lv_area_t txt_coords;
get_txt_coords(obj, &txt_coords);
@ -1222,17 +1214,17 @@ static lv_design_res_t lv_label_design(lv_obj_t * obj, const lv_area_t * clip_ar
lv_label_align_t align = lv_label_get_align(obj);
lv_txt_flag_t flag = LV_TXT_FLAG_NONE;
if(label->recolor != 0) flag |= LV_TXT_FLAG_RECOLOR;
if(label->expand != 0) flag |= LV_TXT_FLAG_EXPAND;
if(label->long_mode == LV_LABEL_LONG_EXPAND) flag |= LV_TXT_FLAG_FIT;
if(ext->recolor != 0) flag |= LV_TXT_FLAG_RECOLOR;
if(ext->expand != 0) flag |= LV_TXT_FLAG_EXPAND;
if(ext->long_mode == LV_LABEL_LONG_EXPAND) flag |= LV_TXT_FLAG_FIT;
if(align == LV_LABEL_ALIGN_CENTER) flag |= LV_TXT_FLAG_CENTER;
if(align == LV_LABEL_ALIGN_RIGHT) flag |= LV_TXT_FLAG_RIGHT;
lv_draw_label_dsc_t label_draw_dsc;
lv_draw_label_dsc_init(&label_draw_dsc);
label_draw_dsc.ofs_x = label->offset.x;
label_draw_dsc.ofs_y = label->offset.y;
label_draw_dsc.ofs_x = ext->offset.x;
label_draw_dsc.ofs_y = ext->offset.y;
label_draw_dsc.flag = flag;
lv_obj_init_draw_label_dsc(obj, LV_PART_MAIN, &label_draw_dsc);
@ -1245,10 +1237,10 @@ static lv_design_res_t lv_label_design(lv_obj_t * obj, const lv_area_t * clip_ar
/* In SROLL and SROLL_CIRC mode the CENTER and RIGHT are pointless so remove them.
* (In addition they will result misalignment is this case)*/
if((label->long_mode == LV_LABEL_LONG_SROLL || label->long_mode == LV_LABEL_LONG_SROLL_CIRC) &&
(label->align == LV_LABEL_ALIGN_CENTER || label->align == LV_LABEL_ALIGN_RIGHT)) {
if((ext->long_mode == LV_LABEL_LONG_SROLL || ext->long_mode == LV_LABEL_LONG_SROLL_CIRC) &&
(ext->align == LV_LABEL_ALIGN_CENTER || ext->align == LV_LABEL_ALIGN_RIGHT)) {
lv_point_t size;
_lv_txt_get_size(&size, label->text, label_draw_dsc.font, label_draw_dsc.letter_space, label_draw_dsc.line_space,
_lv_txt_get_size(&size, ext->text, label_draw_dsc.font, label_draw_dsc.letter_space, label_draw_dsc.line_space,
LV_COORD_MAX, flag);
if(size.x > lv_area_get_width(&txt_coords)) {
label_draw_dsc.flag &= ~LV_TXT_FLAG_RIGHT;
@ -1256,8 +1248,8 @@ static lv_design_res_t lv_label_design(lv_obj_t * obj, const lv_area_t * clip_ar
}
}
#if LV_LABEL_LONG_TXT_HINT
lv_draw_label_hint_t * hint = &label->hint;
if(label->long_mode == LV_LABEL_LONG_SROLL_CIRC || lv_area_get_height(&txt_coords) < LV_LABEL_HINT_HEIGHT_LIMIT)
lv_draw_label_hint_t * hint = &ext->hint;
if(ext->long_mode == LV_LABEL_LONG_SROLL_CIRC || lv_area_get_height(&txt_coords) < LV_LABEL_HINT_HEIGHT_LIMIT)
hint = NULL;
#else
@ -1265,28 +1257,28 @@ static lv_design_res_t lv_label_design(lv_obj_t * obj, const lv_area_t * clip_ar
lv_draw_label_hint_t * hint = NULL;
#endif
lv_draw_label(&txt_coords, &txt_clip, &label_draw_dsc, label->text, hint);
lv_draw_label(&txt_coords, &txt_clip, &label_draw_dsc, ext->text, hint);
if(label->long_mode == LV_LABEL_LONG_SROLL_CIRC) {
if(ext->long_mode == LV_LABEL_LONG_SROLL_CIRC) {
lv_point_t size;
_lv_txt_get_size(&size, label->text, label_draw_dsc.font, label_draw_dsc.letter_space, label_draw_dsc.line_space,
_lv_txt_get_size(&size, ext->text, label_draw_dsc.font, label_draw_dsc.letter_space, label_draw_dsc.line_space,
LV_COORD_MAX, flag);
/*Draw the text again nlabel to the original to make an circular effect */
if(size.x > lv_area_get_width(&txt_coords)) {
label_draw_dsc.ofs_x = label->offset.x + size.x +
label_draw_dsc.ofs_x = ext->offset.x + size.x +
lv_font_get_glyph_width(label_draw_dsc.font, ' ', ' ') * LV_LABEL_WAIT_CHAR_COUNT;
label_draw_dsc.ofs_y = label->offset.y;
label_draw_dsc.ofs_y = ext->offset.y;
lv_draw_label(&txt_coords, &txt_clip, &label_draw_dsc, label->text, hint);
lv_draw_label(&txt_coords, &txt_clip, &label_draw_dsc, ext->text, hint);
}
/*Draw the text again below the original to make an circular effect */
if(size.y > lv_area_get_height(&txt_coords)) {
label_draw_dsc.ofs_x = label->offset.x;
label_draw_dsc.ofs_y = label->offset.y + size.y + lv_font_get_line_height(label_draw_dsc.font);
label_draw_dsc.ofs_x = ext->offset.x;
label_draw_dsc.ofs_y = ext->offset.y + size.y + lv_font_get_line_height(label_draw_dsc.font);
lv_draw_label(&txt_coords, &txt_clip, &label_draw_dsc, label->text, hint);
lv_draw_label(&txt_coords, &txt_clip, &label_draw_dsc, ext->text, hint);
}
}
} else if(mode == LV_DESIGN_DRAW_POST) {
@ -1308,11 +1300,11 @@ static lv_res_t lv_label_signal(lv_obj_t * obj, lv_signal_t sign, void * param)
lv_res_t res;
/* Include the ancient signal function */
res = lv_label.base_p->signal_cb(obj, sign, param);
res = lv_obj.signal_cb(obj, sign, param);
if(res != LV_RES_OK) return res;
lv_label_t * label = (lv_label_t *) obj;
lv_label_ext_t * ext = obj->ext_attr;
if(sign == LV_SIGNAL_STYLE_CHG) {
/*Revert dots for proper refresh*/
@ -1320,15 +1312,15 @@ static lv_res_t lv_label_signal(lv_obj_t * obj, lv_signal_t sign, void * param)
lv_label_refr_text(obj);
}
else if(sign == LV_SIGNAL_COORD_CHG) {
if(lv_area_get_width(&label->coords) != lv_area_get_width(param) ||
lv_area_get_height(&label->coords) != lv_area_get_height(param)) {
if(lv_area_get_width(&obj->coords) != lv_area_get_width(param) ||
lv_area_get_height(&obj->coords) != lv_area_get_height(param)) {
lv_label_revert_dots(obj);
lv_label_refr_text(obj);
}
}
else if(sign == LV_SIGNAL_BASE_DIR_CHG) {
#if LV_USE_BIDI
if(label->static_txt == 0) lv_label_set_text(label, NULL);
if(ext->static_txt == 0) lv_label_set_text(label, NULL);
#endif
}
@ -1338,38 +1330,38 @@ static lv_res_t lv_label_signal(lv_obj_t * obj, lv_signal_t sign, void * param)
static void lv_label_revert_dots(lv_obj_t * obj)
{
lv_label_t * label = (lv_label_t *) obj;
lv_label_ext_t * ext = obj->ext_attr;
if(label->long_mode != LV_LABEL_LONG_DOT) return;
if(label->dot_end == LV_LABEL_DOT_END_INV) return;
uint32_t letter_i = label->dot_end - LV_LABEL_DOT_NUM;
uint32_t byte_i = _lv_txt_encoded_get_byte_id(label->text, letter_i);
if(ext->long_mode != LV_LABEL_LONG_DOT) return;
if(ext->dot_end == LV_LABEL_DOT_END_INV) return;
uint32_t letter_i = ext->dot_end - LV_LABEL_DOT_NUM;
uint32_t byte_i = _lv_txt_encoded_get_byte_id(ext->text, letter_i);
/*Restore the characters*/
uint8_t i = 0;
char * dot_tmp = lv_label_get_dot_tmp(obj);
while(label->text[byte_i + i] != '\0') {
label->text[byte_i + i] = dot_tmp[i];
while(ext->text[byte_i + i] != '\0') {
ext->text[byte_i + i] = dot_tmp[i];
i++;
}
label->text[byte_i + i] = dot_tmp[i];
ext->text[byte_i + i] = dot_tmp[i];
lv_label_dot_tmp_free(obj);
label->dot_end = LV_LABEL_DOT_END_INV;
ext->dot_end = LV_LABEL_DOT_END_INV;
}
#if LV_USE_ANIMATION
static void lv_label_set_offset_x(lv_obj_t * obj, lv_coord_t x)
{
lv_label_t * label = (lv_label_t *) obj;
label->offset.x = x;
lv_label_ext_t * ext = obj->ext_attr;
ext->offset.x = x;
lv_obj_invalidate(obj);
}
static void lv_label_set_offset_y(lv_obj_t * obj, lv_coord_t y)
{
lv_label_t * label = (lv_label_t *) obj;
label->offset.y = y;
lv_label_ext_t * ext = obj->ext_attr;
ext->offset.y = y;
lv_obj_invalidate(obj);
}
#endif
@ -1384,24 +1376,24 @@ static void lv_label_set_offset_y(lv_obj_t * obj, lv_coord_t y)
static bool lv_label_set_dot_tmp(lv_obj_t * obj, char * data, uint32_t len)
{
lv_label_t * label = (lv_label_t *) obj;
lv_label_ext_t * ext = obj->ext_attr;
lv_label_dot_tmp_free(obj); /* Deallocate any existing space */
if(len > sizeof(char *)) {
/* Memory needs to be allocated. Allocates an additional byte
* for a NULL-terminator so it can be copied. */
label->dot.tmp_ptr = lv_mem_alloc(len + 1);
if(label->dot.tmp_ptr == NULL) {
ext->dot.tmp_ptr = lv_mem_alloc(len + 1);
if(ext->dot.tmp_ptr == NULL) {
LV_LOG_ERROR("Failed to allocate memory for dot_tmp_ptr");
return false;
}
_lv_memcpy(label->dot.tmp_ptr, data, len);
label->dot.tmp_ptr[len] = '\0';
label->dot_tmp_alloc = true;
_lv_memcpy(ext->dot.tmp_ptr, data, len);
ext->dot.tmp_ptr[len] = '\0';
ext->dot_tmp_alloc = true;
}
else {
/* Characters can be directly stored in object */
label->dot_tmp_alloc = false;
_lv_memcpy(label->dot.tmp, data, len);
ext->dot_tmp_alloc = false;
_lv_memcpy(ext->dot.tmp, data, len);
}
return true;
}
@ -1413,12 +1405,12 @@ static bool lv_label_set_dot_tmp(lv_obj_t * obj, char * data, uint32_t len)
*/
static char * lv_label_get_dot_tmp(lv_obj_t * obj)
{
lv_label_t * label = (lv_label_t *) obj;
if(label->dot_tmp_alloc) {
return label->dot.tmp_ptr;
lv_label_ext_t * ext = obj->ext_attr;
if(ext->dot_tmp_alloc) {
return ext->dot.tmp_ptr;
}
else {
return label->dot.tmp;
return ext->dot.tmp;
}
}
@ -1429,12 +1421,12 @@ static char * lv_label_get_dot_tmp(lv_obj_t * obj)
*/
static void lv_label_dot_tmp_free(lv_obj_t * obj)
{
lv_label_t * label = (lv_label_t *) obj;
if(label->dot_tmp_alloc && label->dot.tmp_ptr) {
lv_mem_free(label->dot.tmp_ptr);
lv_label_ext_t * ext = obj->ext_attr;
if(ext->dot_tmp_alloc && ext->dot.tmp_ptr) {
lv_mem_free(ext->dot.tmp_ptr);
}
label->dot_tmp_alloc = false;
label->dot.tmp_ptr = NULL;
ext->dot_tmp_alloc = false;
ext->dot.tmp_ptr = NULL;
}
static void get_txt_coords(const lv_obj_t * obj, lv_area_t * area)

View File

@ -60,54 +60,37 @@ enum {
typedef uint8_t lv_label_align_t;
LV_CLASS_DECLARE_START(lv_label, lv_obj);
#define _lv_label_constructor void (*constructor)(struct _lv_obj_t * obj, struct _lv_obj_t * parent, const struct _lv_obj_t * copy)
typedef struct {
char * text;
union {
char * tmp_ptr; /* Pointer to the allocated memory containing the character replaced by dots*/
char tmp[LV_LABEL_DOT_NUM + 1]; /* Directly store the characters if <=4 characters */
} dot;
uint32_t dot_end; /*The real text length, used in dot mode*/
#if LV_USE_ANIMATION
#define LV_LABEL_ANIM_DATA uint32_t anim_speed;
#else
#define LV_LABEL_ANIM_DATA
uint32_t anim_speed;
#endif
#if LV_LABEL_LONG_TXT_HINT
#define LV_LABEL_HINT_DATA lv_draw_label_hint_t hint;
#else
#define LV_LABEL_HINT_DATA
lv_draw_label_hint_t hint;
#endif
#if LV_LABEL_TEXT_SEL
#define LV_LABEL_TEXT_SEL_DATA uint32_t sel_start; uint32_t sel_end;
#else
#define LV_LABEL_TEXT_SEL_DATA
uint32_t sel_start; uint32_t sel_end;
#endif
lv_point_t offset; /*Text draw position offset*/
lv_label_long_mode_t long_mode : 3; /*Determinate what to do with the long texts*/
uint8_t static_txt : 1; /*Flag to indicate the text is static*/
uint8_t align : 2; /*Align type from 'lv_label_align_t'*/
uint8_t recolor : 1; /*Enable in-line letter re-coloring*/
uint8_t expand : 1; /*Ignore real width (used by the library with LV_LABEL_LONG_SROLL)*/
uint8_t dot_tmp_alloc : 1; /*1: dot_tmp has been allocated;.0: dot_tmp directly holds up to 4 bytes of characters */
}lv_label_ext_t;
#define _lv_label_data \
_lv_obj_data \
char * text; \
union { \
char * tmp_ptr; /* Pointer to the allocated memory containing the character replaced by dots*/ \
char tmp[LV_LABEL_DOT_NUM + 1]; /* Directly store the characters if <=4 characters */ \
} dot; \
uint32_t dot_end; /*The real text length, used in dot mode*/ \
LV_LABEL_ANIM_DATA /*Speed of scroll and roll animation in px/sec unit*/ \
LV_LABEL_HINT_DATA /*Used to buffer info about large text*/ \
LV_LABEL_TEXT_SEL_DATA \
lv_point_t offset; /*Text draw position offset*/ \
lv_label_long_mode_t long_mode : 3; /*Determinate what to do with the long texts*/ \
uint8_t static_txt : 1; /*Flag to indicate the text is static*/ \
uint8_t align : 2; /*Align type from 'lv_label_align_t'*/ \
uint8_t recolor : 1; /*Enable in-line letter re-coloring*/ \
uint8_t expand : 1; /*Ignore real width (used by the library with LV_LABEL_LONG_SROLL)*/ \
uint8_t dot_tmp_alloc : 1; /*1: dot_tmp has been allocated;.0: dot_tmp directly holds up to 4 bytes of characters */ \
#define _lv_label_class_dsc \
_lv_obj_class_dsc
LV_CLASS_DECLARE_END(lv_label, lv_obj);
extern lv_label_class_t lv_label;
extern const lv_obj_class_t lv_label;
/**********************
* GLOBAL PROTOTYPES

View File

@ -236,7 +236,7 @@ static lv_res_t lv_line_signal(lv_obj_t * line, lv_signal_t sign, void * param)
}
else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) {
/*The corner of the skew lines is out of the intended area*/
lv_style_int_t line_width = lv_obj_get_style_line_width(line, LV_LINE_PART_MAIN);
lv_coord_t line_width = lv_obj_get_style_line_width(line, LV_LINE_PART_MAIN);
lv_coord_t * s = param;
if(*s < line_width) *s = line_width;
}
@ -253,7 +253,7 @@ static lv_res_t lv_line_signal(lv_obj_t * line, lv_signal_t sign, void * param)
h = LV_MATH_MAX(ext->point_array[i].y, h);
}
lv_style_int_t line_width = lv_obj_get_style_line_width(line, LV_LINE_PART_MAIN);
lv_coord_t line_width = lv_obj_get_style_line_width(line, LV_LINE_PART_MAIN);
w += line_width;
h += line_width;
p->x = w;

View File

@ -308,9 +308,9 @@ void lv_linemeter_draw_scale(lv_obj_t * lmeter, const lv_area_t * clip_area, uin
{
lv_linemeter_ext_t * ext = lv_obj_get_ext_attr(lmeter);
lv_style_int_t left = lv_obj_get_style_pad_left(lmeter, LV_LINEMETER_PART_MAIN);
lv_style_int_t right = lv_obj_get_style_pad_right(lmeter, LV_LINEMETER_PART_MAIN);
lv_style_int_t top = lv_obj_get_style_pad_top(lmeter, LV_LINEMETER_PART_MAIN);
lv_coord_t left = lv_obj_get_style_pad_left(lmeter, LV_LINEMETER_PART_MAIN);
lv_coord_t right = lv_obj_get_style_pad_right(lmeter, LV_LINEMETER_PART_MAIN);
lv_coord_t top = lv_obj_get_style_pad_top(lmeter, LV_LINEMETER_PART_MAIN);
lv_coord_t r_out = (lv_obj_get_width(lmeter) - left - right) / 2 ;
lv_coord_t r_in = r_out - lv_obj_get_style_scale_width(lmeter, part);
@ -335,7 +335,7 @@ void lv_linemeter_draw_scale(lv_obj_t * lmeter, const lv_area_t * clip_area, uin
line_dsc.raw_end = 1;
#endif
lv_style_int_t end_line_width = lv_obj_get_style_scale_end_line_width(lmeter, part);
lv_coord_t end_line_width = lv_obj_get_style_scale_end_line_width(lmeter, part);
#if LV_LINEMETER_PRECISE > 0
lv_area_t mask_area;
@ -467,8 +467,8 @@ void lv_linemeter_draw_scale(lv_obj_t * lmeter, const lv_area_t * clip_area, uin
#endif
if(part == LV_LINEMETER_PART_MAIN && level < ext->line_cnt - 1) {
lv_style_int_t border_width = lv_obj_get_style_scale_border_width(lmeter, part);
lv_style_int_t end_border_width = lv_obj_get_style_scale_end_border_width(lmeter, part);
lv_coord_t border_width = lv_obj_get_style_scale_border_width(lmeter, part);
lv_coord_t end_border_width = lv_obj_get_style_scale_end_border_width(lmeter, part);
if(border_width || end_border_width) {
int16_t end_angle = ((level) * ext->scale_angle) / (ext->line_cnt - 1) + angle_ofs;

View File

@ -30,20 +30,25 @@
/**********************
* STATIC PROTOTYPES
**********************/
static void lv_table_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy);
static void lv_table_destructor(lv_obj_t * obj);
static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_area, lv_design_mode_t mode);
static lv_res_t lv_table_signal(lv_obj_t * table, lv_signal_t sign, void * param);
static lv_style_list_t * lv_table_get_style(lv_obj_t * table, uint8_t part);
static lv_coord_t get_row_height(lv_obj_t * table, uint16_t row_id, const lv_font_t ** font,
lv_style_int_t * letter_space, lv_style_int_t * line_space,
lv_style_int_t * cell_left, lv_style_int_t * cell_right, lv_style_int_t * cell_top, lv_style_int_t * cell_bottom);
static lv_coord_t get_row_height(lv_obj_t * table, uint16_t row_id, const lv_font_t * font,
lv_coord_t letter_space, lv_coord_t line_space,
lv_coord_t cell_left, lv_coord_t cell_right, lv_coord_t cell_top, lv_coord_t cell_bottom);
static void refr_size(lv_obj_t * table);
/**********************
* STATIC VARIABLES
**********************/
static lv_signal_cb_t ancestor_signal;
static lv_design_cb_t ancestor_design;
const lv_obj_class_t lv_table = {
.constructor = lv_table_constructor,
.destructor = lv_table_destructor,
.signal_cb = lv_table_signal,
.design_cb = lv_table_design,
.ext_size = sizeof(lv_table_ext_t),
};
/**********************
* MACROS
**********************/
@ -58,74 +63,9 @@ static lv_design_cb_t ancestor_design;
* @param copy pointer to a table object, if not NULL then the new object will be copied from it
* @return pointer to the created table
*/
lv_obj_t * lv_table_create(lv_obj_t * par, const lv_obj_t * copy)
lv_obj_t * lv_table_create(lv_obj_t * parent, const lv_obj_t * copy)
{
LV_LOG_TRACE("table create started");
/*Create the ancestor of table*/
lv_obj_t * table = lv_obj_create(par, copy);
LV_ASSERT_MEM(table);
if(table == NULL) return NULL;
/*Allocate the table type specific extended data*/
lv_table_ext_t * ext = lv_obj_allocate_ext_attr(table, sizeof(lv_table_ext_t));
LV_ASSERT_MEM(ext);
if(ext == NULL) {
lv_obj_del(table);
return NULL;
}
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(table);
if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_cb(table);
/*Initialize the allocated 'ext' */
ext->cell_data = NULL;
ext->col_cnt = 0;
ext->row_cnt = 0;
ext->row_h = NULL;
ext->col_w = NULL;
ext->cell_types = 1;
uint16_t i;
for(i = 0; i < LV_TABLE_CELL_STYLE_CNT; i++) {
lv_style_list_init(&ext->cell_style[i]);
}
/*The signal and design functions are not copied so set them here*/
lv_obj_set_signal_cb(table, lv_table_signal);
lv_obj_set_design_cb(table, lv_table_design);
/*Init the new table table*/
if(copy == NULL) {
ext->col_cnt = 1;
ext->row_cnt = 1;
ext->col_w = lv_mem_alloc(ext->col_cnt * sizeof(ext->col_w[0]));
ext->row_h = lv_mem_alloc(ext->row_cnt * sizeof(ext->row_h[0]));
ext->col_w[0] = LV_DPI;
ext->row_h[0] = LV_DPI; /*It will be overwritten when the theme is applied*/
ext->cell_data = lv_mem_realloc(ext->cell_data, ext->row_cnt * ext->col_cnt * sizeof(char *));
ext->cell_data[0] = NULL;
lv_obj_set_size(table, LV_SIZE_AUTO, LV_SIZE_AUTO);
lv_theme_apply(table, LV_THEME_TABLE);
}
/*Copy an existing table*/
else {
lv_table_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
for(i = 0; i < LV_TABLE_CELL_STYLE_CNT; i++) {
lv_style_list_copy(&ext->cell_style[i], &copy_ext->cell_style[i]);
}
lv_table_set_row_cnt(table, copy_ext->row_cnt);
lv_table_set_col_cnt(table, copy_ext->col_cnt);
/*Refresh the style with new signal function*/
_lv_obj_refresh_style(table, LV_OBJ_PART_ALL, LV_STYLE_PROP_ALL);
}
LV_LOG_INFO("table created");
return table;
return lv_obj_create_from_class(&lv_table, parent, copy);
}
/*=====================
@ -145,7 +85,7 @@ void lv_table_set_cell_value(lv_obj_t * table, uint16_t row, uint16_t col, const
LV_ASSERT_OBJ(table, LV_OBJX_NAME);
LV_ASSERT_NULL(txt);
lv_table_ext_t * ext = lv_obj_get_ext_attr(table);
lv_table_ext_t * ext = table->ext_attr;
/*Auto expand*/
if(col >= ext->col_cnt) lv_table_set_col_cnt(table, col + 1);
@ -170,7 +110,6 @@ void lv_table_set_cell_value(lv_obj_t * table, uint16_t row, uint16_t col, const
format.s.align = LV_LABEL_ALIGN_LEFT;
#endif
format.s.right_merge = 0;
format.s.type = 0;
format.s.crop = 0;
}
@ -207,7 +146,7 @@ void lv_table_set_cell_value_fmt(lv_obj_t * table, uint16_t row, uint16_t col, c
LV_ASSERT_OBJ(table, LV_OBJX_NAME);
LV_ASSERT_STR(fmt);
lv_table_ext_t * ext = lv_obj_get_ext_attr(table);
lv_table_ext_t * ext = table->ext_attr;
if(col >= ext->col_cnt) {
LV_LOG_WARN("lv_table_set_cell_value: invalid column");
return;
@ -237,7 +176,6 @@ void lv_table_set_cell_value_fmt(lv_obj_t * table, uint16_t row, uint16_t col, c
format.s.align = LV_LABEL_ALIGN_LEFT;
#endif
format.s.right_merge = 0;
format.s.type = 0;
format.s.crop = 0;
}
@ -299,7 +237,7 @@ void lv_table_set_row_cnt(lv_obj_t * table, uint16_t row_cnt)
{
LV_ASSERT_OBJ(table, LV_OBJX_NAME);
lv_table_ext_t * ext = lv_obj_get_ext_attr(table);
lv_table_ext_t * ext = table->ext_attr;
uint16_t old_row_cnt = ext->row_cnt;
ext->row_cnt = row_cnt;
@ -330,7 +268,7 @@ void lv_table_set_col_cnt(lv_obj_t * table, uint16_t col_cnt)
{
LV_ASSERT_OBJ(table, LV_OBJX_NAME);
lv_table_ext_t * ext = lv_obj_get_ext_attr(table);
lv_table_ext_t * ext = table->ext_attr;
uint16_t old_col_cnt = ext->col_cnt;
ext->col_cnt = col_cnt;
ext->col_w = lv_mem_realloc(ext->col_w, col_cnt * sizeof(ext->row_h[0]));
@ -366,7 +304,7 @@ void lv_table_set_col_width(lv_obj_t * table, uint16_t col_id, lv_coord_t w)
{
LV_ASSERT_OBJ(table, LV_OBJX_NAME);
lv_table_ext_t * ext = lv_obj_get_ext_attr(table);
lv_table_ext_t * ext = table->ext_attr;
/*Auto expand*/
if(col_id >= ext->col_cnt) lv_table_set_col_cnt(table, col_id + 1);
@ -386,7 +324,7 @@ void lv_table_set_cell_align(lv_obj_t * table, uint16_t row, uint16_t col, lv_la
{
LV_ASSERT_OBJ(table, LV_OBJX_NAME);
lv_table_ext_t * ext = lv_obj_get_ext_attr(table);
lv_table_ext_t * ext = table->ext_attr;
/*Auto expand*/
if(col >= ext->col_cnt) lv_table_set_col_cnt(table, col + 1);
@ -409,47 +347,6 @@ void lv_table_set_cell_align(lv_obj_t * table, uint16_t row, uint16_t col, lv_la
ext->cell_data[cell][0] = format.format_byte;
}
/**
* Set the type of a cell.
* @param table pointer to a Table object
* @param row id of the row [0 .. row_cnt -1]
* @param col id of the column [0 .. col_cnt -1]
* @param type 1,2,3 or 4. The cell style will be chosen accordingly.
*/
void lv_table_set_cell_type(lv_obj_t * table, uint16_t row, uint16_t col, uint8_t type)
{
LV_ASSERT_OBJ(table, LV_OBJX_NAME);
lv_table_ext_t * ext = lv_obj_get_ext_attr(table);
/*Auto expand*/
if(col >= ext->col_cnt) lv_table_set_col_cnt(table, col + 1);
if(row >= ext->row_cnt) lv_table_set_row_cnt(table, row + 1);
uint32_t cell = row * ext->col_cnt + col;
if(ext->cell_data[cell] == NULL) {
ext->cell_data[cell] = lv_mem_alloc(2); /*+1: trailing '\0; +1: format byte*/
LV_ASSERT_MEM(ext->cell_data[cell]);
if(ext->cell_data[cell] == NULL) return;
ext->cell_data[cell][0] = 0;
ext->cell_data[cell][1] = '\0';
}
if(type > 0) type--; /*User gives 1,2,3,4 but easier to handle 0, 1, 2, 3*/
if(type >= LV_TABLE_CELL_STYLE_CNT) type = LV_TABLE_CELL_STYLE_CNT - 1;
lv_table_cell_format_t format;
format.format_byte = ext->cell_data[cell][0];
format.s.type = type;
ext->cell_data[cell][0] = format.format_byte;
ext->cell_types |= 1 << type;
lv_obj_invalidate(table);
}
/**
* Set the cell crop. (Don't adjust the height of the cell according to its content)
* @param table pointer to a Table object
@ -461,7 +358,7 @@ void lv_table_set_cell_crop(lv_obj_t * table, uint16_t row, uint16_t col, bool c
{
LV_ASSERT_OBJ(table, LV_OBJX_NAME);
lv_table_ext_t * ext = lv_obj_get_ext_attr(table);
lv_table_ext_t * ext = table->ext_attr;
/*Auto expand*/
if(col >= ext->col_cnt) lv_table_set_col_cnt(table, col + 1);
@ -495,7 +392,7 @@ void lv_table_set_cell_merge_right(lv_obj_t * table, uint16_t row, uint16_t col,
{
LV_ASSERT_OBJ(table, LV_OBJX_NAME);
lv_table_ext_t * ext = lv_obj_get_ext_attr(table);
lv_table_ext_t * ext = table->ext_attr;
/*Auto expand*/
if(col >= ext->col_cnt) lv_table_set_col_cnt(table, col + 1);
@ -519,6 +416,15 @@ void lv_table_set_cell_merge_right(lv_obj_t * table, uint16_t row, uint16_t col,
refr_size(table);
}
void lv_table_set_cell_drawer(lv_obj_t * obj, lv_table_cell_drawer_cb_t drawer_cb)
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_table_ext_t * ext = obj->ext_attr;
ext->drawer_cb = drawer_cb;
lv_obj_invalidate(obj);
}
/*=====================
* Getter functions
*====================*/
@ -534,7 +440,7 @@ const char * lv_table_get_cell_value(lv_obj_t * table, uint16_t row, uint16_t co
{
LV_ASSERT_OBJ(table, LV_OBJX_NAME);
lv_table_ext_t * ext = lv_obj_get_ext_attr(table);
lv_table_ext_t * ext = table->ext_attr;
if(row >= ext->row_cnt || col >= ext->col_cnt) {
LV_LOG_WARN("lv_table_set_cell_value: invalid row or column");
return "";
@ -555,7 +461,7 @@ uint16_t lv_table_get_row_cnt(lv_obj_t * table)
{
LV_ASSERT_OBJ(table, LV_OBJX_NAME);
lv_table_ext_t * ext = lv_obj_get_ext_attr(table);
lv_table_ext_t * ext = table->ext_attr;
return ext->row_cnt;
}
@ -568,7 +474,7 @@ uint16_t lv_table_get_col_cnt(lv_obj_t * table)
{
LV_ASSERT_OBJ(table, LV_OBJX_NAME);
lv_table_ext_t * ext = lv_obj_get_ext_attr(table);
lv_table_ext_t * ext = table->ext_attr;
return ext->col_cnt;
}
@ -582,7 +488,7 @@ lv_coord_t lv_table_get_col_width(lv_obj_t * table, uint16_t col_id)
{
LV_ASSERT_OBJ(table, LV_OBJX_NAME);
lv_table_ext_t * ext = lv_obj_get_ext_attr(table);
lv_table_ext_t * ext = table->ext_attr;
if(col_id >= ext->col_cnt) {
LV_LOG_WARN("lv_table_set_col_width: too big 'col_id'. Must be < LV_TABLE_COL_MAX.");
@ -604,7 +510,7 @@ lv_label_align_t lv_table_get_cell_align(lv_obj_t * table, uint16_t row, uint16_
{
LV_ASSERT_OBJ(table, LV_OBJX_NAME);
lv_table_ext_t * ext = lv_obj_get_ext_attr(table);
lv_table_ext_t * ext = table->ext_attr;
if(row >= ext->row_cnt || col >= ext->col_cnt) {
LV_LOG_WARN("lv_table_set_cell_align: invalid row or column");
return LV_LABEL_ALIGN_LEFT; /*Just return with something*/
@ -620,33 +526,6 @@ lv_label_align_t lv_table_get_cell_align(lv_obj_t * table, uint16_t row, uint16_
}
}
/**
* Get the type of a cell
* @param table pointer to a Table object
* @param row id of the row [0 .. row_cnt -1]
* @param col id of the column [0 .. col_cnt -1]
* @return 1,2,3 or 4
*/
lv_label_align_t lv_table_get_cell_type(lv_obj_t * table, uint16_t row, uint16_t col)
{
LV_ASSERT_OBJ(table, LV_OBJX_NAME);
lv_table_ext_t * ext = lv_obj_get_ext_attr(table);
if(row >= ext->row_cnt || col >= ext->col_cnt) {
LV_LOG_WARN("lv_table_get_cell_type: invalid row or column");
return 1; /*Just return with something*/
}
uint32_t cell = row * ext->col_cnt + col;
if(ext->cell_data[cell] == NULL)
return 1; /*Just return with something*/
else {
lv_table_cell_format_t format;
format.format_byte = ext->cell_data[cell][0];
return format.s.type + 1; /*0,1,2,3 is stored but user sees 1,2,3,4*/
}
}
/**
* Get the crop property of a cell
* @param table pointer to a Table object
@ -658,7 +537,7 @@ lv_label_align_t lv_table_get_cell_crop(lv_obj_t * table, uint16_t row, uint16_t
{
LV_ASSERT_OBJ(table, LV_OBJX_NAME);
lv_table_ext_t * ext = lv_obj_get_ext_attr(table);
lv_table_ext_t * ext = table->ext_attr;
if(row >= ext->row_cnt || col >= ext->col_cnt) {
LV_LOG_WARN("lv_table_get_cell_crop: invalid row or column");
return false; /*Just return with something*/
@ -685,7 +564,7 @@ bool lv_table_get_cell_merge_right(lv_obj_t * table, uint16_t row, uint16_t col)
{
LV_ASSERT_OBJ(table, LV_OBJX_NAME);
lv_table_ext_t * ext = lv_obj_get_ext_attr(table);
lv_table_ext_t * ext = table->ext_attr;
if(row >= ext->row_cnt || col >= ext->col_cnt) {
LV_LOG_WARN("lv_table_get_cell_merge_right: invalid row or column");
return false;
@ -711,7 +590,7 @@ bool lv_table_get_cell_merge_right(lv_obj_t * table, uint16_t row, uint16_t col)
*/
lv_res_t lv_table_get_pressed_cell(lv_obj_t * table, uint16_t * row, uint16_t * col)
{
lv_table_ext_t * ext = lv_obj_get_ext_attr(table);
lv_table_ext_t * ext = table->ext_attr;
lv_indev_type_t type = lv_indev_get_type(lv_indev_get_act());
if(type != LV_INDEV_TYPE_POINTER && type != LV_INDEV_TYPE_BUTTON) {
@ -727,7 +606,7 @@ lv_res_t lv_table_get_pressed_cell(lv_obj_t * table, uint16_t * row, uint16_t *
if(col) {
lv_coord_t x = p.x;
x -= table->coords.x1;
x -= lv_obj_get_style_pad_left(table, LV_TABLE_PART_BG);
x -= lv_obj_get_style_pad_left(table, LV_PART_MAIN);
*col = 0;
tmp = 0;
for(*col = 0; *col < ext->col_cnt; (*col)++) {
@ -739,7 +618,7 @@ lv_res_t lv_table_get_pressed_cell(lv_obj_t * table, uint16_t * row, uint16_t *
if(row) {
lv_coord_t y = p.y;
y -= table->coords.y1;
y -= lv_obj_get_style_pad_top(table, LV_TABLE_PART_BG);
y -= lv_obj_get_style_pad_top(table, LV_PART_MAIN);
*row = 0;
tmp = 0;
@ -757,6 +636,64 @@ lv_res_t lv_table_get_pressed_cell(lv_obj_t * table, uint16_t * row, uint16_t *
* STATIC FUNCTIONS
**********************/
static void lv_table_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy)
{
LV_LOG_TRACE("lv_table create started");
LV_CLASS_CONSTRUCTOR_BEGIN(obj, lv_table)
lv_obj.constructor(obj, parent, copy);
lv_table_ext_t * ext = obj->ext_attr;
/*Initialize the allocated 'ext' */
ext->cell_data = NULL;
ext->col_cnt = 0;
ext->row_cnt = 0;
ext->row_h = NULL;
ext->col_w = NULL;
/*Init the new table table*/
if(copy == NULL) {
ext->col_cnt = 1;
ext->row_cnt = 1;
ext->col_w = lv_mem_alloc(ext->col_cnt * sizeof(ext->col_w[0]));
ext->row_h = lv_mem_alloc(ext->row_cnt * sizeof(ext->row_h[0]));
ext->col_w[0] = LV_DPI;
ext->row_h[0] = LV_DPI; /*It will be overwritten when the theme is applied*/
ext->cell_data = lv_mem_realloc(ext->cell_data, ext->row_cnt * ext->col_cnt * sizeof(char *));
ext->cell_data[0] = NULL;
lv_obj_set_size(obj, LV_SIZE_AUTO, LV_SIZE_AUTO);
}
/*Copy an existing table*/
else {
lv_table_ext_t * copy_ext = copy->ext_attr;
lv_table_set_row_cnt(obj, copy_ext->row_cnt);
lv_table_set_col_cnt(obj, copy_ext->col_cnt);
}
LV_CLASS_CONSTRUCTOR_END(obj, lv_table)
LV_LOG_INFO("table created");
}
static void lv_table_destructor(lv_obj_t * obj)
{
// /*Free the cell texts*/
// uint16_t i;
// for(i = 0; i < ext->col_cnt * ext->row_cnt; i++) {
// if(ext->cell_data[i]) {
// lv_mem_free(ext->cell_data[i]);
// ext->cell_data[i] = NULL;
// }
// }
//
// if(ext->cell_data) lv_mem_free(ext->cell_data);
// if(ext->row_h) lv_mem_free(ext->row_h);
//
// for(i = 0; i < LV_TABLE_CELL_STYLE_CNT; i++) {
// _lv_obj_reset_style_list_no_refr(table, LV_TABLE_PART_CELL1 + i);
// }
}
/**
* Handle the drawing related tasks of the tables
* @param table pointer to an object
@ -771,50 +708,39 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_
{
/*Return false if the object is not covers the mask_p area*/
if(mode == LV_DESIGN_COVER_CHK) {
return ancestor_design(table, clip_area, mode);
return lv_obj.design_cb(table, clip_area, mode);
}
/*Draw the object*/
else if(mode == LV_DESIGN_DRAW_MAIN) {
/*Draw the background*/
ancestor_design(table, clip_area, mode);
lv_obj.design_cb(table, clip_area, mode);
lv_table_ext_t * ext = lv_obj_get_ext_attr(table);
lv_table_ext_t * ext = table->ext_attr;
lv_point_t txt_size;
lv_area_t cell_area;
lv_area_t txt_area;
lv_txt_flag_t txt_flags;
lv_style_int_t bg_top = lv_obj_get_style_pad_top(table, LV_TABLE_PART_BG);
lv_style_int_t bg_bottom = lv_obj_get_style_pad_bottom(table, LV_TABLE_PART_BG);
lv_style_int_t bg_left = lv_obj_get_style_pad_left(table, LV_TABLE_PART_BG);
lv_style_int_t bg_right = lv_obj_get_style_pad_right(table, LV_TABLE_PART_BG);
lv_coord_t bg_top = lv_obj_get_style_pad_top(table, LV_PART_MAIN);
lv_coord_t bg_bottom = lv_obj_get_style_pad_bottom(table, LV_PART_MAIN);
lv_coord_t bg_left = lv_obj_get_style_pad_left(table, LV_PART_MAIN);
lv_coord_t bg_right = lv_obj_get_style_pad_right(table, LV_PART_MAIN);
lv_draw_rect_dsc_t rect_dsc[LV_TABLE_CELL_STYLE_CNT];
lv_draw_label_dsc_t label_dsc[LV_TABLE_CELL_STYLE_CNT];
lv_draw_line_dsc_t line_dsc[LV_TABLE_CELL_STYLE_CNT];
lv_style_int_t cell_left[LV_TABLE_CELL_STYLE_CNT];
lv_style_int_t cell_right[LV_TABLE_CELL_STYLE_CNT];
lv_style_int_t cell_top[LV_TABLE_CELL_STYLE_CNT];
lv_style_int_t cell_bottom[LV_TABLE_CELL_STYLE_CNT];
lv_coord_t cell_left = lv_obj_get_style_pad_left(table, LV_PART_ITEM);
lv_coord_t cell_right = lv_obj_get_style_pad_right(table, LV_PART_ITEM);
lv_coord_t cell_top = lv_obj_get_style_pad_top(table, LV_PART_ITEM);
lv_coord_t cell_bottom = lv_obj_get_style_pad_bottom(table, LV_PART_ITEM);
uint16_t i;
for(i = 0; i < LV_TABLE_CELL_STYLE_CNT; i++) {
if((ext->cell_types & (1 << i)) == 0) continue; /*Skip unused cell types*/
lv_draw_rect_dsc_init(&rect_dsc[i]);
lv_obj_init_draw_rect_dsc(table, LV_TABLE_PART_CELL1 + i, &rect_dsc[i]);
lv_draw_rect_dsc_t rect_dsc_base;
lv_draw_rect_dsc_t rect_dsc_drawer; /*Passed to the drawer_cb to modify it*/
lv_draw_rect_dsc_init(&rect_dsc_base);
lv_obj_init_draw_rect_dsc(table, LV_PART_ITEM, &rect_dsc_base);
lv_draw_label_dsc_init(&label_dsc[i]);
lv_obj_init_draw_label_dsc(table, LV_TABLE_PART_CELL1 + i, &label_dsc[i]);
lv_draw_line_dsc_init(&line_dsc[i]);
lv_obj_init_draw_line_dsc(table, LV_TABLE_PART_CELL1 + i, &line_dsc[i]);
cell_left[i] = lv_obj_get_style_pad_left(table, LV_TABLE_PART_CELL1 + i);
cell_right[i] = lv_obj_get_style_pad_right(table, LV_TABLE_PART_CELL1 + i);
cell_top[i] = lv_obj_get_style_pad_top(table, LV_TABLE_PART_CELL1 + i);
cell_bottom[i] = lv_obj_get_style_pad_bottom(table, LV_TABLE_PART_CELL1 + i);
}
lv_draw_label_dsc_t label_dsc_base;
lv_draw_label_dsc_t label_dsc_drawer; /*Passed to the drawer_cb to modify it*/
lv_draw_label_dsc_init(&label_dsc_base);
lv_obj_init_draw_label_dsc(table, LV_PART_ITEM, &label_dsc_base);
uint16_t col;
uint16_t row;
@ -836,7 +762,6 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_
else cell_area.x2 = table->coords.x1 + bg_left - 1 - scroll_x;
for(col = 0; col < ext->col_cnt; col++) {
lv_table_cell_format_t format;
if(ext->cell_data[cell]) {
format.format_byte = ext->cell_data[cell][0];
@ -844,7 +769,6 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_
else {
format.s.right_merge = 0;
format.s.align = LV_LABEL_ALIGN_LEFT;
format.s.type = 0;
format.s.crop = 1;
}
@ -859,13 +783,14 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_
uint16_t col_merge = 0;
for(col_merge = 0; col_merge + col < ext->col_cnt - 1; col_merge++) {
if(ext->cell_data[cell + col_merge] != NULL) {
if(ext->cell_data[cell + col_merge]) {
format.format_byte = ext->cell_data[cell + col_merge][0];
if(format.s.right_merge)
if(rtl) cell_area.x1 -= ext->col_w[col + col_merge + 1];
else cell_area.x2 += ext->col_w[col + col_merge + 1];
else
else {
break;
}
}
else {
break;
@ -878,46 +803,53 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_
continue;
}
uint8_t cell_type = format.s.type;
/*Expand the cell area with a half border to avoid drawing 2 borders next to each other*/
lv_area_t cell_area_border;
lv_area_copy(&cell_area_border, &cell_area);
if((rect_dsc[cell_type].border_side & LV_BORDER_SIDE_LEFT) && cell_area_border.x1 > table->coords.x1 + bg_left) {
cell_area_border.x1 -= rect_dsc[cell_type].border_width / 2;
if((rect_dsc_base.border_side & LV_BORDER_SIDE_LEFT) && cell_area_border.x1 > table->coords.x1 + bg_left) {
cell_area_border.x1 -= rect_dsc_base.border_width / 2;
}
if((rect_dsc[cell_type].border_side & LV_BORDER_SIDE_TOP) && cell_area_border.y1 > table->coords.y1 + bg_top) {
cell_area_border.y1 -= rect_dsc[cell_type].border_width / 2;
if((rect_dsc_base.border_side & LV_BORDER_SIDE_TOP) && cell_area_border.y1 > table->coords.y1 + bg_top) {
cell_area_border.y1 -= rect_dsc_base.border_width / 2;
}
if((rect_dsc[cell_type].border_side & LV_BORDER_SIDE_RIGHT) && cell_area_border.x2 < table->coords.x2 - bg_right - 1) {
cell_area_border.x2 += rect_dsc[cell_type].border_width / 2 + (rect_dsc[cell_type].border_width & 0x1);
if((rect_dsc_base.border_side & LV_BORDER_SIDE_RIGHT) && cell_area_border.x2 < table->coords.x2 - bg_right - 1) {
cell_area_border.x2 += rect_dsc_base.border_width / 2 + (rect_dsc_base.border_width & 0x1);
}
if((rect_dsc[cell_type].border_side & LV_BORDER_SIDE_BOTTOM) &&
if((rect_dsc_base.border_side & LV_BORDER_SIDE_BOTTOM) &&
cell_area_border.y2 < table->coords.y2 - bg_bottom - 1) {
cell_area_border.y2 += rect_dsc[cell_type].border_width / 2 + (rect_dsc[cell_type].border_width & 0x1);
cell_area_border.y2 += rect_dsc_base.border_width / 2 + (rect_dsc_base.border_width & 0x1);
}
lv_draw_rect(&cell_area_border, clip_area, &rect_dsc[cell_type]);
lv_draw_rect_dsc_t * rect_dsc_act = &rect_dsc_base;
lv_draw_label_dsc_t * label_dsc_act = &label_dsc_base;
if(ext->drawer_cb) {
_lv_memcpy(&rect_dsc_drawer, &rect_dsc_base, sizeof(lv_draw_rect_dsc_t));
_lv_memcpy(&label_dsc_drawer, &label_dsc_base, sizeof(lv_draw_label_dsc_t));
bool drawn = ext->drawer_cb(table, row, col, &rect_dsc_drawer, &label_dsc_drawer, &cell_area_border, clip_area);
if(drawn) continue;
rect_dsc_act = &rect_dsc_drawer;
label_dsc_act = &label_dsc_drawer;
}
lv_draw_rect(&cell_area_border, clip_area, rect_dsc_act);
if(ext->cell_data[cell]) {
txt_area.x1 = cell_area.x1 + cell_left[cell_type];
txt_area.x2 = cell_area.x2 - cell_right[cell_type];
txt_area.y1 = cell_area.y1 + cell_top[cell_type];
txt_area.y2 = cell_area.y2 - cell_bottom[cell_type];
txt_area.x1 = cell_area.x1 + cell_left;
txt_area.x2 = cell_area.x2 - cell_right;
txt_area.y1 = cell_area.y1 + cell_top;
txt_area.y2 = cell_area.y2 - cell_bottom;
/*Align the content to the middle if not cropped*/
if(format.s.crop == 0) {
txt_flags = LV_TXT_FLAG_NONE;
}
else {
txt_flags = LV_TXT_FLAG_EXPAND;
}
if(format.s.crop == 0) txt_flags = LV_TXT_FLAG_NONE;
else txt_flags = LV_TXT_FLAG_EXPAND;
_lv_txt_get_size(&txt_size, ext->cell_data[cell] + 1, label_dsc[cell_type].font,
label_dsc[cell_type].letter_space, label_dsc[cell_type].line_space,
_lv_txt_get_size(&txt_size, ext->cell_data[cell] + 1, label_dsc_base.font,
label_dsc_base.letter_space, label_dsc_base.line_space,
lv_area_get_width(&txt_area), txt_flags);
label_dsc[cell_type].flag = 0;
label_dsc_base.flag = 0;
/*Align the content to the middle if not cropped*/
if(format.s.crop == 0) {
txt_area.y1 = cell_area.y1 + h_row / 2 - txt_size.y / 2;
@ -927,13 +859,13 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_
switch(format.s.align) {
default:
case LV_LABEL_ALIGN_LEFT:
label_dsc[cell_type].flag |= LV_TXT_FLAG_NONE;
label_dsc_base.flag |= LV_TXT_FLAG_NONE;
break;
case LV_LABEL_ALIGN_RIGHT:
label_dsc[cell_type].flag |= LV_TXT_FLAG_RIGHT;
label_dsc_base.flag |= LV_TXT_FLAG_RIGHT;
break;
case LV_LABEL_ALIGN_CENTER:
label_dsc[cell_type].flag |= LV_TXT_FLAG_CENTER;
label_dsc_base.flag |= LV_TXT_FLAG_CENTER;
break;
}
@ -941,27 +873,7 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_
bool label_mask_ok;
label_mask_ok = _lv_area_intersect(&label_mask, clip_area, &cell_area);
if(label_mask_ok) {
lv_draw_label(&txt_area, &label_mask, &label_dsc[cell_type], ext->cell_data[cell] + 1, NULL);
}
/*Draw lines after '\n's*/
lv_point_t p1;
lv_point_t p2;
p1.x = cell_area.x1;
p2.x = cell_area.x2;
for(i = 1; ext->cell_data[cell][i] != '\0'; i++) {
if(ext->cell_data[cell][i] == '\n') {
ext->cell_data[cell][i] = '\0';
_lv_txt_get_size(&txt_size, ext->cell_data[cell] + 1, label_dsc[cell_type].font,
label_dsc[cell_type].letter_space, label_dsc[cell_type].line_space,
lv_area_get_width(&txt_area), txt_flags);
p1.y = txt_area.y1 + txt_size.y + label_dsc[cell_type].line_space / 2;
p2.y = txt_area.y1 + txt_size.y + label_dsc[cell_type].line_space / 2;
lv_draw_line(&p1, &p2, clip_area, &line_dsc[cell_type]);
ext->cell_data[cell][i] = '\n';
}
lv_draw_label(&txt_area, &label_mask, label_dsc_act, ext->cell_data[cell] + 1, NULL);
}
}
@ -972,7 +884,7 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_
}
/*Post draw when the children are drawn*/
else if(mode == LV_DESIGN_DRAW_POST) {
ancestor_design(table, clip_area, mode);
lv_obj.design_cb(table, clip_area, mode);
}
return LV_DESIGN_RES_OK;
@ -985,44 +897,18 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_
* @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_table_signal(lv_obj_t * table, lv_signal_t sign, void * param)
static lv_res_t lv_table_signal(lv_obj_t * obj, lv_signal_t sign, void * param)
{
lv_res_t res;
/* Include the ancient signal function */
res = ancestor_signal(table, sign, param);
res = lv_obj.signal_cb(obj, sign, param);
if(res != LV_RES_OK) return res;
lv_table_ext_t * ext = lv_obj_get_ext_attr(table);
lv_table_ext_t * ext = obj->ext_attr;
if(sign == LV_SIGNAL_GET_TYPE) {
return _lv_obj_handle_get_type_signal(param, LV_OBJX_NAME);
}
else if(sign == LV_SIGNAL_GET_STYLE) {
lv_get_style_info_t * info = param;
info->result = lv_table_get_style(table, info->part);
if(info->result != NULL) return LV_RES_OK;
else return ancestor_signal(table, sign, param);
}
else if(sign == LV_SIGNAL_CLEANUP) {
/*Free the cell texts*/
uint16_t i;
for(i = 0; i < ext->col_cnt * ext->row_cnt; i++) {
if(ext->cell_data[i]) {
lv_mem_free(ext->cell_data[i]);
ext->cell_data[i] = NULL;
}
}
if(ext->cell_data) lv_mem_free(ext->cell_data);
if(ext->row_h) lv_mem_free(ext->row_h);
for(i = 0; i < LV_TABLE_CELL_STYLE_CNT; i++) {
_lv_obj_reset_style_list_no_refr(table, LV_TABLE_PART_CELL1 + i);
}
}
else if(sign == LV_SIGNAL_STYLE_CHG) {
refr_size(table);
if(sign == LV_SIGNAL_STYLE_CHG) {
refr_size(obj);
}
else if(sign == LV_SIGNAL_GET_SELF_SIZE) {
lv_point_t * p = param;
@ -1041,55 +927,20 @@ static lv_res_t lv_table_signal(lv_obj_t * table, lv_signal_t sign, void * param
}
/**
* Get the style descriptor of a part of the object
* @param table pointer the object
* @param part the part from. (LV_TABLE_PART_...)
* @return pointer to the style descriptor of the specified part
*/
static lv_style_list_t * lv_table_get_style(lv_obj_t * table, uint8_t part)
{
LV_ASSERT_OBJ(table, LV_OBJX_NAME);
lv_table_ext_t * ext = lv_obj_get_ext_attr(table);
/* Because of the presence of LV_TABLE_PART_BG, LV_TABLE_PART_CELL<i> has an integer value
of <i>. This comes in useful to extend above code with more cell types as follows */
if(part == LV_TABLE_PART_BG) {
return &table->style_list;
}
else if(part >= 1 && part <= LV_TABLE_CELL_STYLE_CNT) {
return &ext->cell_style[part - 1];
}
return NULL;
}
static void refr_size(lv_obj_t * table)
{
lv_table_ext_t * ext = lv_obj_get_ext_attr(table);
lv_table_ext_t * ext = table->ext_attr;
uint32_t i;
lv_style_int_t cell_left[LV_TABLE_CELL_STYLE_CNT];
lv_style_int_t cell_right[LV_TABLE_CELL_STYLE_CNT];
lv_style_int_t cell_top[LV_TABLE_CELL_STYLE_CNT];
lv_style_int_t cell_bottom[LV_TABLE_CELL_STYLE_CNT];
lv_style_int_t letter_space[LV_TABLE_CELL_STYLE_CNT];
lv_style_int_t line_space[LV_TABLE_CELL_STYLE_CNT];
const lv_font_t * font[LV_TABLE_CELL_STYLE_CNT];
for(i = 0; i < LV_TABLE_CELL_STYLE_CNT; i++) {
if((ext->cell_types & (1 << i)) == 0) continue; /*Skip unused cell types*/
cell_left[i] = lv_obj_get_style_pad_left(table, LV_TABLE_PART_CELL1 + i);
cell_right[i] = lv_obj_get_style_pad_right(table, LV_TABLE_PART_CELL1 + i);
cell_top[i] = lv_obj_get_style_pad_top(table, LV_TABLE_PART_CELL1 + i);
cell_bottom[i] = lv_obj_get_style_pad_bottom(table, LV_TABLE_PART_CELL1 + i);
letter_space[i] = lv_obj_get_style_text_letter_space(table, LV_TABLE_PART_CELL1 + i);
line_space[i] = lv_obj_get_style_text_line_space(table, LV_TABLE_PART_CELL1 + i);
font[i] = lv_obj_get_style_text_font(table, LV_TABLE_PART_CELL1 + i);
}
lv_coord_t cell_left = lv_obj_get_style_pad_left(table, LV_PART_ITEM);
lv_coord_t cell_right = lv_obj_get_style_pad_right(table, LV_PART_ITEM);
lv_coord_t cell_top = lv_obj_get_style_pad_top(table, LV_PART_ITEM);
lv_coord_t cell_bottom = lv_obj_get_style_pad_bottom(table, LV_PART_ITEM);
lv_coord_t letter_space = lv_obj_get_style_text_letter_space(table, LV_PART_ITEM);
lv_coord_t line_space = lv_obj_get_style_text_line_space(table, LV_PART_ITEM);
const lv_font_t * font = lv_obj_get_style_text_font(table, LV_PART_ITEM);
for(i = 0; i < ext->row_cnt; i++) {
ext->row_h[i] = get_row_height(table, i, font, letter_space, line_space,
@ -1099,18 +950,18 @@ static void refr_size(lv_obj_t * table)
_lv_obj_handle_self_size_chg(table);
}
static lv_coord_t get_row_height(lv_obj_t * table, uint16_t row_id, const lv_font_t ** font,
lv_style_int_t * letter_space, lv_style_int_t * line_space,
lv_style_int_t * cell_left, lv_style_int_t * cell_right, lv_style_int_t * cell_top, lv_style_int_t * cell_bottom)
static lv_coord_t get_row_height(lv_obj_t * table, uint16_t row_id, const lv_font_t * font,
lv_coord_t letter_space, lv_coord_t line_space,
lv_coord_t cell_left, lv_coord_t cell_right, lv_coord_t cell_top, lv_coord_t cell_bottom)
{
lv_table_ext_t * ext = lv_obj_get_ext_attr(table);
lv_table_ext_t * ext = table->ext_attr;
lv_point_t txt_size;
lv_coord_t txt_w;
uint16_t row_start = row_id * ext->col_cnt;
uint16_t cell;
uint16_t col;
lv_coord_t h_max = lv_font_get_line_height(font[0]) + cell_top[0] + cell_bottom[0];
lv_coord_t h_max = lv_font_get_line_height(font) + cell_top + cell_bottom;
for(cell = row_start, col = 0; cell < row_start + ext->col_cnt; cell++, col++) {
if(ext->cell_data[cell] != NULL) {
@ -1133,21 +984,20 @@ static lv_coord_t get_row_height(lv_obj_t * table, uint16_t row_id, const lv_fon
lv_table_cell_format_t format;
format.format_byte = ext->cell_data[cell][0];
uint8_t cell_type = format.s.type;
/*With text crop assume 1 line*/
if(format.s.crop) {
h_max = LV_MATH_MAX(lv_font_get_line_height(font[cell_type]) + cell_top[cell_type] + cell_bottom[cell_type],
h_max = LV_MATH_MAX(lv_font_get_line_height(font) + cell_top + cell_bottom,
h_max);
}
/*Without text crop calculate the height of the text in the cell*/
else {
txt_w -= cell_left[cell_type] + cell_right[cell_type];
txt_w -= cell_left + cell_right;
_lv_txt_get_size(&txt_size, ext->cell_data[cell] + 1, font[cell_type],
letter_space[cell_type], line_space[cell_type], txt_w, LV_TXT_FLAG_NONE);
_lv_txt_get_size(&txt_size, ext->cell_data[cell] + 1, font,
letter_space, line_space, txt_w, LV_TXT_FLAG_NONE);
h_max = LV_MATH_MAX(txt_size.y + cell_top[cell_type] + cell_bottom[cell_type], h_max);
h_max = LV_MATH_MAX(txt_size.y + cell_top + cell_bottom, h_max);
cell += col_merge;
col += col_merge;
}

View File

@ -28,26 +28,13 @@ extern "C" {
/*********************
* DEFINES
*********************/
#ifndef LV_TABLE_COL_MAX
#define LV_TABLE_COL_MAX 12
#endif
/*
Maximum allowable value of LV_TABLE_CELL_STYLE_CNT is 16
because of restriction of lv_table_cell_format_t.type to no more than
4 bits so that lv_table_cell_format_t.s will not exceed 8 bits
*/
#ifndef LV_TABLE_CELL_STYLE_CNT
# define LV_TABLE_CELL_STYLE_CNT 4
#endif
#if (LV_TABLE_CELL_STYLE_CNT > 16)
# error "LV_TABLE_CELL_STYLE_CNT cannot exceed 16"
#endif
/**********************
* TYPEDEFS
**********************/
typedef bool (*lv_table_cell_drawer_cb_t)(lv_obj_t * table, uint32_t row, uint32_t cell, lv_draw_rect_dsc_t * rect_draw_dsc, lv_draw_label_dsc_t * label_draw_dsc, const lv_area_t * draw_area, const lv_area_t * clip_area);
/**
* Internal table cell format structure.
*
@ -57,7 +44,6 @@ typedef union {
struct {
uint8_t align : 2;
uint8_t right_merge : 1;
uint8_t type : 4; // upto 16 values
uint8_t crop : 1;
} s;
uint8_t format_byte;
@ -70,20 +56,11 @@ typedef struct {
uint16_t row_cnt;
char ** cell_data;
lv_coord_t * row_h;
lv_style_list_t cell_style[LV_TABLE_CELL_STYLE_CNT];
lv_coord_t * col_w;
uint16_t cell_types : LV_TABLE_CELL_STYLE_CNT; /*Keep track which cell types exists to avoid dealing with unused ones*/
lv_table_cell_drawer_cb_t drawer_cb;
} lv_table_ext_t;
/*Parts of the table*/
enum {
LV_TABLE_PART_BG, /* Because of this member, LV_PART.*CELL1 has enum value of 1, */
LV_TABLE_PART_CELL1, /* LV_PART.*CELL2 has an enum value of 2 and so on upto the maximum */
LV_TABLE_PART_CELL2, /* number of styles specified by LV_TABLE_CELL_STYLE_CNT */
LV_TABLE_PART_CELL3,
LV_TABLE_PART_CELL4, /* CELL 5-16 are not needed to be defined, the values in this enum
are there for backward compatibility */
};
extern const lv_obj_class_t lv_table;
/**********************
* GLOBAL PROTOTYPES
@ -151,15 +128,6 @@ void lv_table_set_col_width(lv_obj_t * table, uint16_t col_id, lv_coord_t w);
*/
void lv_table_set_cell_align(lv_obj_t * table, uint16_t row, uint16_t col, lv_label_align_t align);
/**
* Set the type of a cell.
* @param table pointer to a Table object
* @param row id of the row [0 .. row_cnt -1]
* @param col id of the column [0 .. col_cnt -1]
* @param type 1,2,3 or 4. The cell style will be chosen accordingly.
*/
void lv_table_set_cell_type(lv_obj_t * table, uint16_t row, uint16_t col, uint8_t type);
/**
* Set the cell crop. (Don't adjust the height of the cell according to its content)
* @param table pointer to a Table object
@ -178,6 +146,8 @@ void lv_table_set_cell_crop(lv_obj_t * table, uint16_t row, uint16_t col, bool c
*/
void lv_table_set_cell_merge_right(lv_obj_t * table, uint16_t row, uint16_t col, bool en);
void lv_table_set_cell_drawer(lv_obj_t * obj, lv_table_cell_drawer_cb_t drawer_cb);
/*=====================
* Getter functions
*====================*/

View File

@ -1160,7 +1160,7 @@ void lv_textarea_cursor_down(lv_obj_t * ta)
/*Increment the y with one line and keep the valid x*/
lv_style_int_t line_space = lv_obj_get_style_text_line_space(ta, LV_TEXTAREA_PART_MAIN);
lv_coord_t line_space = lv_obj_get_style_text_line_space(ta, LV_TEXTAREA_PART_MAIN);
const lv_font_t * font = lv_obj_get_style_text_font(ta, LV_TEXTAREA_PART_MAIN);
lv_coord_t font_h = lv_font_get_line_height(font);
pos.y += font_h + line_space + 1;
@ -1192,7 +1192,7 @@ void lv_textarea_cursor_up(lv_obj_t * ta)
lv_label_get_letter_pos(ext->label, lv_textarea_get_cursor_pos(ta), &pos);
/*Decrement the y with one line and keep the valid x*/
lv_style_int_t line_space = lv_obj_get_style_text_line_space(ta, LV_TEXTAREA_PART_MAIN);
lv_coord_t line_space = lv_obj_get_style_text_line_space(ta, LV_TEXTAREA_PART_MAIN);
const lv_font_t * font = lv_obj_get_style_text_font(ta, LV_TEXTAREA_PART_MAIN);
lv_coord_t font_h = lv_font_get_line_height(font);
pos.y -= font_h + line_space - 1;
@ -1277,8 +1277,8 @@ static lv_res_t lv_textarea_signal(lv_obj_t * ta, lv_signal_t sign, void * param
else if(sign == LV_SIGNAL_STYLE_CHG) {
if(ext->label) {
if(ext->one_line) {
lv_style_int_t top = lv_obj_get_style_pad_top(ta, LV_TEXTAREA_PART_MAIN);
lv_style_int_t bottom = lv_obj_get_style_pad_bottom(ta, LV_TEXTAREA_PART_MAIN);
lv_coord_t top = lv_obj_get_style_pad_top(ta, LV_TEXTAREA_PART_MAIN);
lv_coord_t bottom = lv_obj_get_style_pad_bottom(ta, LV_TEXTAREA_PART_MAIN);
const lv_font_t * font = lv_obj_get_style_text_font(ta, LV_TEXTAREA_PART_MAIN);
/*In one line mode refresh the Text Area height because 'vpad' can modify it*/
@ -1501,7 +1501,7 @@ static void refr_cursor_area(lv_obj_t * ta)
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
const lv_font_t * font = lv_obj_get_style_text_font(ta, LV_TEXTAREA_PART_MAIN);
lv_style_int_t line_space = lv_obj_get_style_text_line_space(ta, LV_TEXTAREA_PART_MAIN);
lv_coord_t line_space = lv_obj_get_style_text_line_space(ta, LV_TEXTAREA_PART_MAIN);
uint32_t cur_pos = lv_textarea_get_cursor_pos(ta);
const char * txt = lv_label_get_text(ext->label);
@ -1549,10 +1549,10 @@ static void refr_cursor_area(lv_obj_t * ta)
ext->cursor.txt_byte_pos = byte_pos;
/*Calculate the cursor according to its type*/
lv_style_int_t top = lv_obj_get_style_pad_top(ta, LV_TEXTAREA_PART_CURSOR);
lv_style_int_t bottom = lv_obj_get_style_pad_bottom(ta, LV_TEXTAREA_PART_CURSOR);
lv_style_int_t left = lv_obj_get_style_pad_left(ta, LV_TEXTAREA_PART_CURSOR);
lv_style_int_t right = lv_obj_get_style_pad_right(ta, LV_TEXTAREA_PART_CURSOR);
lv_coord_t top = lv_obj_get_style_pad_top(ta, LV_TEXTAREA_PART_CURSOR);
lv_coord_t bottom = lv_obj_get_style_pad_bottom(ta, LV_TEXTAREA_PART_CURSOR);
lv_coord_t left = lv_obj_get_style_pad_left(ta, LV_TEXTAREA_PART_CURSOR);
lv_coord_t right = lv_obj_get_style_pad_right(ta, LV_TEXTAREA_PART_CURSOR);
lv_area_t cur_area;
cur_area.x1 = letter_pos.x - left;
@ -1774,8 +1774,8 @@ static void draw_cursor(lv_obj_t * ta, const lv_area_t * clip_area)
_lv_memcpy(letter_buf, &txt[ext->cursor.txt_byte_pos], _lv_txt_encoded_size(&txt[ext->cursor.txt_byte_pos]));
if(cur_dsc.bg_opa == LV_OPA_COVER) {
lv_style_int_t left = lv_obj_get_style_pad_left(ta, LV_TEXTAREA_PART_CURSOR);
lv_style_int_t top = lv_obj_get_style_pad_top(ta, LV_TEXTAREA_PART_CURSOR);
lv_coord_t left = lv_obj_get_style_pad_left(ta, LV_TEXTAREA_PART_CURSOR);
lv_coord_t top = lv_obj_get_style_pad_top(ta, LV_TEXTAREA_PART_CURSOR);
cur_area.x1 += left;
cur_area.y1 += top;

View File

@ -72,7 +72,7 @@ static void empty_style(void)
lv_style_list_init(&style_list);
lv_res_t found;
lv_style_int_t value;
lv_coord_t value;
lv_opa_t opa;
const void * ptr;
lv_color_t color;
@ -107,7 +107,7 @@ static void add_remove_read_prop(void)
_lv_style_list_add_style(&style_list, &style);
lv_res_t found;
lv_style_int_t value;
lv_coord_t value;
lv_opa_t opa;
const void * ptr;
lv_color_t color;
@ -185,7 +185,7 @@ static void cascade(void)
_lv_style_list_add_style(&style_list, &style_second);
lv_res_t found;
lv_style_int_t value;
lv_coord_t value;
lv_opa_t opa;
const void * ptr;
lv_color_t color;
@ -281,7 +281,7 @@ static void copy(void)
lv_style_copy(&style_dest, &style_src);
int16_t weight;
lv_style_int_t value;
lv_coord_t value;
weight = _lv_style_get_int(&style_dest, LV_STYLE_TEXT_LINE_SPACE, &value);
lv_test_assert_int_eq(0, weight, "Get a copied property from a style");
@ -336,7 +336,7 @@ static void states(void)
_lv_style_set_int(&style_first, LV_STYLE_TEXT_LINE_SPACE | (LV_STATE_PRESSED) << LV_STYLE_STATE_POS, 7);
lv_res_t found;
lv_style_int_t value;
lv_coord_t value;
found = _lv_style_list_get_int(&style_list, LV_STYLE_TEXT_LINE_SPACE, &value);
lv_test_assert_int_eq(LV_RES_OK, found, "Get an 'int' property in normal state");