mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
lv_btn_set_styles() revert to set all styles paramter list
This commit is contained in:
parent
919a8e81ea
commit
0dbc0f0442
@ -284,9 +284,6 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, const lv_style_
|
||||
uint32_t letter;
|
||||
while(i < line_end) {
|
||||
letter = txt_utf8_next(txt, &i);
|
||||
if(letter == ':') {
|
||||
letter = ':';
|
||||
}
|
||||
/*Handle the re-color command*/
|
||||
if((flag & TXT_FLAG_RECOLOR) != 0) {
|
||||
if(letter == TXT_RECOLOR_CMD) {
|
||||
@ -933,7 +930,7 @@ static void lv_draw_rect_border_corner(const area_t * cords_p, const area_t * ma
|
||||
uint16_t radius = style->body.radius;
|
||||
uint16_t bwidth = style->body.border.width;
|
||||
color_t bcolor = style->body.border.color;
|
||||
opa_t bopa = (uint16_t)((uint16_t) style->opa * style->body.border.opa ) >> 8;
|
||||
opa_t bopa = (uint32_t)((uint32_t) style->opa * style->body.border.opa ) >> 8;
|
||||
|
||||
/*0 px border width drawn as 1 px, so decrement the bwidth*/
|
||||
bwidth--;
|
||||
|
@ -26,11 +26,11 @@ extern "C" {
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LV_ACTION_RES_INV = 0, /*Typically indicates that the object is deleted (become invalid) in the action function*/
|
||||
LV_ACTION_RES_OK, /*The object is valid (no deleted) after the action*/
|
||||
}lv_action_res_t;
|
||||
LV_RES_INV = 0, /*Typically indicates that the object is deleted (become invalid) in the action function*/
|
||||
LV_RES_OK, /*The object is valid (no deleted) after the action*/
|
||||
}lv_res_t;
|
||||
|
||||
typedef lv_action_res_t ( * lv_action_t) (struct __LV_OBJ_T * obj);
|
||||
typedef lv_res_t (*lv_action_t) (struct __LV_OBJ_T * obj);
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
|
@ -90,10 +90,10 @@ void lv_init(void)
|
||||
act_scr = def_scr;
|
||||
|
||||
top_layer = lv_obj_create(NULL, NULL);
|
||||
lv_obj_set_style(top_layer, &lv_style_transp_tight);
|
||||
lv_obj_set_style(top_layer, &lv_style_transp_fit);
|
||||
|
||||
sys_layer = lv_obj_create(NULL, NULL);
|
||||
lv_obj_set_style(sys_layer, &lv_style_transp_tight);
|
||||
lv_obj_set_style(sys_layer, &lv_style_transp_fit);
|
||||
|
||||
/*Refresh the screen*/
|
||||
lv_obj_invalidate(act_scr);
|
||||
@ -325,6 +325,21 @@ void lv_obj_del(lv_obj_t * obj)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all children of an object
|
||||
* @param obj pointer to an object
|
||||
*/
|
||||
void lv_obj_clear(lv_obj_t *obj)
|
||||
{
|
||||
lv_obj_t *child = lv_obj_get_child(obj, NULL);
|
||||
|
||||
while(child) {
|
||||
lv_obj_del(child);
|
||||
child = lv_obj_get_child(obj, child);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal function of the basic object
|
||||
* @param obj pointer to an object
|
||||
@ -869,7 +884,6 @@ void lv_obj_set_hidden(lv_obj_t * obj, bool en)
|
||||
void lv_obj_set_click(lv_obj_t * obj, bool en)
|
||||
{
|
||||
obj->click = (en == true ? 1 : 0);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -985,7 +999,7 @@ void lv_obj_refresh_ext_size(lv_obj_t * obj)
|
||||
lv_obj_invalidate(obj);
|
||||
}
|
||||
|
||||
#if LV_OBJ_FREE_NUMBER != 0
|
||||
#if LV_OBJ_FREE_NUM != 0
|
||||
/**
|
||||
* Set an application specific number for an object.
|
||||
* It can help to identify objects in the application.
|
||||
@ -998,7 +1012,7 @@ void lv_obj_set_free_num(lv_obj_t * obj, uint8_t free_num)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LV_OBJ_FREE_POINTER != 0
|
||||
#if LV_OBJ_FREE_PTR != 0
|
||||
/**
|
||||
* Set an application specific pointer for an object.
|
||||
* It can help to identify objects in the application.
|
||||
@ -1159,7 +1173,7 @@ lv_obj_t * lv_obj_get_parent(lv_obj_t * obj)
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate through the children of an object
|
||||
* Iterate through the children of an object (start from the "youngest")
|
||||
* @param obj pointer to an object
|
||||
* @param child NULL at first call to get the next children
|
||||
* and the previous return value later
|
||||
@ -1176,6 +1190,24 @@ lv_obj_t * lv_obj_get_child(lv_obj_t * obj, lv_obj_t * child)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate through the children of an object (start from the "oldest")
|
||||
* @param obj pointer to an object
|
||||
* @param child NULL at first call to get the next children
|
||||
* and the previous return value later
|
||||
* @return the child after 'act_child' or NULL if no more child
|
||||
*/
|
||||
lv_obj_t * lv_obj_get_child_back(lv_obj_t * obj, lv_obj_t * child)
|
||||
{
|
||||
if(child == NULL) {
|
||||
return ll_get_tail(&obj->child_ll);
|
||||
} else {
|
||||
return ll_get_prev(&obj->child_ll, child);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the children of an object (only children directly on 'obj')
|
||||
* @param obj pointer to an object
|
||||
|
@ -204,6 +204,12 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, lv_obj_t * copy);
|
||||
*/
|
||||
void lv_obj_del(lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Delete all children of an object
|
||||
* @param obj pointer to an object
|
||||
*/
|
||||
void lv_obj_clear(lv_obj_t *obj);
|
||||
|
||||
/**
|
||||
* Signal function of the basic object
|
||||
* @param obj pointer to an object
|
||||
@ -523,6 +529,15 @@ lv_obj_t * lv_obj_get_parent(lv_obj_t * obj);
|
||||
*/
|
||||
lv_obj_t * lv_obj_get_child(lv_obj_t * obj, lv_obj_t * child);
|
||||
|
||||
/**
|
||||
* Iterate through the children of an object (start from the "oldest")
|
||||
* @param obj pointer to an object
|
||||
* @param child NULL at first call to get the next children
|
||||
* and the previous return value later
|
||||
* @return the child after 'act_child' or NULL if no more child
|
||||
*/
|
||||
lv_obj_t * lv_obj_get_child_back(lv_obj_t * obj, lv_obj_t * child);
|
||||
|
||||
/**
|
||||
* Count the children of an object (only children directly on 'obj')
|
||||
* @param obj pointer to an object
|
||||
|
@ -39,6 +39,7 @@ static void lv_style_aimator(lv_style_anim_dsc_t * dsc, int32_t val);
|
||||
**********************/
|
||||
lv_style_t lv_style_scr;
|
||||
lv_style_t lv_style_transp;
|
||||
lv_style_t lv_style_transp_fit;
|
||||
lv_style_t lv_style_transp_tight;
|
||||
lv_style_t lv_style_plain;
|
||||
lv_style_t lv_style_plain_color;
|
||||
@ -47,7 +48,7 @@ lv_style_t lv_style_pretty_color;
|
||||
lv_style_t lv_style_btn_off_released;
|
||||
lv_style_t lv_style_btn_off_pressed;
|
||||
lv_style_t lv_style_btn_on_released;
|
||||
lv_style_t lv_style_btn_on_pressed;;
|
||||
lv_style_t lv_style_btn_on_pressed;
|
||||
lv_style_t lv_style_btn_inactive;
|
||||
|
||||
/**********************
|
||||
@ -136,9 +137,13 @@ void lv_style_init (void)
|
||||
lv_style_transp.body.border.width = 0;
|
||||
|
||||
/*Transparent tight style*/
|
||||
memcpy(&lv_style_transp_tight, &lv_style_transp, sizeof(lv_style_t));
|
||||
lv_style_transp_tight.body.padding.hor = 0;
|
||||
lv_style_transp_tight.body.padding.ver = 0;
|
||||
memcpy(&lv_style_transp_fit, &lv_style_transp, sizeof(lv_style_t));
|
||||
lv_style_transp_fit.body.padding.hor = 0;
|
||||
lv_style_transp_fit.body.padding.ver = 0;
|
||||
|
||||
/*Transparent fitting size*/
|
||||
memcpy(&lv_style_transp_tight, &lv_style_transp_fit, sizeof(lv_style_t));
|
||||
lv_style_transp_tight.body.padding.inner = 0;
|
||||
|
||||
/*Button released style*/
|
||||
memcpy(&lv_style_btn_off_released, &lv_style_plain, sizeof(lv_style_t));
|
||||
|
@ -146,6 +146,7 @@ void lv_style_anim_create(lv_style_anim_t * anim);
|
||||
*************************/
|
||||
extern lv_style_t lv_style_scr;
|
||||
extern lv_style_t lv_style_transp;
|
||||
extern lv_style_t lv_style_transp_fit;
|
||||
extern lv_style_t lv_style_transp_tight;
|
||||
extern lv_style_t lv_style_plain;
|
||||
extern lv_style_t lv_style_plain_color;
|
||||
|
101
lv_objx/lv_btn.c
101
lv_objx/lv_btn.c
@ -59,17 +59,17 @@ lv_obj_t * lv_btn_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
/*Allocate the extended data*/
|
||||
lv_btn_ext_t * ext = lv_obj_allocate_ext_attr(new_btn, sizeof(lv_btn_ext_t));
|
||||
dm_assert(ext);
|
||||
ext->state = LV_BTN_STATE_OFF_RELEASED;
|
||||
ext->state = LV_BTN_STATE_RELEASED;
|
||||
|
||||
ext->actions[LV_BTN_ACTION_PRESS] = NULL;
|
||||
ext->actions[LV_BTN_ACTION_RELEASE] = NULL;
|
||||
ext->actions[LV_BTN_ACTION_LONG_PRESS] = NULL;
|
||||
ext->actions[LV_BTN_ACTION_LONG_PRESS_REPEATE] = NULL;
|
||||
|
||||
ext->styles[LV_BTN_STATE_OFF_RELEASED] = &lv_style_btn_off_released;
|
||||
ext->styles[LV_BTN_STATE_OFF_PRESSED] = &lv_style_btn_off_pressed;
|
||||
ext->styles[LV_BTN_STATE_ON_RELEASED] = &lv_style_btn_on_released;
|
||||
ext->styles[LV_BTN_STATE_ON_PRESSED] = &lv_style_btn_on_pressed;
|
||||
ext->styles[LV_BTN_STATE_RELEASED] = &lv_style_btn_off_released;
|
||||
ext->styles[LV_BTN_STATE_PRESSED] = &lv_style_btn_off_pressed;
|
||||
ext->styles[LV_BTN_STATE_TGL_RELEASED] = &lv_style_btn_on_released;
|
||||
ext->styles[LV_BTN_STATE_TGL_PRESSED] = &lv_style_btn_on_pressed;
|
||||
ext->styles[LV_BTN_STATE_INACTIVE] = &lv_style_btn_inactive;
|
||||
|
||||
ext->long_press_action_executed = 0;
|
||||
@ -80,7 +80,7 @@ lv_obj_t * lv_btn_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
/*If no copy do the basic initialization*/
|
||||
if(copy == NULL) {
|
||||
lv_cont_set_layout(new_btn, LV_CONT_LAYOUT_CENTER);
|
||||
lv_obj_set_style(new_btn, ext->styles[LV_BTN_STATE_OFF_RELEASED]);
|
||||
lv_obj_set_style(new_btn, ext->styles[LV_BTN_STATE_RELEASED]);
|
||||
}
|
||||
/*Copy 'copy'*/
|
||||
else {
|
||||
@ -119,10 +119,10 @@ bool lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param)
|
||||
|
||||
if(sign == LV_SIGNAL_PRESSED) {
|
||||
/*Refresh the state*/
|
||||
if(ext->state == LV_BTN_STATE_OFF_RELEASED) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_OFF_PRESSED);
|
||||
} else if(ext->state == LV_BTN_STATE_ON_RELEASED) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_ON_PRESSED);
|
||||
if(ext->state == LV_BTN_STATE_RELEASED) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_PRESSED);
|
||||
} else if(ext->state == LV_BTN_STATE_TGL_RELEASED) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_TGL_PRESSED);
|
||||
}
|
||||
|
||||
ext->long_press_action_executed = 0;
|
||||
@ -133,38 +133,38 @@ bool lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param)
|
||||
}
|
||||
else if(sign == LV_SIGNAL_PRESS_LOST) {
|
||||
/*Refresh the state*/
|
||||
if(ext->state == LV_BTN_STATE_OFF_PRESSED) lv_btn_set_state(btn, LV_BTN_STATE_OFF_RELEASED);
|
||||
else if(ext->state == LV_BTN_STATE_ON_PRESSED) lv_btn_set_state(btn, LV_BTN_STATE_ON_RELEASED);
|
||||
if(ext->state == LV_BTN_STATE_PRESSED) lv_btn_set_state(btn, LV_BTN_STATE_RELEASED);
|
||||
else if(ext->state == LV_BTN_STATE_TGL_PRESSED) lv_btn_set_state(btn, LV_BTN_STATE_TGL_RELEASED);
|
||||
}
|
||||
else if(sign == LV_SIGNAL_PRESSING) {
|
||||
/*When the button begins to drag revert pressed states to released*/
|
||||
if(lv_indev_is_dragging(param) != false) {
|
||||
if(ext->state == LV_BTN_STATE_OFF_PRESSED) lv_btn_set_state(btn, LV_BTN_STATE_OFF_RELEASED);
|
||||
else if(ext->state == LV_BTN_STATE_ON_PRESSED) lv_btn_set_state(btn, LV_BTN_STATE_ON_RELEASED);
|
||||
if(ext->state == LV_BTN_STATE_PRESSED) lv_btn_set_state(btn, LV_BTN_STATE_RELEASED);
|
||||
else if(ext->state == LV_BTN_STATE_TGL_PRESSED) lv_btn_set_state(btn, LV_BTN_STATE_TGL_RELEASED);
|
||||
}
|
||||
}
|
||||
else if(sign == LV_SIGNAL_RELEASED) {
|
||||
/*If not dragged and it was not long press action then
|
||||
*change state and run the action*/
|
||||
if(lv_indev_is_dragging(param) == false && ext->long_press_action_executed == 0) {
|
||||
if(ext->state == LV_BTN_STATE_OFF_PRESSED && tgl == false) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_OFF_RELEASED);
|
||||
} else if(ext->state == LV_BTN_STATE_ON_PRESSED && tgl == false) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_ON_RELEASED);
|
||||
} else if(ext->state == LV_BTN_STATE_OFF_PRESSED && tgl == true) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_ON_RELEASED);
|
||||
} else if(ext->state == LV_BTN_STATE_ON_PRESSED && tgl == true) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_OFF_RELEASED);
|
||||
if(ext->state == LV_BTN_STATE_PRESSED && tgl == false) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_RELEASED);
|
||||
} else if(ext->state == LV_BTN_STATE_TGL_PRESSED && tgl == false) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_TGL_RELEASED);
|
||||
} else if(ext->state == LV_BTN_STATE_PRESSED && tgl == true) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_TGL_RELEASED);
|
||||
} else if(ext->state == LV_BTN_STATE_TGL_PRESSED && tgl == true) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_RELEASED);
|
||||
}
|
||||
|
||||
if(ext->actions[LV_BTN_ACTION_RELEASE] && state != LV_BTN_STATE_INACTIVE) {
|
||||
valid = ext->actions[LV_BTN_ACTION_RELEASE](btn);
|
||||
}
|
||||
} else { /*If dragged change back the state*/
|
||||
if(ext->state == LV_BTN_STATE_OFF_PRESSED) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_OFF_RELEASED);
|
||||
} else if(ext->state == LV_BTN_STATE_ON_PRESSED) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_ON_RELEASED);
|
||||
if(ext->state == LV_BTN_STATE_PRESSED) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_RELEASED);
|
||||
} else if(ext->state == LV_BTN_STATE_TGL_PRESSED) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_TGL_RELEASED);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -182,22 +182,22 @@ bool lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param)
|
||||
else if(sign == LV_SIGNAL_CONTROLL) {
|
||||
char c = *((char*)param);
|
||||
if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_UP) {
|
||||
if(lv_btn_get_toggle(btn) != false) lv_btn_set_state(btn, LV_BTN_STATE_ON_RELEASED);
|
||||
if(lv_btn_get_toggle(btn) != false) lv_btn_set_state(btn, LV_BTN_STATE_TGL_RELEASED);
|
||||
if(ext->actions[LV_BTN_ACTION_RELEASE] && lv_btn_get_state(btn) != LV_BTN_STATE_INACTIVE) {
|
||||
valid = ext->actions[LV_BTN_ACTION_RELEASE];
|
||||
}
|
||||
} else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_DOWN) {
|
||||
if(lv_btn_get_toggle(btn) != false) lv_btn_set_state(btn, LV_BTN_STATE_OFF_RELEASED);
|
||||
if(lv_btn_get_toggle(btn) != false) lv_btn_set_state(btn, LV_BTN_STATE_RELEASED);
|
||||
if(ext->actions[LV_BTN_ACTION_RELEASE] && lv_btn_get_state(btn) != LV_BTN_STATE_INACTIVE) {
|
||||
valid = ext->actions[LV_BTN_ACTION_RELEASE](btn);
|
||||
}
|
||||
} else if(c == LV_GROUP_KEY_ENTER) {
|
||||
if(lv_btn_get_toggle(btn) != false) {
|
||||
lv_btn_state_t state = lv_btn_get_state(btn);
|
||||
if(state == LV_BTN_STATE_OFF_RELEASED) lv_btn_set_state(btn, LV_BTN_STATE_ON_RELEASED);
|
||||
else if(state == LV_BTN_STATE_OFF_PRESSED) lv_btn_set_state(btn, LV_BTN_STATE_ON_PRESSED);
|
||||
else if(state == LV_BTN_STATE_ON_RELEASED) lv_btn_set_state(btn, LV_BTN_STATE_OFF_RELEASED);
|
||||
else if(state == LV_BTN_STATE_ON_PRESSED) lv_btn_set_state(btn, LV_BTN_STATE_OFF_PRESSED);
|
||||
if(state == LV_BTN_STATE_RELEASED) lv_btn_set_state(btn, LV_BTN_STATE_TGL_RELEASED);
|
||||
else if(state == LV_BTN_STATE_PRESSED) lv_btn_set_state(btn, LV_BTN_STATE_TGL_PRESSED);
|
||||
else if(state == LV_BTN_STATE_TGL_RELEASED) lv_btn_set_state(btn, LV_BTN_STATE_RELEASED);
|
||||
else if(state == LV_BTN_STATE_TGL_PRESSED) lv_btn_set_state(btn, LV_BTN_STATE_PRESSED);
|
||||
}
|
||||
if(ext->actions[LV_BTN_ACTION_RELEASE] && lv_btn_get_state(btn) != LV_BTN_STATE_INACTIVE) {
|
||||
valid = ext->actions[LV_BTN_ACTION_RELEASE](btn);
|
||||
@ -247,10 +247,10 @@ void lv_btn_toggle(lv_obj_t * btn)
|
||||
{
|
||||
lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn);
|
||||
switch(ext->state) {
|
||||
case LV_BTN_STATE_OFF_RELEASED: lv_btn_set_state(btn, LV_BTN_STATE_ON_RELEASED); break;
|
||||
case LV_BTN_STATE_OFF_PRESSED: lv_btn_set_state(btn, LV_BTN_STATE_ON_PRESSED); break;
|
||||
case LV_BTN_STATE_ON_RELEASED: lv_btn_set_state(btn, LV_BTN_STATE_OFF_RELEASED); break;
|
||||
case LV_BTN_STATE_ON_PRESSED: lv_btn_set_state(btn, LV_BTN_STATE_OFF_PRESSED); break;
|
||||
case LV_BTN_STATE_RELEASED: lv_btn_set_state(btn, LV_BTN_STATE_TGL_RELEASED); break;
|
||||
case LV_BTN_STATE_PRESSED: lv_btn_set_state(btn, LV_BTN_STATE_TGL_PRESSED); break;
|
||||
case LV_BTN_STATE_TGL_RELEASED: lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); break;
|
||||
case LV_BTN_STATE_TGL_PRESSED: lv_btn_set_state(btn, LV_BTN_STATE_PRESSED); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@ -267,23 +267,30 @@ void lv_btn_set_action(lv_obj_t * btn, lv_btn_action_t type, lv_action_t action)
|
||||
lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn);
|
||||
ext->actions[type] = action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set styles of a button is each state. Use NULL for any style which are not be changed.
|
||||
* Set styles of a button is each state. Use NULL for any style to leave it unchanged
|
||||
* @param btn pointer to button object
|
||||
* @param rel pointer to a style for releases state
|
||||
* @param pr pointer to a style for pressed state
|
||||
* @param trel pointer to a style for toggled releases state
|
||||
* @param tpr pointer to a style for toggled pressed state
|
||||
* @param ina pointer to a style for inactive state
|
||||
* @param rel_style pointer to a style for releases state
|
||||
* @param pr_style pointer to a style for pressed state
|
||||
* @param tgl_rel_style pointer to a style for toggled releases state
|
||||
* @param tgl_pr_style pointer to a style for toggled pressed state
|
||||
* @param inactive_style pointer to a style for inactive state
|
||||
*/
|
||||
void lv_btn_set_style(lv_obj_t * btn, lv_btn_state_t state, lv_style_t * style)
|
||||
void lv_btn_set_styles(lv_obj_t * btn, lv_style_t *rel_style, lv_style_t *pr_style,
|
||||
lv_style_t *tgl_rel_style, lv_style_t *tgl_pr_style,
|
||||
lv_style_t *inactive_style)
|
||||
{
|
||||
if(state >= LV_BTN_STATE_NUM) return;
|
||||
|
||||
lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn);
|
||||
ext->styles[state] = style;
|
||||
|
||||
if(ext->state == state) lv_obj_set_style(btn, ext->styles[ext->state]);
|
||||
if(rel_style != NULL) ext->styles[LV_BTN_STATE_RELEASED] = rel_style;
|
||||
if(pr_style != NULL) ext->styles[LV_BTN_STATE_PRESSED] = pr_style;
|
||||
if(tgl_rel_style != NULL) ext->styles[LV_BTN_STATE_TGL_RELEASED] = tgl_rel_style;
|
||||
if(tgl_pr_style != NULL) ext->styles[LV_BTN_STATE_TGL_PRESSED] = tgl_pr_style;
|
||||
if(inactive_style != NULL) ext->styles[LV_BTN_STATE_INACTIVE] = inactive_style;
|
||||
|
||||
/*Refresh the object with the new style*/
|
||||
lv_obj_set_style(btn, ext->styles[ext->state]);
|
||||
}
|
||||
|
||||
|
||||
|
@ -35,10 +35,10 @@ extern "C" {
|
||||
/*Button states*/
|
||||
typedef enum
|
||||
{
|
||||
LV_BTN_STATE_OFF_RELEASED,
|
||||
LV_BTN_STATE_OFF_PRESSED,
|
||||
LV_BTN_STATE_ON_RELEASED,
|
||||
LV_BTN_STATE_ON_PRESSED,
|
||||
LV_BTN_STATE_RELEASED,
|
||||
LV_BTN_STATE_PRESSED,
|
||||
LV_BTN_STATE_TGL_RELEASED,
|
||||
LV_BTN_STATE_TGL_PRESSED,
|
||||
LV_BTN_STATE_INACTIVE,
|
||||
LV_BTN_STATE_NUM,
|
||||
}lv_btn_state_t;
|
||||
@ -114,15 +114,17 @@ void lv_btn_toggle(lv_obj_t * btn);
|
||||
void lv_btn_set_action(lv_obj_t * btn, lv_btn_action_t type, lv_action_t action);
|
||||
|
||||
/**
|
||||
* Set styles of a button is each state. Use NULL for any style which are not be changed.
|
||||
* Set styles of a button is each state. Use NULL for any style to leave it unchanged
|
||||
* @param btn pointer to button object
|
||||
* @param rel pointer to a style for releases state
|
||||
* @param pr pointer to a style for pressed state
|
||||
* @param trel pointer to a style for toggled releases state
|
||||
* @param tpr pointer to a style for toggled pressed state
|
||||
* @param ina pointer to a style for inactive state
|
||||
* @param rel_style pointer to a style for releases state
|
||||
* @param pr_style pointer to a style for pressed state
|
||||
* @param tgl_rel_style pointer to a style for toggled releases state
|
||||
* @param tgl_pr_style pointer to a style for toggled pressed state
|
||||
* @param inactive_style pointer to a style for inactive state
|
||||
*/
|
||||
void lv_btn_set_style(lv_obj_t * btn, lv_btn_state_t state, lv_style_t * style);
|
||||
void lv_btn_set_styles(lv_obj_t * btn, lv_style_t *rel_style, lv_style_t *pr_style,
|
||||
lv_style_t *tgl_rel_style, lv_style_t *tgl_pr_style,
|
||||
lv_style_t *inactive_style);
|
||||
|
||||
/**
|
||||
* Get the current state of the button
|
||||
|
@ -78,10 +78,10 @@ lv_obj_t * lv_btnm_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
ext->action = NULL;
|
||||
ext->map_p = NULL;
|
||||
ext->toggle = 0;
|
||||
ext->button_styles[LV_BTN_STATE_OFF_RELEASED] = &lv_style_btn_off_released;
|
||||
ext->button_styles[LV_BTN_STATE_OFF_PRESSED] = &lv_style_btn_off_pressed;
|
||||
ext->button_styles[LV_BTN_STATE_ON_RELEASED] = &lv_style_btn_on_released;
|
||||
ext->button_styles[LV_BTN_STATE_ON_PRESSED] = &lv_style_btn_on_pressed;
|
||||
ext->button_styles[LV_BTN_STATE_RELEASED] = &lv_style_btn_off_released;
|
||||
ext->button_styles[LV_BTN_STATE_PRESSED] = &lv_style_btn_off_pressed;
|
||||
ext->button_styles[LV_BTN_STATE_TGL_RELEASED] = &lv_style_btn_on_released;
|
||||
ext->button_styles[LV_BTN_STATE_TGL_PRESSED] = &lv_style_btn_on_pressed;
|
||||
ext->button_styles[LV_BTN_STATE_INACTIVE] = &lv_style_btn_inactive;
|
||||
|
||||
if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_func(new_btnm);
|
||||
@ -373,20 +373,26 @@ void lv_btnm_set_toggle(lv_obj_t * btnm, bool en, uint16_t id)
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the styles of the buttons of the button matrix
|
||||
* @param btnm pointer to a button matrix object
|
||||
* @param rel pointer to a style for releases state (NULL to leave it unchanged)
|
||||
* @param pr pointer to a style for pressed state (NULL to leave it unchanged)
|
||||
* @param trel pointer to a style for toggled releases state (NULL to leave it unchanged)
|
||||
* @param tpr pointer to a style for toggled pressed state (NULL to leave it unchanged)
|
||||
* @param ina pointer to a style for inactive state (NULL to leave it unchanged)
|
||||
* Set styles of the button is each state. Use NULL for any style to leave it unchanged.
|
||||
* @param btnm pointer to button matrix object
|
||||
* @param rel_style pointer to a style for releases state
|
||||
* @param pr_style pointer to a style for pressed state
|
||||
* @param tgl_rel_style pointer to a style for toggled releases state
|
||||
* @param tgl_pr_style pointer to a style for toggled pressed state
|
||||
* @param inactive_style pointer to a style for inactive state
|
||||
*/
|
||||
void lv_btnm_set_button_style(lv_obj_t *btnm, lv_btn_state_t state, lv_style_t *style)
|
||||
{
|
||||
if(state >= LV_BTN_STATE_NUM) return;
|
||||
void lv_btnm_set_button_style(lv_obj_t *btnm, lv_style_t *rel_style, lv_style_t *pr_style,
|
||||
lv_style_t *tgl_rel_style, lv_style_t *tgl_pr_style,
|
||||
lv_style_t *inactive_style)
|
||||
|
||||
{
|
||||
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
|
||||
ext->button_styles[state] = style;
|
||||
|
||||
if(rel_style != NULL) ext->button_styles[LV_BTN_STATE_RELEASED] = rel_style;
|
||||
if(pr_style != NULL) ext->button_styles[LV_BTN_STATE_PRESSED] = pr_style;
|
||||
if(tgl_rel_style != NULL) ext->button_styles[LV_BTN_STATE_TGL_RELEASED] = tgl_rel_style;
|
||||
if(tgl_pr_style != NULL) ext->button_styles[LV_BTN_STATE_TGL_PRESSED] = tgl_pr_style;
|
||||
if(inactive_style != NULL) ext->button_styles[LV_BTN_STATE_INACTIVE] = inactive_style;
|
||||
|
||||
lv_obj_invalidate(btnm);
|
||||
}
|
||||
@ -489,10 +495,10 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_
|
||||
btn_h = area_get_height(&area_tmp);
|
||||
|
||||
/*Load the style*/
|
||||
if(btn_i != ext->button_id_pressed && btn_i != ext->button_id_toggled) btn_style = lv_btnm_get_button_style(btnm, LV_BTN_STATE_OFF_RELEASED);
|
||||
else if(btn_i == ext->button_id_pressed && btn_i != ext->button_id_toggled) btn_style = lv_btnm_get_button_style(btnm, LV_BTN_STATE_OFF_PRESSED);
|
||||
else if(btn_i != ext->button_id_pressed && btn_i == ext->button_id_toggled) btn_style = lv_btnm_get_button_style(btnm, LV_BTN_STATE_ON_RELEASED);
|
||||
else if(btn_i == ext->button_id_pressed && btn_i == ext->button_id_toggled) btn_style = lv_btnm_get_button_style(btnm, LV_BTN_STATE_ON_PRESSED);
|
||||
if(btn_i != ext->button_id_pressed && btn_i != ext->button_id_toggled) btn_style = lv_btnm_get_button_style(btnm, LV_BTN_STATE_RELEASED);
|
||||
else if(btn_i == ext->button_id_pressed && btn_i != ext->button_id_toggled) btn_style = lv_btnm_get_button_style(btnm, LV_BTN_STATE_PRESSED);
|
||||
else if(btn_i != ext->button_id_pressed && btn_i == ext->button_id_toggled) btn_style = lv_btnm_get_button_style(btnm, LV_BTN_STATE_TGL_RELEASED);
|
||||
else if(btn_i == ext->button_id_pressed && btn_i == ext->button_id_toggled) btn_style = lv_btnm_get_button_style(btnm, LV_BTN_STATE_TGL_PRESSED);
|
||||
|
||||
lv_draw_rect(&area_tmp, mask, btn_style);
|
||||
|
||||
|
@ -40,7 +40,7 @@ extern "C" {
|
||||
/* Type of callback function which is called when a button is released or long pressed on the button matrix
|
||||
* Parameters: button matrix, text of the released button
|
||||
* return LV_ACTION_RES_INV if the button matrix is deleted else LV_ACTION_RES_OK*/
|
||||
typedef lv_action_res_t (*lv_btnm_action_t) (lv_obj_t *, const char *txt);
|
||||
typedef lv_res_t (*lv_btnm_action_t) (lv_obj_t *, const char *txt);
|
||||
|
||||
/*Data of button matrix*/
|
||||
typedef struct
|
||||
@ -110,17 +110,19 @@ void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_action_t cb);
|
||||
*/
|
||||
void lv_btnm_set_toggle(lv_obj_t * btnm, bool en, uint16_t id);
|
||||
|
||||
/**
|
||||
* Set the styles of the buttons of the button matrix
|
||||
* @param btnm pointer to a button matrix object
|
||||
* @param rel pointer to a style for releases state (NULL to leave it unchanged)
|
||||
* @param pr pointer to a style for pressed state (NULL to leave it unchanged)
|
||||
* @param trel pointer to a style for toggled releases state (NULL to leave it unchanged)
|
||||
* @param tpr pointer to a style for toggled pressed state (NULL to leave it unchanged)
|
||||
* @param ina pointer to a style for inactive state (NULL to leave it unchanged)
|
||||
*/
|
||||
void lv_btnm_set_button_style(lv_obj_t *btnm, lv_btn_state_t state, lv_style_t *style);
|
||||
|
||||
/**
|
||||
* Set styles of the button is each state. Use NULL for any style to leave it unchanged.
|
||||
* @param btnm pointer to button matrix object
|
||||
* @param rel_style pointer to a style for releases state
|
||||
* @param pr_style pointer to a style for pressed state
|
||||
* @param tgl_rel_style pointer to a style for toggled releases state
|
||||
* @param tgl_pr_style pointer to a style for toggled pressed state
|
||||
* @param inactive_style pointer to a style for inactive state
|
||||
*/
|
||||
void lv_btnm_set_button_style(lv_obj_t *btnm, lv_style_t *rel_style, lv_style_t *pr_style,
|
||||
lv_style_t *tgl_rel_style, lv_style_t *tgl_pr_style,
|
||||
lv_style_t *inactive_style);
|
||||
/**
|
||||
* Get the current map of a button matrix
|
||||
* @param btnm pointer to a button matrix object
|
||||
|
@ -69,11 +69,9 @@ lv_obj_t * lv_cb_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
/*Init the new checkbox object*/
|
||||
if(copy == NULL) {
|
||||
ext->bullet = lv_btn_create(new_cb, NULL);
|
||||
lv_btn_set_style(new_cb, LV_BTN_STATE_OFF_RELEASED, &lv_style_transp);
|
||||
lv_btn_set_style(new_cb, LV_BTN_STATE_OFF_PRESSED, &lv_style_transp);
|
||||
lv_btn_set_style(new_cb, LV_BTN_STATE_ON_RELEASED, &lv_style_transp);
|
||||
lv_btn_set_style(new_cb, LV_BTN_STATE_ON_PRESSED, &lv_style_transp);
|
||||
lv_btn_set_style(new_cb, LV_BTN_STATE_INACTIVE, &lv_style_transp);
|
||||
lv_btn_set_styles(new_cb, &lv_style_transp, &lv_style_transp,
|
||||
&lv_style_transp, &lv_style_transp,
|
||||
&lv_style_transp);
|
||||
|
||||
lv_cont_set_layout(new_cb, LV_CONT_LAYOUT_ROW_M);
|
||||
lv_cont_set_fit(new_cb, true, true);
|
||||
@ -81,10 +79,9 @@ lv_obj_t * lv_cb_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
|
||||
if(ancestor_bullet_design_f == NULL) ancestor_bullet_design_f = lv_obj_get_design_func(ext->bullet);
|
||||
lv_obj_set_click(ext->bullet, false);
|
||||
lv_btn_set_style(ext->bullet, LV_BTN_STATE_OFF_RELEASED, &lv_style_pretty);
|
||||
lv_btn_set_style(ext->bullet, LV_BTN_STATE_OFF_PRESSED, &lv_style_pretty_color);
|
||||
lv_btn_set_style(ext->bullet, LV_BTN_STATE_ON_RELEASED, &lv_style_btn_on_released);
|
||||
lv_btn_set_style(ext->bullet, LV_BTN_STATE_ON_PRESSED, &lv_style_btn_on_pressed);
|
||||
lv_btn_set_styles(ext->bullet, &lv_style_pretty, &lv_style_pretty_color,
|
||||
&lv_style_btn_on_released, &lv_style_btn_on_pressed,
|
||||
NULL);
|
||||
|
||||
ext->label = lv_label_create(new_cb, NULL);
|
||||
lv_obj_set_style(ext->label, NULL); /*Inherit the style of the parent*/
|
||||
|
@ -29,7 +29,7 @@
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static bool lv_ddlist_design(lv_obj_t * ddlist, const area_t * mask, lv_design_mode_t mode);
|
||||
static lv_action_res_t lv_ddlist_rel_action(lv_obj_t * ddlist);
|
||||
static lv_res_t lv_ddlist_rel_action(lv_obj_t * ddlist);
|
||||
static void lv_ddlist_refr_size(lv_obj_t * ddlist, uint16_t anim_time);
|
||||
static void lv_ddlist_pos_act_option(lv_obj_t * ddlist);
|
||||
|
||||
@ -457,7 +457,7 @@ static bool lv_ddlist_design(lv_obj_t * ddlist, const area_t * mask, lv_design_m
|
||||
* @param ddlist pointer to a drop down list object
|
||||
* @return LV_ACTION_RES_INV if the ddlist it deleted in the user callback else LV_ACTION_RES_OK
|
||||
*/
|
||||
static lv_action_res_t lv_ddlist_rel_action(lv_obj_t * ddlist)
|
||||
static lv_res_t lv_ddlist_rel_action(lv_obj_t * ddlist)
|
||||
{
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
||||
|
||||
@ -492,7 +492,7 @@ static lv_action_res_t lv_ddlist_rel_action(lv_obj_t * ddlist)
|
||||
}
|
||||
lv_ddlist_refr_size(ddlist, ext->anim_time);
|
||||
|
||||
return LV_ACTION_RES_OK;
|
||||
return LV_RES_OK;
|
||||
|
||||
}
|
||||
|
||||
|
@ -14,10 +14,7 @@
|
||||
#include "../lv_draw/lv_draw.h"
|
||||
#include "misc/fs/fsint.h"
|
||||
#include "misc/fs/ufs/ufs.h"
|
||||
|
||||
#if LV_IMG_ENABLE_SYMBOLS != 0
|
||||
#include "misc/gfx/text.h"
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
@ -31,7 +28,6 @@
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static bool lv_img_design(lv_obj_t * img, const area_t * mask, lv_design_mode_t mode);
|
||||
|
||||
static bool lv_img_is_symbol(const char * txt);
|
||||
|
||||
/**********************
|
||||
@ -192,20 +188,12 @@ void lv_img_set_file(lv_obj_t * img, const char * fn)
|
||||
}
|
||||
/*Handle symbol texts*/
|
||||
else {
|
||||
#if LV_IMG_ENABLE_SYMBOLS
|
||||
lv_style_t * style = lv_obj_get_style(img);
|
||||
point_t size;
|
||||
txt_get_size(&size, fn, style->text.font, style->text.space_letter, style->text.space_line, CORD_MAX, TXT_FLAG_NONE);
|
||||
ext->w = size.x;
|
||||
ext->h = size.y;
|
||||
ext->transp = 1; /*Symbols always have transparent parts*/
|
||||
#else
|
||||
/*Never goes here, just to be sure handle this */
|
||||
ext->w = lv_obj_get_width(img);
|
||||
ext->h = lv_obj_get_height(img);
|
||||
ext->transp = 0;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
if(fn != NULL) {
|
||||
@ -236,7 +224,6 @@ void lv_img_set_auto_size(lv_obj_t * img, bool en)
|
||||
ext->auto_size = (en == false ? 0 : 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enable the upscaling if LV_ANTIALIAS is enabled.
|
||||
* If enabled the object size will be same as the picture size.
|
||||
@ -261,6 +248,20 @@ void lv_img_set_upscale(lv_obj_t * img, bool en)
|
||||
* Getter functions
|
||||
*====================*/
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of the file set for an image
|
||||
* @param img pointer to an image
|
||||
* @return file name
|
||||
*/
|
||||
const char * lv_img_get_file_name(lv_obj_t * img)
|
||||
{
|
||||
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
|
||||
|
||||
return ext->fn;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the auto size enable attribute
|
||||
* @param img pointer to an image
|
||||
@ -312,9 +313,7 @@ static bool lv_img_design(lv_obj_t * img, const area_t * mask, lv_design_mode_t
|
||||
if(ext->h == 0 || ext->w == 0) return true;
|
||||
area_t cords;
|
||||
/*Create a default style for symbol texts*/
|
||||
#if LV_IMG_ENABLE_SYMBOLS != 0
|
||||
bool sym = lv_img_is_symbol(ext->fn);
|
||||
#endif
|
||||
|
||||
lv_obj_get_coords(img, &cords);
|
||||
|
||||
@ -326,13 +325,9 @@ static bool lv_img_design(lv_obj_t * img, const area_t * mask, lv_design_mode_t
|
||||
cords_tmp.x1 = cords.x1;
|
||||
cords_tmp.x2 = cords.x1 + ext->w - 1;
|
||||
for(; cords_tmp.x1 < cords.x2; cords_tmp.x1 += ext->w, cords_tmp.x2 += ext->w) {
|
||||
|
||||
#if LV_IMG_ENABLE_SYMBOLS == 0
|
||||
lv_draw_img(&cords_tmp, mask, style, ext->fn);
|
||||
#else
|
||||
if(sym == false) lv_draw_img(&cords_tmp, mask, style, ext->fn);
|
||||
else lv_draw_label(&cords_tmp, mask, style, ext->fn, TXT_FLAG_NONE, NULL);
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -349,18 +344,13 @@ static bool lv_img_design(lv_obj_t * img, const area_t * mask, lv_design_mode_t
|
||||
*/
|
||||
static bool lv_img_is_symbol(const char * txt)
|
||||
{
|
||||
/*If the symbols are not enabled always tell false*/
|
||||
#if LV_IMG_ENABLE_SYMBOLS == 0
|
||||
return false;
|
||||
#endif
|
||||
|
||||
if(txt == NULL) return false;
|
||||
|
||||
/* if txt begins with an upper case letter then it refers to a driver
|
||||
* so it is a file name*/
|
||||
if(txt[0] >= 'A' && txt[0] <= 'Z') return false;
|
||||
|
||||
/*If not returned during the above tests then it is symbol text*/
|
||||
/*If not returned during the above tests then consider as text*/
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -100,6 +100,13 @@ void lv_img_set_auto_size(lv_obj_t * img, bool en);
|
||||
*/
|
||||
void lv_img_set_upscale(lv_obj_t * img, bool en);
|
||||
|
||||
/**
|
||||
* Get the name of the file set for an image
|
||||
* @param img pointer to an image
|
||||
* @return file name
|
||||
*/
|
||||
const char * lv_img_get_file_name(lv_obj_t * img);
|
||||
|
||||
/**
|
||||
* Get the auto size enable attribute
|
||||
* @param img pointer to an image
|
||||
|
@ -27,7 +27,7 @@
|
||||
static bool lv_kb_design(lv_obj_t * kb, const area_t * mask, lv_design_mode_t mode);
|
||||
#endif
|
||||
|
||||
static lv_action_res_t lv_app_kb_action(lv_obj_t * kb, const char * txt);
|
||||
static lv_res_t lv_app_kb_action(lv_obj_t * kb, const char * txt);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@ -315,10 +315,10 @@ static bool lv_kb_design(lv_obj_t * kb, const area_t * mask, lv_design_mode_t mo
|
||||
* @param i the index of the released button from the current btnm map
|
||||
* @return LV_ACTION_RES_INV if the btnm is deleted else LV_ACTION_RES_OK
|
||||
*/
|
||||
static lv_action_res_t lv_app_kb_action(lv_obj_t * kb, const char * txt)
|
||||
static lv_res_t lv_app_kb_action(lv_obj_t * kb, const char * txt)
|
||||
{
|
||||
lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb);
|
||||
if(ext->ta == NULL) return LV_ACTION_RES_OK;
|
||||
if(ext->ta == NULL) return LV_RES_OK;
|
||||
|
||||
/*Do the corresponding action according to the text of the button*/
|
||||
if(strcmp(txt, "abc") == 0) {
|
||||
@ -355,14 +355,14 @@ static lv_action_res_t lv_app_kb_action(lv_obj_t * kb, const char * txt)
|
||||
}
|
||||
} else if(strcmp(txt, "Hide") == 0) {
|
||||
if(ext->close_action) ext->close_action(kb);
|
||||
return LV_ACTION_RES_INV;
|
||||
return LV_RES_INV;
|
||||
} else if(strcmp(txt, "Ok") == 0) {
|
||||
if(ext->ok_action) ext->ok_action(kb);
|
||||
return LV_ACTION_RES_INV;
|
||||
return LV_RES_INV;
|
||||
} else {
|
||||
lv_ta_add_text(ext->ta, txt);
|
||||
}
|
||||
return LV_ACTION_RES_OK;
|
||||
return LV_RES_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -68,10 +68,10 @@ lv_obj_t * lv_list_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
|
||||
ext->sb_out = 0;
|
||||
ext->style_img = NULL;
|
||||
ext->styles_btn[LV_BTN_STATE_OFF_RELEASED] = &lv_style_btn_off_released;
|
||||
ext->styles_btn[LV_BTN_STATE_OFF_PRESSED] = &lv_style_btn_off_pressed;
|
||||
ext->styles_btn[LV_BTN_STATE_ON_RELEASED] = &lv_style_btn_on_released;
|
||||
ext->styles_btn[LV_BTN_STATE_OFF_PRESSED] = &lv_style_btn_on_pressed;
|
||||
ext->styles_btn[LV_BTN_STATE_RELEASED] = &lv_style_btn_off_released;
|
||||
ext->styles_btn[LV_BTN_STATE_PRESSED] = &lv_style_btn_off_pressed;
|
||||
ext->styles_btn[LV_BTN_STATE_TGL_RELEASED] = &lv_style_btn_on_released;
|
||||
ext->styles_btn[LV_BTN_STATE_PRESSED] = &lv_style_btn_on_pressed;
|
||||
ext->styles_btn[LV_BTN_STATE_INACTIVE] = &lv_style_btn_inactive;
|
||||
|
||||
lv_obj_set_signal_func(new_list, lv_list_signal);
|
||||
@ -80,16 +80,16 @@ lv_obj_t * lv_list_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
if(copy == NULL) {
|
||||
lv_obj_set_size(new_list, 2 * LV_DPI, 3 * LV_DPI);
|
||||
lv_cont_set_layout(ext->page.scrl, LV_LIST_LAYOUT_DEF);
|
||||
lv_obj_set_style(new_list, &lv_style_transp_tight);
|
||||
lv_obj_set_style(new_list, &lv_style_transp_fit);
|
||||
lv_obj_set_style(lv_page_get_scrl(new_list), &lv_style_pretty);
|
||||
lv_page_set_sb_mode(new_list, LV_PAGE_SB_MODE_AUTO);
|
||||
} else {
|
||||
lv_list_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
|
||||
|
||||
lv_list_set_styles_btn(new_list, copy_ext->styles_btn[LV_BTN_STATE_OFF_RELEASED],
|
||||
copy_ext->styles_btn[LV_BTN_STATE_OFF_PRESSED],
|
||||
copy_ext->styles_btn[LV_BTN_STATE_ON_RELEASED],
|
||||
copy_ext->styles_btn[LV_BTN_STATE_ON_PRESSED],
|
||||
lv_list_set_styles_btn(new_list, copy_ext->styles_btn[LV_BTN_STATE_RELEASED],
|
||||
copy_ext->styles_btn[LV_BTN_STATE_PRESSED],
|
||||
copy_ext->styles_btn[LV_BTN_STATE_TGL_RELEASED],
|
||||
copy_ext->styles_btn[LV_BTN_STATE_TGL_PRESSED],
|
||||
copy_ext->styles_btn[LV_BTN_STATE_INACTIVE]);
|
||||
lv_list_set_style_img(new_list, copy_ext->style_img);
|
||||
|
||||
@ -128,19 +128,19 @@ bool lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param)
|
||||
btn = lv_list_get_next_btn(list, btn);
|
||||
}
|
||||
if(btn_prev != NULL) {
|
||||
lv_btn_set_state(btn_prev, LV_BTN_STATE_OFF_PRESSED);
|
||||
lv_btn_set_state(btn_prev, LV_BTN_STATE_PRESSED);
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_DEFOCUS) {
|
||||
/*Get the 'pressed' button*/
|
||||
lv_obj_t * btn = NULL;
|
||||
btn = lv_list_get_next_btn(list, btn);
|
||||
while(btn != NULL) {
|
||||
if(lv_btn_get_state(btn) == LV_BTN_STATE_OFF_PRESSED) break;
|
||||
if(lv_btn_get_state(btn) == LV_BTN_STATE_PRESSED) break;
|
||||
btn = lv_list_get_next_btn(list, btn);
|
||||
}
|
||||
|
||||
if(btn != NULL) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_OFF_RELEASED);
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_RELEASED);
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_CONTROLL) {
|
||||
char c = *((char*)param);
|
||||
@ -150,14 +150,14 @@ bool lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param)
|
||||
lv_obj_t * btn_prev = NULL;
|
||||
btn = lv_list_get_next_btn(list, btn);
|
||||
while(btn != NULL) {
|
||||
if(lv_btn_get_state(btn) == LV_BTN_STATE_OFF_PRESSED) break;
|
||||
if(lv_btn_get_state(btn) == LV_BTN_STATE_PRESSED) break;
|
||||
btn_prev = btn;
|
||||
btn = lv_list_get_next_btn(list, btn);
|
||||
}
|
||||
|
||||
if(btn_prev != NULL && btn != NULL) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_OFF_RELEASED);
|
||||
lv_btn_set_state(btn_prev, LV_BTN_STATE_OFF_PRESSED);
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_RELEASED);
|
||||
lv_btn_set_state(btn_prev, LV_BTN_STATE_PRESSED);
|
||||
lv_page_focus(list, btn_prev, LV_LIST_FOCUS_TIME);
|
||||
}
|
||||
} else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_UP) {
|
||||
@ -165,15 +165,15 @@ bool lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param)
|
||||
lv_obj_t * btn = NULL;
|
||||
btn = lv_list_get_next_btn(list, btn);
|
||||
while(btn != NULL) {
|
||||
if(lv_btn_get_state(btn) == LV_BTN_STATE_OFF_PRESSED) break;
|
||||
if(lv_btn_get_state(btn) == LV_BTN_STATE_PRESSED) break;
|
||||
btn = lv_list_get_next_btn(list, btn);
|
||||
}
|
||||
|
||||
if(btn != NULL) {
|
||||
lv_obj_t * btn_prev = lv_list_get_next_btn(list, btn);
|
||||
if(btn_prev != NULL) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_OFF_RELEASED);
|
||||
lv_btn_set_state(btn_prev, LV_BTN_STATE_OFF_PRESSED);
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_RELEASED);
|
||||
lv_btn_set_state(btn_prev, LV_BTN_STATE_PRESSED);
|
||||
lv_page_focus(list, btn_prev, LV_LIST_FOCUS_TIME);
|
||||
}
|
||||
}
|
||||
@ -182,7 +182,7 @@ bool lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param)
|
||||
lv_obj_t * btn = NULL;
|
||||
btn = lv_list_get_next_btn(list, btn);
|
||||
while(btn != NULL) {
|
||||
if(lv_btn_get_state(btn) == LV_BTN_STATE_OFF_PRESSED) break;
|
||||
if(lv_btn_get_state(btn) == LV_BTN_STATE_PRESSED) break;
|
||||
btn = lv_list_get_next_btn(list, btn);
|
||||
}
|
||||
|
||||
@ -363,20 +363,16 @@ void lv_list_set_styles_btn(lv_obj_t * list, lv_style_t * rel, lv_style_t * pr,
|
||||
{
|
||||
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
|
||||
|
||||
ext->styles_btn[LV_BTN_STATE_OFF_RELEASED] = rel;
|
||||
ext->styles_btn[LV_BTN_STATE_OFF_PRESSED] = pr;
|
||||
ext->styles_btn[LV_BTN_STATE_ON_RELEASED] = trel;
|
||||
ext->styles_btn[LV_BTN_STATE_ON_PRESSED] = tpr;
|
||||
ext->styles_btn[LV_BTN_STATE_RELEASED] = rel;
|
||||
ext->styles_btn[LV_BTN_STATE_PRESSED] = pr;
|
||||
ext->styles_btn[LV_BTN_STATE_TGL_RELEASED] = trel;
|
||||
ext->styles_btn[LV_BTN_STATE_TGL_PRESSED] = tpr;
|
||||
ext->styles_btn[LV_BTN_STATE_INACTIVE] = ina;
|
||||
|
||||
lv_obj_t * liste = lv_list_get_next_btn(list, NULL);
|
||||
while(liste != NULL)
|
||||
{
|
||||
lv_btn_set_style(liste, LV_BTN_STATE_OFF_RELEASED, rel);
|
||||
lv_btn_set_style(liste, LV_BTN_STATE_OFF_PRESSED, pr);
|
||||
lv_btn_set_style(liste, LV_BTN_STATE_ON_RELEASED, trel);
|
||||
lv_btn_set_style(liste, LV_BTN_STATE_ON_PRESSED, tpr);
|
||||
lv_btn_set_style(liste, LV_BTN_STATE_INACTIVE, ina);
|
||||
lv_btn_set_styles(liste, rel, pr, trel, tpr, ina);
|
||||
liste = lv_list_get_next_btn(list, liste);
|
||||
}
|
||||
}
|
||||
@ -431,7 +427,7 @@ lv_obj_t * lv_list_get_element_label(lv_obj_t * liste)
|
||||
if(label == NULL) return NULL;
|
||||
|
||||
while(label->signal_func != lv_label_signal) {
|
||||
label = lv_obj_get_child(liste, NULL);
|
||||
label = lv_obj_get_child(liste, label);
|
||||
if(label == NULL) break;
|
||||
}
|
||||
|
||||
@ -450,7 +446,7 @@ lv_obj_t * lv_list_get_element_img(lv_obj_t * liste)
|
||||
if(img == NULL) return NULL;
|
||||
|
||||
while(img->signal_func != lv_img_signal) {
|
||||
img = lv_obj_get_child(liste, NULL);
|
||||
img = lv_obj_get_child(liste, img);
|
||||
if(img == NULL) break;
|
||||
}
|
||||
|
||||
@ -496,7 +492,7 @@ lv_style_t * lv_list_get_style_img(lv_obj_t * list, lv_btn_state_t state)
|
||||
{
|
||||
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
|
||||
|
||||
if(ext->style_img == NULL) return lv_list_get_style_liste(list, LV_BTN_STATE_OFF_RELEASED);
|
||||
if(ext->style_img == NULL) return lv_list_get_style_liste(list, LV_BTN_STATE_RELEASED);
|
||||
|
||||
return ext->style_img;
|
||||
}
|
||||
|
@ -142,8 +142,7 @@ bool lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param)
|
||||
btn = lv_obj_get_child(ext->btnh, NULL);
|
||||
while(btn != NULL) {
|
||||
/*Refresh the next button's style*/
|
||||
lv_btn_set_style(btn, LV_BTN_STATE_OFF_RELEASED, ext->style_btn_rel);
|
||||
lv_btn_set_style(btn, LV_BTN_STATE_OFF_PRESSED, ext->style_btn_pr);
|
||||
lv_btn_set_styles(btn, ext->style_btn_rel, ext->style_btn_pr, NULL, NULL, NULL);
|
||||
btn = lv_obj_get_child(ext->btnh, btn);
|
||||
}
|
||||
}
|
||||
@ -158,7 +157,7 @@ bool lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param)
|
||||
btn = lv_obj_get_child(ext->btnh, btn);
|
||||
}
|
||||
if(btn_prev != NULL) {
|
||||
lv_btn_set_state(btn_prev, LV_BTN_STATE_OFF_PRESSED);
|
||||
lv_btn_set_state(btn_prev, LV_BTN_STATE_PRESSED);
|
||||
}
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_DEFOCUS) {
|
||||
@ -167,12 +166,12 @@ bool lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param)
|
||||
lv_obj_t * btn = NULL;
|
||||
btn = lv_obj_get_child(ext->btnh, btn);
|
||||
while(btn != NULL) {
|
||||
if(lv_btn_get_state(btn) == LV_BTN_STATE_OFF_PRESSED) break;
|
||||
if(lv_btn_get_state(btn) == LV_BTN_STATE_PRESSED) break;
|
||||
btn = lv_obj_get_child(ext->btnh, btn);
|
||||
}
|
||||
|
||||
if(btn != NULL) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_OFF_RELEASED);
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_RELEASED);
|
||||
}
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_CONTROLL) {
|
||||
@ -185,14 +184,14 @@ bool lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param)
|
||||
lv_obj_t * btn_prev = NULL;
|
||||
btn = lv_obj_get_child(ext->btnh, btn);
|
||||
while(btn != NULL) {
|
||||
if(lv_btn_get_state(btn) == LV_BTN_STATE_OFF_PRESSED) break;
|
||||
if(lv_btn_get_state(btn) == LV_BTN_STATE_PRESSED) break;
|
||||
btn_prev = btn;
|
||||
btn = lv_obj_get_child(ext->btnh, btn);
|
||||
}
|
||||
|
||||
if(btn_prev != NULL && btn != NULL) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_OFF_RELEASED);
|
||||
lv_btn_set_state(btn_prev, LV_BTN_STATE_OFF_PRESSED);
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_RELEASED);
|
||||
lv_btn_set_state(btn_prev, LV_BTN_STATE_PRESSED);
|
||||
}
|
||||
}
|
||||
} else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_DOWN) {
|
||||
@ -201,15 +200,15 @@ bool lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param)
|
||||
lv_obj_t * btn = NULL;
|
||||
btn = lv_obj_get_child(ext->btnh, btn);
|
||||
while(btn != NULL) {
|
||||
if(lv_btn_get_state(btn) == LV_BTN_STATE_OFF_PRESSED) break;
|
||||
if(lv_btn_get_state(btn) == LV_BTN_STATE_PRESSED) break;
|
||||
btn = lv_obj_get_child(ext->btnh, btn);
|
||||
}
|
||||
|
||||
if(btn != NULL) {
|
||||
lv_obj_t * btn_prev = lv_obj_get_child(ext->btnh, btn);
|
||||
if(btn_prev != NULL) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_OFF_RELEASED);
|
||||
lv_btn_set_state(btn_prev, LV_BTN_STATE_OFF_PRESSED);
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_RELEASED);
|
||||
lv_btn_set_state(btn_prev, LV_BTN_STATE_PRESSED);
|
||||
}
|
||||
}
|
||||
|
||||
@ -220,7 +219,7 @@ bool lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param)
|
||||
lv_obj_t * btn = NULL;
|
||||
btn = lv_obj_get_child(ext->btnh, btn);
|
||||
while(btn != NULL) {
|
||||
if(lv_btn_get_state(btn) == LV_BTN_STATE_OFF_PRESSED) break;
|
||||
if(lv_btn_get_state(btn) == LV_BTN_STATE_PRESSED) break;
|
||||
btn = lv_obj_get_child(ext->btnh, btn);
|
||||
}
|
||||
|
||||
@ -242,13 +241,13 @@ bool lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param)
|
||||
* @param btn pointer to the released button
|
||||
* @return always lv_action_res_t because the button is deleted with the mesage box
|
||||
*/
|
||||
lv_action_res_t lv_mbox_close_action(lv_obj_t * btn)
|
||||
lv_res_t lv_mbox_close_action(lv_obj_t * btn)
|
||||
{
|
||||
lv_obj_t * mbox = lv_mbox_get_from_btn(btn);
|
||||
|
||||
lv_obj_del(mbox);
|
||||
|
||||
return LV_ACTION_RES_INV;
|
||||
return LV_RES_INV;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -274,8 +273,7 @@ lv_obj_t * lv_mbox_add_btn(lv_obj_t * mbox, const char * btn_txt, lv_action_t re
|
||||
lv_obj_t * btn;
|
||||
btn = lv_btn_create(ext->btnh, NULL);
|
||||
lv_btn_set_action(btn, LV_BTN_ACTION_RELEASE, rel_action);
|
||||
lv_btn_set_style(btn, LV_BTN_STATE_OFF_RELEASED, ext->style_btn_rel);
|
||||
lv_btn_set_style(btn, LV_BTN_STATE_OFF_PRESSED, ext->style_btn_pr);
|
||||
lv_btn_set_styles(btn, ext->style_btn_rel, ext->style_btn_pr, NULL, NULL, NULL);
|
||||
lv_cont_set_fit(btn, true, true);
|
||||
|
||||
lv_obj_t * label;
|
||||
@ -324,8 +322,7 @@ void lv_mbox_set_styles_btn(lv_obj_t * mbox, lv_style_t * rel, lv_style_t * pr)
|
||||
lv_obj_t * btn = lv_obj_get_child(ext->btnh, NULL);
|
||||
|
||||
while(btn != NULL) {
|
||||
lv_btn_set_style(btn, LV_BTN_STATE_OFF_RELEASED, rel);
|
||||
lv_btn_set_style(btn, LV_BTN_STATE_OFF_PRESSED, pr);
|
||||
lv_btn_set_styles(btn, rel, pr, NULL, NULL, NULL);
|
||||
btn = lv_obj_get_child(mbox, btn);
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ bool lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param);
|
||||
* @param btn pointer to the released button
|
||||
* @return always lv_action_res_t because the button is deleted with the mesage box
|
||||
*/
|
||||
lv_action_res_t lv_mbox_close_action(lv_obj_t * btn);
|
||||
lv_res_t lv_mbox_close_action(lv_obj_t * btn);
|
||||
|
||||
/**
|
||||
* Add a button to the message box
|
||||
|
@ -111,7 +111,7 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
lv_obj_set_click(ext->label, false);
|
||||
lv_obj_set_style(new_ta, &lv_style_pretty);
|
||||
lv_page_set_sb_mode(new_ta, LV_PAGE_SB_MODE_AUTO);
|
||||
lv_obj_set_style(lv_page_get_scrl(new_ta), &lv_style_transp_tight);
|
||||
lv_obj_set_style(lv_page_get_scrl(new_ta), &lv_style_transp_fit);
|
||||
lv_obj_set_size(new_ta, LV_TA_DEF_WIDTH, LV_TA_DEF_HEIGHT);
|
||||
}
|
||||
/*Copy an existing object*/
|
||||
|
@ -34,7 +34,7 @@ static bool tabscrl_signal(lv_obj_t * tab_scrl, lv_signal_t sign, void * param);
|
||||
static void tabpage_pressed_hadler(lv_obj_t * tabview, lv_obj_t * tabpage);
|
||||
static void tabpage_pressing_hadler(lv_obj_t * tabview, lv_obj_t * tabpage);
|
||||
static void tabpage_press_lost_hadler(lv_obj_t * tabview, lv_obj_t * tabpage);
|
||||
static lv_action_res_t tab_btnm_action(lv_obj_t * tab_btnm, const char * tab_name);
|
||||
static lv_res_t tab_btnm_action(lv_obj_t * tab_btnm, const char * tab_name);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@ -72,12 +72,13 @@ lv_obj_t * lv_tabview_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
/*Initialize the allocated 'ext' */
|
||||
ext->drag_h = 0;
|
||||
ext->draging = 0;
|
||||
ext->tab_act = 0;
|
||||
ext->tab_cur = 0;
|
||||
ext->point_last.x = 0;
|
||||
ext->point_last.y = 0;
|
||||
ext->content = NULL;
|
||||
ext->indic = NULL;
|
||||
ext->tabs = NULL;
|
||||
ext->tab_load_action = NULL;
|
||||
ext->anim_time = LV_TABVIEW_ANIM_TIME;
|
||||
ext->tab_name_ptr = dm_alloc(sizeof(char*));
|
||||
ext->tab_name_ptr[0] = "";
|
||||
@ -106,7 +107,7 @@ lv_obj_t * lv_tabview_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
lv_cont_set_fit(ext->content, true, false);
|
||||
lv_cont_set_layout(ext->content, LV_CONT_LAYOUT_ROW_T);
|
||||
lv_obj_set_height(ext->content, LV_VER_RES);
|
||||
lv_obj_set_style(ext->content, &lv_style_transp_tight);
|
||||
lv_obj_set_style(ext->content, &lv_style_transp_fit);
|
||||
lv_obj_align(ext->content, ext->tabs, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
|
||||
}
|
||||
/*Copy an existing tab*/
|
||||
@ -118,6 +119,7 @@ lv_obj_t * lv_tabview_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
ext->indic = lv_obj_create(ext->tabs, copy_ext->indic);
|
||||
ext->content = lv_cont_create(new_tabview, copy_ext->content);
|
||||
ext->anim_time = copy_ext->anim_time;
|
||||
ext->tab_load_action = copy_ext->tab_load_action;
|
||||
|
||||
ext->tab_name_ptr = dm_alloc(sizeof(char*));
|
||||
ext->tab_name_ptr[0] = "";
|
||||
@ -188,7 +190,7 @@ lv_obj_t * lv_tabview_add_tab(lv_obj_t * tabview, const char * name)
|
||||
lv_obj_t * h = lv_page_create(ext->content, NULL);
|
||||
lv_obj_set_size(h, lv_obj_get_width(tabview), lv_obj_get_height(tabview) - lv_obj_get_height(ext->tabs));
|
||||
lv_obj_set_style(h, &lv_style_plain);
|
||||
lv_obj_set_style(lv_page_get_scrl(h), &lv_style_transp_tight);
|
||||
lv_obj_set_style(lv_page_get_scrl(h), &lv_style_transp_fit);
|
||||
lv_obj_set_signal_func(h, tabpage_signal);
|
||||
lv_page_set_sb_mode(h, LV_PAGE_SB_MODE_AUTO);
|
||||
if(page_scrl_signal == NULL) page_scrl_signal = lv_obj_get_signal_func(lv_page_get_scrl(h));
|
||||
@ -206,11 +208,11 @@ lv_obj_t * lv_tabview_add_tab(lv_obj_t * tabview, const char * name)
|
||||
lv_style_t * style_tabs = lv_obj_get_style(ext->tabs);
|
||||
cord_t indic_width = (lv_obj_get_width(tabview) - style_tabs->body.padding.inner * (ext->tab_cnt - 1) - 2 * style_tabs->body.padding.hor) / ext->tab_cnt;
|
||||
lv_obj_set_width(ext->indic, indic_width);
|
||||
lv_obj_set_x(ext->indic, indic_width * ext->tab_act + style_tabs->body.padding.inner * ext->tab_act + style_tabs->body.padding.hor);
|
||||
lv_obj_set_x(ext->indic, indic_width * ext->tab_cur + style_tabs->body.padding.inner * ext->tab_cur + style_tabs->body.padding.hor);
|
||||
|
||||
/*Set the first tab as active*/
|
||||
if(ext->tab_cnt == 1) {
|
||||
ext->tab_act = 0;
|
||||
ext->tab_cur = 0;
|
||||
lv_tabview_set_act(tabview, 0, false);
|
||||
}
|
||||
|
||||
@ -232,7 +234,10 @@ void lv_tabview_set_act(lv_obj_t * tabview, uint16_t id, bool anim_en)
|
||||
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
||||
lv_style_t * style = lv_obj_get_style(ext->content);
|
||||
|
||||
ext->tab_act = id >= ext->tab_cnt ? ext->tab_cnt - 1 : id;
|
||||
if(id >= ext->tab_cnt) id = ext->tab_cnt - 1;
|
||||
if(ext->tab_load_action) ext->tab_load_action(tabview, id);
|
||||
|
||||
ext->tab_cur = id;
|
||||
|
||||
cord_t cont_x = -(lv_obj_get_width(tabview) * id + style->body.padding.inner * id + style->body.padding.hor);
|
||||
if(ext->anim_time == 0 || anim_en == false) {
|
||||
@ -278,9 +283,22 @@ void lv_tabview_set_act(lv_obj_t * tabview, uint16_t id, bool anim_en)
|
||||
anim_create(&a);
|
||||
}
|
||||
|
||||
lv_btnm_set_toggle(ext->tabs, true, ext->tab_act);
|
||||
lv_btnm_set_toggle(ext->tabs, true, ext->tab_cur);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an action to call when a tab is loaded (Good to create content only if required)
|
||||
* lv_tabview_get_act() still gives the current (old) tab (to remove content from here)
|
||||
* @param tabview pointer to a tabview object
|
||||
* @param action pointer to a function to call when a tab is loaded
|
||||
*/
|
||||
void lv_tabview_set_tab_load_action(lv_obj_t *tabview, lv_tabview_action_t action)
|
||||
{
|
||||
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
||||
ext->tab_load_action = action;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the animation time of tab view when a new tab is loaded
|
||||
* @param tabview pointer to Tab view object
|
||||
@ -305,7 +323,7 @@ void lv_tabview_set_anim_time(lv_obj_t * tabview, uint16_t anim_time_ms)
|
||||
uint16_t lv_tabview_get_tab_act(lv_obj_t * tabview)
|
||||
{
|
||||
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
||||
return ext->tab_act;
|
||||
return ext->tab_cur;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -329,11 +347,11 @@ lv_obj_t * lv_tabview_get_tab_page(lv_obj_t * tabview, uint16_t id)
|
||||
{
|
||||
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
||||
uint16_t i = 0;
|
||||
lv_obj_t * page = lv_obj_get_child(ext->content, NULL);
|
||||
lv_obj_t * page = lv_obj_get_child_back(ext->content, NULL);
|
||||
|
||||
while(page != NULL && i != id) {
|
||||
i++;
|
||||
page = lv_obj_get_child(ext->content, page);
|
||||
page = lv_obj_get_child_back(ext->content, page);
|
||||
}
|
||||
|
||||
if(i == id) return page;
|
||||
@ -363,6 +381,17 @@ lv_obj_t * lv_tabview_get_indic(lv_obj_t * tabview)
|
||||
return ext->indic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tab load action
|
||||
* @param tabview pointer to a tabview object
|
||||
* @param return the current tab load action
|
||||
*/
|
||||
lv_tabview_action_t lv_tabview_get_tab_load_action(lv_obj_t *tabview)
|
||||
{
|
||||
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
||||
return ext->tab_load_action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the animation time of tab view when a new tab is loaded
|
||||
* @param tabview pointer to Tab view object
|
||||
@ -404,7 +433,7 @@ void lv_tabview_realign(lv_obj_t * tabview)
|
||||
|
||||
lv_obj_align(ext->indic, ext->tabs, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
|
||||
|
||||
lv_tabview_set_act(tabview, ext->tab_act, false);
|
||||
lv_tabview_set_act(tabview, ext->tab_cur, false);
|
||||
}
|
||||
|
||||
/**********************
|
||||
@ -556,7 +585,7 @@ static void tabpage_pressing_hadler(lv_obj_t * tabview, lv_obj_t * tabpage)
|
||||
lv_style_t * indic_style = lv_obj_get_style(ext->indic);
|
||||
cord_t p = ((tabpage->coords.x1 - tabview->coords.x1) * (indic_width + tabs_style->body.padding.inner)) / lv_obj_get_width(tabview);
|
||||
|
||||
lv_obj_set_x(ext->indic, indic_width * ext->tab_act + tabs_style->body.padding.inner * ext->tab_act + indic_style->body.padding.hor - p);
|
||||
lv_obj_set_x(ext->indic, indic_width * ext->tab_cur + tabs_style->body.padding.inner * ext->tab_cur + indic_style->body.padding.hor - p);
|
||||
}
|
||||
}
|
||||
|
||||
@ -588,13 +617,14 @@ static void tabpage_press_lost_hadler(lv_obj_t * tabview, lv_obj_t * tabpage)
|
||||
cord_t page_x1 = tabpage->coords.x1 + x_predict;
|
||||
cord_t page_x2 = tabpage->coords.x2 + x_predict;
|
||||
|
||||
uint16_t tab_cur = ext->tab_cur;
|
||||
if(page_x1 > (tabview->coords.x2 - tabview->coords.x1) / 2) {
|
||||
if(ext->tab_act != 0) ext->tab_act--;
|
||||
if(tab_cur != 0) tab_cur--;
|
||||
} else if(page_x2 < (tabview->coords.x2 - tabview->coords.x1) / 2) {
|
||||
if(ext->tab_act < ext->tab_cnt - 1) ext->tab_act++;
|
||||
if(tab_cur < ext->tab_cnt - 1) tab_cur++;
|
||||
}
|
||||
|
||||
lv_tabview_set_act(tabview, ext->tab_act, true);
|
||||
lv_tabview_set_act(tabview, tab_cur, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -603,10 +633,9 @@ static void tabpage_press_lost_hadler(lv_obj_t * tabview, lv_obj_t * tabpage)
|
||||
* @param id the id of the tab (>= 0)
|
||||
* @return LV_ACTION_RES_OK because the button matrix in not deleted in the function
|
||||
*/
|
||||
static lv_action_res_t tab_btnm_action(lv_obj_t * tab_btnm, const char * tab_name)
|
||||
static lv_res_t tab_btnm_action(lv_obj_t * tab_btnm, const char * tab_name)
|
||||
{
|
||||
lv_obj_t * tab = lv_obj_get_parent(tab_btnm);
|
||||
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tab);
|
||||
const char ** tabs_map = lv_btnm_get_map(tab_btnm);
|
||||
|
||||
uint8_t i = 0;
|
||||
@ -616,10 +645,9 @@ static lv_action_res_t tab_btnm_action(lv_obj_t * tab_btnm, const char * tab_nam
|
||||
i++;
|
||||
}
|
||||
|
||||
ext->tab_act = i;
|
||||
lv_tabview_set_act(tab, i, true);
|
||||
|
||||
return LV_ACTION_RES_OK;
|
||||
return LV_RES_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -37,6 +37,10 @@ extern "C" {
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/* parametes: pointer to a tabview object, tab_id*/
|
||||
typedef void (*lv_tabview_action_t)(lv_obj_t *, uint16_t);
|
||||
|
||||
/*Data of tab*/
|
||||
typedef struct
|
||||
{
|
||||
@ -47,12 +51,12 @@ typedef struct
|
||||
lv_obj_t * content; /*A rectangle to show the current tab*/
|
||||
const char ** tab_name_ptr;
|
||||
point_t point_last;
|
||||
uint16_t tab_act;
|
||||
uint16_t tab_cur;
|
||||
uint16_t tab_cnt;
|
||||
uint16_t anim_time;
|
||||
uint8_t draging :1;
|
||||
uint8_t drag_h :1;
|
||||
|
||||
lv_tabview_action_t tab_load_action;
|
||||
}lv_tabview_ext_t;
|
||||
|
||||
/**********************
|
||||
@ -89,12 +93,28 @@ void lv_tabview_realign(lv_obj_t * tabview);
|
||||
*/
|
||||
void lv_tabview_set_act(lv_obj_t * tabview, uint16_t id, bool anim_en);
|
||||
|
||||
/**
|
||||
* Set an action to call when a tab is loaded (Good to create content only if required)
|
||||
* lv_tabview_get_act() still gives the current (old) tab (to remove content from here)
|
||||
* @param tabview pointer to a tabview object
|
||||
* @param action pointer to a function to call when a tab is loaded
|
||||
*/
|
||||
void lv_tabview_set_tab_load_action(lv_obj_t *tabview,lv_tabview_action_t action);
|
||||
|
||||
/**
|
||||
* Set the animation time of tab view when a new tab is loaded
|
||||
* @param tabview pointer to Tab view object
|
||||
* @param anim_time_ms time of animation in milliseconds
|
||||
*/
|
||||
void lv_tabview_set_anim_time(lv_obj_t * tabview, uint16_t anim_time_ms);
|
||||
|
||||
/**
|
||||
* Get the index of the currently active tab
|
||||
* @param tabview pointer to Tab view object
|
||||
* @return the active tab index
|
||||
*/
|
||||
uint16_t lv_tabview_get_tab_act(lv_obj_t * tabview);
|
||||
|
||||
/**
|
||||
* Get the number of tabs
|
||||
* @param tabview pointer to Tab view object
|
||||
@ -131,6 +151,18 @@ lv_obj_t * lv_tabview_get_indic(lv_obj_t * tabview);
|
||||
*/
|
||||
lv_obj_t * lv_tabview_add_tab(lv_obj_t * tabview, const char * name);
|
||||
|
||||
/**
|
||||
* Get the tab load action
|
||||
* @param tabview pointer to a tabview object
|
||||
* @param return the current tab load action
|
||||
*/
|
||||
lv_tabview_action_t lv_tabview_get_tab_load_action(lv_obj_t *tabview);
|
||||
/**
|
||||
* Get the animation time of tab view when a new tab is loaded
|
||||
* @param tabview pointer to Tab view object
|
||||
* @return time of animation in milliseconds
|
||||
*/
|
||||
uint16_t lv_tabview_get_anim_time(lv_obj_t * tabview, uint16_t anim_time_ms);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
|
@ -97,7 +97,7 @@ lv_obj_t * lv_win_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
/*Create a holder for the control buttons*/
|
||||
ext->btnh = lv_cont_create(ext->header, NULL);
|
||||
lv_cont_set_fit(ext->btnh, true, false);
|
||||
lv_obj_set_style(ext->btnh, &lv_style_transp_tight);
|
||||
lv_obj_set_style(ext->btnh, &lv_style_transp_fit);
|
||||
lv_cont_set_layout(ext->btnh, LV_CONT_LAYOUT_ROW_M);
|
||||
|
||||
lv_obj_set_signal_func(new_win, lv_win_signal);
|
||||
@ -209,8 +209,7 @@ lv_obj_t * lv_win_add_cbtn(lv_obj_t * win, const char * img_path, lv_action_t re
|
||||
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
|
||||
|
||||
lv_obj_t * btn = lv_btn_create(ext->btnh, NULL);
|
||||
lv_btn_set_style(btn, LV_BTN_STATE_OFF_RELEASED, ext->style_cbtn_rel);
|
||||
lv_btn_set_style(btn, LV_BTN_STATE_OFF_PRESSED, ext->style_cbtn_pr);
|
||||
lv_btn_set_styles(btn, ext->style_cbtn_rel, ext->style_cbtn_pr, NULL, NULL, NULL);
|
||||
lv_obj_set_size(btn, ext->cbtn_size, ext->cbtn_size);
|
||||
lv_btn_set_action(btn, LV_BTN_ACTION_RELEASE, rel_action);
|
||||
|
||||
@ -228,13 +227,13 @@ lv_obj_t * lv_win_add_cbtn(lv_obj_t * win, const char * img_path, lv_action_t re
|
||||
* @param btn pointer to the released button
|
||||
* @return always LV_ACTION_RES_INV because the button is deleted with the window
|
||||
*/
|
||||
lv_action_res_t lv_win_close_action(lv_obj_t * btn)
|
||||
lv_res_t lv_win_close_action(lv_obj_t * btn)
|
||||
{
|
||||
lv_obj_t * win = lv_win_get_from_cbtn(btn);
|
||||
|
||||
lv_obj_del(win);
|
||||
|
||||
return LV_ACTION_RES_INV;
|
||||
return LV_RES_INV;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -277,8 +276,7 @@ void lv_win_set_styles_cbtn(lv_obj_t * win, lv_style_t * rel, lv_style_t * pr)
|
||||
lv_obj_t * cbtn;
|
||||
cbtn = lv_obj_get_child(ext->btnh, NULL);
|
||||
while(cbtn != NULL) {
|
||||
lv_btn_set_style(cbtn, LV_BTN_STATE_OFF_RELEASED, ext->style_cbtn_rel);
|
||||
lv_btn_set_style(cbtn, LV_BTN_STATE_OFF_PRESSED, ext->style_cbtn_pr);
|
||||
lv_btn_set_styles(cbtn, ext->style_cbtn_rel, ext->style_cbtn_pr, NULL, NULL, NULL);
|
||||
|
||||
cbtn = lv_obj_get_child(ext->btnh, cbtn);
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ lv_obj_t * lv_win_add_cbtn(lv_obj_t * win, const char * img_path, lv_action_t re
|
||||
* @param indev_proc pointer to the caller input device
|
||||
* @return always LV_ACTION_RES_INV because the button is deleted with the window
|
||||
*/
|
||||
lv_action_res_t lv_win_close_action(lv_obj_t * btn);
|
||||
lv_res_t lv_win_close_action(lv_obj_t * btn);
|
||||
|
||||
/**
|
||||
* Set the title of a window
|
||||
|
Loading…
x
Reference in New Issue
Block a user