mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
simplify checkbox and btnmatrix
This commit is contained in:
parent
25691a4d94
commit
1b15a7b875
@ -66,6 +66,10 @@ void _lv_scroll_handler(lv_indev_proc_t * proc)
|
||||
* 4. If can be scrolled on the current axis (hor/ver) save it as candidate (at least show an elastic scroll effect)
|
||||
* 5. Use the last candidate. Always the "deepest" parent or the object from point 3 */
|
||||
while(proc->types.pointer.scroll_obj) {
|
||||
if(lv_obj_has_flag(proc->types.pointer.scroll_obj, LV_OBJ_FLAG_SCROLLABLE) == false) {
|
||||
proc->types.pointer.scroll_obj = lv_obj_get_parent(proc->types.pointer.scroll_obj);
|
||||
continue;
|
||||
}
|
||||
|
||||
/*Decide if it's a horizontal or vertical scroll*/
|
||||
bool hor_en = false;
|
||||
|
@ -284,7 +284,11 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy)
|
||||
/*Set attributes*/
|
||||
new_obj->scroll_mode = LV_SCROLL_MODE_AUTO;
|
||||
new_obj->scroll_dir = LV_DIR_ALL;
|
||||
new_obj->flags = LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SNAPABLE | LV_OBJ_FLAG_PRESS_LOCK | LV_OBJ_FLAG_CLICK_FOCUSABLE;
|
||||
new_obj->flags = LV_OBJ_FLAG_CLICKABLE;
|
||||
new_obj->flags |= LV_OBJ_FLAG_SNAPABLE;
|
||||
new_obj->flags |= LV_OBJ_FLAG_PRESS_LOCK;
|
||||
new_obj->flags |= LV_OBJ_FLAG_CLICK_FOCUSABLE;
|
||||
new_obj->flags |= LV_OBJ_FLAG_SCROLLABLE;
|
||||
if(parent) new_obj->flags |= LV_OBJ_FLAG_GESTURE_BUBBLE;
|
||||
new_obj->state = LV_STATE_DEFAULT;
|
||||
new_obj->scroll.x = 0;
|
||||
@ -1890,6 +1894,7 @@ static lv_res_t lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param)
|
||||
lv_obj_set_size(obj, obj->w_set, obj->h_set);
|
||||
}
|
||||
|
||||
/*If the changed children was a grid item refresh this objects grid*/
|
||||
if(obj->grid) {
|
||||
lv_obj_t * child = param;
|
||||
if(child) {
|
||||
|
@ -130,7 +130,6 @@ enum {
|
||||
LV_SIGNAL_REFR_EXT_DRAW_PAD, /**< Object's extra padding has changed */
|
||||
LV_SIGNAL_GET_TYPE, /**< LVGL needs to retrieve the object's type */
|
||||
LV_SIGNAL_GET_STYLE, /**< Get the style of an object*/
|
||||
LV_SIGNAL_GET_SELF_SIZE, /**< If there are virtual content on the widget get it's size*/
|
||||
|
||||
/*Input device related*/
|
||||
LV_SIGNAL_HIT_TEST, /**< Advanced hit-testing */
|
||||
|
@ -397,6 +397,8 @@ void _lv_obj_refresh_ext_draw_pad(lv_obj_t * obj)
|
||||
*/
|
||||
void _lv_obj_draw_scrollbar(lv_obj_t * obj, const lv_area_t * clip_area)
|
||||
{
|
||||
if(lv_obj_has_flag(obj, LV_OBJ_FLAG_SCROLLABLE) == false) return;
|
||||
|
||||
lv_scroll_dir_t sm = lv_obj_get_scroll_mode(obj);
|
||||
if(sm == LV_SCROLL_MODE_OFF) {
|
||||
return;
|
||||
|
@ -586,19 +586,6 @@ bool _lv_obj_is_grid_item(lv_obj_t * obj)
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the virtual content on an object
|
||||
* (E.g. some texts which are "just drawn" and there is not real object behind them)
|
||||
* @param obj pointer to an object
|
||||
* @param p store the result size here
|
||||
*/
|
||||
void _lv_obj_get_self_size(lv_obj_t * obj, lv_point_t * p)
|
||||
{
|
||||
p->x = 0;
|
||||
p->y = 0;
|
||||
lv_signal_send(obj, LV_SIGNAL_GET_SELF_SIZE, p);
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
@ -231,14 +231,6 @@ void _lv_obj_move_children_by(struct _lv_obj_t * obj, lv_coord_t x_diff, lv_coor
|
||||
*/
|
||||
bool _lv_obj_is_grid_item(struct _lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get the size of the virtual content on an object
|
||||
* (E.g. some texts which are "just drawn" and there is not real object behind them)
|
||||
* @param obj pointer to an object
|
||||
* @param p store the result size here
|
||||
*/
|
||||
void _lv_obj_get_self_size(lv_obj_t * obj, lv_point_t * p);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
@ -196,13 +196,7 @@ lv_coord_t lv_obj_get_scroll_bottom(const lv_obj_t * obj)
|
||||
child_res = y2;
|
||||
}
|
||||
|
||||
lv_point_t self_size;
|
||||
_lv_obj_get_self_size(obj, &self_size);
|
||||
self_size.y += obj->coords.y1 + lv_obj_get_style_pad_top(obj, LV_OBJ_PART_MAIN) + obj->scroll.y;
|
||||
|
||||
lv_coord_t y_max = LV_MATH_MAX(child_res, self_size.y) - obj->coords.y2;
|
||||
|
||||
return y_max + lv_obj_get_style_pad_bottom(obj, LV_OBJ_PART_MAIN);
|
||||
return child_res - obj->coords.y2 + lv_obj_get_style_pad_bottom(obj, LV_OBJ_PART_MAIN);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -243,13 +237,7 @@ lv_coord_t lv_obj_get_scroll_right(const lv_obj_t * obj)
|
||||
|
||||
}
|
||||
|
||||
lv_point_t self_size;
|
||||
_lv_obj_get_self_size(obj, &self_size);
|
||||
self_size.x += obj->coords.x1 + lv_obj_get_style_pad_left(obj, LV_OBJ_PART_MAIN) + obj->scroll.x;
|
||||
|
||||
lv_coord_t x_max = LV_MATH_MAX(child_res, self_size.x) - obj->coords.x2;
|
||||
|
||||
return x_max + lv_obj_get_style_pad_right(obj, LV_OBJ_PART_MAIN);
|
||||
return child_res - obj->coords.x2 + lv_obj_get_style_pad_right(obj, LV_OBJ_PART_MAIN);
|
||||
}
|
||||
|
||||
/**********************
|
||||
|
@ -815,7 +815,6 @@ void _lv_obj_refresh_style(lv_obj_t * obj, uint8_t part, lv_style_property_t pro
|
||||
case LV_STYLE_PAD_BOTTOM:
|
||||
case LV_STYLE_PAD_LEFT:
|
||||
case LV_STYLE_PAD_RIGHT:
|
||||
case LV_STYLE_PAD_INNER:
|
||||
case LV_STYLE_MARGIN_TOP:
|
||||
case LV_STYLE_MARGIN_BOTTOM:
|
||||
case LV_STYLE_MARGIN_LEFT:
|
||||
@ -1243,7 +1242,6 @@ static void style_snapshot(lv_obj_t * obj, uint8_t part, style_snapshot_t * shot
|
||||
shot->pad_bottom = lv_obj_get_style_pad_bottom(obj, part);
|
||||
shot->pad_right = lv_obj_get_style_pad_right(obj, part);
|
||||
shot->pad_left = lv_obj_get_style_pad_left(obj, part);
|
||||
shot->pad_inner = lv_obj_get_style_pad_inner(obj, part);
|
||||
shot->margin_top = lv_obj_get_style_margin_top(obj, part);
|
||||
shot->margin_bottom = lv_obj_get_style_margin_bottom(obj, part);
|
||||
shot->margin_left = lv_obj_get_style_margin_left(obj, part);
|
||||
@ -1276,7 +1274,6 @@ static _lv_style_state_cmp_t style_snapshot_compare(style_snapshot_t * shot1, st
|
||||
if(shot1->pad_left != shot2->pad_right) return _LV_STYLE_STATE_CMP_DIFF;
|
||||
if(shot1->pad_right != shot2->pad_right) return _LV_STYLE_STATE_CMP_DIFF;
|
||||
if(shot1->pad_top != shot2->pad_top) return _LV_STYLE_STATE_CMP_DIFF;
|
||||
if(shot1->pad_inner != shot2->pad_inner) return _LV_STYLE_STATE_CMP_DIFF;
|
||||
if(shot1->margin_top != shot2->margin_top) return _LV_STYLE_STATE_CMP_DIFF;
|
||||
if(shot1->margin_bottom != shot2->margin_bottom) return _LV_STYLE_STATE_CMP_DIFF;
|
||||
if(shot1->margin_left != shot2->margin_left) return _LV_STYLE_STATE_CMP_DIFF;
|
||||
|
@ -411,7 +411,6 @@ _LV_OBJ_STYLE_SET_GET_DECLARE(PAD_TOP, pad_top, lv_style_int_t, _int, scalar)
|
||||
_LV_OBJ_STYLE_SET_GET_DECLARE(PAD_BOTTOM, pad_bottom, lv_style_int_t, _int, scalar)
|
||||
_LV_OBJ_STYLE_SET_GET_DECLARE(PAD_LEFT, pad_left, lv_style_int_t, _int, scalar)
|
||||
_LV_OBJ_STYLE_SET_GET_DECLARE(PAD_RIGHT, pad_right, lv_style_int_t, _int, scalar)
|
||||
_LV_OBJ_STYLE_SET_GET_DECLARE(PAD_INNER, pad_inner, lv_style_int_t, _int, scalar)
|
||||
_LV_OBJ_STYLE_SET_GET_DECLARE(MARGIN_TOP, margin_top, lv_style_int_t, _int, scalar)
|
||||
_LV_OBJ_STYLE_SET_GET_DECLARE(MARGIN_BOTTOM, margin_bottom, lv_style_int_t, _int, scalar)
|
||||
_LV_OBJ_STYLE_SET_GET_DECLARE(MARGIN_LEFT, margin_left, lv_style_int_t, _int, scalar)
|
||||
|
@ -110,11 +110,10 @@ enum {
|
||||
LV_STYLE_PROP_INIT(LV_STYLE_PAD_BOTTOM, 0x1, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_NONE),
|
||||
LV_STYLE_PROP_INIT(LV_STYLE_PAD_LEFT, 0x1, LV_STYLE_ID_VALUE + 2, LV_STYLE_ATTR_NONE),
|
||||
LV_STYLE_PROP_INIT(LV_STYLE_PAD_RIGHT, 0x1, LV_STYLE_ID_VALUE + 3, LV_STYLE_ATTR_NONE),
|
||||
LV_STYLE_PROP_INIT(LV_STYLE_PAD_INNER, 0x1, LV_STYLE_ID_VALUE + 4, LV_STYLE_ATTR_NONE),
|
||||
LV_STYLE_PROP_INIT(LV_STYLE_MARGIN_TOP, 0x1, LV_STYLE_ID_VALUE + 5, LV_STYLE_ATTR_NONE),
|
||||
LV_STYLE_PROP_INIT(LV_STYLE_MARGIN_BOTTOM, 0x1, LV_STYLE_ID_VALUE + 6, LV_STYLE_ATTR_NONE),
|
||||
LV_STYLE_PROP_INIT(LV_STYLE_MARGIN_LEFT, 0x1, LV_STYLE_ID_VALUE + 7, LV_STYLE_ATTR_NONE),
|
||||
LV_STYLE_PROP_INIT(LV_STYLE_MARGIN_RIGHT, 0x1, LV_STYLE_ID_VALUE + 8, LV_STYLE_ATTR_NONE),
|
||||
LV_STYLE_PROP_INIT(LV_STYLE_MARGIN_TOP, 0x1, LV_STYLE_ID_VALUE + 4, LV_STYLE_ATTR_NONE),
|
||||
LV_STYLE_PROP_INIT(LV_STYLE_MARGIN_BOTTOM, 0x1, LV_STYLE_ID_VALUE + 5, LV_STYLE_ATTR_NONE),
|
||||
LV_STYLE_PROP_INIT(LV_STYLE_MARGIN_LEFT, 0x1, LV_STYLE_ID_VALUE + 6, LV_STYLE_ATTR_NONE),
|
||||
LV_STYLE_PROP_INIT(LV_STYLE_MARGIN_RIGHT, 0x1, LV_STYLE_ID_VALUE + 7, LV_STYLE_ATTR_NONE),
|
||||
|
||||
LV_STYLE_PROP_INIT(LV_STYLE_BG_BLEND_MODE, 0x2, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE),
|
||||
LV_STYLE_PROP_INIT(LV_STYLE_BG_MAIN_STOP, 0x2, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_NONE),
|
||||
|
@ -225,7 +225,7 @@ static void clear_styles(lv_obj_t * obj, lv_theme_style_t name)
|
||||
|
||||
#if LV_USE_BTNMATRIX
|
||||
case LV_THEME_BTNMATRIX:
|
||||
_lv_obj_reset_style_list_no_refr(obj, LV_BTNMATRIX_PART_BG);
|
||||
_lv_obj_reset_style_list_no_refr(obj, LV_BTNMATRIX_PART_MAIN);
|
||||
_lv_obj_reset_style_list_no_refr(obj, LV_BTNMATRIX_PART_BTN);
|
||||
break;
|
||||
#endif
|
||||
|
@ -80,7 +80,6 @@ typedef struct {
|
||||
lv_style_t bg_click;
|
||||
lv_style_t bg_sec;
|
||||
lv_style_t btn;
|
||||
lv_style_t pad_inner;
|
||||
lv_style_t pad_small;
|
||||
|
||||
#if LV_USE_ARC
|
||||
@ -94,6 +93,10 @@ typedef struct {
|
||||
lv_style_t bar_indic;
|
||||
#endif
|
||||
|
||||
#if LV_USE_BTNMATRIX
|
||||
lv_style_t btnmatrix_btn;
|
||||
#endif
|
||||
|
||||
#if LV_USE_CALENDAR
|
||||
lv_style_t calendar_date_nums, calendar_header, calendar_daynames;
|
||||
#endif
|
||||
@ -236,7 +239,6 @@ static void basic_init(void)
|
||||
lv_style_set_pad_right(&styles->bg, LV_STATE_DEFAULT, PAD_DEF + BORDER_WIDTH);
|
||||
lv_style_set_pad_top(&styles->bg, LV_STATE_DEFAULT, PAD_DEF + BORDER_WIDTH);
|
||||
lv_style_set_pad_bottom(&styles->bg, LV_STATE_DEFAULT, PAD_DEF + BORDER_WIDTH);
|
||||
lv_style_set_pad_inner(&styles->bg, LV_STATE_DEFAULT, PAD_DEF);
|
||||
lv_style_set_transition_time(&styles->bg, LV_STATE_DEFAULT, TRANSITION_TIME);
|
||||
lv_style_set_transition_prop_6(&styles->bg, LV_STATE_DEFAULT, LV_STYLE_BORDER_COLOR);
|
||||
|
||||
@ -308,7 +310,6 @@ static void basic_init(void)
|
||||
lv_style_set_pad_right(&styles->btn, LV_STATE_DEFAULT, LV_DPX(40));
|
||||
lv_style_set_pad_top(&styles->btn, LV_STATE_DEFAULT, LV_DPX(15));
|
||||
lv_style_set_pad_bottom(&styles->btn, LV_STATE_DEFAULT, LV_DPX(15));
|
||||
lv_style_set_pad_inner(&styles->btn, LV_STATE_DEFAULT, LV_DPX(20));
|
||||
lv_style_set_outline_width(&styles->btn, LV_STATE_DEFAULT, OUTLINE_WIDTH);
|
||||
lv_style_set_outline_opa(&styles->btn, LV_STATE_DEFAULT, LV_OPA_0);
|
||||
lv_style_set_outline_opa(&styles->btn, LV_STATE_FOCUSED, LV_OPA_50);
|
||||
@ -321,18 +322,12 @@ static void basic_init(void)
|
||||
lv_style_set_transition_delay(&styles->btn, LV_STATE_DEFAULT, TRANSITION_TIME);
|
||||
lv_style_set_transition_delay(&styles->btn, LV_STATE_PRESSED, 0);
|
||||
|
||||
style_init_reset(&styles->pad_inner);
|
||||
|
||||
lv_style_set_pad_inner(&styles->pad_inner, LV_STATE_DEFAULT,
|
||||
lv_disp_get_size_category(NULL) <= LV_DISP_MEDIUM_LIMIT ? LV_DPX(20) : LV_DPX(40));
|
||||
|
||||
style_init_reset(&styles->pad_small);
|
||||
lv_style_int_t pad_small_value = lv_disp_get_size_category(NULL) <= LV_DISP_MEDIUM_LIMIT ? LV_DPX(10) : LV_DPX(20);
|
||||
lv_style_set_pad_left(&styles->pad_small, LV_STATE_DEFAULT, pad_small_value);
|
||||
lv_style_set_pad_right(&styles->pad_small, LV_STATE_DEFAULT, pad_small_value);
|
||||
lv_style_set_pad_top(&styles->pad_small, LV_STATE_DEFAULT, pad_small_value);
|
||||
lv_style_set_pad_bottom(&styles->pad_small, LV_STATE_DEFAULT, pad_small_value);
|
||||
lv_style_set_pad_inner(&styles->pad_small, LV_STATE_DEFAULT, pad_small_value);
|
||||
}
|
||||
|
||||
static void cont_init(void)
|
||||
@ -349,6 +344,14 @@ static void btn_init(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
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 label_init(void)
|
||||
{
|
||||
#if LV_USE_LABEL != 0
|
||||
@ -623,12 +626,14 @@ static void checkbox_init(void)
|
||||
#if LV_USE_CHECKBOX != 0
|
||||
style_init_reset(&styles->cb_bg);
|
||||
lv_style_set_radius(&styles->cb_bg, LV_STATE_DEFAULT, LV_DPX(4));
|
||||
lv_style_set_pad_inner(&styles->cb_bg, LV_STATE_DEFAULT, LV_DPX(10));
|
||||
lv_style_set_pad_left(&styles->cb_bg, LV_STATE_DEFAULT, LV_DPX(30));
|
||||
lv_style_set_pad_top(&styles->cb_bg, LV_STATE_DEFAULT, LV_DPX(3));
|
||||
lv_style_set_pad_bottom(&styles->cb_bg, LV_STATE_DEFAULT, LV_DPX(3));
|
||||
lv_style_set_outline_color(&styles->cb_bg, LV_STATE_DEFAULT, theme.color_primary);
|
||||
lv_style_set_outline_opa(&styles->cb_bg, LV_STATE_DEFAULT, LV_OPA_TRANSP);
|
||||
lv_style_set_outline_opa(&styles->cb_bg, LV_STATE_FOCUSED, LV_OPA_50);
|
||||
lv_style_set_outline_width(&styles->cb_bg, LV_STATE_DEFAULT, OUTLINE_WIDTH);
|
||||
lv_style_set_outline_pad(&styles->cb_bg, LV_STATE_DEFAULT, LV_DPX(10));
|
||||
lv_style_set_outline_pad(&styles->cb_bg, LV_STATE_DEFAULT, LV_DPX(6));
|
||||
lv_style_set_transition_time(&styles->cb_bg, LV_STATE_DEFAULT, TRANSITION_TIME);
|
||||
lv_style_set_transition_prop_6(&styles->cb_bg, LV_STATE_DEFAULT, LV_STYLE_OUTLINE_OPA);
|
||||
|
||||
@ -649,10 +654,6 @@ static void checkbox_init(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
static void btnmatrix_init(void)
|
||||
{
|
||||
}
|
||||
|
||||
static void keyboard_init(void)
|
||||
{
|
||||
#if LV_USE_KEYBOARD
|
||||
@ -927,6 +928,7 @@ lv_theme_t * lv_theme_material_init(lv_color_t color_primary, lv_color_t color_s
|
||||
basic_init();
|
||||
cont_init();
|
||||
btn_init();
|
||||
btnmatrix_init();
|
||||
label_init();
|
||||
bar_init();
|
||||
img_init();
|
||||
@ -942,7 +944,6 @@ lv_theme_t * lv_theme_material_init(lv_color_t color_primary, lv_color_t color_s
|
||||
calendar_init();
|
||||
cpicker_init();
|
||||
checkbox_init();
|
||||
btnmatrix_init();
|
||||
keyboard_init();
|
||||
msgbox_init();
|
||||
page_init();
|
||||
@ -996,13 +997,14 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj, lv_theme_style_t name)
|
||||
|
||||
#if LV_USE_BTNMATRIX
|
||||
case LV_THEME_BTNMATRIX:
|
||||
list = _lv_obj_get_style_list(obj, LV_BTNMATRIX_PART_BG);
|
||||
list = _lv_obj_get_style_list(obj, LV_BTNMATRIX_PART_MAIN);
|
||||
_lv_style_list_add_style(list, &styles->bg);
|
||||
_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->bg);
|
||||
_lv_style_list_add_style(list, &styles->bg_click);
|
||||
_lv_style_list_add_style(list, &styles->btnmatrix_btn);
|
||||
break;
|
||||
#endif
|
||||
|
||||
|
@ -37,7 +37,6 @@ typedef struct {
|
||||
lv_style_t pad_none;
|
||||
lv_style_t pad_normal;
|
||||
lv_style_t pad_small;
|
||||
lv_style_t pad_inner;
|
||||
lv_style_t txt_underline;
|
||||
|
||||
#if LV_USE_ARC
|
||||
@ -137,7 +136,6 @@ static void basic_init(void)
|
||||
lv_style_set_pad_right(&styles->bg, LV_STATE_DEFAULT, LV_DPI / 10);
|
||||
lv_style_set_pad_top(&styles->bg, LV_STATE_DEFAULT, LV_DPI / 10);
|
||||
lv_style_set_pad_bottom(&styles->bg, LV_STATE_DEFAULT, LV_DPI / 10);
|
||||
lv_style_set_pad_inner(&styles->bg, LV_STATE_DEFAULT, LV_DPI / 10);
|
||||
|
||||
style_init_reset(&styles->clip_corner);
|
||||
lv_style_set_clip_corner(&styles->clip_corner, LV_STATE_DEFAULT, true);
|
||||
@ -190,24 +188,18 @@ static void basic_init(void)
|
||||
lv_style_set_pad_right(&styles->pad_none, LV_STATE_DEFAULT, 0);
|
||||
lv_style_set_pad_top(&styles->pad_none, LV_STATE_DEFAULT, 0);
|
||||
lv_style_set_pad_bottom(&styles->pad_none, LV_STATE_DEFAULT, 0);
|
||||
lv_style_set_pad_inner(&styles->pad_none, LV_STATE_DEFAULT, 0);
|
||||
|
||||
style_init_reset(&styles->pad_normal);
|
||||
lv_style_set_pad_left(&styles->pad_normal, LV_STATE_DEFAULT, LV_DPI / 10);
|
||||
lv_style_set_pad_right(&styles->pad_normal, LV_STATE_DEFAULT, LV_DPI / 10);
|
||||
lv_style_set_pad_top(&styles->pad_normal, LV_STATE_DEFAULT, LV_DPI / 10);
|
||||
lv_style_set_pad_bottom(&styles->pad_normal, LV_STATE_DEFAULT, LV_DPI / 10);
|
||||
lv_style_set_pad_inner(&styles->pad_normal, LV_STATE_DEFAULT, LV_DPI / 10);
|
||||
|
||||
style_init_reset(&styles->pad_small);
|
||||
lv_style_set_pad_left(&styles->pad_small, LV_STATE_DEFAULT, LV_DPI / 20);
|
||||
lv_style_set_pad_right(&styles->pad_small, LV_STATE_DEFAULT, LV_DPI / 20);
|
||||
lv_style_set_pad_top(&styles->pad_small, LV_STATE_DEFAULT, LV_DPI / 20);
|
||||
lv_style_set_pad_bottom(&styles->pad_small, LV_STATE_DEFAULT, LV_DPI / 20);
|
||||
lv_style_set_pad_inner(&styles->pad_small, LV_STATE_DEFAULT, LV_DPI / 20);
|
||||
|
||||
style_init_reset(&styles->pad_inner);
|
||||
lv_style_set_pad_inner(&styles->pad_inner, LV_STATE_DEFAULT, LV_DPI / 15);
|
||||
|
||||
style_init_reset(&styles->txt_underline);
|
||||
lv_style_set_text_decor(&styles->txt_underline, LV_STATE_FOCUSED, LV_TEXT_DECOR_UNDERLINE);
|
||||
@ -590,7 +582,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj, lv_theme_style_t name)
|
||||
|
||||
#if LV_USE_BTNMATRIX
|
||||
case LV_THEME_BTNMATRIX:
|
||||
list = _lv_obj_get_style_list(obj, LV_BTNMATRIX_PART_BG);
|
||||
list = _lv_obj_get_style_list(obj, LV_BTNMATRIX_PART_MAIN);
|
||||
_lv_style_list_add_style(list, &styles->bg);
|
||||
|
||||
list = _lv_obj_get_style_list(obj, LV_BTNMATRIX_PART_BTN);
|
||||
|
@ -75,7 +75,6 @@ static void basic_init(void)
|
||||
lv_style_set_pad_right(&styles->bg, LV_STATE_DEFAULT, LV_DPI / 10);
|
||||
lv_style_set_pad_top(&styles->bg, LV_STATE_DEFAULT, LV_DPI / 10);
|
||||
lv_style_set_pad_bottom(&styles->bg, LV_STATE_DEFAULT, LV_DPI / 10);
|
||||
lv_style_set_pad_inner(&styles->bg, LV_STATE_DEFAULT, LV_DPI / 10);
|
||||
|
||||
style_init_reset(&styles->btn);
|
||||
lv_style_set_bg_color(&styles->btn, LV_STATE_PRESSED, lv_color_hex3(0xccc));
|
||||
@ -108,7 +107,6 @@ static void basic_init(void)
|
||||
lv_style_set_pad_right(&styles->tight, LV_STATE_DEFAULT, 0);
|
||||
lv_style_set_pad_top(&styles->tight, LV_STATE_DEFAULT, 0);
|
||||
lv_style_set_pad_bottom(&styles->tight, LV_STATE_DEFAULT, 0);
|
||||
lv_style_set_pad_inner(&styles->tight, LV_STATE_DEFAULT, 0);
|
||||
}
|
||||
|
||||
static void arc_init(void)
|
||||
@ -439,7 +437,7 @@ void theme_apply(lv_theme_t * th, lv_obj_t * obj, lv_theme_style_t name)
|
||||
|
||||
#if LV_USE_BTNMATRIX
|
||||
case LV_THEME_BTNMATRIX:
|
||||
list = _lv_obj_get_style_list(obj, LV_BTNMATRIX_PART_BG);
|
||||
list = _lv_obj_get_style_list(obj, LV_BTNMATRIX_PART_MAIN);
|
||||
_lv_style_list_add_style(list, &styles->bg);
|
||||
|
||||
list = _lv_obj_get_style_list(obj, LV_BTNMATRIX_PART_BTN);
|
||||
|
@ -42,7 +42,6 @@ static lv_design_res_t lv_bar_design(lv_obj_t * bar, const lv_area_t * clip_area
|
||||
static lv_res_t lv_bar_signal(lv_obj_t * bar, lv_signal_t sign, void * param);
|
||||
static lv_style_list_t * lv_bar_get_style(lv_obj_t * bar, uint8_t part);
|
||||
|
||||
static void draw_bg(lv_obj_t * bar, const lv_area_t * clip_area);
|
||||
static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area);
|
||||
|
||||
#if LV_USE_ANIMATION
|
||||
@ -112,6 +111,7 @@ lv_obj_t * lv_bar_create(lv_obj_t * parent, lv_obj_t * copy)
|
||||
|
||||
if(copy == NULL) {
|
||||
lv_obj_clear_flag(bar, LV_OBJ_FLAG_CHECKABLE);
|
||||
lv_obj_clear_flag(bar, LV_OBJ_FLAG_SCROLLABLE);
|
||||
lv_obj_set_size(bar, LV_DPI * 2, LV_DPI / 10);
|
||||
lv_bar_set_value(bar, ext->cur_value, false);
|
||||
|
||||
@ -370,7 +370,8 @@ static lv_design_res_t lv_bar_design(lv_obj_t * bar, const lv_area_t * clip_area
|
||||
return ancestor_design(bar, clip_area, mode);
|
||||
}
|
||||
else if(mode == LV_DESIGN_DRAW_MAIN) {
|
||||
draw_bg(bar, clip_area);
|
||||
// draw_bg(bar, clip_area);
|
||||
ancestor_design(bar, clip_area, mode);
|
||||
draw_indic(bar, clip_area);
|
||||
|
||||
/*Get the value and draw it after the indicator*/
|
||||
@ -385,40 +386,11 @@ static lv_design_res_t lv_bar_design(lv_obj_t * bar, const lv_area_t * clip_area
|
||||
lv_draw_rect(&bar->coords, clip_area, &draw_dsc);
|
||||
}
|
||||
else if(mode == LV_DESIGN_DRAW_POST) {
|
||||
/*If the border is drawn later disable loading other properties*/
|
||||
if(lv_obj_get_style_border_post(bar, LV_OBJ_PART_MAIN)) {
|
||||
lv_draw_rect_dsc_t draw_dsc;
|
||||
lv_draw_rect_dsc_init(&draw_dsc);
|
||||
draw_dsc.bg_opa = LV_OPA_TRANSP;
|
||||
draw_dsc.pattern_opa = LV_OPA_TRANSP;
|
||||
draw_dsc.outline_opa = LV_OPA_TRANSP;
|
||||
draw_dsc.shadow_opa = LV_OPA_TRANSP;
|
||||
draw_dsc.value_opa = LV_OPA_TRANSP;
|
||||
lv_obj_init_draw_rect_dsc(bar, LV_OBJ_PART_MAIN, &draw_dsc);
|
||||
|
||||
lv_draw_rect(&bar->coords, clip_area, &draw_dsc);
|
||||
}
|
||||
ancestor_design(bar, clip_area, mode);
|
||||
}
|
||||
return LV_DESIGN_RES_OK;
|
||||
}
|
||||
|
||||
static void draw_bg(lv_obj_t * bar, const lv_area_t * clip_area)
|
||||
{
|
||||
/*Simply draw the background*/
|
||||
lv_draw_rect_dsc_t draw_dsc;
|
||||
lv_draw_rect_dsc_init(&draw_dsc);
|
||||
/*If the border is drawn later disable loading its properties*/
|
||||
if(lv_obj_get_style_border_post(bar, LV_BAR_PART_MAIN)) {
|
||||
draw_dsc.border_opa = LV_OPA_TRANSP;
|
||||
}
|
||||
|
||||
/*value will be drawn later*/
|
||||
draw_dsc.value_opa = LV_OPA_TRANSP;
|
||||
lv_obj_init_draw_rect_dsc(bar, LV_BAR_PART_MAIN, &draw_dsc);
|
||||
lv_draw_rect(&bar->coords, clip_area, &draw_dsc);
|
||||
|
||||
}
|
||||
|
||||
static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area)
|
||||
{
|
||||
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
||||
|
@ -39,12 +39,12 @@ static bool button_is_repeat_disabled(lv_btnmatrix_ctrl_t ctrl_bits);
|
||||
static bool button_is_inactive(lv_btnmatrix_ctrl_t ctrl_bits);
|
||||
static bool button_is_click_trig(lv_btnmatrix_ctrl_t ctrl_bits);
|
||||
static bool button_is_tgl_enabled(lv_btnmatrix_ctrl_t ctrl_bits);
|
||||
static bool button_get_tgl_state(lv_btnmatrix_ctrl_t ctrl_bits);
|
||||
static bool button_get_checked(lv_btnmatrix_ctrl_t ctrl_bits);
|
||||
static uint16_t get_button_from_point(lv_obj_t * btnm, lv_point_t * p);
|
||||
static void allocate_btn_areas_and_controls(const lv_obj_t * btnm, const char ** map);
|
||||
static void invalidate_button_area(const lv_obj_t * btnm, uint16_t btn_idx);
|
||||
static bool maps_are_identical(const char ** map1, const char ** map2);
|
||||
static void make_one_button_toggled(lv_obj_t * btnm, uint16_t btn_idx);
|
||||
static void make_one_button_checked(lv_obj_t * btnm, uint16_t btn_idx);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@ -140,17 +140,6 @@ void lv_btnmatrix_set_map(lv_obj_t * btnm, const char * map[])
|
||||
LV_ASSERT_OBJ(btnm, LV_OBJX_NAME);
|
||||
LV_ASSERT_NULL(map);
|
||||
|
||||
/*
|
||||
* lv_btnmatrix_set_map is called on receipt of signals such as
|
||||
* LV_SIGNAL_CORD_CHG regardless of whether the map has changed (e.g.
|
||||
* calling lv_obj_align on the map will trigger this).
|
||||
*
|
||||
* We check if the map has changed here to avoid overwriting changes made
|
||||
* to hidden/longpress/disabled states after the map was originally set.
|
||||
*
|
||||
* TODO: separate all map set/allocation from layout code below and skip
|
||||
* set/allocation when map hasn't changed.
|
||||
*/
|
||||
lv_btnmatrix_ext_t * ext = lv_obj_get_ext_attr(btnm);
|
||||
if(!maps_are_identical(ext->map_p, map)) {
|
||||
|
||||
@ -159,102 +148,79 @@ void lv_btnmatrix_set_map(lv_obj_t * btnm, const char * map[])
|
||||
}
|
||||
ext->map_p = map;
|
||||
|
||||
/*Set size and positions of the buttons*/
|
||||
lv_style_int_t left = lv_obj_get_style_pad_left(btnm, LV_BTNMATRIX_PART_BG);
|
||||
lv_style_int_t right = lv_obj_get_style_pad_right(btnm, LV_BTNMATRIX_PART_BG);
|
||||
lv_style_int_t top = lv_obj_get_style_pad_top(btnm, LV_BTNMATRIX_PART_BG);
|
||||
lv_style_int_t bottom = lv_obj_get_style_pad_bottom(btnm, LV_BTNMATRIX_PART_BG);
|
||||
lv_style_int_t inner = lv_obj_get_style_pad_inner(btnm, LV_BTNMATRIX_PART_BG);
|
||||
lv_bidi_dir_t base_dir = lv_obj_get_base_dir(btnm);
|
||||
|
||||
lv_coord_t max_w = lv_obj_get_width(btnm) - left - right;
|
||||
lv_coord_t max_h = lv_obj_get_height(btnm) - top - bottom;
|
||||
lv_coord_t act_y = top;
|
||||
/*Set size and positions of the buttons*/
|
||||
lv_style_int_t left = lv_obj_get_style_pad_left(btnm, LV_BTNMATRIX_PART_MAIN);
|
||||
lv_style_int_t top = lv_obj_get_style_pad_top(btnm, LV_BTNMATRIX_PART_MAIN);
|
||||
lv_coord_t row_gap = LV_MATH_MAX(lv_obj_get_style_margin_top(btnm, LV_BTNMATRIX_PART_BTN), lv_obj_get_style_margin_bottom(btnm, LV_BTNMATRIX_PART_BTN));
|
||||
lv_coord_t col_gap = LV_MATH_MAX(lv_obj_get_style_margin_left(btnm, LV_BTNMATRIX_PART_BTN), lv_obj_get_style_margin_right(btnm, LV_BTNMATRIX_PART_BTN));
|
||||
|
||||
lv_coord_t max_w = lv_obj_get_width_fit(btnm);
|
||||
lv_coord_t max_h = lv_obj_get_height_fit(btnm);
|
||||
|
||||
/*Count the lines to calculate button height*/
|
||||
uint8_t line_cnt = 1;
|
||||
uint8_t li;
|
||||
for(li = 0; strlen(map[li]) != 0; li++) {
|
||||
if(strcmp(map[li], "\n") == 0) line_cnt++;
|
||||
uint8_t row_cnt = 1;
|
||||
uint32_t i;
|
||||
for(i = 0; strlen(map[i]) != 0; i++) {
|
||||
if(strcmp(map[i], "\n") == 0) row_cnt++;
|
||||
}
|
||||
|
||||
lv_coord_t btn_h = max_h - ((line_cnt - 1) * inner);
|
||||
btn_h = btn_h / line_cnt;
|
||||
btn_h--; /*-1 because e.g. height = 100 means 101 pixels (0..100)*/
|
||||
/*Calculate the position of each row*/
|
||||
lv_coord_t max_h_no_gap = max_h - (row_gap * (row_cnt - 1));
|
||||
|
||||
/* Count the units and the buttons in a line
|
||||
* (A button can be 1,2,3... unit wide)*/
|
||||
uint16_t unit_act_cnt; /*Number of units currently put in a row*/
|
||||
uint16_t i_tot = 0; /*Act. index in the str map*/
|
||||
uint16_t btn_i = 0; /*Act. index of button areas*/
|
||||
const char ** map_p_tmp = map;
|
||||
uint32_t txt_tot_i = 0; /*Act. index in the str map*/
|
||||
uint32_t btn_tot_i = 0; /*Act. index of button areas*/
|
||||
const char ** map_row = map;
|
||||
|
||||
/*Count the units and the buttons in a line*/
|
||||
while(1) {
|
||||
uint32_t row;
|
||||
for(row = 0; row < row_cnt; row++) {
|
||||
uint16_t unit_cnt = 0; /*Number of units in a row*/
|
||||
uint16_t btn_cnt = 0; /*Number of buttons in a row*/
|
||||
/*Count the buttons in a line*/
|
||||
while(strcmp(map_p_tmp[btn_cnt], "\n") != 0 && strlen(map_p_tmp[btn_cnt]) != 0) { /*Check a line*/
|
||||
unit_cnt += get_button_width(ext->ctrl_bits[btn_i + btn_cnt]);
|
||||
/*Count the buttons and units in this row*/
|
||||
while(strcmp(map_row[btn_cnt], "\n") != 0 && strlen(map_row[btn_cnt]) != '\0') {
|
||||
unit_cnt += get_button_width(ext->ctrl_bits[btn_tot_i + btn_cnt]);
|
||||
btn_cnt++;
|
||||
}
|
||||
|
||||
/*Make sure the last row is at the bottom of 'btnm'*/
|
||||
if(map_p_tmp[btn_cnt][0] == '\0') { /*Last row?*/
|
||||
btn_h = lv_obj_get_height(btnm) - act_y - bottom - 1;
|
||||
}
|
||||
|
||||
lv_bidi_dir_t base_dir = lv_obj_get_base_dir(btnm);
|
||||
|
||||
/*Only deal with the non empty lines*/
|
||||
if(btn_cnt != 0) {
|
||||
/*Calculate the width of all units*/
|
||||
lv_coord_t all_unit_w = max_w - ((unit_cnt - 1) * inner);
|
||||
|
||||
/*Set the button size and positions and set the texts*/
|
||||
uint16_t i;
|
||||
lv_coord_t act_x;
|
||||
|
||||
unit_act_cnt = 0;
|
||||
for(i = 0; i < btn_cnt; i++) {
|
||||
uint8_t btn_unit_w = get_button_width(ext->ctrl_bits[btn_i]);
|
||||
/* one_unit_w = all_unit_w / unit_cnt
|
||||
* act_unit_w = one_unit_w * button_width
|
||||
* do this two operations but the multiply first to divide a greater number */
|
||||
lv_coord_t act_unit_w = (all_unit_w * btn_unit_w) / unit_cnt + inner * (btn_unit_w - 1);
|
||||
act_unit_w--; /*-1 because e.g. width = 100 means 101 pixels (0..100)*/
|
||||
|
||||
/*Always recalculate act_x because of rounding errors */
|
||||
if(base_dir == LV_BIDI_DIR_RTL) {
|
||||
act_x = (unit_act_cnt * all_unit_w) / unit_cnt + unit_act_cnt * inner;
|
||||
act_x = lv_obj_get_width(btnm) - right - act_x - act_unit_w - 1;
|
||||
}
|
||||
else {
|
||||
act_x = (unit_act_cnt * all_unit_w) / unit_cnt + unit_act_cnt * inner +
|
||||
left;
|
||||
}
|
||||
/* Set the button's area.
|
||||
* If inner padding is zero then use the prev. button x2 as x1 to avoid rounding
|
||||
* errors*/
|
||||
if(btn_i != 0 && inner == 0 && ((act_x != left && base_dir != LV_BIDI_DIR_RTL) ||
|
||||
(act_x + act_unit_w == max_w - right && base_dir == LV_BIDI_DIR_RTL))) {
|
||||
lv_area_set(&ext->button_areas[btn_i], ext->button_areas[btn_i - 1].x2, act_y, act_x + act_unit_w,
|
||||
act_y + btn_h);
|
||||
}
|
||||
else {
|
||||
lv_area_set(&ext->button_areas[btn_i], act_x, act_y, act_x + act_unit_w, act_y + btn_h);
|
||||
}
|
||||
|
||||
unit_act_cnt += btn_unit_w;
|
||||
|
||||
i_tot++;
|
||||
btn_i++;
|
||||
}
|
||||
if(btn_cnt == 0) {
|
||||
map_row = &map_row[btn_cnt + 1]; /*Set the map to the next row*/
|
||||
continue;
|
||||
}
|
||||
act_y += btn_h + inner + 1;
|
||||
|
||||
if(strlen(map_p_tmp[btn_cnt]) == 0) break; /*Break on end of map*/
|
||||
map_p_tmp = &map_p_tmp[btn_cnt + 1]; /*Set the map to the next line*/
|
||||
i_tot++; /*Skip the '\n'*/
|
||||
lv_coord_t row_y1 = top + (max_h_no_gap * row) / row_cnt + row * row_gap;
|
||||
lv_coord_t row_y2 = top + (max_h_no_gap * (row + 1)) / row_cnt + row * row_gap;
|
||||
|
||||
|
||||
/*Set the button size and positions*/
|
||||
lv_coord_t max_w_no_gap = max_w - (col_gap * (btn_cnt - 1));
|
||||
uint32_t row_unit_cnt = 0; /*The current unit position in the row*/
|
||||
uint32_t btn;
|
||||
for(btn = 0; btn < btn_cnt; btn++, btn_tot_i++, txt_tot_i++) {
|
||||
uint32_t btn_u = get_button_width(ext->ctrl_bits[btn_tot_i]);
|
||||
|
||||
lv_coord_t btn_x1 = (max_w_no_gap * row_unit_cnt) / unit_cnt + btn * col_gap;
|
||||
lv_coord_t btn_x2 = (max_w_no_gap * (row_unit_cnt + btn_u)) / unit_cnt + btn * col_gap;
|
||||
|
||||
/*If RTL start from the right*/
|
||||
if(base_dir == LV_BIDI_DIR_RTL) {
|
||||
lv_coord_t tmp = btn_x1;
|
||||
btn_x1 = btn_x2;
|
||||
btn_x2 = tmp;
|
||||
btn_x1 = left + max_w - btn_x1;
|
||||
btn_x2 = left + max_w - btn_x2;
|
||||
}
|
||||
|
||||
lv_area_set(&ext->button_areas[btn_tot_i], btn_x1, row_y1, btn_x2, row_y2);
|
||||
|
||||
row_unit_cnt += btn_u;
|
||||
}
|
||||
|
||||
map_row = &map_row[btn_cnt + 1]; /*Set the map to the next line*/
|
||||
}
|
||||
|
||||
lv_obj_invalidate(btnm);
|
||||
@ -407,13 +373,13 @@ void lv_btnmatrix_set_btn_width(lv_obj_t * btnm, uint16_t btn_id, uint8_t width)
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the button matrix like a selector widget (only one button may be toggled at a time).
|
||||
* Make the button matrix like a selector widget (only one button may be checked at a time).
|
||||
* `Checkable` must be enabled on the buttons you want to be selected with `lv_btnmatrix_set_ctrl` or
|
||||
* `lv_btnmatrix_set_btn_ctrl_all`.
|
||||
* @param btnm Button matrix object
|
||||
* @param one_chk Whether "one check" mode is enabled
|
||||
* @param btnm pointer to a button matrix object
|
||||
* @param one_chk whether "one check" mode is enabled
|
||||
*/
|
||||
void lv_btnmatrix_set_one_check(lv_obj_t * btnm, bool one_chk)
|
||||
void lv_btnmatrix_set_one_checked(lv_obj_t * btnm, bool one_chk)
|
||||
{
|
||||
LV_ASSERT_OBJ(btnm, LV_OBJX_NAME);
|
||||
|
||||
@ -421,7 +387,7 @@ void lv_btnmatrix_set_one_check(lv_obj_t * btnm, bool one_chk)
|
||||
ext->one_check = one_chk;
|
||||
|
||||
/*If more than one button is toggled only the first one should be*/
|
||||
make_one_button_toggled(btnm, 0);
|
||||
make_one_button_checked(btnm, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -429,7 +395,7 @@ void lv_btnmatrix_set_one_check(lv_obj_t * btnm, bool one_chk)
|
||||
* @param btnm pointer to a btnmatrix object
|
||||
* @param align LV_LABEL_ALIGN_LEFT, LV_LABEL_ALIGN_RIGHT or LV_LABEL_ALIGN_CENTER
|
||||
*/
|
||||
void lv_btnmatrix_set_align(lv_obj_t * btnm, lv_label_align_t align)
|
||||
void lv_btnmatrix_set_text_align(lv_obj_t * btnm, lv_label_align_t align)
|
||||
{
|
||||
LV_ASSERT_OBJ(btnm, LV_OBJX_NAME);
|
||||
|
||||
@ -573,7 +539,7 @@ bool lv_btnmatrix_get_btn_ctrl(lv_obj_t * btnm, uint16_t btn_id, lv_btnmatrix_ct
|
||||
* @param btnm Button matrix object
|
||||
* @return whether "one check" mode is enabled
|
||||
*/
|
||||
bool lv_btnmatrix_get_one_check(const lv_obj_t * btnm)
|
||||
bool lv_btnmatrix_get_one_checked(const lv_obj_t * btnm)
|
||||
{
|
||||
LV_ASSERT_OBJ(btnm, LV_OBJX_NAME);
|
||||
|
||||
@ -674,8 +640,8 @@ static lv_design_res_t lv_btnmatrix_design(lv_obj_t * btnm, const lv_area_t * cl
|
||||
bool chk_inited = false;
|
||||
bool disabled_inited = false;
|
||||
|
||||
lv_style_int_t padding_top = lv_obj_get_style_pad_top(btnm, LV_BTNMATRIX_PART_BG);
|
||||
lv_style_int_t padding_bottom = lv_obj_get_style_pad_bottom(btnm, LV_BTNMATRIX_PART_BG);
|
||||
lv_style_int_t padding_top = lv_obj_get_style_pad_top(btnm, LV_BTNMATRIX_PART_MAIN);
|
||||
lv_style_int_t padding_bottom = lv_obj_get_style_pad_bottom(btnm, LV_BTNMATRIX_PART_MAIN);
|
||||
|
||||
for(btn_i = 0; btn_i < ext->btn_cnt; btn_i++, txt_i++) {
|
||||
/*Search the next valid text in the map*/
|
||||
@ -699,7 +665,7 @@ static lv_design_res_t lv_btnmatrix_design(lv_obj_t * btnm, const lv_area_t * cl
|
||||
lv_draw_rect_dsc_t * draw_rect_dsc_act;
|
||||
lv_draw_label_dsc_t * draw_label_dsc_act;
|
||||
lv_state_t btn_state = LV_STATE_DEFAULT;
|
||||
if(button_get_tgl_state(ext->ctrl_bits[btn_i])) btn_state |= LV_STATE_CHECKED;
|
||||
if(button_get_checked(ext->ctrl_bits[btn_i])) btn_state |= LV_STATE_CHECKED;
|
||||
if(button_is_inactive(ext->ctrl_bits[btn_i])) btn_state |= LV_STATE_DISABLED;
|
||||
if(btn_i == ext->btn_id_pr) btn_state |= LV_STATE_PRESSED;
|
||||
if(btn_i == ext->btn_id_focused) {
|
||||
@ -830,12 +796,12 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa
|
||||
/* Include the ancient signal function */
|
||||
res = ancestor_signal(btnm, sign, param);
|
||||
if(res != LV_RES_OK) return res;
|
||||
if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, LV_OBJX_NAME);
|
||||
if(sign == LV_SIGNAL_GET_TYPE) return _lv_obj_handle_get_type_signal(param, LV_OBJX_NAME);
|
||||
|
||||
lv_btnmatrix_ext_t * ext = lv_obj_get_ext_attr(btnm);
|
||||
lv_point_t p;
|
||||
if(sign == LV_SIGNAL_CLEANUP) {
|
||||
lv_obj_clean_style_list(btnm, LV_BTNMATRIX_PART_BTN);
|
||||
_lv_obj_reset_style_list_no_refr(btnm, LV_BTNMATRIX_PART_BTN);
|
||||
lv_mem_free(ext->button_areas);
|
||||
lv_mem_free(ext->ctrl_bits);
|
||||
}
|
||||
@ -843,7 +809,9 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa
|
||||
lv_btnmatrix_set_map(btnm, ext->map_p);
|
||||
}
|
||||
else if(sign == LV_SIGNAL_COORD_CHG) {
|
||||
if(lv_obj_get_width(btnm) != lv_area_get_width(param) || lv_obj_get_height(btnm) != lv_area_get_height(param)) {
|
||||
if(param &&
|
||||
(lv_obj_get_width(btnm) != lv_area_get_width(param) || lv_obj_get_height(btnm) != lv_area_get_height(param)))
|
||||
{
|
||||
lv_btnmatrix_set_map(btnm, ext->map_p);
|
||||
}
|
||||
}
|
||||
@ -920,13 +888,13 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa
|
||||
/*Toggle the button if enabled*/
|
||||
if(button_is_tgl_enabled(ext->ctrl_bits[ext->btn_id_pr]) &&
|
||||
!button_is_inactive(ext->ctrl_bits[ext->btn_id_pr])) {
|
||||
if(button_get_tgl_state(ext->ctrl_bits[ext->btn_id_pr]) && !ext->one_check) {
|
||||
ext->ctrl_bits[ext->btn_id_pr] &= (~LV_BTNMATRIX_CTRL_CHECK_STATE);
|
||||
if(button_get_checked(ext->ctrl_bits[ext->btn_id_pr]) && !ext->one_check) {
|
||||
ext->ctrl_bits[ext->btn_id_pr] &= (~LV_BTNMATRIX_CTRL_CHECKED);
|
||||
}
|
||||
else {
|
||||
ext->ctrl_bits[ext->btn_id_pr] |= LV_BTNMATRIX_CTRL_CHECK_STATE;
|
||||
ext->ctrl_bits[ext->btn_id_pr] |= LV_BTNMATRIX_CTRL_CHECKED;
|
||||
}
|
||||
if(ext->one_check) make_one_button_toggled(btnm, ext->btn_id_pr);
|
||||
if(ext->one_check) make_one_button_checked(btnm, ext->btn_id_pr);
|
||||
}
|
||||
|
||||
/*Invalidate to old pressed area*/;
|
||||
@ -1018,7 +986,8 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa
|
||||
lv_obj_invalidate(btnm);
|
||||
}
|
||||
else if(c == LV_KEY_DOWN) {
|
||||
lv_style_int_t pad_inner = lv_obj_get_style_pad_inner(btnm, LV_BTNMATRIX_PART_BG);
|
||||
lv_coord_t col_gap = LV_MATH_MAX(lv_obj_get_style_margin_left(btnm, LV_BTNMATRIX_PART_BTN), lv_obj_get_style_margin_right(btnm, LV_BTNMATRIX_PART_BTN));
|
||||
|
||||
/*Find the area below the the current*/
|
||||
if(ext->btn_id_focused == LV_BTNMATRIX_BTN_NONE) {
|
||||
ext->btn_id_focused = 0;
|
||||
@ -1031,7 +1000,7 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa
|
||||
for(area_below = ext->btn_id_focused; area_below < ext->btn_cnt; area_below++) {
|
||||
if(ext->button_areas[area_below].y1 > ext->button_areas[ext->btn_id_focused].y1 &&
|
||||
pr_center >= ext->button_areas[area_below].x1 &&
|
||||
pr_center <= ext->button_areas[area_below].x2 + pad_inner &&
|
||||
pr_center <= ext->button_areas[area_below].x2 + col_gap &&
|
||||
button_is_inactive(ext->ctrl_bits[area_below]) == false &&
|
||||
button_is_hidden(ext->ctrl_bits[area_below]) == false) {
|
||||
break;
|
||||
@ -1044,7 +1013,7 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa
|
||||
lv_obj_invalidate(btnm);
|
||||
}
|
||||
else if(c == LV_KEY_UP) {
|
||||
lv_style_int_t pad_inner = lv_obj_get_style_pad_inner(btnm, LV_BTNMATRIX_PART_BG);
|
||||
lv_coord_t col_gap = LV_MATH_MAX(lv_obj_get_style_margin_left(btnm, LV_BTNMATRIX_PART_BTN), lv_obj_get_style_margin_right(btnm, LV_BTNMATRIX_PART_BTN));
|
||||
/*Find the area below the the current*/
|
||||
if(ext->btn_id_focused == LV_BTNMATRIX_BTN_NONE) {
|
||||
ext->btn_id_focused = 0;
|
||||
@ -1056,7 +1025,7 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa
|
||||
|
||||
for(area_above = ext->btn_id_focused; area_above >= 0; area_above--) {
|
||||
if(ext->button_areas[area_above].y1 < ext->button_areas[ext->btn_id_focused].y1 &&
|
||||
pr_center >= ext->button_areas[area_above].x1 - pad_inner &&
|
||||
pr_center >= ext->button_areas[area_above].x1 - col_gap &&
|
||||
pr_center <= ext->button_areas[area_above].x2 &&
|
||||
button_is_inactive(ext->ctrl_bits[area_above]) == false &&
|
||||
button_is_hidden(ext->ctrl_bits[area_above]) == false) {
|
||||
@ -1094,7 +1063,7 @@ static lv_style_list_t * lv_btnmatrix_get_style(lv_obj_t * btnm, uint8_t part)
|
||||
lv_style_list_t * style_dsc_p;
|
||||
|
||||
switch(part) {
|
||||
case LV_BTNMATRIX_PART_BG:
|
||||
case LV_BTNMATRIX_PART_MAIN:
|
||||
style_dsc_p = &btnm->style_list;
|
||||
break;
|
||||
case LV_BTNMATRIX_PART_BTN:
|
||||
@ -1182,9 +1151,9 @@ static bool button_is_tgl_enabled(lv_btnmatrix_ctrl_t ctrl_bits)
|
||||
return (ctrl_bits & LV_BTNMATRIX_CTRL_CHECKABLE) ? true : false;
|
||||
}
|
||||
|
||||
static bool button_get_tgl_state(lv_btnmatrix_ctrl_t ctrl_bits)
|
||||
static bool button_get_checked(lv_btnmatrix_ctrl_t ctrl_bits)
|
||||
{
|
||||
return (ctrl_bits & LV_BTNMATRIX_CTRL_CHECK_STATE) ? true : false;
|
||||
return (ctrl_bits & LV_BTNMATRIX_CTRL_CHECKED) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1203,16 +1172,20 @@ static uint16_t get_button_from_point(lv_obj_t * btnm, lv_point_t * p)
|
||||
|
||||
lv_coord_t w = lv_obj_get_width(btnm);
|
||||
lv_coord_t h = lv_obj_get_height(btnm);
|
||||
lv_style_int_t pleft = lv_obj_get_style_pad_left(btnm, LV_BTNMATRIX_PART_BG);
|
||||
lv_style_int_t pright = lv_obj_get_style_pad_right(btnm, LV_BTNMATRIX_PART_BG);
|
||||
lv_style_int_t ptop = lv_obj_get_style_pad_top(btnm, LV_BTNMATRIX_PART_BG);
|
||||
lv_style_int_t pbottom = lv_obj_get_style_pad_bottom(btnm, LV_BTNMATRIX_PART_BG);
|
||||
lv_style_int_t pinner = lv_obj_get_style_pad_inner(btnm, LV_BTNMATRIX_PART_BG);
|
||||
lv_style_int_t pleft = lv_obj_get_style_pad_left(btnm, LV_BTNMATRIX_PART_MAIN);
|
||||
lv_style_int_t pright = lv_obj_get_style_pad_right(btnm, LV_BTNMATRIX_PART_MAIN);
|
||||
lv_style_int_t ptop = lv_obj_get_style_pad_top(btnm, LV_BTNMATRIX_PART_MAIN);
|
||||
lv_style_int_t pbottom = lv_obj_get_style_pad_bottom(btnm, LV_BTNMATRIX_PART_MAIN);
|
||||
lv_coord_t row_gap = LV_MATH_MAX(lv_obj_get_style_margin_top(btnm, LV_BTNMATRIX_PART_BTN), lv_obj_get_style_margin_bottom(btnm, LV_BTNMATRIX_PART_BTN));
|
||||
lv_coord_t col_gap = LV_MATH_MAX(lv_obj_get_style_margin_left(btnm, LV_BTNMATRIX_PART_BTN), lv_obj_get_style_margin_right(btnm, LV_BTNMATRIX_PART_BTN));
|
||||
|
||||
/*Get the half inner padding. Button look larger with this value. (+1 for rounding error)*/
|
||||
pinner = (pinner / 2) + 1 + (pinner & 1);
|
||||
|
||||
pinner = LV_MATH_MIN(pinner, BTN_EXTRA_CLICK_AREA_MAX);
|
||||
/*Get the half gap. Button look larger with this value. (+1 for rounding error)*/
|
||||
row_gap = (row_gap / 2) + 1 + (row_gap & 1);
|
||||
col_gap = (col_gap / 2) + 1 + (col_gap & 1);
|
||||
|
||||
row_gap = LV_MATH_MIN(row_gap, BTN_EXTRA_CLICK_AREA_MAX);
|
||||
col_gap = LV_MATH_MIN(col_gap, BTN_EXTRA_CLICK_AREA_MAX);
|
||||
pright = LV_MATH_MIN(pright, BTN_EXTRA_CLICK_AREA_MAX);
|
||||
ptop = LV_MATH_MIN(ptop, BTN_EXTRA_CLICK_AREA_MAX);
|
||||
pbottom = LV_MATH_MIN(pbottom, BTN_EXTRA_CLICK_AREA_MAX);
|
||||
@ -1220,18 +1193,18 @@ static uint16_t get_button_from_point(lv_obj_t * btnm, lv_point_t * p)
|
||||
for(i = 0; i < ext->btn_cnt; i++) {
|
||||
lv_area_copy(&btn_area, &ext->button_areas[i]);
|
||||
if(btn_area.x1 <= pleft) btn_area.x1 += btnm_cords.x1 - LV_MATH_MIN(pleft, BTN_EXTRA_CLICK_AREA_MAX);
|
||||
else btn_area.x1 += btnm_cords.x1 - pinner;
|
||||
else btn_area.x1 += btnm_cords.x1 - col_gap;
|
||||
|
||||
if(btn_area.y1 <= ptop) btn_area.y1 += btnm_cords.y1 - LV_MATH_MIN(ptop, BTN_EXTRA_CLICK_AREA_MAX);
|
||||
else btn_area.y1 += btnm_cords.y1 - pinner;
|
||||
else btn_area.y1 += btnm_cords.y1 - row_gap;
|
||||
|
||||
if(btn_area.x2 >= w - pright - 2) btn_area.x2 += btnm_cords.x1 + LV_MATH_MIN(pright,
|
||||
BTN_EXTRA_CLICK_AREA_MAX); /*-2 for rounding error*/
|
||||
else btn_area.x2 += btnm_cords.x1 + pinner;
|
||||
else btn_area.x2 += btnm_cords.x1 + col_gap;
|
||||
|
||||
if(btn_area.y2 >= h - pbottom - 2) btn_area.y2 += btnm_cords.y1 + LV_MATH_MIN(pbottom,
|
||||
BTN_EXTRA_CLICK_AREA_MAX); /*-2 for rounding error*/
|
||||
else btn_area.y2 += btnm_cords.y1 + pinner;
|
||||
else btn_area.y2 += btnm_cords.y1 + row_gap;
|
||||
|
||||
if(_lv_area_is_point_on(&btn_area, p, 0) != false) {
|
||||
break;
|
||||
@ -1288,14 +1261,14 @@ static bool maps_are_identical(const char ** map1, const char ** map2)
|
||||
* @param btnm Button matrix object
|
||||
* @param btn_idx Button that should remain toggled
|
||||
*/
|
||||
static void make_one_button_toggled(lv_obj_t * btnm, uint16_t btn_idx)
|
||||
static void make_one_button_checked(lv_obj_t * btnm, uint16_t btn_idx)
|
||||
{
|
||||
/*Save whether the button was toggled*/
|
||||
bool was_toggled = lv_btnmatrix_get_btn_ctrl(btnm, btn_idx, LV_BTNMATRIX_CTRL_CHECK_STATE);
|
||||
bool was_toggled = lv_btnmatrix_get_btn_ctrl(btnm, btn_idx, LV_BTNMATRIX_CTRL_CHECKED);
|
||||
|
||||
lv_btnmatrix_clear_btn_ctrl_all(btnm, LV_BTNMATRIX_CTRL_CHECK_STATE);
|
||||
lv_btnmatrix_clear_btn_ctrl_all(btnm, LV_BTNMATRIX_CTRL_CHECKED);
|
||||
|
||||
if(was_toggled) lv_btnmatrix_set_btn_ctrl(btnm, btn_idx, LV_BTNMATRIX_CTRL_CHECK_STATE);
|
||||
if(was_toggled) lv_btnmatrix_set_btn_ctrl(btnm, btn_idx, LV_BTNMATRIX_CTRL_CHECKED);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -40,8 +40,8 @@ enum {
|
||||
LV_BTNMATRIX_CTRL_NO_REPEAT = 0x0010, /**< Do not repeat press this button. */
|
||||
LV_BTNMATRIX_CTRL_DISABLED = 0x0020, /**< Disable this button. */
|
||||
LV_BTNMATRIX_CTRL_CHECKABLE = 0x0040, /**< Button *can* be toggled. */
|
||||
LV_BTNMATRIX_CTRL_CHECK_STATE = 0x0080, /**< Button is currently toggled (e.g. checked). */
|
||||
LV_BTNMATRIX_CTRL_CLICK_TRIG = 0x0100, /**< 1: Send LV_EVENT_SELECTED on CLICK, 0: Send LV_EVENT_SELECTED on PRESS*/
|
||||
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*/
|
||||
};
|
||||
typedef uint16_t lv_btnmatrix_ctrl_t;
|
||||
|
||||
@ -63,7 +63,7 @@ typedef struct {
|
||||
} lv_btnmatrix_ext_t;
|
||||
|
||||
enum {
|
||||
LV_BTNMATRIX_PART_BG,
|
||||
LV_BTNMATRIX_PART_MAIN,
|
||||
LV_BTNMATRIX_PART_BTN,
|
||||
};
|
||||
typedef uint8_t lv_btnmatrix_part_t;
|
||||
@ -163,20 +163,20 @@ void lv_btnmatrix_clear_btn_ctrl_all(lv_obj_t * btnm, lv_btnmatrix_ctrl_t ctrl);
|
||||
void lv_btnmatrix_set_btn_width(lv_obj_t * btnm, uint16_t btn_id, uint8_t width);
|
||||
|
||||
/**
|
||||
* Make the button matrix like a selector widget (only one button may be toggled at a time).
|
||||
* Make the button matrix like a selector widget (only one button may be checked at a time).
|
||||
* `Checkable` must be enabled on the buttons you want to be selected with `lv_btnmatrix_set_ctrl` or
|
||||
* `lv_btnmatrix_set_btn_ctrl_all`.
|
||||
* @param btnm Button matrix object
|
||||
* @param one_chk Whether "one check" mode is enabled
|
||||
* @param btnm pointer to a button matrix object
|
||||
* @param one_chk whether "one check" mode is enabled
|
||||
*/
|
||||
void lv_btnmatrix_set_one_check(lv_obj_t * btnm, bool one_chk);
|
||||
void lv_btnmatrix_set_one_checked(lv_obj_t * btnm, bool one_chk);
|
||||
|
||||
/**
|
||||
* Set the align of the map text (left, right or center)
|
||||
* Set the align of the texts (left, right or center)
|
||||
* @param btnm pointer to a btnmatrix object
|
||||
* @param align LV_LABEL_ALIGN_LEFT, LV_LABEL_ALIGN_RIGHT or LV_LABEL_ALIGN_CENTER
|
||||
*/
|
||||
void lv_btnmatrix_set_align(lv_obj_t * btnm, lv_label_align_t align);
|
||||
void lv_btnmatrix_set_text_align(lv_obj_t * btnm, lv_label_align_t align);
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
@ -204,14 +204,6 @@ bool lv_btnmatrix_get_recolor(const lv_obj_t * btnm);
|
||||
*/
|
||||
uint16_t lv_btnmatrix_get_active_btn(const lv_obj_t * btnm);
|
||||
|
||||
/**
|
||||
* Get the text of the lastly "activated" button by the user (pressed, released etc)
|
||||
* Useful in the the `event_cb`
|
||||
* @param btnm pointer to button matrix object
|
||||
* @return text of the last released button (NULL: if unset)
|
||||
*/
|
||||
const char * lv_btnmatrix_get_active_btn_text(const lv_obj_t * btnm);
|
||||
|
||||
/**
|
||||
* Get the focused button's index.
|
||||
* @param btnm pointer to button matrix object
|
||||
@ -232,18 +224,18 @@ const char * lv_btnmatrix_get_btn_text(const lv_obj_t * btnm, uint16_t btn_id);
|
||||
* Get the whether a control value is enabled or disabled for button of a button matrix
|
||||
* @param btnm pointer to a button matrix object
|
||||
* @param btn_id the index a button not counting new line characters. (E.g. the return value of
|
||||
* lv_btnmatrix_get_pressed/released)
|
||||
* lv_btnmatrix_get_active)
|
||||
* @param ctrl control values to check (ORed value can be used)
|
||||
* @return true: long press repeat is disabled; false: long press repeat enabled
|
||||
*/
|
||||
bool lv_btnmatrix_get_btn_ctrl(lv_obj_t * btnm, uint16_t btn_id, lv_btnmatrix_ctrl_t ctrl);
|
||||
|
||||
/**
|
||||
* Find whether "one toggle" mode is enabled.
|
||||
* Find whether "one checked" mode is enabled.
|
||||
* @param btnm Button matrix object
|
||||
* @return whether "one toggle" mode is enabled
|
||||
* @return whether "one checked" mode is enabled
|
||||
*/
|
||||
bool lv_btnmatrix_get_one_check(const lv_obj_t * btnm);
|
||||
bool lv_btnmatrix_get_one_checked(const lv_obj_t * btnm);
|
||||
|
||||
/**
|
||||
* Get the align attribute
|
||||
|
@ -54,7 +54,7 @@ lv_obj_t * lv_checkbox_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
LV_LOG_TRACE("check box create started");
|
||||
|
||||
/*Create the ancestor basic object*/
|
||||
lv_obj_t * cb = lv_obj_create(par, copy);
|
||||
lv_obj_t * cb = lv_label_create(par, copy);
|
||||
LV_ASSERT_MEM(cb);
|
||||
if(cb == NULL) return NULL;
|
||||
|
||||
@ -68,8 +68,6 @@ lv_obj_t * lv_checkbox_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ext->static_txt = 1;
|
||||
ext->text = "Check box";
|
||||
lv_style_list_init(&ext->style_bullet);
|
||||
|
||||
lv_obj_set_signal_cb(cb, lv_checkbox_signal);
|
||||
@ -77,9 +75,9 @@ lv_obj_t * lv_checkbox_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
|
||||
/*Init the new checkbox object*/
|
||||
if(copy == NULL) {
|
||||
lv_label_set_text_static(cb, "Check box");
|
||||
lv_theme_apply(cb, LV_THEME_CHECKBOX);
|
||||
lv_obj_add_flag(cb, LV_OBJ_FLAG_CLICKABLE);
|
||||
lv_obj_set_size(cb, LV_SIZE_AUTO, LV_SIZE_AUTO);
|
||||
|
||||
}
|
||||
else {
|
||||
@ -87,12 +85,6 @@ lv_obj_t * lv_checkbox_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
lv_checkbox_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
|
||||
lv_style_list_copy(&ext->style_bullet, ©_ext->style_bullet);
|
||||
|
||||
ext->static_txt = copy_ext->static_txt;
|
||||
if(copy_ext->static_txt) ext->text = copy_ext->text;
|
||||
else {
|
||||
ext->text = lv_mem_alloc(strlen(copy_ext->text) + 1);
|
||||
strcpy(ext->text, copy_ext->text);
|
||||
}
|
||||
/*Refresh the style with new signal function*/
|
||||
_lv_obj_refresh_style(cb, LV_OBJ_PART_ALL, LV_STYLE_PROP_ALL);
|
||||
}
|
||||
@ -106,66 +98,10 @@ lv_obj_t * lv_checkbox_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
* Setter functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Set the text of a check box. `txt` will be copied and may be deallocated
|
||||
* after this function returns.
|
||||
* @param cb pointer to a check box
|
||||
* @param txt the text of the check box. NULL to refresh with the current text.
|
||||
*/
|
||||
void lv_checkbox_set_text(lv_obj_t * cb, const char * txt)
|
||||
{
|
||||
LV_ASSERT_OBJ(cb, LV_OBJX_NAME);
|
||||
|
||||
lv_checkbox_ext_t * ext = lv_obj_get_ext_attr(cb);
|
||||
if(ext->static_txt) {
|
||||
ext->static_txt = 0;
|
||||
ext->text = NULL;
|
||||
}
|
||||
|
||||
ext->text = lv_mem_realloc(ext->text, strlen(txt) + 1);
|
||||
strcpy(ext->text, txt);
|
||||
|
||||
lv_signal_send(cb, LV_SIGNAL_CHILD_CHG, NULL);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the text of a check box. `txt` must not be deallocated during the life
|
||||
* of this checkbox.
|
||||
* @param cb pointer to a check box
|
||||
* @param txt the text of the check box. NULL to refresh with the current text.
|
||||
*/
|
||||
void lv_checkbox_set_text_static(lv_obj_t * cb, const char * txt)
|
||||
{
|
||||
LV_ASSERT_OBJ(cb, LV_OBJX_NAME);
|
||||
|
||||
lv_checkbox_ext_t * ext = lv_obj_get_ext_attr(cb);
|
||||
if(ext->static_txt == 0) {
|
||||
ext->static_txt = 1;
|
||||
lv_mem_free(ext->text);
|
||||
ext->text = NULL;
|
||||
}
|
||||
|
||||
ext->text = txt;
|
||||
}
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Get the text of a check box
|
||||
* @param cb pointer to check box object
|
||||
* @return pointer to the text of the check box
|
||||
*/
|
||||
const char * lv_checkbox_get_text(const lv_obj_t * cb)
|
||||
{
|
||||
LV_ASSERT_OBJ(cb, LV_OBJX_NAME);
|
||||
|
||||
lv_checkbox_ext_t * ext = lv_obj_get_ext_attr(cb);
|
||||
return ext->text;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
@ -192,19 +128,12 @@ static lv_design_res_t lv_checkbox_design(lv_obj_t * cb, const lv_area_t * clip_
|
||||
lv_checkbox_ext_t * ext = lv_obj_get_ext_attr(cb);
|
||||
|
||||
const lv_font_t * font = lv_obj_get_style_text_font(cb, LV_CHECKBOX_PART_MAIN);
|
||||
lv_style_int_t letter_sp = lv_obj_get_style_text_letter_space(cb, LV_CHECKBOX_PART_MAIN);
|
||||
lv_style_int_t line_sp = lv_obj_get_style_text_line_space(cb, LV_CHECKBOX_PART_MAIN);
|
||||
lv_coord_t line_height = lv_font_get_line_height(font);
|
||||
lv_coord_t line_height = lv_font_get_line_height(font);
|
||||
|
||||
lv_coord_t bg_leftp = lv_obj_get_style_pad_left(cb, LV_CHECKBOX_PART_MAIN);
|
||||
lv_coord_t bg_rightp = lv_obj_get_style_pad_right(cb, LV_CHECKBOX_PART_MAIN);
|
||||
lv_coord_t bg_topp = lv_obj_get_style_pad_top(cb, LV_CHECKBOX_PART_MAIN);
|
||||
lv_coord_t bg_bottomp = lv_obj_get_style_pad_bottom(cb, LV_CHECKBOX_PART_MAIN);
|
||||
|
||||
lv_coord_t bullet_leftm = lv_obj_get_style_margin_left(cb, LV_CHECKBOX_PART_BULLET);
|
||||
lv_coord_t bullet_rightm = lv_obj_get_style_margin_right(cb, LV_CHECKBOX_PART_BULLET);
|
||||
lv_coord_t bullet_topm = lv_obj_get_style_margin_top(cb, LV_CHECKBOX_PART_BULLET);
|
||||
lv_coord_t bullet_bottomm = lv_obj_get_style_margin_bottom(cb, LV_CHECKBOX_PART_BULLET);
|
||||
|
||||
lv_coord_t bullet_leftp = lv_obj_get_style_pad_left(cb, LV_CHECKBOX_PART_BULLET);
|
||||
lv_coord_t bullet_rightp = lv_obj_get_style_pad_right(cb, LV_CHECKBOX_PART_BULLET);
|
||||
@ -215,27 +144,12 @@ static lv_design_res_t lv_checkbox_design(lv_obj_t * cb, const lv_area_t * clip_
|
||||
lv_draw_rect_dsc_init(&bullet_dsc);
|
||||
lv_obj_init_draw_rect_dsc(cb, LV_CHECKBOX_PART_BULLET, &bullet_dsc);
|
||||
lv_area_t bullet_area;
|
||||
bullet_area.x1 = cb->coords.x1 + bg_leftp + bullet_leftm;
|
||||
bullet_area.x2 = bullet_area.x1 + line_height + bullet_leftp + bullet_rightp;
|
||||
bullet_area.y1 = cb->coords.y1 + bg_topp + bullet_topm;
|
||||
bullet_area.y2 = bullet_area.y1 + line_height + bullet_topp + bullet_bottomp;
|
||||
bullet_area.x1 = cb->coords.x1 + bullet_leftm;
|
||||
bullet_area.x2 = bullet_area.x1 + line_height + bullet_leftp + bullet_rightp - 1;
|
||||
bullet_area.y1 = cb->coords.y1 + bg_topp - bullet_topp + bullet_topm;
|
||||
bullet_area.y2 = bullet_area.y1 + line_height + bullet_topp + bullet_bottomp - 1;
|
||||
|
||||
lv_draw_rect(&bullet_area, clip_area, &bullet_dsc);
|
||||
|
||||
lv_point_t text_size;
|
||||
_lv_txt_get_size(&text_size, ext->text, font, letter_sp, line_sp, LV_COORD_MAX, LV_TXT_FLAG_RECOLOR);
|
||||
|
||||
lv_coord_t y_ofs = (lv_area_get_height(&bullet_area) - line_height) / 2; /*Align the text to the bullet's center line*/
|
||||
lv_area_t text_area;
|
||||
text_area.x1 = bullet_area.x2 + bullet_rightm;
|
||||
text_area.x2 = text_area.x1 + text_size.x;
|
||||
text_area.y1 = bullet_area.y1 + bg_topp + y_ofs;
|
||||
text_area.y2 = text_area.y1 + text_size.y;
|
||||
|
||||
lv_draw_label_dsc_t label_dsc;
|
||||
lv_draw_label_dsc_init(&label_dsc);
|
||||
lv_obj_init_draw_label_dsc(cb, LV_CHECKBOX_PART_MAIN, &label_dsc);
|
||||
lv_draw_label(&text_area, clip_area, &label_dsc, ext->text, NULL);
|
||||
} else {
|
||||
ancestor_design(cb, clip_area, mode);
|
||||
}
|
||||
@ -267,33 +181,6 @@ static lv_res_t lv_checkbox_signal(lv_obj_t * cb, lv_signal_t sign, void * param
|
||||
else if (sign == LV_SIGNAL_GET_TYPE) {
|
||||
return _lv_obj_handle_get_type_signal(param, LV_OBJX_NAME);
|
||||
}
|
||||
else if (sign == LV_SIGNAL_GET_SELF_SIZE) {
|
||||
const lv_font_t * font = lv_obj_get_style_text_font(cb, LV_CHECKBOX_PART_MAIN);
|
||||
lv_style_int_t letter_sp = lv_obj_get_style_text_letter_space(cb, LV_CHECKBOX_PART_MAIN);
|
||||
lv_style_int_t line_sp = lv_obj_get_style_text_line_space(cb, LV_CHECKBOX_PART_MAIN);
|
||||
lv_point_t text_size;
|
||||
_lv_txt_get_size(&text_size, ext->text, font, letter_sp, line_sp, LV_COORD_MAX, LV_TXT_FLAG_RECOLOR);
|
||||
|
||||
lv_coord_t line_height = lv_font_get_line_height(font);
|
||||
|
||||
lv_coord_t bullet_leftm = lv_obj_get_style_margin_left(cb, LV_CHECKBOX_PART_BULLET);
|
||||
lv_coord_t bullet_rightm = lv_obj_get_style_margin_right(cb, LV_CHECKBOX_PART_BULLET);
|
||||
lv_coord_t bullet_topm = lv_obj_get_style_margin_top(cb, LV_CHECKBOX_PART_BULLET);
|
||||
lv_coord_t bullet_bottomm = lv_obj_get_style_margin_bottom(cb, LV_CHECKBOX_PART_BULLET);
|
||||
|
||||
lv_coord_t bullet_leftp = lv_obj_get_style_pad_left(cb, LV_CHECKBOX_PART_BULLET);
|
||||
lv_coord_t bullet_rightp = lv_obj_get_style_pad_right(cb, LV_CHECKBOX_PART_BULLET);
|
||||
lv_coord_t bullet_topp = lv_obj_get_style_pad_top(cb, LV_CHECKBOX_PART_BULLET);
|
||||
lv_coord_t bullet_bottomp = lv_obj_get_style_pad_bottom(cb, LV_CHECKBOX_PART_BULLET);
|
||||
|
||||
lv_point_t bullet_size;
|
||||
bullet_size.x = line_height + bullet_leftm + bullet_rightm + bullet_leftp + bullet_rightp;
|
||||
bullet_size.y = line_height + bullet_topm + bullet_bottomm + bullet_topp + bullet_bottomp;
|
||||
|
||||
lv_point_t * size_res = param;
|
||||
size_res->x = bullet_size.x + text_size.x;
|
||||
size_res->y = LV_MATH_MAX(bullet_size.y, text_size.y);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ extern "C" {
|
||||
#error "lv_cb: lv_label is required. Enable it in lv_conf.h (LV_USE_LABEL 1) "
|
||||
#endif
|
||||
|
||||
#include "../lv_core/lv_obj.h"
|
||||
#include "lv_label.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
@ -38,12 +38,10 @@ extern "C" {
|
||||
|
||||
/*Data of check box*/
|
||||
typedef struct {
|
||||
/*No inherited ext, derived from the base object */
|
||||
lv_label_ext_t label_ext;
|
||||
|
||||
/*New data for this widget */
|
||||
lv_style_list_t style_bullet;
|
||||
char * text; /*Pointer to button*/
|
||||
uint32_t static_txt :1;
|
||||
} lv_checkbox_ext_t;
|
||||
|
||||
/** Checkbox styles. */
|
||||
@ -70,21 +68,28 @@ lv_obj_t * lv_checkbox_create(lv_obj_t * par, const lv_obj_t * copy);
|
||||
* Setter functions
|
||||
*====================*/
|
||||
|
||||
|
||||
/**
|
||||
* Set the text of a check box. `txt` will be copied and may be deallocated
|
||||
* after this function returns.
|
||||
* @param cb pointer to a check box
|
||||
* @param txt the text of the check box.
|
||||
* @param txt the text of the check box. NULL to refresh with the current text.
|
||||
*/
|
||||
void lv_checkbox_set_text(lv_obj_t * cb, const char * txt);
|
||||
static inline void lv_checkbox_set_text(lv_obj_t * cb, const char * txt)
|
||||
{
|
||||
lv_label_set_text(cb, txt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the text of a check box. `txt` must not be deallocated during the life
|
||||
* of this checkbox.
|
||||
* @param cb pointer to a check box
|
||||
* @param txt the text of the check box.
|
||||
* @param txt the text of the check box. NULL to refresh with the current text.
|
||||
*/
|
||||
void lv_checkbox_set_text_static(lv_obj_t * cb, const char * txt);
|
||||
static inline void lv_checkbox_set_text_static(lv_obj_t * cb, const char * txt)
|
||||
{
|
||||
lv_label_set_text_static(cb, txt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the state of the check box
|
||||
@ -117,7 +122,10 @@ static inline void lv_checkbox_set_disabled(lv_obj_t * cb, bool dis)
|
||||
* @param cb pointer to check box object
|
||||
* @return pointer to the text of the check box
|
||||
*/
|
||||
const char * lv_checkbox_get_text(const lv_obj_t * cb);
|
||||
static inline const char * lv_checkbox_get_text(const lv_obj_t * cb)
|
||||
{
|
||||
return lv_label_get_text(cb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current state of the check box
|
||||
|
Loading…
x
Reference in New Issue
Block a user