add lv_xxx_style_t and unify style set/get

This commit is contained in:
Gabor Kiss-Vamosi
2017-11-15 15:50:33 +01:00
parent 39075fe06d
commit 86daac1424
42 changed files with 1796 additions and 1787 deletions

View File

@@ -68,6 +68,7 @@ void lv_style_init (void)
* HUE = 210*/
/*Screen style*/
lv_style_scr.glass = 0;
lv_style_scr.body.opa = OPA_COVER;
lv_style_scr.body.color_main = COLOR_WHITE;
lv_style_scr.body.color_gradient = COLOR_WHITE;
@@ -76,7 +77,6 @@ void lv_style_init (void)
lv_style_scr.body.padding.hor = LV_DPI / 10;
lv_style_scr.body.padding.inner = LV_DPI / 10;
lv_style_scr.body.empty = 0;
lv_style_scr.glass = 0;
lv_style_scr.body.border.color = COLOR_BLACK;
lv_style_scr.body.border.opa = OPA_COVER;

View File

@@ -162,23 +162,25 @@ void lv_bar_set_range(lv_obj_t * bar, int16_t min, int16_t max)
lv_obj_invalidate(bar);
}
/**
* Set the styles of a bar
* Set a style of a bar
* @param bar pointer to a bar object
* @param bg pointer to the background's style (NULL to leave unchanged)
* @param indic pointer to the indicator's style (NULL to leave unchanged)
* @param type which style should be set
* @param style pointer to a style
*/
void lv_bar_set_style(lv_obj_t * bar, lv_style_t * bg, lv_style_t * indic)
void lv_bar_set_style(lv_obj_t *bar, lv_bar_style_t type, lv_style_t *style)
{
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
if(indic != NULL) {
ext->style_inicator = indic;
bar->signal_func(bar, LV_SIGNAL_REFR_EXT_SIZE, NULL);
}
if(bg != NULL) {
lv_obj_set_style(bar, bg);
switch (type) {
case LV_BAR_STYLE_BG:
lv_obj_set_style(bar, style);
break;
case LV_BAR_STYLE_INDIC:
ext->style_inicator = style;
lv_obj_refresh_ext_size(bar);
break;
}
}
@@ -233,6 +235,26 @@ lv_style_t * lv_bar_get_style_indicator(lv_obj_t * bar)
return ext->style_inicator;
}
/**
* Get a style of a bar
* @param bar pointer to a bar object
* @param type which style should be get
* @return style pointer to a style
*/
lv_style_t * lv_bar_get_style(lv_obj_t *bar, lv_bar_style_t type)
{
lv_bar_ext_t *ext = lv_obj_get_ext_attr(bar);
switch (type) {
case LV_BAR_STYLE_BG: return lv_obj_get_style(bar);
case LV_BAR_STYLE_INDIC: return ext->style_inicator;
default: return NULL;
}
/*To avoid warning*/
return NULL;
}
/**********************
* STATIC FUNCTIONS
**********************/
@@ -302,7 +324,7 @@ static lv_res_t lv_bar_signal(lv_obj_t * bar, lv_signal_t sign, void * param)
if(style_indic->body.shadow.width > bar->ext_size) bar->ext_size = style_indic->body.shadow.width;
}
return LV_RES_OK;
return res;
}

View File

@@ -40,6 +40,11 @@ typedef struct
lv_style_t *style_inicator; /*Style of the indicator*/
}lv_bar_ext_t;
typedef enum {
LV_BAR_STYLE_BG,
LV_BAR_STYLE_INDIC,
}lv_bar_style_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
@@ -81,12 +86,12 @@ void lv_bar_set_value_anim(lv_obj_t * bar, int16_t value, uint16_t anim_time);
void lv_bar_set_range(lv_obj_t * bar, int16_t min, int16_t max);
/**
* Set the styles of a bar
* Set a style of a bar
* @param bar pointer to a bar object
* @param bg pointer to the background's style (NULL to leave unchanged)
* @param indic pointer to the indicator's style (NULL to leave unchanged)
* @param type which style should be set
* @param style pointer to a style
*/
void lv_bar_set_style(lv_obj_t * bar, lv_style_t * bg, lv_style_t * indic);
void lv_bar_set_style(lv_obj_t *bar, lv_bar_style_t type, lv_style_t *style);
/*=====================
* Getter functions
@@ -113,23 +118,14 @@ int16_t lv_bar_get_min_value(lv_obj_t * bar);
*/
int16_t lv_bar_get_max_value(lv_obj_t * bar);
/**
* Get the style of bar background
* @param bar pointer to a bar object
* @return pointer to the bar's background style
*/
static inline lv_style_t * lv_bar_get_style_bg(lv_obj_t *bar)
{
return lv_obj_get_style(bar);
}
/**
* Get the style of bar indicator
* Get a style of a bar
* @param bar pointer to a bar object
* @return pointer to the bar indicator style
* @param type which style should be get
* @return style pointer to a style
*/
lv_style_t * lv_bar_get_style_indicator(lv_obj_t * bar);
lv_style_t * lv_bar_get_style(lv_obj_t *bar, lv_bar_style_t type);
/**********************
* MACROS

View File

@@ -60,18 +60,18 @@ 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_RELEASED;
ext->state = LV_BTN_STATE_REL;
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_RELEASED] = &lv_style_btn_released;
ext->styles[LV_BTN_STATE_PRESSED] = &lv_style_btn_pressed;
ext->styles[LV_BTN_STATE_TGL_RELEASED] = &lv_style_btn_tgl_released;
ext->styles[LV_BTN_STATE_TGL_PRESSED] = &lv_style_btn_tgl_pressed;
ext->styles[LV_BTN_STATE_INACTIVE] = &lv_style_btn_inactive;
ext->styles[LV_BTN_STATE_REL] = &lv_style_btn_released;
ext->styles[LV_BTN_STATE_PR] = &lv_style_btn_pressed;
ext->styles[LV_BTN_STATE_TGL_REL] = &lv_style_btn_tgl_released;
ext->styles[LV_BTN_STATE_TGL_PR] = &lv_style_btn_tgl_pressed;
ext->styles[LV_BTN_STATE_INA] = &lv_style_btn_inactive;
ext->long_press_action_executed = 0;
ext->toggle = 0;
@@ -81,7 +81,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_btn_set_layout(new_btn, LV_CONT_LAYOUT_CENTER);
lv_obj_set_style(new_btn, ext->styles[LV_BTN_STATE_RELEASED]);
lv_obj_set_style(new_btn, ext->styles[LV_BTN_STATE_REL]);
}
/*Copy 'copy'*/
else {
@@ -136,10 +136,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_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;
case LV_BTN_STATE_REL: lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL); break;
case LV_BTN_STATE_PR: lv_btn_set_state(btn, LV_BTN_STATE_TGL_PR); break;
case LV_BTN_STATE_TGL_REL: lv_btn_set_state(btn, LV_BTN_STATE_REL); break;
case LV_BTN_STATE_TGL_PR: lv_btn_set_state(btn, LV_BTN_STATE_PR); break;
default: break;
}
}
@@ -158,25 +158,32 @@ 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 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 tgl_rel pointer to a style for toggled releases state
* @param tgl_pr pointer to a style for toggled pressed state
* @param ina pointer to a style for inactive state
* Set a style of a button
* @param btn pointer to a button object
* @param type which style should be set
* @param style pointer to a style
*/
void lv_btn_set_style(lv_obj_t * btn, lv_style_t *rel, lv_style_t *pr,
lv_style_t *tgl_rel, lv_style_t *tgl_pr,
lv_style_t *ina)
void lv_btn_set_style(lv_obj_t *btn, lv_btn_style_t type, lv_style_t *style)
{
lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn);
lv_btn_ext_t *ext = lv_obj_get_ext_attr(btn);
if(rel != NULL) ext->styles[LV_BTN_STATE_RELEASED] = rel;
if(pr != NULL) ext->styles[LV_BTN_STATE_PRESSED] = pr;
if(tgl_rel != NULL) ext->styles[LV_BTN_STATE_TGL_RELEASED] = tgl_rel;
if(tgl_pr != NULL) ext->styles[LV_BTN_STATE_TGL_PRESSED] = tgl_pr;
if(ina != NULL) ext->styles[LV_BTN_STATE_INACTIVE] = ina;
switch (type) {
case LV_BTN_STYLE_REL:
ext->styles[LV_BTN_STATE_REL] = style;
break;
case LV_BTN_STYLE_PR:
ext->styles[LV_BTN_STATE_PR] = style;
break;
case LV_BTN_STYLE_TGL_REL:
ext->styles[LV_BTN_STATE_TGL_REL] = style;
break;
case LV_BTN_STYLE_TGL_PR:
ext->styles[LV_BTN_STATE_TGL_PR] = style;
break;
case LV_BTN_STYLE_INA:
ext->styles[LV_BTN_STATE_INA] = style;
break;
}
/*Refresh the object with the new style*/
lv_obj_set_style(btn, ext->styles[ext->state]);
@@ -224,18 +231,26 @@ lv_action_t lv_btn_get_action(lv_obj_t * btn, lv_btn_action_t type)
}
/**
* Get the style of a button in a given state
* Get a style of a button
* @param btn pointer to a button object
* @param state a state from 'lv_btn_state_t' in which style should be get
* @return pointer to the style in the given state
* @param type which style should be get
* @return style pointer to a style
*/
lv_style_t * lv_btn_get_style(lv_obj_t * btn, lv_btn_state_t state)
lv_style_t * lv_btn_get_style(lv_obj_t *btn, lv_btn_style_t type)
{
if(state >= LV_BTN_STATE_NUM) return lv_obj_get_style(lv_obj_get_parent(btn));
lv_btn_ext_t *ext = lv_obj_get_ext_attr(btn);
lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn);
if(ext->styles[state] == NULL) return lv_obj_get_style(lv_obj_get_parent(btn));
return ext->styles[state];
switch (type) {
case LV_BTN_STYLE_REL: return ext->styles[LV_BTN_STATE_REL];
case LV_BTN_STYLE_PR: return ext->styles[LV_BTN_STATE_PR];
case LV_BTN_STYLE_TGL_REL: return ext->styles[LV_BTN_STATE_TGL_REL];
case LV_BTN_STYLE_TGL_PR: return ext->styles[LV_BTN_STATE_TGL_PR];
case LV_BTN_STYLE_INA: return ext->styles[LV_BTN_STATE_INA];
default: return NULL;
}
/*To avoid warning*/
return NULL;
}
/**********************
@@ -263,93 +278,93 @@ static lv_res_t 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_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);
if(ext->state == LV_BTN_STATE_REL) {
lv_btn_set_state(btn, LV_BTN_STATE_PR);
} else if(ext->state == LV_BTN_STATE_TGL_REL) {
lv_btn_set_state(btn, LV_BTN_STATE_TGL_PR);
}
ext->long_press_action_executed = 0;
/*Call the press action, 'param' is the caller indev_proc*/
if(ext->actions[LV_BTN_ACTION_PRESS] && state != LV_BTN_STATE_INACTIVE) {
if(ext->actions[LV_BTN_ACTION_PRESS] && state != LV_BTN_STATE_INA) {
res = ext->actions[LV_BTN_ACTION_PRESS](btn);
}
}
else if(sign == LV_SIGNAL_PRESS_LOST) {
/*Refresh the state*/
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);
if(ext->state == LV_BTN_STATE_PR) lv_btn_set_state(btn, LV_BTN_STATE_REL);
else if(ext->state == LV_BTN_STATE_TGL_PR) lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL);
}
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_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);
if(ext->state == LV_BTN_STATE_PR) lv_btn_set_state(btn, LV_BTN_STATE_REL);
else if(ext->state == LV_BTN_STATE_TGL_PR) lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL);
}
}
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_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->state == LV_BTN_STATE_PR && tgl == false) {
lv_btn_set_state(btn, LV_BTN_STATE_REL);
} else if(ext->state == LV_BTN_STATE_TGL_PR && tgl == false) {
lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL);
} else if(ext->state == LV_BTN_STATE_PR && tgl == true) {
lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL);
} else if(ext->state == LV_BTN_STATE_TGL_PR && tgl == true) {
lv_btn_set_state(btn, LV_BTN_STATE_REL);
}
if(ext->actions[LV_BTN_ACTION_RELEASE] && state != LV_BTN_STATE_INACTIVE) {
if(ext->actions[LV_BTN_ACTION_RELEASE] && state != LV_BTN_STATE_INA) {
res = ext->actions[LV_BTN_ACTION_RELEASE](btn);
}
} else { /*If dragged change back the state*/
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);
if(ext->state == LV_BTN_STATE_PR) {
lv_btn_set_state(btn, LV_BTN_STATE_REL);
} else if(ext->state == LV_BTN_STATE_TGL_PR) {
lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL);
}
}
}
else if(sign == LV_SIGNAL_LONG_PRESS) {
if(ext->actions[LV_BTN_ACTION_LONG_PRESS] && state != LV_BTN_STATE_INACTIVE) {
if(ext->actions[LV_BTN_ACTION_LONG_PRESS] && state != LV_BTN_STATE_INA) {
ext->long_press_action_executed = 1;
res = ext->actions[LV_BTN_ACTION_LONG_PRESS](btn);
}
}
else if(sign == LV_SIGNAL_LONG_PRESS_REP) {
if(ext->actions[LV_BTN_ACTION_LONG_PRESS_REPEATE] && state != LV_BTN_STATE_INACTIVE) {
if(ext->actions[LV_BTN_ACTION_LONG_PRESS_REPEATE] && state != LV_BTN_STATE_INA) {
res = ext->actions[LV_BTN_ACTION_LONG_PRESS_REPEATE](btn);
}
}
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_TGL_RELEASED);
if(ext->actions[LV_BTN_ACTION_RELEASE] && lv_btn_get_state(btn) != LV_BTN_STATE_INACTIVE) {
if(lv_btn_get_toggle(btn) != false) lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL);
if(ext->actions[LV_BTN_ACTION_RELEASE] && lv_btn_get_state(btn) != LV_BTN_STATE_INA) {
res = ext->actions[LV_BTN_ACTION_RELEASE](btn);
}
} 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_RELEASED);
if(ext->actions[LV_BTN_ACTION_RELEASE] && lv_btn_get_state(btn) != LV_BTN_STATE_INACTIVE) {
if(lv_btn_get_toggle(btn) != false) lv_btn_set_state(btn, LV_BTN_STATE_REL);
if(ext->actions[LV_BTN_ACTION_RELEASE] && lv_btn_get_state(btn) != LV_BTN_STATE_INA) {
res = 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_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(state == LV_BTN_STATE_REL) lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL);
else if(state == LV_BTN_STATE_PR) lv_btn_set_state(btn, LV_BTN_STATE_TGL_PR);
else if(state == LV_BTN_STATE_TGL_REL) lv_btn_set_state(btn, LV_BTN_STATE_REL);
else if(state == LV_BTN_STATE_TGL_PR) lv_btn_set_state(btn, LV_BTN_STATE_PR);
}
if(ext->actions[LV_BTN_ACTION_RELEASE] && lv_btn_get_state(btn) != LV_BTN_STATE_INACTIVE) {
if(ext->actions[LV_BTN_ACTION_RELEASE] && lv_btn_get_state(btn) != LV_BTN_STATE_INA) {
res = ext->actions[LV_BTN_ACTION_RELEASE](btn);
}
}
}
return LV_RES_OK;
return res;
}

View File

@@ -35,11 +35,11 @@ extern "C" {
/*Button states*/
typedef enum
{
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_REL,
LV_BTN_STATE_PR,
LV_BTN_STATE_TGL_REL,
LV_BTN_STATE_TGL_PR,
LV_BTN_STATE_INA,
LV_BTN_STATE_NUM,
}lv_btn_state_t;
@@ -65,12 +65,18 @@ typedef struct
uint8_t long_press_action_executed :1; /*1: Long press action executed (Handled by the library)*/
}lv_btn_ext_t;
typedef enum {
LV_BTN_STYLE_REL,
LV_BTN_STYLE_PR,
LV_BTN_STYLE_TGL_REL,
LV_BTN_STYLE_TGL_PR,
LV_BTN_STYLE_INA,
}lv_btn_style_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Create a button objects
* @param par pointer to an object, it will be the parent of the new button
@@ -132,18 +138,14 @@ static inline void lv_btn_set_fit(lv_obj_t * btn, bool hor_en, bool ver_en)
lv_cont_set_fit(btn, hor_en, ver_en);
}
/**
* Set styles of a button is each state. Use NULL for any style to leave it unchanged
* Set a style of a button.
* @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 tgl_rel pointer to a style for toggled releases state
* @param tgl_pr pointer to a style for toggled pressed state
* @param ina pointer to a style for inactive state
*/
void lv_btn_set_style(lv_obj_t * btn, lv_style_t *rel, lv_style_t *pr,
lv_style_t *tgl_rel, lv_style_t *tgl_pr,
lv_style_t *ina);
* @param type which style should be set
* @param style pointer to a style
* */
void lv_btn_set_style(lv_obj_t * btn, lv_btn_style_t type, lv_style_t *style);
/*=====================
* Getter functions
@@ -201,12 +203,12 @@ static inline bool lv_btn_get_ver_fit(lv_obj_t * btn)
}
/**
* Get the style of a button in a given state
* @param btn pointer to a button object
* @param state a state from 'lv_btn_state_t' in which style should be get
* @return pointer to the style in the given state
*/
lv_style_t * lv_btn_get_style(lv_obj_t * btn, lv_btn_state_t state);
* Get style of a button.
* @param btn pointer to button object
* @param type which style should be get
* @return style pointer to the style
* */
lv_style_t * lv_btn_get_style(lv_obj_t * btn, lv_btn_style_t type);
/**********************
* MACROS

View File

@@ -78,11 +78,11 @@ 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->styles_btn[LV_BTN_STATE_RELEASED] = &lv_style_btn_released;
ext->styles_btn[LV_BTN_STATE_PRESSED] = &lv_style_btn_pressed;
ext->styles_btn[LV_BTN_STATE_TGL_RELEASED] = &lv_style_btn_tgl_released;
ext->styles_btn[LV_BTN_STATE_TGL_PRESSED] = &lv_style_btn_tgl_pressed;
ext->styles_btn[LV_BTN_STATE_INACTIVE] = &lv_style_btn_inactive;
ext->styles_btn[LV_BTN_STATE_REL] = &lv_style_btn_released;
ext->styles_btn[LV_BTN_STATE_PR] = &lv_style_btn_pressed;
ext->styles_btn[LV_BTN_STATE_TGL_REL] = &lv_style_btn_tgl_released;
ext->styles_btn[LV_BTN_STATE_TGL_PR] = &lv_style_btn_tgl_pressed;
ext->styles_btn[LV_BTN_STATE_INA] = &lv_style_btn_inactive;
if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_func(new_btnm);
@@ -234,7 +234,7 @@ void lv_btnm_set_toggle(lv_obj_t * btnm, bool en, uint16_t id)
ext->toggle = en == false ? 0 : 1;
if(ext->toggle != 0) {
if(id > ext->btn_cnt) id = LV_BTNM_PR_NONE;
if(id >= ext->btn_cnt) id = ext->btn_cnt - 1;
ext->btn_id_toggled = id;
} else {
ext->btn_id_toggled = LV_BTNM_PR_NONE;
@@ -244,28 +244,40 @@ void lv_btnm_set_toggle(lv_obj_t * btnm, bool en, uint16_t id)
}
/**
* 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 pointer to a style for releases state
* @param pr pointer to a style for pressed state
* @param tgl_rel pointer to a style for toggled releases state
* @param tgl_pr pointer to a style for toggled pressed state
* @param ina pointer to a style for inactive state
* Set a style of a button matrix
* @param btnm pointer to a button matrix object
* @param type which style should be set
* @param style pointer to a style
*/
void lv_btnm_set_style_btn(lv_obj_t *btnm, lv_style_t *rel, lv_style_t *pr,
lv_style_t *tgl_rel, lv_style_t *tgl_pr,
lv_style_t *ina)
void lv_btnm_set_style(lv_obj_t *btnm, lv_btnm_style_t type, lv_style_t *style)
{
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
lv_btnm_ext_t *ext = lv_obj_get_ext_attr(btnm);
if(rel != NULL) ext->styles_btn[LV_BTN_STATE_RELEASED] = rel;
if(pr != NULL) ext->styles_btn[LV_BTN_STATE_PRESSED] = pr;
if(tgl_rel != NULL) ext->styles_btn[LV_BTN_STATE_TGL_RELEASED] = tgl_rel;
if(tgl_pr != NULL) ext->styles_btn[LV_BTN_STATE_TGL_PRESSED] = tgl_pr;
if(ina != NULL) ext->styles_btn[LV_BTN_STATE_INACTIVE] = ina;
lv_obj_invalidate(btnm);
switch (type) {
case LV_BTNM_STYLE_BG:
lv_obj_set_style(btnm, style);
break;
case LV_BTNM_STYLE_BTN_REL:
ext->styles_btn[LV_BTN_STATE_REL] = style;
lv_obj_invalidate(btnm);
break;
case LV_BTNM_STYLE_BTN_PR:
ext->styles_btn[LV_BTN_STATE_PR] = style;
lv_obj_invalidate(btnm);
break;
case LV_BTNM_STYLE_BTN_TGL_REL:
ext->styles_btn[LV_BTN_STATE_TGL_REL] = style;
lv_obj_invalidate(btnm);
break;
case LV_BTNM_STYLE_BTN_TGL_PR:
ext->styles_btn[LV_BTN_STATE_TGL_PR] = style;
lv_obj_invalidate(btnm);
break;
case LV_BTNM_STYLE_BTN_INA:
ext->styles_btn[LV_BTN_STATE_INA] = style;
lv_obj_invalidate(btnm);
break;
}
}
/*=====================
@@ -295,21 +307,39 @@ lv_btnm_action_t lv_btnm_get_action(lv_obj_t * btnm)
}
/**
* Get the style of buttons in button matrix
* @param btnm pointer to a button matrix object
* @param state style in this state (LV_BTN_STATE_PR or LV_BTN_STATE_REL)
* @return pointer the button style in the given state
* Get the toggled button
* @param btnm pointer to button matrix object
* @return index of the currently toggled button (0: if unset)
*/
lv_style_t * lv_btnm_get_style_btn(lv_obj_t * btnm, lv_btn_state_t state)
uint16_t lv_btnm_get_toggled(lv_obj_t * btnm)
{
if(state >= LV_BTN_STATE_NUM) return lv_obj_get_style(btnm);
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
lv_style_t * style = ext->styles_btn[state];
if(style == NULL) style = lv_obj_get_style(btnm);
if(ext->toggle == 0) return 0;
else return ext->btn_id_toggled;}
return style;
/**
* Get a style of a button matrix
* @param btnm pointer to a button matrix object
* @param type which style should be get
* @return style pointer to a style
*/
lv_style_t * lv_btnm_get_style(lv_obj_t *btnm, lv_btnm_style_t type)
{
lv_btnm_ext_t *ext = lv_obj_get_ext_attr(btnm);
switch (type) {
case LV_BTNM_STYLE_BG: return lv_obj_get_style(btnm);
case LV_BTNM_STYLE_BTN_REL: return ext->styles_btn[LV_BTN_STATE_REL];
case LV_BTNM_STYLE_BTN_PR: return ext->styles_btn[LV_BTN_STATE_PR];
case LV_BTNM_STYLE_BTN_TGL_REL: return ext->styles_btn[LV_BTN_STATE_TGL_REL];
case LV_BTNM_STYLE_BTN_TGL_PR: return ext->styles_btn[LV_BTN_STATE_TGL_PR];
case LV_BTNM_STYLE_BTN_INA: return ext->styles_btn[LV_BTN_STATE_INA];
default: return NULL;
}
/*To avoid warning*/
return NULL;
}
/**********************
@@ -366,11 +396,11 @@ 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(button_is_inactive(ext->map_p[txt_i])) btn_style = lv_btnm_get_style_btn(btnm, LV_BTN_STATE_INACTIVE);
else if(btn_i != ext->btn_id_pressed && btn_i != ext->btn_id_toggled) btn_style = lv_btnm_get_style_btn(btnm, LV_BTN_STATE_RELEASED);
else if(btn_i == ext->btn_id_pressed && btn_i != ext->btn_id_toggled) btn_style = lv_btnm_get_style_btn(btnm, LV_BTN_STATE_PRESSED);
else if(btn_i != ext->btn_id_pressed && btn_i == ext->btn_id_toggled) btn_style = lv_btnm_get_style_btn(btnm, LV_BTN_STATE_TGL_RELEASED);
else if(btn_i == ext->btn_id_pressed && btn_i == ext->btn_id_toggled) btn_style = lv_btnm_get_style_btn(btnm, LV_BTN_STATE_TGL_PRESSED);
if(button_is_inactive(ext->map_p[txt_i])) btn_style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BTN_INA);
else if(btn_i != ext->btn_id_pressed && btn_i != ext->btn_id_toggled) btn_style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BTN_REL);
else if(btn_i == ext->btn_id_pressed && btn_i != ext->btn_id_toggled) btn_style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BTN_PR);
else if(btn_i != ext->btn_id_pressed && btn_i == ext->btn_id_toggled) btn_style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BTN_TGL_REL);
else if(btn_i == ext->btn_id_pressed && btn_i == ext->btn_id_toggled) btn_style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BTN_TGL_PR);
lv_draw_rect(&area_tmp, mask, btn_style);
/*Calculate the size of the text*/

View File

@@ -57,6 +57,15 @@ typedef struct
uint8_t toggle :1; /*Enable toggling*/
}lv_btnm_ext_t;
typedef enum {
LV_BTNM_STYLE_BG,
LV_BTNM_STYLE_BTN_REL,
LV_BTNM_STYLE_BTN_PR,
LV_BTNM_STYLE_BTN_TGL_REL,
LV_BTNM_STYLE_BTN_TGL_PR,
LV_BTNM_STYLE_BTN_INA,
}lv_btnm_style_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
@@ -105,27 +114,12 @@ void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_action_t action);
void lv_btnm_set_toggle(lv_obj_t * btnm, bool en, uint16_t id);
/**
* Set the style of a button matrix's background
* Set a style of a button matrix
* @param btnm pointer to a button matrix object
* @param bg pointer to the background style
* @param type which style should be set
* @param style pointer to a style
*/
static inline void lv_btnm_set_style(lv_obj_t *btnm, lv_style_t * bg)
{
lv_obj_set_style(btnm, bg);
}
/**
* 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 pointer to a style for releases state
* @param pr pointer to a style for pressed state
* @param tgl_rel pointer to a style for toggled releases state
* @param tgl_pr pointer to a style for toggled pressed state
* @param ina pointer to a style for inactive state
*/
void lv_btnm_set_style_btn(lv_obj_t *btnm, lv_style_t *rel, lv_style_t *pr,
lv_style_t *tgl_rel, lv_style_t *tgl_pr,
lv_style_t *ina);
void lv_btnm_set_style(lv_obj_t *btnm, lv_btnm_style_t type, lv_style_t *style);
/*=====================
* Getter functions
@@ -145,23 +139,21 @@ const char ** lv_btnm_get_map(lv_obj_t * btnm);
*/
lv_btnm_action_t lv_btnm_get_action(lv_obj_t * btnm);
/**
* Get the style of a button matrix
* @param btnm pointer to a button matrix object
* @return pointer to the backgrond style
*/
static inline lv_style_t * lv_btnm_get_style_bg(lv_obj_t *btnm)
{
return lv_obj_get_style(btnm);
}
/**
* Get the style of buttons in button matrix
* @param btnm pointer to a button matrix object
* @param state style in this state (LV_BTN_STATE_PR or LV_BTN_STATE_REL)
* @return pointer the button style in the given state
* Get the toggled button
* @param btnm pointer to button matrix object
* @return index of the currently toggled button (0: if unset)
*/
lv_style_t * lv_btnm_get_style_btn(lv_obj_t * btnm, lv_btn_state_t state);
uint16_t lv_btnm_get_toggled(lv_obj_t * btnm);
/**
* Get a style of a button matrix
* @param btnm pointer to a button matrix object
* @param type which style should be get
* @return style pointer to a style
*/
lv_style_t * lv_btnm_get_style(lv_obj_t *btnm, lv_btnm_style_t type);
/**********************
* MACROS

View File

@@ -69,14 +69,11 @@ lv_obj_t * lv_cb_create(lv_obj_t * par, lv_obj_t * copy)
ext->bullet = lv_btn_create(new_cb, NULL);
if(ancestor_bullet_design == NULL) ancestor_bullet_design = lv_obj_get_design_func(ext->bullet);
lv_obj_set_click(ext->bullet, false);
lv_btn_set_style(ext->bullet, &lv_style_pretty, &lv_style_pretty_color,
&lv_style_btn_tgl_released, &lv_style_btn_tgl_pressed,
NULL);
ext->label = lv_label_create(new_cb, NULL);
lv_obj_set_style(ext->label, NULL); /*Inherit the style of the parent*/
lv_cb_set_style(new_cb, &lv_style_transp);
lv_cb_set_style(new_cb,LV_CB_STYLE_BG, &lv_style_transp);
lv_cb_set_text(new_cb, "Check box");
lv_cont_set_layout(new_cb, LV_CONT_LAYOUT_ROW_M);
lv_cont_set_fit(new_cb, true, true);
@@ -113,23 +110,43 @@ void lv_cb_set_text(lv_obj_t * cb, const char * txt)
}
/**
* Set styles of a checkbox's bullet in each state. Use NULL for any style to leave it unchanged
* Set a style of a check box
* @param cb pointer to check box object
* @param rel pointer to a style for releases state
* @param pr pointer to a style for pressed state
* @param tgl_rel pointer to a style for toggled releases state
* @param tgl_pr pointer to a style for toggled pressed state
* @param ina pointer to a style for inactive state
*/
void lv_cb_set_style_bullet(lv_obj_t *cb, lv_style_t *rel, lv_style_t *pr,
lv_style_t *tgl_rel, lv_style_t *tgl_pr,
lv_style_t *ina)
* @param type which style should be set
* @param style pointer to a style
* */
void lv_cb_set_style(lv_obj_t * cb, lv_cb_style_t type, lv_style_t *style)
{
lv_cb_ext_t * ext = lv_obj_get_ext_attr(cb);
lv_btn_set_style(ext->bullet, rel, pr, tgl_rel, tgl_pr, ina);
switch (type) {
case LV_CB_STYLE_BG:
lv_btn_set_style(cb, LV_BTN_STYLE_REL, style);
lv_btn_set_style(cb, LV_BTN_STYLE_PR, style);
lv_btn_set_style(cb, LV_BTN_STYLE_TGL_REL, style);
lv_btn_set_style(cb, LV_BTN_STYLE_TGL_PR, style);
lv_btn_set_style(cb, LV_BTN_STYLE_INA, style);
break;
case LV_CB_STYLE_RELEASED:
lv_btn_set_style(ext->bullet, LV_BTN_STYLE_REL, style);
break;
case LV_CB_STYLE_PRESSED:
lv_btn_set_style(ext->bullet, LV_BTN_STYLE_PR, style);
break;
case LV_CB_STYLE_TGL_RELEASED:
lv_btn_set_style(ext->bullet, LV_BTN_STYLE_TGL_REL, style);
break;
case LV_CB_STYLE_TGL_PRESSED:
lv_btn_set_style(ext->bullet, LV_BTN_STYLE_TGL_PR, style);
break;
case LV_CB_STYLE_INACTIVE:
lv_btn_set_style(ext->bullet, LV_BTN_STYLE_INA, style);
break;
}
}
/*=====================
* Getter functions
*====================*/
@@ -145,15 +162,28 @@ const char * lv_cb_get_text(lv_obj_t * cb)
return lv_label_get_text(ext->label);
}
/**
* Get styles of a checkbox's bullet in a state.
* @param state a state from 'lv_btn_state_t' in which style should be get
* @return pointer to the style in the given state
*/
lv_style_t * lv_cb_get_style_bullet(lv_obj_t *cb, lv_btn_state_t state)
* Get a style of a button
* @param cb pointer to check box object
* @param type which style should be get
* @return style pointer to the style
* */
lv_style_t * lv_cb_get_style(lv_obj_t * cb, lv_cb_style_t type)
{
lv_cb_ext_t * ext = lv_obj_get_ext_attr(cb);
return lv_btn_get_style(ext->bullet, state);
switch (type) {
case LV_CB_STYLE_RELEASED: return lv_btn_get_style(ext->bullet, LV_BTN_STYLE_REL);
case LV_CB_STYLE_PRESSED: return lv_btn_get_style(ext->bullet, LV_BTN_STYLE_PR);
case LV_CB_STYLE_TGL_RELEASED: return lv_btn_get_style(ext->bullet, LV_BTN_STYLE_TGL_REL);
case LV_CB_STYLE_TGL_PRESSED: return lv_btn_get_style(ext->bullet, LV_BTN_STYLE_TGL_PR);
case LV_CB_STYLE_INACTIVE: return lv_btn_get_style(ext->bullet, LV_BTN_STYLE_INA);
default: return NULL;
}
/*To avoid awrning*/
return NULL;
}
/**********************
@@ -269,7 +299,7 @@ static lv_res_t lv_cb_signal(lv_obj_t * cb, lv_signal_t sign, void * param)
}
}
return LV_RES_OK;
return res;
}
#endif

View File

@@ -46,6 +46,15 @@ typedef struct
lv_obj_t * label; /*Pointer to label*/
}lv_cb_ext_t;
typedef enum {
LV_CB_STYLE_BG,
LV_CB_STYLE_RELEASED,
LV_CB_STYLE_PRESSED,
LV_CB_STYLE_TGL_RELEASED,
LV_CB_STYLE_TGL_PRESSED,
LV_CB_STYLE_INACTIVE,
}lv_cb_style_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
@@ -76,7 +85,7 @@ void lv_cb_set_text(lv_obj_t * cb, const char * txt);
*/
static inline void lv_cb_set_checked(lv_obj_t * cb, bool checked)
{
lv_btn_set_state(cb, checked ? LV_BTN_STATE_TGL_RELEASED : LV_BTN_STATE_RELEASED);
lv_btn_set_state(cb, checked ? LV_BTN_STATE_TGL_REL : LV_BTN_STATE_REL);
}
/**
@@ -85,7 +94,7 @@ static inline void lv_cb_set_checked(lv_obj_t * cb, bool checked)
*/
static inline void lv_cb_set_inactive(lv_obj_t * cb)
{
lv_btn_set_state(cb, LV_BTN_STATE_INACTIVE);
lv_btn_set_state(cb, LV_BTN_STATE_INA);
}
/**
@@ -97,32 +106,14 @@ static inline void lv_cb_set_action(lv_obj_t * cb, lv_action_t action)
lv_btn_set_action(cb, LV_BTN_ACTION_RELEASE, action);
}
/**
* Set styles of a checkbox's background is each state. Use NULL for any style to leave it unchanged
* @param cb pointer to check box object
* @param rel pointer to a style for releases state
* @param pr pointer to a style for pressed state
* @param tgl_rel pointer to a style for toggled releases state
* @param tgl_pr pointer to a style for toggled pressed state
* @param ina pointer to a style for inactive state
*/
static inline void lv_cb_set_style(lv_obj_t *cb, lv_style_t *bg)
{
lv_btn_set_style(cb, bg, bg, bg, bg, bg);
}
/**
* Set styles of a checkbox's bullet in each state. Use NULL for any style to leave it unchanged
* Set a style of a check box
* @param cb pointer to check box object
* @param rel pointer to a style for releases state
* @param pr pointer to a style for pressed state
* @param tgl_rel pointer to a style for toggled releases state
* @param tgl_pr pointer to a style for toggled pressed state
* @param ina pointer to a style for inactive state
*/
void lv_cb_set_style_bullet(lv_obj_t *cb, lv_style_t *rel, lv_style_t *pr,
lv_style_t *tgl_rel, lv_style_t *tgl_pr,
lv_style_t *ina);
* @param type which style should be set
* @param style pointer to a style
* */
void lv_cb_set_style(lv_obj_t * cb, lv_cb_style_t type, lv_style_t *style);
/*=====================
* Getter functions
@@ -142,7 +133,7 @@ const char * lv_cb_get_text(lv_obj_t * cb);
*/
static inline bool lv_cb_get_checked(lv_obj_t * cb)
{
return lv_btn_get_state(cb) == LV_BTN_STATE_RELEASED ? true : false;
return lv_btn_get_state(cb) == LV_BTN_STATE_REL ? true : false;
}
/**
@@ -155,23 +146,14 @@ static inline lv_action_t lv_cb_get_action(lv_obj_t * cb)
return lv_btn_get_action(cb, LV_BTN_ACTION_RELEASE);
}
/**
* Get the style of a check box's background in a given state
* @param cb pointer to a check box object
* @param state a state from 'lv_btn_state_t' in which style should be get
* @return pointer to the style in the given state
*/
static inline lv_style_t * lv_cb_get_style_bg(lv_obj_t * cb)
{
return lv_btn_get_style(cb, lv_btn_get_state(cb));
}
/**
* Get styles of a checkbox's bullet in a state.
* @param state a state from 'lv_btn_state_t' in which style should be get
* @return pointer to the style in the given state
*/
lv_style_t * lv_cb_get_style_bullet(lv_obj_t *cb, lv_btn_state_t state);
* Get a style of a button
* @param cb pointer to check box object
* @param type which style should be get
* @return style pointer to the style
* */
lv_style_t * lv_cb_get_style(lv_obj_t * cb, lv_cb_style_t type);
/**********************
* MACROS

View File

@@ -29,16 +29,17 @@
* STATIC PROTOTYPES
**********************/
static bool lv_chart_design(lv_obj_t * chart, const area_t * mask, lv_design_mode_t mode);
static lv_res_t lv_chart_signal(lv_obj_t * chart, lv_signal_t sign, void * param);
static void lv_chart_draw_div(lv_obj_t * chart, const area_t * mask);
static void lv_chart_draw_lines(lv_obj_t * chart, const area_t * mask);
static void lv_chart_draw_points(lv_obj_t * chart, const area_t * mask);
static void lv_chart_draw_cols(lv_obj_t * chart, const area_t * mask);
/**********************
* STATIC VARIABLES
**********************/
static lv_design_func_t ancestor_design_f;
static lv_signal_func_t ancestor_signal;
/**********************
* MACROS
@@ -48,10 +49,6 @@ static lv_design_func_t ancestor_design_f;
* GLOBAL FUNCTIONS
**********************/
/*-----------------
* Create function
*-----------------*/
/**
* Create a chart background objects
* @param par pointer to an object, it will be the parent of the new chart background
@@ -67,19 +64,20 @@ lv_obj_t * lv_chart_create(lv_obj_t * par, lv_obj_t * copy)
/*Allocate the object type specific extended data*/
lv_chart_ext_t * ext = lv_obj_allocate_ext_attr(new_chart, sizeof(lv_chart_ext_t));
dm_assert(ext);
ll_init(&ext->dl_ll, sizeof(lv_chart_dl_t));
ext->dl_num = 0;
ll_init(&ext->series_ll, sizeof(lv_chart_series_t));
ext->series.num = 0;
ext->ymin = LV_CHART_YMIN_DEF;
ext->ymax = LV_CHART_YMAX_DEF;
ext->hdiv_cnt = LV_CHART_HDIV_DEF;
ext->vdiv_cnt = LV_CHART_VDIV_DEF;
ext->pnum = LV_CHART_PNUM_DEF;
ext->point_cnt = LV_CHART_PNUM_DEF;
ext->type = LV_CHART_TYPE_LINE;
ext->dl_opa = OPA_COVER;
ext->dl_dark = OPA_50;
ext->dl_width = 2 << LV_ANTIALIAS;
ext->series.opa = OPA_COVER;
ext->series.dark = OPA_50;
ext->series.width = 2 << LV_ANTIALIAS;
if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_func(new_chart);
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_chart);
lv_obj_set_signal_func(new_chart, lv_chart_signal);
lv_obj_set_design_func(new_chart, lv_chart_design);
@@ -95,8 +93,8 @@ lv_obj_t * lv_chart_create(lv_obj_t * par, lv_obj_t * copy)
ext->ymax = ext_copy->ymax;
ext->hdiv_cnt = ext_copy->hdiv_cnt;
ext->vdiv_cnt = ext_copy->vdiv_cnt;
ext->pnum = ext_copy->pnum;
ext->dl_opa = ext_copy->dl_opa;
ext->point_cnt = ext_copy->point_cnt;
ext->series.opa = ext_copy->series.opa;
/*Refresh the style with new signal function*/
lv_obj_refresh_style(new_chart);
@@ -105,73 +103,40 @@ lv_obj_t * lv_chart_create(lv_obj_t * par, lv_obj_t * copy)
return new_chart;
}
/**
* Signal function of the chart background
* @param chart pointer to a chart background object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
*/
bool lv_chart_signal(lv_obj_t * chart, lv_signal_t sign, void * param)
{
bool valid;
/* Include the ancient signal function */
valid = lv_obj_signal(chart, sign, param);
/* The object can be deleted so check its validity and then
* make the object specific signal handling */
if(valid != false) {
cord_t ** datal;
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
if(sign == LV_SIGNAL_CLEANUP) {
LL_READ(ext->dl_ll, datal) {
dm_free(*datal);
}
ll_clear(&ext->dl_ll);
}
}
return valid;
}
/*======================
* Add/remove functions
*=====================*/
/**
* Allocate and add a data line to the chart
* Allocate and add a data series to the chart
* @param chart pointer to a chart object
* @param color color of the data line
* @return pointer to the allocated data line (
* @param color color of the data series
* @return pointer to the allocated data series
*/
lv_chart_dl_t * lv_chart_add_data_line(lv_obj_t * chart, color_t color)
lv_chart_series_t * lv_chart_add_series(lv_obj_t * chart, color_t color)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
lv_chart_dl_t * dl = ll_ins_head(&ext->dl_ll);
lv_chart_series_t *ser = ll_ins_head(&ext->series_ll);
cord_t def = (ext->ymin + ext->ymax) >> 1; /*half range as default value*/
if(dl == NULL) return NULL;
if(ser == NULL) return NULL;
dl->color = color;
ser->color = color;
dl->points = dm_alloc(sizeof(cord_t) * ext->pnum);
ser->points = dm_alloc(sizeof(cord_t) * ext->point_cnt);
uint16_t i;
cord_t * p_tmp = dl->points;
for(i = 0; i < ext->pnum; i++) {
cord_t * p_tmp = ser->points;
for(i = 0; i < ext->point_cnt; i++) {
*p_tmp = def;
p_tmp++;
}
ext->dl_num++;
ext->series.num++;
return dl;
return ser;
}
/**
* Refresh a chart if its data line has changed
* @param chart pointer to chart object
*/
void lv_chart_refresh(lv_obj_t * chart)
{
lv_obj_invalidate(chart);
}
/*=====================
* Setter functions
*====================*/
@@ -193,10 +158,8 @@ void lv_chart_set_div_line_count(lv_obj_t * chart, uint8_t hdiv, uint8_t vdiv)
}
/**
* Set the minimal and maximal x and y values
* Set the minimal and maximal y values
* @param chart pointer to a graph background object
* @param xmin x minimum value
* @param xmax x maximum value
* @param ymin y minimum value
* @param ymax y maximum value
*/
@@ -226,87 +189,87 @@ void lv_chart_set_type(lv_obj_t * chart, lv_chart_type_t type)
/**
* Set the number of points on a data line on a chart
* @param chart pointer r to chart object
* @param pnum new number of points on the data lines
* @param point_cnt new number of points on the data lines
*/
void lv_chart_set_pnum(lv_obj_t * chart, uint16_t pnum)
void lv_chart_set_point_count(lv_obj_t * chart, uint16_t point_cnt)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
lv_chart_dl_t * dl;
uint16_t pnum_old = ext->pnum;
lv_chart_series_t *ser;
uint16_t point_cnt_old = ext->point_cnt;
uint16_t i;
cord_t def = (ext->ymin + ext->ymax) >> 1; /*half range as default value*/
if(pnum < 1) pnum = 1;
if(point_cnt < 1) point_cnt = 1;
LL_READ_BACK(ext->dl_ll, dl) {
dl->points = dm_realloc(dl->points, sizeof(cord_t) * pnum);
LL_READ_BACK(ext->series_ll, ser) {
ser->points = dm_realloc(ser->points, sizeof(cord_t) * point_cnt);
/*Initialize the new points*/
if(pnum > pnum_old) {
for(i = pnum_old - 1; i < pnum; i++) {
dl->points[i] = def;
if(point_cnt > point_cnt_old) {
for(i = point_cnt_old - 1; i < point_cnt; i++) {
ser->points[i] = def;
}
}
}
ext->pnum = pnum;
ext->point_cnt = point_cnt;
lv_chart_refresh(chart);
}
/**
* Set the opacity of the data lines
* @param chart pointer to chart object
* @param opa opacity of the data lines
* Set the opacity of the data series
* @param chart pointer to a chart object
* @param opa opacity of the data series
*/
void lv_chart_set_dl_opa(lv_obj_t * chart, opa_t opa)
void lv_chart_set_series_opa(lv_obj_t * chart, opa_t opa)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
ext->dl_opa = opa;
ext->series.opa = opa;
lv_obj_invalidate(chart);
}
/**
* Set the line width or point radius of the data lines
* @param chart pointer to chart object
* Set the line width or point radius of the data series
* @param chart pointer to a chart object
* @param width the new width
*/
void lv_chart_set_dl_width(lv_obj_t * chart, cord_t width)
void lv_chart_set_series_width(lv_obj_t * chart, cord_t width)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
ext->dl_width = width;
ext->series.width = width;
lv_obj_invalidate(chart);
}
/**
* Set the dark effect on the bottom of the points or columns
* @param chart pointer to chart object
* @param chart pointer to a chart object
* @param dark_eff dark effect level (OPA_TRANSP to turn off)
*/
void lv_chart_set_dl_dark(lv_obj_t * chart, opa_t dark_eff)
void lv_chart_set_series_darking(lv_obj_t * chart, opa_t dark_eff)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
ext->dl_dark = dark_eff;
ext->series.dark = dark_eff;
}
/**
* Shift all data right and set the most right data on a data line
* @param chart pointer to chart object
* @param dl pointer to a data line on 'chart'
* @param ser pointer to a data series on 'chart'
* @param y the new value of the most right data
*/
void lv_chart_set_next(lv_obj_t * chart, lv_chart_dl_t * dl, cord_t y)
void lv_chart_set_next(lv_obj_t * chart, lv_chart_series_t * ser, cord_t y)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
uint16_t i;
for(i = 0; i < ext->pnum - 1; i++) {
dl->points[i] = dl->points[i + 1];
for(i = 0; i < ext->point_cnt - 1; i++) {
ser->points[i] = ser->points[i + 1];
}
dl->points[ext->pnum - 1] = y;
ser->points[ext->point_cnt - 1] = y;
lv_chart_refresh(chart);
}
/*=====================
* Getter functions
*====================*/
@@ -319,7 +282,6 @@ void lv_chart_set_next(lv_obj_t * chart, lv_chart_dl_t * dl, cord_t y)
lv_chart_type_t lv_chart_get_type(lv_obj_t * chart)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
return ext->type;
}
@@ -328,33 +290,32 @@ lv_chart_type_t lv_chart_get_type(lv_obj_t * chart)
* @param chart pointer to chart object
* @return point number on each data line
*/
uint16_t lv_chart_get_pnum(lv_obj_t * chart)
uint16_t lv_chart_get_point_cnt(lv_obj_t * chart)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
return ext->pnum;
return ext->point_cnt;
}
/**
* Get the opacity of the data lines
* Get the opacity of the data series
* @param chart pointer to chart object
* @return the opacity of the data lines
* @return the opacity of the data series
*/
opa_t lv_chart_get_dl_opa(lv_obj_t * chart)
opa_t lv_chart_get_series_opa(lv_obj_t * chart)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
return ext->dl_opa;
return ext->series.opa;
}
/**
* Get the data line width
* Get the data series width
* @param chart pointer to chart object
* @return the width the data lines (lines or points)
* @return the width the data series (lines or points)
*/
cord_t lv_chart_get_dl_width(lv_obj_t * chart)
cord_t lv_chart_get_series_width(lv_obj_t * chart)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
return ext->dl_width;
return ext->series.width;
}
/**
@@ -362,16 +323,29 @@ cord_t lv_chart_get_dl_width(lv_obj_t * chart)
* @param chart pointer to chart object
* @return dark effect level (OPA_TRANSP to turn off)
*/
opa_t lv_chart_get_dl_dark(lv_obj_t * chart, opa_t dark_eff)
opa_t lv_chart_get_series_darking(lv_obj_t * chart, opa_t dark_eff)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
return ext->dl_dark;
return ext->series.dark;
}
/*=====================
* Other functions
*====================*/
/**
* Refresh a chart if its data line has changed
* @param chart pointer to chart object
*/
void lv_chart_refresh(lv_obj_t * chart)
{
lv_obj_invalidate(chart);
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Handle the drawing related tasks of the chart backgrounds
* @param chart pointer to an object
@@ -402,6 +376,32 @@ static bool lv_chart_design(lv_obj_t * chart, const area_t * mask, lv_design_mod
return true;
}
/**
* Signal function of the chart background
* @param chart pointer to a chart background object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
*/
static lv_res_t lv_chart_signal(lv_obj_t * chart, lv_signal_t sign, void * param)
{
lv_res_t res;
/* Include the ancient signal function */
res = ancestor_signal(chart, sign, param);
if(res != LV_RES_OK) return res;
if(sign == LV_SIGNAL_CLEANUP) {
cord_t ** datal;
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
LL_READ(ext->series_ll, datal) {
dm_free(*datal);
}
ll_clear(&ext->series_ll);
}
return res;
}
/**
* Draw the division lines on chart background
* @param chart pointer to chart object
@@ -475,7 +475,6 @@ static void lv_chart_draw_div(lv_obj_t * chart, const area_t * mask)
static void lv_chart_draw_lines(lv_obj_t * chart, const area_t * mask)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
lv_style_t * style = lv_obj_get_style(chart);
uint8_t i;
point_t p1;
@@ -485,29 +484,29 @@ static void lv_chart_draw_lines(lv_obj_t * chart, const area_t * mask)
cord_t x_ofs = chart->coords.x1;
cord_t y_ofs = chart->coords.y1;
int32_t y_tmp;
lv_chart_dl_t * dl;
lv_chart_series_t *ser;
lv_style_t lines;
lv_style_copy(&lines, &lv_style_plain);
lines.body.opa = (uint16_t)((uint16_t)style->body.opa * ext->dl_opa) >> 8;
lines.line.width = ext->dl_width;
lines.line.opa = ext->series.opa;
lines.line.width = ext->series.width;
/*Go through all data lines*/
LL_READ_BACK(ext->dl_ll, dl) {
lines.line.color = dl->color;
LL_READ_BACK(ext->series_ll, ser) {
lines.line.color = ser->color;
p1.x = 0 + x_ofs;
p2.x = 0 + x_ofs;
y_tmp = (int32_t)((int32_t) dl->points[0] - ext->ymin) * h;
y_tmp = (int32_t)((int32_t) ser->points[0] - ext->ymin) * h;
y_tmp = y_tmp / (ext->ymax - ext->ymin);
p2.y = h - y_tmp + y_ofs;
for(i = 1; i < ext->pnum; i ++) {
for(i = 1; i < ext->point_cnt; i ++) {
p1.x = p2.x;
p1.y = p2.y;
p2.x = ((w * i) / (ext->pnum - 1)) + x_ofs;
p2.x = ((w * i) / (ext->point_cnt - 1)) + x_ofs;
y_tmp = (int32_t)((int32_t) dl->points[i] - ext->ymin) * h;
y_tmp = (int32_t)((int32_t) ser->points[i] - ext->ymin) * h;
y_tmp = y_tmp / (ext->ymax - ext->ymin);
p2.y = h - y_tmp + y_ofs;
@@ -524,7 +523,6 @@ static void lv_chart_draw_lines(lv_obj_t * chart, const area_t * mask)
static void lv_chart_draw_points(lv_obj_t * chart, const area_t * mask)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
lv_style_t * style = lv_obj_get_style(chart);
uint8_t i;
area_t cir_a;
@@ -533,28 +531,28 @@ static void lv_chart_draw_points(lv_obj_t * chart, const area_t * mask)
cord_t x_ofs = chart->coords.x1;
cord_t y_ofs = chart->coords.y1;
int32_t y_tmp;
lv_chart_dl_t * dl;
uint8_t dl_cnt = 0;
lv_chart_series_t * ser;
uint8_t series_cnt = 0;
lv_style_t style_point;
lv_style_copy(&style_point, &lv_style_plain);
style_point.body.border.width = 0;
style_point.body.empty = 0;
style_point.body.radius = LV_RADIUS_CIRCLE;
style_point.body.opa = (uint16_t)((uint16_t)style->body.opa * ext->dl_opa) >> 8;
style_point.body.radius = ext->dl_width;
style_point.body.opa = ext->series.opa;
style_point.body.radius = ext->series.width;
/*Go through all data lines*/
LL_READ_BACK(ext->dl_ll, dl) {
style_point.body.color_main = dl->color;
style_point.body.color_gradient = color_mix(COLOR_BLACK, dl->color, ext->dl_dark);
LL_READ_BACK(ext->series_ll, ser) {
style_point.body.color_main = ser->color;
style_point.body.color_gradient = color_mix(COLOR_BLACK, ser->color, ext->series.dark);
for(i = 0; i < ext->pnum; i ++) {
cir_a.x1 = ((w * i) / (ext->pnum - 1)) + x_ofs;
for(i = 0; i < ext->point_cnt; i ++) {
cir_a.x1 = ((w * i) / (ext->point_cnt - 1)) + x_ofs;
cir_a.x2 = cir_a.x1 + style_point.body.radius;
cir_a.x1 -= style_point.body.radius;
y_tmp = (int32_t)((int32_t) dl->points[i] - ext->ymin) * h;
y_tmp = (int32_t)((int32_t) ser->points[i] - ext->ymin) * h;
y_tmp = y_tmp / (ext->ymax - ext->ymin);
cir_a.y1 = h - y_tmp + y_ofs;
cir_a.y2 = cir_a.y1 + style_point.body.radius;
@@ -562,7 +560,7 @@ static void lv_chart_draw_points(lv_obj_t * chart, const area_t * mask)
lv_draw_rect(&cir_a, mask, &style_point);
}
dl_cnt++;
series_cnt++;
}
}
@@ -574,7 +572,6 @@ static void lv_chart_draw_points(lv_obj_t * chart, const area_t * mask)
static void lv_chart_draw_cols(lv_obj_t * chart, const area_t * mask)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
lv_style_t * style = lv_obj_get_style(chart);
uint8_t i;
area_t col_a;
@@ -583,35 +580,35 @@ static void lv_chart_draw_cols(lv_obj_t * chart, const area_t * mask)
cord_t w = lv_obj_get_width(chart);
cord_t h = lv_obj_get_height(chart);
int32_t y_tmp;
lv_chart_dl_t * dl;
lv_chart_series_t *ser;
lv_style_t rects;
cord_t col_w = w / ((ext->dl_num + 1) * ext->pnum); /* Suppose + 1 dl as separator*/
cord_t col_w = w / ((ext->series.num + 1) * ext->point_cnt); /* Suppose + 1 series as separator*/
cord_t x_ofs = col_w / 2; /*Shift with a half col.*/
lv_style_copy(&rects, &lv_style_plain);
rects.body.border.width = 0;
rects.body.empty = 0;
rects.body.radius = 0;
rects.body.opa = (uint16_t)((uint16_t)style->body.opa * ext->dl_opa) >> 8;
rects.body.opa = ext->series.opa;
col_a.y2 = chart->coords.y2;
cord_t x_act;
/*Go through all points*/
for(i = 0; i < ext->pnum; i ++) {
x_act = (int32_t)((int32_t) w * i) / ext->pnum;
for(i = 0; i < ext->point_cnt; i ++) {
x_act = (int32_t)((int32_t) w * i) / ext->point_cnt;
x_act += chart->coords.x1 + x_ofs;
/*Draw the current point of all data line*/
LL_READ_BACK(ext->dl_ll, dl) {
rects.body.color_main = dl->color;
rects.body.color_gradient = color_mix(COLOR_BLACK, dl->color, ext->dl_dark);
LL_READ_BACK(ext->series_ll, ser) {
rects.body.color_main = ser->color;
rects.body.color_gradient = color_mix(COLOR_BLACK, ser->color, ext->series.dark);
col_a.x1 = x_act;
col_a.x2 = col_a.x1 + col_w;
x_act += col_w;
y_tmp = (int32_t)((int32_t) dl->points[i] - ext->ymin) * h;
y_tmp = (int32_t)((int32_t) ser->points[i] - ext->ymin) * h;
y_tmp = y_tmp / (ext->ymax - ext->ymin);
col_a.y1 = h - y_tmp + chart->coords.y1;

View File

@@ -30,24 +30,26 @@ typedef struct
{
cord_t * points;
color_t color;
}lv_chart_dl_t;
}lv_chart_series_t;
/*Data of chart */
typedef struct
{
/*No inherited ext*/ /*Ext. of ancestor*/
/*New data for this type */
ll_dsc_t dl_ll; /*Linked list for the data line pointers (stores lv_chart_dl_t)*/
ll_dsc_t series_ll; /*Linked list for the data line pointers (stores lv_chart_dl_t)*/
cord_t ymin; /*y min value (used to scale the data)*/
cord_t ymax; /*y max value (used to scale the data)*/
uint8_t hdiv_cnt; /*Number of horizontal division lines*/
uint8_t vdiv_cnt; /*Number of vertical division lines*/
uint16_t pnum; /*Point number in a data line*/
cord_t dl_width; /*Line width or point radius*/
uint8_t dl_num; /*Number of data lines in dl_ll*/
opa_t dl_opa; /*Opacity of data lines*/
opa_t dl_dark; /*Dark level of the point/column bottoms*/
uint16_t point_cnt; /*Point number in a data line*/
uint8_t type :3; /*Line, column or point chart (from 'lv_chart_type_t')*/
struct {
cord_t width; /*Line width or point radius*/
uint8_t num; /*Number of data lines in dl_ll*/
opa_t opa; /*Opacity of data lines*/
opa_t dark; /*Dark level of the point/column bottoms*/
}series;
}lv_chart_ext_t;
/*Chart types*/
@@ -71,27 +73,21 @@ typedef enum
*/
lv_obj_t * lv_chart_create(lv_obj_t * par, lv_obj_t * copy);
/**
* Signal function of the chart background
* @param chart pointer to a chart background object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
*/
bool lv_chart_signal(lv_obj_t * chart, lv_signal_t sign, void * param);
/*======================
* Add/remove functions
*=====================*/
/**
* Allocate and add a data line to the chart
* Allocate and add a data series to the chart
* @param chart pointer to a chart object
* @param color color of the data line
* @return pointer to the allocated data line (
* @param color color of the data series
* @return pointer to the allocated data series
*/
lv_chart_dl_t * lv_chart_add_data_line(lv_obj_t * chart, color_t color);
lv_chart_series_t * lv_chart_add_series(lv_obj_t * chart, color_t color);
/**
* Refresh a chart if its data line has changed
* @param chart pointer to chart object
*/
void lv_chart_refresh(lv_obj_t * chart);
/*=====================
* Setter functions
*====================*/
/**
* Set the number of horizontal and vertical division lines
@@ -102,10 +98,8 @@ void lv_chart_refresh(lv_obj_t * chart);
void lv_chart_set_div_line_count(lv_obj_t * chart, uint8_t hdiv, uint8_t vdiv);
/**
* Set the minimal and maximal x and y values
* Set the minimal and maximal y values
* @param chart pointer to a graph background object
* @param xmin x minimum value
* @param xmax x maximum value
* @param ymin y minimum value
* @param ymax y maximum value
*/
@@ -121,38 +115,52 @@ void lv_chart_set_type(lv_obj_t * chart, lv_chart_type_t type);
/**
* Set the number of points on a data line on a chart
* @param chart pointer r to chart object
* @param pnum new number of points on the data lines
* @param point_cnt new number of points on the data lines
*/
void lv_chart_set_pnum(lv_obj_t * chart, uint16_t pnum);
void lv_chart_set_point_count(lv_obj_t * chart, uint16_t point_cnt);
/**
* Set the opacity of the data lines
* @param chart pointer to chart object
* @param opa opacity of the data lines
* Set the opacity of the data series
* @param chart pointer to a chart object
* @param opa opacity of the data series
*/
void lv_chart_set_dl_opa(lv_obj_t * chart, opa_t opa);
void lv_chart_set_series_opa(lv_obj_t * chart, opa_t opa);
/**
* Set the line width or point radius of the data lines
* @param chart pointer to chart object
* Set the line width or point radius of the data series
* @param chart pointer to a chart object
* @param width the new width
*/
void lv_chart_set_dl_width(lv_obj_t * chart, cord_t width);
void lv_chart_set_series_width(lv_obj_t * chart, cord_t width);
/**
* Set the dark effect on the bottom of the points or columns
* @param chart pointer to chart object
* @param chart pointer to a chart object
* @param dark_eff dark effect level (OPA_TRANSP to turn off)
*/
void lv_chart_set_dl_dark(lv_obj_t * chart, opa_t dark_eff);
void lv_chart_set_series_darking(lv_obj_t * chart, opa_t dark_eff);
/**
* Shift all data right and set the most right data on a data line
* @param chart pointer to chart object
* @param dl pointer to a data line on 'chart'
* @param ser pointer to a data series on 'chart'
* @param y the new value of the most right data
*/
void lv_chart_set_next(lv_obj_t * chart, lv_chart_dl_t * dl, cord_t y);
void lv_chart_set_next(lv_obj_t * chart, lv_chart_series_t * ser, cord_t y);
/**
* Set the style of a chart
* @param chart pointer to a chart object
* @param style pointer to a style
*/
static inline void lv_chart_set_style(lv_obj_t *chart, lv_style_t *style)
{
lv_obj_set_style(chart, style);
}
/*=====================
* Getter functions
*====================*/
/**
* Get the type of a chart
@@ -166,28 +174,48 @@ lv_chart_type_t lv_chart_get_type(lv_obj_t * chart);
* @param chart pointer to chart object
* @return point number on each data line
*/
uint16_t lv_chart_get_pnum(lv_obj_t * chart);
uint16_t lv_chart_get_point_cnt(lv_obj_t * chart);
/**
* Get the opacity of the data lines
* Get the opacity of the data series
* @param chart pointer to chart object
* @return the opacity of the data lines
* @return the opacity of the data series
*/
opa_t lv_chart_get_dl_opa(lv_obj_t * chart);
opa_t lv_chart_get_series_opa(lv_obj_t * chart);
/**
* Get the data line width
* Get the data series width
* @param chart pointer to chart object
* @return the width the data lines (lines or points)
* @return the width the data series (lines or points)
*/
cord_t lv_chart_get_dl_width(lv_obj_t * chart);
cord_t lv_chart_get_series_width(lv_obj_t * chart);
/**
* Get the dark effect level on the bottom of the points or columns
* @param chart pointer to chart object
* @return dark effect level (OPA_TRANSP to turn off)
*/
opa_t lv_chart_get_dl_dark(lv_obj_t * chart, opa_t dark_eff);
opa_t lv_chart_get_series_darking(lv_obj_t * chart, opa_t dark_eff);
/**
* Get the style of an chart object
* @param chart pointer to an chart object
* @return pointer to the chart's style
*/
static inline lv_style_t* lv_chart_get_style(lv_obj_t *chart)
{
return lv_obj_get_style(chart);
}
/*=====================
* Other functions
*====================*/
/**
* Refresh a chart if its data line has changed
* @param chart pointer to chart object
*/
void lv_chart_refresh(lv_obj_t * chart);
/**********************
* MACROS

View File

@@ -202,7 +202,7 @@ static lv_res_t lv_cont_signal(lv_obj_t * cont, lv_signal_t sign, void * param)
}
}
return LV_RES_OK;
return res;
}

View File

@@ -93,7 +93,9 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy)
lv_cont_set_fit(new_ddlist, true, false);
lv_page_set_release_action(new_ddlist, lv_ddlist_release_action);
lv_page_set_sb_mode(new_ddlist, LV_PAGE_SB_MODE_DRAG);
lv_ddlist_set_style(new_ddlist, &lv_style_pretty, NULL, &lv_style_plain_color);
lv_page_set_style(new_ddlist, LV_PAGE_STYLE_SCRL, &lv_style_transp_tight);
lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_BG, &lv_style_pretty);
lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_SELECTED, &lv_style_plain_color);
lv_ddlist_set_options(new_ddlist, "Option 1\nOption 2\nOption 3");
}
/*Copy an existing drop down list*/
@@ -195,19 +197,28 @@ void lv_ddlist_set_anim_time(lv_obj_t * ddlist, uint16_t anim_time)
}
/**
* Set the style of a drop down list
* Set a style of a drop down list
* @param ddlist pointer to a drop down list object
* @param bg pointer to the new style of the background
* @param sb pointer to the new style of the scrollbars (only visible with fix height)
* @param sel pointer to the new style of the select rectangle
* @param type which style should be set
* @param style pointer to a style
*/
void lv_ddlist_set_style(lv_obj_t * ddlist, lv_style_t *bg, lv_style_t *sb, lv_style_t *sel)
void lv_ddlist_set_style(lv_obj_t *ddlist, lv_ddlist_style_t type, lv_style_t *style)
{
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
if(sel != NULL) ext->selected_style = sel;
lv_obj_set_style(ext->options_label, bg);
lv_page_set_style(ddlist, bg, &lv_style_transp_tight, sb);
switch (type) {
case LV_DDLIST_STYLE_BG:
lv_page_set_style(ddlist, LV_PAGE_STYLE_BG, style);
break;
case LV_DDLIST_STYLE_SB:
lv_page_set_style(ddlist, LV_PAGE_STYLE_SB, style);
break;
case LV_DDLIST_STYLE_SELECTED:
ext->selected_style = style;
lv_obj_t *scrl = lv_page_get_scrl(ddlist);
lv_obj_refresh_ext_size(scrl); /*Because of the wider selected rectangle*/
break;
}
}
/*=====================
@@ -295,19 +306,27 @@ uint16_t lv_ddlist_get_anim_time(lv_obj_t * ddlist)
return ext->anim_time;
}
/**
* Get the style of the rectangle on the selected option
* Get a style of a drop down list
* @param ddlist pointer to a drop down list object
* @return pointer the style of the select rectangle
* @param type which style should be get
* @return style pointer to a style
*/
lv_style_t * lv_ddlist_get_style_select(lv_obj_t * ddlist)
lv_style_t * lv_ddlist_get_style(lv_obj_t *ddlist, lv_ddlist_style_t type)
{
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
if(ext->selected_style == NULL) return lv_obj_get_style(ddlist);
return ext->selected_style;
switch (type) {
case LV_DDLIST_STYLE_BG: return lv_page_get_style(ddlist, LV_PAGE_STYLE_BG);
case LV_DDLIST_STYLE_SB: return lv_page_get_style(ddlist, LV_PAGE_STYLE_SB);
case LV_DDLIST_STYLE_SELECTED: return ext->selected_style;
default: return NULL;
}
/*To avoid warning*/
return NULL;
}
/*=====================
* Other functions
*====================*/
@@ -365,7 +384,7 @@ static bool lv_ddlist_design(lv_obj_t * ddlist, const area_t * mask, lv_design_m
/*If the list is opened draw a rectangle under the selected item*/
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
if(ext->opened != 0) {
lv_style_t *style = lv_ddlist_get_style_bg(ddlist);
lv_style_t *style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG);
const font_t * font = style->text.font;
cord_t font_h = font_get_height_scale(font);
area_t rect_area;
@@ -404,8 +423,6 @@ lv_res_t lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * param)
if(sign == LV_SIGNAL_STYLE_CHG) {
lv_ddlist_refr_size(ddlist, 0);
lv_obj_t *scrl = lv_page_get_scrl(ddlist);
lv_obj_refresh_ext_size(scrl); /*Because of the wider selected rectangle*/
}
else if(sign == LV_SIGNAL_FOCUS) {
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
@@ -470,7 +487,7 @@ static lv_res_t lv_ddlist_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void *
/* Because of the wider selected rectangle ext. size
* In this way by dragging the scrollable part the wider rectangle area can be redrawn too*/
lv_obj_t *ddlist = lv_obj_get_parent(scrl);
lv_style_t *style = lv_ddlist_get_style_bg(ddlist);
lv_style_t *style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG);
if(scrl->ext_size < style->body.padding.hor) scrl->ext_size = style->body.padding.hor;
}

View File

@@ -51,6 +51,11 @@ typedef struct
cord_t fix_height; /*Height if the ddlist is opened. (0: auto-size)*/
}lv_ddlist_ext_t;
typedef enum {
LV_DDLIST_STYLE_BG,
LV_DDLIST_STYLE_SELECTED,
LV_DDLIST_STYLE_SB,
}lv_ddlist_style_t;
/**********************
* GLOBAL PROTOTYPES
@@ -113,14 +118,14 @@ static inline void lv_ddlist_set_sb_mode(lv_obj_t * ddlist, lv_page_sb_mode_t mo
*/
void lv_ddlist_set_anim_time(lv_obj_t * ddlist, uint16_t anim_time);
/**
* Set the style of a drop down list
* Set a style of a drop down list
* @param ddlist pointer to a drop down list object
* @param bg pointer to the new style of the background
* @param sb pointer to the new style of the scrollbars (only visible with fix height)
* @param sel pointer to the new style of the select rectangle
*/
void lv_ddlist_set_style(lv_obj_t * ddlist, lv_style_t *bg, lv_style_t *sb, lv_style_t *sel);
* @param type which style should be set
* @param style pointer to a style
* */
void lv_ddlist_set_style(lv_obj_t *ddlist, lv_ddlist_style_t type, lv_style_t *style);
/*=====================
* Getter functions
@@ -132,6 +137,7 @@ void lv_ddlist_set_style(lv_obj_t * ddlist, lv_style_t *bg, lv_style_t *sb, lv_s
* @return the options separated by '\n'-s (E.g. "Option1\nOption2\nOption3")
*/
const char * lv_ddlist_get_options(lv_obj_t * ddlist);
/**
* Get the selected option
* @param ddlist pointer to drop down list object
@@ -145,6 +151,7 @@ uint16_t lv_ddlist_get_selected(lv_obj_t * ddlist);
* @param buf pointer to an array to store the string
*/
void lv_ddlist_get_selected_str(lv_obj_t * ddlist, char * buf);
/**
* Get the "option selected" callback function
* @param ddlist pointer to a drop down list
@@ -176,32 +183,14 @@ static inline lv_page_sb_mode_t lv_ddlist_get_sb_mode(lv_obj_t * ddlist)
*/
uint16_t lv_ddlist_get_anim_time(lv_obj_t * ddlist);
/**
* Get the style of the drop down list background
* @param ddlist pointer to a drop down list object
* @return pointer to the style of the background
*/
static inline lv_style_t * lv_ddlist_get_style_bg(lv_obj_t * ddlist)
{
return lv_page_get_style_bg(ddlist);
}
/**
* Get the style of the scrollbars of a drop down list
* @param ddlist pointer to a drop down list object
* @return pointer to the style of the scrollbars
*/
static inline lv_style_t * lv_ddlist_get_style_sb(lv_obj_t * ddlist)
{
return lv_page_get_style_sb(ddlist);
}
/**
* Get the style of the rectangle on the selected option
* Get a style of a drop down list
* @param ddlist pointer to a drop down list object
* @return pointer the style of the select rectangle
* @param type which style should be get
* @return style pointer to a style
*/
lv_style_t * lv_ddlist_get_style_select(lv_obj_t * ddlist);
lv_style_t * lv_ddlist_get_style(lv_obj_t *ddlist, lv_ddlist_style_t type);
/*=====================
* Other functions

View File

@@ -90,7 +90,7 @@ lv_obj_t * lv_gauge_create(lv_obj_t * par, lv_obj_t * copy)
lv_gauge_set_scale(new_gauge, LV_GAUGE_DEF_ANGLE, LV_GAUGE_DEF_LINE_COUNT, LV_GAUGE_DEF_LABEL_COUNT);
lv_gauge_set_needle_count(new_gauge, 1, NULL);
lv_obj_set_size(new_gauge, 2 * LV_DPI, 2 * LV_DPI);
lv_obj_set_style(new_gauge, &lv_style_pretty);
lv_obj_set_style(new_gauge, &lv_style_pretty_color);
}
/*Copy an existing gauge*/
else {
@@ -259,9 +259,9 @@ static bool lv_gauge_design(lv_obj_t * gauge, const area_t * mask, lv_design_mod
/*Temporally modify the line meter to draw thicker and longer lines where labels are*/
lv_style_t style_tmp;
lv_style_copy(&style_tmp, style);
ext->lmeter.line_cnt = ext->label_count; /*Only to labels*/
ext->lmeter.line_cnt = ext->label_count; /*Only to labels*/
style_tmp.line.width = style_tmp.line.width * 2; /*Ticker lines*/
style_tmp.body.padding.hor = style_tmp.body.padding.hor * 2; /*Longer lines*/
style_tmp.body.padding.hor = style_tmp.body.padding.hor * 2; /*Longer lines*/
gauge->style_p = &style_tmp;
ancestor_design(gauge, mask, mode); /*To draw lines*/

View File

@@ -184,10 +184,11 @@ static inline uint16_t lv_gauge_get_scale_angle(lv_obj_t * gauge)
* @param gauge pointer to a gauge object
* @return pointer to the gauge's style
*/
static inline lv_style_t * lv_gauge_get_style_bg(lv_obj_t *gauge)
static inline lv_style_t * lv_gauge_get_style(lv_obj_t *gauge)
{
return lv_obj_get_style(gauge);
}
/**********************
* MACROS
**********************/

View File

@@ -335,7 +335,7 @@ static lv_res_t lv_img_signal(lv_obj_t * img, lv_signal_t sign, void * param)
}
}
return LV_RES_OK;
return res;
}

View File

@@ -135,7 +135,7 @@ bool lv_img_get_upscale(lv_obj_t * img);
/**
* Get the style of an image object
* @param img pointer to an image object
* @return the style an image
* @return pointer to the image's style
*/
static inline lv_style_t* lv_img_get_style(lv_obj_t *img)
{

View File

@@ -185,6 +185,35 @@ void lv_kb_set_close_action(lv_obj_t * kb, lv_action_t action)
ext->close_action = action;
}
/**
* Set a style of a keyboard
* @param kb pointer to a keyboard object
* @param type which style should be set
* @param style pointer to a style
*/
void lv_kb_set_style(lv_obj_t *kb, lv_kb_style_t type, lv_style_t *style)
{
switch (type) {
case LV_KB_STYLE_BG:
lv_btnm_set_style(kb, LV_BTNM_STYLE_BG, style);
break;
case LV_KB_STYLE_BTN_REL:
lv_btnm_set_style(kb, LV_BTNM_STYLE_BTN_REL, style);
break;
case LV_KB_STYLE_BTN_PR:
lv_btnm_set_style(kb, LV_BTNM_STYLE_BTN_PR, style);
break;
case LV_KB_STYLE_BTN_TGL_REL:
lv_btnm_set_style(kb, LV_BTNM_STYLE_BTN_TGL_REL, style);
break;
case LV_KB_STYLE_BTN_TGL_PR:
lv_btnm_set_style(kb, LV_BTNM_STYLE_BTN_TGL_PR, style);
break;
case LV_KB_STYLE_BTN_INA:
lv_btnm_set_style(kb, LV_BTNM_STYLE_BTN_INA, style);
break;
}
}
/*=====================
* Getter functions
@@ -246,6 +275,27 @@ lv_action_t lv_kb_get_close_action(lv_obj_t * kb, lv_action_t action)
return ext->close_action;
}
/**
* Get a style of a keyboard
* @param kb pointer to a keyboard object
* @param type which style should be get
* @return style pointer to a style
*/
lv_style_t * lv_kb_get_style(lv_obj_t *kb, lv_kb_style_t type)
{
switch (type) {
case LV_KB_STYLE_BG: return lv_btnm_get_style(kb, LV_BTNM_STYLE_BG);
case LV_KB_STYLE_BTN_REL: return lv_btnm_get_style(kb, LV_BTNM_STYLE_BTN_REL);
case LV_KB_STYLE_BTN_PR: return lv_btnm_get_style(kb, LV_BTNM_STYLE_BTN_PR);
case LV_KB_STYLE_BTN_TGL_REL: return lv_btnm_get_style(kb, LV_BTNM_STYLE_BTN_TGL_REL);
case LV_KB_STYLE_BTN_TGL_PR: return lv_btnm_get_style(kb, LV_BTNM_STYLE_BTN_TGL_PR);
case LV_KB_STYLE_BTN_INA: return lv_btnm_get_style(kb, LV_BTNM_STYLE_BTN_INA);
default: return NULL;
}
/*To avoid warning*/
return NULL;
}
/**********************
* STATIC FUNCTIONS
@@ -302,18 +352,18 @@ static lv_res_t lv_app_kb_action(lv_obj_t * kb, const char * txt)
if(strcmp(txt, "Enter") == 0)lv_ta_add_char(ext->ta, '\n');
else if(strcmp(txt, SYMBOL_LEFT) == 0) lv_ta_cursor_left(ext->ta);
else if(strcmp(txt, SYMBOL_RIGHT) == 0) lv_ta_cursor_right(ext->ta);
else if(strcmp(txt, "Del") == 0) lv_ta_del(ext->ta);
else if(strcmp(txt, "Del") == 0) lv_ta_del_char(ext->ta);
else if(strcmp(txt, "+/-") == 0) {
uint16_t cur = lv_ta_get_cursor_pos(ext->ta);
const char * ta_txt = lv_ta_get_text(ext->ta);
if(ta_txt[0] == '-') {
lv_ta_set_cursor_pos(ext->ta, 1);
lv_ta_del(ext->ta);
lv_ta_del_char(ext->ta);
lv_ta_add_char(ext->ta, '+');
lv_ta_set_cursor_pos(ext->ta, cur);
} else if(ta_txt[0] == '+') {
lv_ta_set_cursor_pos(ext->ta, 1);
lv_ta_del(ext->ta);
lv_ta_del_char(ext->ta);
lv_ta_add_char(ext->ta, '-');
lv_ta_set_cursor_pos(ext->ta, cur);
} else {

View File

@@ -44,14 +44,19 @@ typedef struct {
lv_action_t close_action; /*Called when the "Hide" button is clicked*/
}lv_kb_ext_t;
typedef enum {
LV_KB_STYLE_BG,
LV_KB_STYLE_BTN_REL,
LV_KB_STYLE_BTN_PR,
LV_KB_STYLE_BTN_TGL_REL,
LV_KB_STYLE_BTN_TGL_PR,
LV_KB_STYLE_BTN_INA,
}lv_kb_style_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/*-----------------
* Create function
*-----------------*/
/**
* Create a keyboard objects
* @param par pointer to an object, it will be the parent of the new keyboard
@@ -100,30 +105,12 @@ void lv_kb_set_ok_action(lv_obj_t * kb, lv_action_t action);
void lv_kb_set_close_action(lv_obj_t * kb, lv_action_t action);
/**
* Set the style of a keyboards's background
* Set a style of a keyboard
* @param kb pointer to a keyboard object
* @param bg pointer to the background style
* @param type which style should be set
* @param style pointer to a style
*/
static inline void lv_kb_set_style(lv_obj_t *kb, lv_style_t * bg)
{
lv_btnm_set_style(kb, bg);
}
/**
* Set styles of the buttons is each state. Use NULL for any style to leave it unchanged.
* @param kb pointer to keyboard object
* @param rel pointer to a style for releases state
* @param pr pointer to a style for pressed state
* @param tgl_rel pointer to a style for toggled releases state
* @param tgl_pr pointer to a style for toggled pressed state
* @param ina pointer to a style for inactive state
*/
static inline void lv_kb_set_style_btn(lv_obj_t *kb, lv_style_t *rel, lv_style_t *pr,
lv_style_t *tgl_rel, lv_style_t *tgl_pr,
lv_style_t *ina)
{
lv_btnm_set_style_btn(kb, rel, pr, tgl_rel, tgl_pr, ina);
}
void lv_kb_set_style(lv_obj_t *kb, lv_kb_style_t type, lv_style_t *style);
/*=====================
* Getter functions
@@ -165,25 +152,12 @@ lv_action_t lv_kb_get_ok_action(lv_obj_t * kb, lv_action_t action);
lv_action_t lv_kb_get_close_action(lv_obj_t * kb, lv_action_t action);
/**
* Get the style of a keyboard
* Get a style of a keyboard
* @param kb pointer to a keyboard object
* @return pointer to the background style
* @param type which style should be get
* @return style pointer to a style
*/
static inline lv_style_t * lv_kb_get_style_bg(lv_obj_t *kb)
{
return lv_btnm_get_style_bg(kb);
}
/**
* Get the style of the buttons of keyboard
* @param kb pointer to a keyboard object
* @param state style in this state (LV_BTN_STATE_PR or LV_BTN_STATE_REL)
* @return pointer the button style in the given state
*/
static inline lv_style_t * lv_kb_kb_style_btn(lv_obj_t *kb, lv_btn_state_t state)
{
return lv_btnm_get_style_btn(kb, state);
}
lv_style_t * lv_kb_get_style(lv_obj_t *kb, lv_kb_style_t type);
/**********************
* MACROS

View File

@@ -234,7 +234,7 @@ uint16_t lv_label_get_letter_on(lv_obj_t * label, point_t * pos);
/**
* Get the style of an label object
* @param label pointer to an label object
* @return the style an label
* @return pointer to the label's style
*/
static inline lv_style_t* lv_label_get_style(lv_obj_t *label)
{

View File

@@ -28,11 +28,13 @@
* STATIC PROTOTYPES
**********************/
static bool lv_led_design(lv_obj_t * led, const area_t * mask, lv_design_mode_t mode);
static lv_res_t lv_led_signal(lv_obj_t * led, lv_signal_t sign, void * param);
/**********************
* STATIC VARIABLES
**********************/
static lv_design_func_t ancestor_design_f;
static lv_signal_func_t ancestor_signal;
/**********************
* MACROS
@@ -42,10 +44,6 @@ static lv_design_func_t ancestor_design_f;
* GLOBAL FUNCTIONS
**********************/
/*-----------------
* Create function
*-----------------*/
/**
* Create a led objects
* @param par pointer to an object, it will be the parent of the new led
@@ -57,14 +55,14 @@ lv_obj_t * lv_led_create(lv_obj_t * par, lv_obj_t * copy)
/*Create the ancestor basic object*/
lv_obj_t * new_led = lv_obj_create(par, copy);
dm_assert(new_led);
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_led);
if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_func(new_led);
/*Allocate the object type specific extended data*/
lv_led_ext_t * ext = lv_obj_allocate_ext_attr(new_led, sizeof(lv_led_ext_t));
dm_assert(ext);
ext->bright = LV_LED_BRIGHT_ON;
if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_func(new_led);
lv_obj_set_signal_func(new_led, lv_led_signal);
lv_obj_set_design_func(new_led, lv_led_design);
@@ -85,29 +83,6 @@ lv_obj_t * lv_led_create(lv_obj_t * par, lv_obj_t * copy)
return new_led;
}
/**
* Signal function of the led
* @param led pointer to a led object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return true: the object is still valid (not deleted), false: the object become invalid
*/
bool lv_led_signal(lv_obj_t * led, lv_signal_t sign, void * param)
{
bool valid;
/* Include the ancient signal function */
valid = lv_obj_signal(led, sign, param);
/* The object can be deleted so check its validity and then
* make the object specific signal handling */
if(valid != false) {
}
return valid;
}
/*=====================
* Setter functions
*====================*/
@@ -216,4 +191,21 @@ static bool lv_led_design(lv_obj_t * led, const area_t * mask, lv_design_mode_t
return true;
}
/**
* Signal function of the led
* @param led pointer to a led object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
*/
static lv_res_t lv_led_signal(lv_obj_t * led, lv_signal_t sign, void * param)
{
lv_res_t res;
/* Include the ancient signal function */
res = ancestor_signal(led, sign, param);
if(res != LV_RES_OK) return res;
return res;
}
#endif

View File

@@ -46,15 +46,6 @@ typedef struct
*/
lv_obj_t * lv_led_create(lv_obj_t * par, lv_obj_t * copy);
/**
* Signal function of the led
* @param led pointer to a led object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return true: the object is still valid (not deleted), false: the object become invalid
*/
bool lv_led_signal(lv_obj_t * led, lv_signal_t sign, void * param);
/**
* Set the brightness of a LED object
* @param led pointer to a LED object
@@ -87,6 +78,27 @@ void lv_led_tgl(lv_obj_t * led);
*/
uint8_t lv_led_get_bright(lv_obj_t * led);
/**
* Set the style of a led
* @param led pointer to a led object
* @param style pointer to a style
*/
static inline void lv_led_set_style(lv_obj_t *led, lv_style_t *style)
{
lv_obj_set_style(led, style);
}
/**
* Get the style of an led object
* @param led pointer to an led object
* @return pointer to the led's style
*/
static inline lv_style_t* lv_led_get_style(lv_obj_t *led)
{
return lv_obj_get_style(led);
}
/**********************
* MACROS
**********************/

View File

@@ -281,6 +281,6 @@ static lv_res_t lv_line_signal(lv_obj_t * line, lv_signal_t sign, void * param)
res = lv_obj_signal(line, sign, param);
if(res != LV_RES_OK) return res;
return LV_RES_OK;
return res;
}
#endif

View File

@@ -122,13 +122,13 @@ bool lv_line_get_y_inv(lv_obj_t * line);
bool lv_line_get_upscale(lv_obj_t * line);
/**
* Get the style of an image object
* Get the style of an line object
* @param line pointer to an line object
* @return the style an image
* @return pointer to the line's style
*/
static inline lv_style_t* lv_line_get_style(lv_obj_t *img)
static inline lv_style_t* lv_line_get_style(lv_obj_t *line)
{
return lv_obj_get_style(img);
return lv_obj_get_style(line);
}
/**********************

View File

@@ -66,11 +66,11 @@ lv_obj_t * lv_list_create(lv_obj_t * par, lv_obj_t * copy)
dm_assert(ext);
ext->style_img = NULL;
ext->styles_btn[LV_BTN_STATE_RELEASED] = &lv_style_btn_released;
ext->styles_btn[LV_BTN_STATE_PRESSED] = &lv_style_btn_pressed;
ext->styles_btn[LV_BTN_STATE_TGL_RELEASED] = &lv_style_btn_tgl_released;
ext->styles_btn[LV_BTN_STATE_PRESSED] = &lv_style_btn_tgl_pressed;
ext->styles_btn[LV_BTN_STATE_INACTIVE] = &lv_style_btn_inactive;
ext->styles_btn[LV_BTN_STATE_REL] = &lv_style_btn_released;
ext->styles_btn[LV_BTN_STATE_PR] = &lv_style_btn_pressed;
ext->styles_btn[LV_BTN_STATE_TGL_REL] = &lv_style_btn_tgl_released;
ext->styles_btn[LV_BTN_STATE_PR] = &lv_style_btn_tgl_pressed;
ext->styles_btn[LV_BTN_STATE_INA] = &lv_style_btn_inactive;
ext->anim_time = LV_LIST_FOCUS_TIME;
lv_obj_set_signal_func(new_list, lv_list_signal);
@@ -79,17 +79,12 @@ 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_page_set_scrl_layout(new_list, LV_LIST_LAYOUT_DEF);
lv_list_set_style(new_list, &lv_style_transp_fit, &lv_style_pretty, NULL);
lv_page_set_sb_mode(new_list, LV_PAGE_SB_MODE_DRAG);
lv_list_set_style(new_list, LV_LIST_STYLE_BG, &lv_style_transp_fit);
lv_list_set_style(new_list, LV_LIST_STYLE_SCRL, &lv_style_pretty);
} else {
lv_list_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
lv_list_set_style_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_obj_t *copy_btn = lv_obj_get_child_back(lv_page_get_scrl(copy), NULL);
lv_obj_t *new_btn;
while(copy_btn) {
@@ -100,6 +95,12 @@ lv_obj_t * lv_list_create(lv_obj_t * par, lv_obj_t * copy)
copy_btn = lv_obj_get_child_back(lv_page_get_scrl(copy), copy_btn);
}
lv_list_set_style(new_list, LV_LIST_STYLE_BTN_REL, copy_ext->styles_btn[LV_BTN_STATE_REL]);
lv_list_set_style(new_list, LV_LIST_STYLE_BTN_PR, copy_ext->styles_btn[LV_BTN_STATE_PR]);
lv_list_set_style(new_list, LV_LIST_STYLE_BTN_TGL_REL, copy_ext->styles_btn[LV_BTN_STATE_TGL_REL]);
lv_list_set_style(new_list, LV_LIST_STYLE_BTN_TGL_PR, copy_ext->styles_btn[LV_BTN_STATE_TGL_REL]);
lv_list_set_style(new_list, LV_LIST_STYLE_BTN_INA, copy_ext->styles_btn[LV_BTN_STATE_INA]);
/*Refresh the style with new signal function*/
lv_obj_refresh_style(new_list);
}
@@ -127,9 +128,11 @@ lv_obj_t * lv_list_add(lv_obj_t * list, const char * img_fn, const char * txt, l
/*Create a list element with the image an the text*/
lv_obj_t * liste;
liste = lv_btn_create(list, NULL);
lv_btn_set_style(liste, ext->styles_btn[LV_BTN_STATE_RELEASED], ext->styles_btn[LV_BTN_STATE_PRESSED],
ext->styles_btn[LV_BTN_STATE_TGL_PRESSED], ext->styles_btn[LV_BTN_STATE_TGL_PRESSED],
ext->styles_btn[LV_BTN_STATE_INACTIVE]);
lv_btn_set_style(liste, LV_BTN_STYLE_REL, ext->styles_btn[LV_BTN_STATE_REL]);
lv_btn_set_style(liste, LV_BTN_STYLE_PR, ext->styles_btn[LV_BTN_STATE_PR]);
lv_btn_set_style(liste, LV_BTN_STYLE_TGL_REL, ext->styles_btn[LV_BTN_STATE_TGL_REL]);
lv_btn_set_style(liste, LV_BTN_STYLE_TGL_PR, ext->styles_btn[LV_BTN_STATE_TGL_PR]);
lv_btn_set_style(liste, LV_BTN_STYLE_INA, ext->styles_btn[LV_BTN_STATE_INA]);
lv_btn_set_action(liste, LV_BTN_ACTION_RELEASE, rel_action);
lv_page_glue_obj(liste, true);
@@ -162,8 +165,6 @@ lv_obj_t * lv_list_add(lv_obj_t * list, const char * img_fn, const char * txt, l
if(label_signal == NULL) label_signal = lv_obj_get_signal_func(label);
}
return liste;
}
@@ -183,32 +184,57 @@ void lv_list_set_anim_time(lv_obj_t *list, uint16_t anim_time)
}
/**
* Set styles of the list elements of a list in each state
* @param list pointer to list object
* @param rel pointer to a style for releases state
* @param pr pointer to a style for pressed state
* @param tgl_rel pointer to a style for toggled releases state
* @param tgl_pr pointer to a style for toggled pressed state
* @param ina pointer to a style for inactive state
* Set a style of a list
* @param list pointer to a list object
* @param type which style should be set
* @param style pointer to a style
*/
void lv_list_set_style_btn(lv_obj_t * list, lv_style_t * rel, lv_style_t * pr,
lv_style_t * tgl_rel, lv_style_t * tgl_pr,
lv_style_t * ina)
void lv_list_set_style(lv_obj_t *list, lv_list_style_t type, lv_style_t *style)
{
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
lv_list_ext_t *ext = lv_obj_get_ext_attr(list);
if(rel != NULL) ext->styles_btn[LV_BTN_STATE_RELEASED] = rel;
if(pr != NULL) ext->styles_btn[LV_BTN_STATE_PRESSED] = pr;
if(tgl_rel != NULL) ext->styles_btn[LV_BTN_STATE_TGL_RELEASED] = tgl_rel;
if(tgl_pr != NULL) ext->styles_btn[LV_BTN_STATE_TGL_PRESSED] = tgl_pr;
if(ina != NULL) ext->styles_btn[LV_BTN_STATE_INACTIVE] = ina;
switch (type) {
case LV_LIST_STYLE_BG:
lv_page_set_style(list, LV_PAGE_STYLE_BG, style);
break;
case LV_LIST_STYLE_SCRL:
lv_page_set_style(list, LV_PAGE_STYLE_SCRL, style);
break;
case LV_LIST_STYLE_SB:
lv_page_set_style(list, LV_PAGE_STYLE_SB, style);
break;
case LV_LIST_STYLE_BTN_REL:
ext->styles_btn[LV_BTN_STATE_REL] = style;
break;
case LV_LIST_STYLE_BTN_PR:
ext->styles_btn[LV_BTN_STATE_PR] = style;
break;
case LV_LIST_STYLE_BTN_TGL_REL:
ext->styles_btn[LV_BTN_STATE_TGL_REL] = style;
break;
case LV_LIST_STYLE_BTN_TGL_PR:
ext->styles_btn[LV_BTN_STATE_TGL_PR] = style;
break;
case LV_LIST_STYLE_BTN_INA:
ext->styles_btn[LV_BTN_STATE_INA] = style;
break;
}
/*Refresh all existing buttons*/
lv_obj_t * liste = get_next_btn(list, NULL);
while(liste != NULL)
/*Refresh existing buttons' style*/
if(type == LV_LIST_STYLE_BTN_PR || type == LV_LIST_STYLE_BTN_REL ||
type == LV_LIST_STYLE_BTN_TGL_REL || type == LV_LIST_STYLE_BTN_TGL_PR ||
type == LV_LIST_STYLE_BTN_INA)
{
lv_btn_set_style(liste, rel, pr, tgl_rel, tgl_pr, ina);
liste = get_next_btn(list, liste);
lv_obj_t * liste = get_next_btn(list, NULL);
while(liste != NULL) {
lv_btn_set_style(liste, LV_BTN_STYLE_REL, ext->styles_btn[LV_BTN_STYLE_REL]);
lv_btn_set_style(liste, LV_BTN_STYLE_PR, ext->styles_btn[LV_BTN_STYLE_PR]);
lv_btn_set_style(liste, LV_BTN_STYLE_TGL_REL, ext->styles_btn[LV_BTN_STYLE_TGL_REL]);
lv_btn_set_style(liste, LV_BTN_STYLE_TGL_PR, ext->styles_btn[LV_BTN_STYLE_TGL_PR]);
lv_btn_set_style(liste, LV_BTN_STYLE_INA, ext->styles_btn[LV_BTN_STYLE_INA]);
liste = get_next_btn(list, liste);
}
}
}
@@ -280,20 +306,30 @@ uint16_t lv_list_get_anim_time(lv_obj_t *list)
}
/**
* Get the style of the list elements in a given state
* Get a style of a list
* @param list pointer to a list object
* @param state a state from 'lv_btn_state_t' in which style should be get
* @return pointer to the style in the given state
*/
lv_style_t * lv_list_get_style_btn(lv_obj_t * list, lv_btn_state_t state)
* @param type which style should be get
* @return style pointer to a style
* */
lv_style_t * lv_list_get_style(lv_obj_t *list, lv_btn_style_t type)
{
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
lv_list_ext_t *ext = lv_obj_get_ext_attr(list);
if(ext->styles_btn[state] == NULL) return lv_obj_get_style(list);
switch (type) {
case LV_LIST_STYLE_BG: return lv_page_get_style(list, LV_PAGE_STYLE_BG);
case LV_LIST_STYLE_SCRL: return lv_page_get_style(list, LV_PAGE_STYLE_SB);
case LV_LIST_STYLE_SB: return lv_page_get_style(list, LV_PAGE_STYLE_SCRL);
case LV_LIST_STYLE_BTN_REL: return ext->styles_btn[LV_BTN_STATE_REL];
case LV_LIST_STYLE_BTN_PR: return ext->styles_btn[LV_BTN_STATE_PR];
case LV_LIST_STYLE_BTN_TGL_REL: return ext->styles_btn[LV_BTN_STATE_TGL_REL];
case LV_LIST_STYLE_BTN_TGL_PR: return ext->styles_btn[LV_BTN_STATE_TGL_PR];
case LV_LIST_STYLE_BTN_INA: return ext->styles_btn[LV_BTN_STATE_INA];
default: return NULL;
}
return ext->styles_btn[state];
/*To avoid warning*/
return NULL;
}
/*=====================
* Other functions
*====================*/
@@ -432,7 +468,7 @@ static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param)
btn = get_next_btn(list, btn);
}
if(btn_prev != NULL) {
lv_btn_set_state(btn_prev, LV_BTN_STATE_PRESSED);
lv_btn_set_state(btn_prev, LV_BTN_STATE_PR);
}
}
else if(sign == LV_SIGNAL_DEFOCUS) {
@@ -440,12 +476,12 @@ static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param)
lv_obj_t * btn = NULL;
btn = get_next_btn(list, btn);
while(btn != NULL) {
if(lv_btn_get_state(btn) == LV_BTN_STATE_PRESSED) break;
if(lv_btn_get_state(btn) == LV_BTN_STATE_PR) break;
btn = get_next_btn(list, btn);
}
if(btn != NULL) {
lv_btn_set_state(btn, LV_BTN_STATE_RELEASED);
lv_btn_set_state(btn, LV_BTN_STATE_REL);
}
}
else if(sign == LV_SIGNAL_CONTROLL) {
@@ -457,14 +493,14 @@ static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param)
lv_list_ext_t *ext = lv_obj_get_ext_attr(list);
btn = get_next_btn(list, btn);
while(btn != NULL) {
if(lv_btn_get_state(btn) == LV_BTN_STATE_PRESSED) break;
if(lv_btn_get_state(btn) == LV_BTN_STATE_PR) break;
btn_prev = btn;
btn = get_next_btn(list, btn);
}
if(btn_prev != NULL && btn != NULL) {
lv_btn_set_state(btn, LV_BTN_STATE_RELEASED);
lv_btn_set_state(btn_prev, LV_BTN_STATE_PRESSED);
lv_btn_set_state(btn, LV_BTN_STATE_REL);
lv_btn_set_state(btn_prev, LV_BTN_STATE_PR);
lv_page_focus(list, btn_prev, ext->anim_time);
}
}
@@ -474,15 +510,15 @@ static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param)
lv_list_ext_t *ext = lv_obj_get_ext_attr(list);
btn = get_next_btn(list, btn);
while(btn != NULL) {
if(lv_btn_get_state(btn) == LV_BTN_STATE_PRESSED) break;
if(lv_btn_get_state(btn) == LV_BTN_STATE_PR) break;
btn = get_next_btn(list, btn);
}
if(btn != NULL) {
lv_obj_t * btn_prev = get_next_btn(list, btn);
if(btn_prev != NULL) {
lv_btn_set_state(btn, LV_BTN_STATE_RELEASED);
lv_btn_set_state(btn_prev, LV_BTN_STATE_PRESSED);
lv_btn_set_state(btn, LV_BTN_STATE_REL);
lv_btn_set_state(btn_prev, LV_BTN_STATE_PR);
lv_page_focus(list, btn_prev, ext->anim_time);
}
}
@@ -491,7 +527,7 @@ static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param)
lv_obj_t * btn = NULL;
btn = get_next_btn(list, btn);
while(btn != NULL) {
if(lv_btn_get_state(btn) == LV_BTN_STATE_PRESSED) break;
if(lv_btn_get_state(btn) == LV_BTN_STATE_PR) break;
btn = get_next_btn(list, btn);
}
@@ -502,7 +538,7 @@ static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param)
}
}
}
return LV_RES_OK;
return res;
}
/**
@@ -532,7 +568,7 @@ static lv_obj_t * get_next_btn(lv_obj_t * list, lv_obj_t * prev_btn)
static void refr_btn_width(lv_obj_t *list)
{
lv_style_t *style = lv_list_get_style_bg(list);
lv_style_t *style = lv_list_get_style(list, LV_LIST_STYLE_BG);
lv_style_t *style_scrl = lv_obj_get_style(lv_page_get_scrl(list));
cord_t w = lv_obj_get_width(list);
cord_t btn_w = w - (style->body.padding.hor + style_scrl->body.padding.hor) * 2;

View File

@@ -53,6 +53,17 @@ typedef struct
lv_style_t *style_img; /*Style of the list element images on buttons*/
}lv_list_ext_t;
typedef enum {
LV_LIST_STYLE_BG,
LV_LIST_STYLE_SCRL,
LV_LIST_STYLE_SB,
LV_LIST_STYLE_BTN_REL,
LV_LIST_STYLE_BTN_PR,
LV_LIST_STYLE_BTN_TGL_REL,
LV_LIST_STYLE_BTN_TGL_PR,
LV_LIST_STYLE_BTN_INA,
}lv_list_style_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
@@ -100,30 +111,14 @@ static inline void lv_list_set_sb_mode(lv_obj_t * list, lv_page_sb_mode_t mode)
lv_page_set_sb_mode(list, mode);
}
/**
* Set a new styles for the list
* @param list pointer to a list object
* @param bg pointer to a style for the background (typically transparent)
* @param scrl pointer to a style for the scrollable area
* @param sb pointer to a style for the scroll bars
*/
static inline void lv_list_set_style(lv_obj_t *list, lv_style_t *bg, lv_style_t *scrl, lv_style_t *sb)
{
lv_page_set_style(list, bg, scrl, sb);
}
/**
* Set styles of the list elements of a list in each state
* @param list pointer to list object
* @param rel pointer to a style for releases state
* @param pr pointer to a style for pressed state
* @param tgl_rel pointer to a style for toggled releases state
* @param tgl_pr pointer to a style for toggled pressed state
* @param ina pointer to a style for inactive state
* Set a style of a list
* @param list pointer to a list object
* @param type which style should be set
* @param style pointer to a style
*/
void lv_list_set_style_btn(lv_obj_t * list, lv_style_t * rel, lv_style_t * pr,
lv_style_t * tgl_rel, lv_style_t * tgl_pr,
lv_style_t * ina);
void lv_list_set_style(lv_obj_t *list, lv_list_style_t type, lv_style_t *style);
/*=====================
* Getter functions
@@ -167,42 +162,12 @@ static inline lv_page_sb_mode_t lv_list_get_sb_mode(lv_obj_t * list)
}
/**
* Get a style of a list's background
* Get a style of a list
* @param list pointer to a list object
* @return pointer to the background's style
*/
static inline lv_style_t * lv_list_get_style_bg(lv_obj_t *list)
{
return lv_page_get_style_bg(list);
}
/**
* Get a style of a list's scrollable part
* @param list pointer to a list object
* @return pointer to the scrollable"s style
*/
static inline lv_style_t * lv_list_get_style_scrl(lv_obj_t *list)
{
return lv_page_get_style_scrl(list);
}
/**
* Get the style of the scrollbars of a list
* @param list pointer to a list object
* @return pointer to the style of the scrollbars
*/
static inline lv_style_t * lv_list_get_style_sb(lv_obj_t *list)
{
return lv_page_get_style_sb(list);
}
/**
* Get the style of the list elements in a given state
* @param list pointer to a list object
* @param state a state from 'lv_btn_state_t' in which style should be get
* @return pointer to the style in the given state
*/
lv_style_t * lv_list_get_style_btn(lv_obj_t * list, lv_btn_state_t state);
* @param type which style should be get
* @return style pointer to a style
* */
lv_style_t * lv_list_get_style(lv_obj_t *list, lv_btn_style_t type);
/*=====================
* Other functions

View File

@@ -296,7 +296,7 @@ static lv_res_t lv_lmeter_signal(lv_obj_t * lmeter, lv_signal_t sign, void * par
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
}
return LV_RES_OK;
return res;
}

View File

@@ -28,7 +28,7 @@
* STATIC PROTOTYPES
**********************/
static lv_res_t lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param);
static void btnh_resize(lv_obj_t *mbox);
static void mbox_realign(lv_obj_t *mbox);
/**********************
* STATIC VARIABLES
@@ -59,46 +59,34 @@ lv_obj_t * lv_mbox_create(lv_obj_t * par, lv_obj_t * copy)
/*Allocate the message box type specific extended data*/
lv_mbox_ext_t * ext = lv_obj_allocate_ext_attr(new_mbox, sizeof(lv_mbox_ext_t));
dm_assert(ext);
ext->txt = NULL;
ext->btnh = NULL;
ext->style_btn_rel = &lv_style_btn_released;
ext->style_btn_pr = &lv_style_btn_pressed;
ext->text = NULL;
ext->btnm = NULL;
ext->anim_time = LV_MBOX_CLOSE_ANIM_TIME;
ext->btn_width = 0;
/*The signal and design functions are not copied so set them here*/
lv_obj_set_signal_func(new_mbox, lv_mbox_signal);
/*Init the new message box message box*/
if(copy == NULL) {
lv_cont_set_layout(new_mbox, LV_CONT_LAYOUT_COL_M);
lv_cont_set_fit(new_mbox, true, true);
ext->text = lv_label_create(new_mbox, NULL);
lv_label_set_align(ext->text, LV_LABEL_ALIGN_CENTER);
lv_label_set_long_mode(ext->text, LV_LABEL_LONG_BREAK);
lv_label_set_text(ext->text, "Message");
ext->txt = lv_label_create(new_mbox, NULL);
lv_label_set_align(ext->txt, LV_LABEL_ALIGN_CENTER);
lv_label_set_text(ext->txt, "Message");
lv_cont_set_layout(new_mbox, LV_CONT_LAYOUT_COL_M);
lv_cont_set_fit(new_mbox, false, true);
lv_obj_set_width(new_mbox, LV_HOR_RES / 3);
lv_obj_set_style(new_mbox, &lv_style_pretty);
lv_mbox_set_style(new_mbox, LV_MBOX_STYLE_BG, &lv_style_pretty);
}
/*Copy an existing message box*/
else {
lv_mbox_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
ext->txt = lv_label_create(new_mbox, copy_ext->txt);
ext->btn_width = copy_ext->btn_width;
ext->text = lv_label_create(new_mbox, copy_ext->text);
/*Copy the buttons and the label on them*/
if(copy_ext->btnh != NULL) {
lv_obj_t * btn_copy;
const char * btn_txt_copy;
LL_READ_BACK(copy_ext->btnh->child_ll, btn_copy) {
btn_txt_copy = lv_label_get_text(lv_obj_get_child(btn_copy, NULL));
lv_mbox_add_btn(new_mbox, btn_txt_copy, lv_btn_get_action(btn_copy, LV_BTN_ACTION_RELEASE));
}
}
lv_mbox_set_style(new_mbox, lv_mbox_get_style_bg(copy), lv_mbox_get_style_btnh(copy));
lv_mbox_set_style_btn(new_mbox, copy_ext->style_btn_rel, copy_ext->style_btn_pr);
if(copy_ext->btnm) ext->btnm = lv_btnm_create(new_mbox, copy_ext->btnm);
/*Refresh the style with new signal function*/
lv_obj_refresh_style(new_mbox);
@@ -108,57 +96,27 @@ lv_obj_t * lv_mbox_create(lv_obj_t * par, lv_obj_t * copy)
}
/**
* A release action which can be assigned to a message box button to close it
* @param btn pointer to the released button
* @return always lv_action_res_t because the button is deleted with the mesage box
*/
lv_res_t lv_mbox_close_action(lv_obj_t * btn)
{
lv_obj_t * mbox = lv_mbox_get_from_btn(btn);
bool deleted = lv_mbox_get_anim_time(mbox) ? false : true;
lv_mbox_start_auto_close(mbox, 0);
return deleted ? LV_RES_INV : LV_RES_OK;
}
/**
* Add a button to the message box
* Set button to the message box
* @param mbox pointer to message box object
* @param btn_txt the text of the button
* @param rel_action a function which will be called when the button is released
* @return pointer to the created button (lv_btn)
* @param btn_map button descriptor (button matrix map).
* E.g. a const char *txt[] = {"ok", "close", ""} (Can not be local variable)
* @param action a function which will be called when a button is released
*/
lv_obj_t * lv_mbox_add_btn(lv_obj_t * mbox, const char * btn_txt, lv_action_t rel_action)
void lv_mbox_set_btns(lv_obj_t * mbox, const char **btn_map, lv_btnm_action_t action)
{
lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
/*Create a button holder if it is not existed yet*/
if(ext->btnh == NULL) {
ext->btnh = lv_cont_create(mbox, NULL);
lv_obj_set_style(ext->btnh, &lv_style_transp_fit);
lv_obj_set_click(ext->btnh, false);
lv_cont_set_fit(ext->btnh, false, true);
lv_cont_set_layout(ext->btnh, LV_CONT_LAYOUT_PRETTY);
/*Create a button matrix if not exists yet*/
if(ext->btnm == NULL) {
ext->btnm = lv_btnm_create(mbox, NULL);
lv_obj_set_height(ext->btnm, LV_DPI / 2);
lv_btnm_set_style(ext->btnm, LV_BTNM_STYLE_BG, &lv_style_transp_fit);
}
lv_obj_t *btn = lv_btn_create(ext->btnh, NULL);
lv_btn_set_action(btn, LV_BTN_ACTION_RELEASE, rel_action);
lv_btn_set_style(btn, ext->style_btn_rel, ext->style_btn_pr, NULL, NULL, NULL);
lv_btnm_set_map(ext->btnm, btn_map);
lv_btnm_set_action(ext->btnm, action);
if(ext->btn_width) {
lv_btn_set_fit(btn, false, true);
lv_obj_set_width(btn, ext->btn_width);
} else {
lv_btn_set_fit(btn, true, true);
}
lv_obj_t *label = lv_label_create(btn, NULL);
lv_label_set_text(label, btn_txt);
btnh_resize(mbox);
return btn;
mbox_realign(mbox);
}
/*=====================
@@ -173,34 +131,9 @@ lv_obj_t * lv_mbox_add_btn(lv_obj_t * mbox, const char * btn_txt, lv_action_t re
void lv_mbox_set_text(lv_obj_t * mbox, const char * txt)
{
lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
lv_label_set_text(ext->txt, txt);
lv_label_set_text(ext->text, txt);
btnh_resize(mbox);
}
/**
* Set the width of the buttons
* @param mbox pointer to message box object
* @param w width of the buttons or 0 to use auto fit
*/
void lv_mbox_set_btn_width(lv_obj_t *mbox, cord_t w)
{
lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
ext->btn_width = w;
if(ext->btnh == NULL) return;
lv_obj_t *btn = lv_obj_get_child(ext->btnh, NULL);
while(btn != NULL) {
if(w) {
lv_btn_set_fit(btn, false, true);
lv_obj_set_width(btn, w);
} else {
lv_btn_set_fit(btn, true, true);
}
btn = lv_obj_get_child(ext->btnh, btn);
}
btnh_resize(mbox);
mbox_realign(mbox);
}
/**
@@ -245,43 +178,42 @@ void lv_mbox_stop_auto_close(lv_obj_t * mbox)
}
/**
* Set the styles of a message box
* Set a style of a message box
* @param mbox pointer to a message box object
* @param bg pointer to the new background style
* @param btnh pointer to the new button holder style
* @param type which style should be set
* @param style pointer to a style
*/
void lv_mbox_set_style(lv_obj_t *mbox, lv_style_t *bg, lv_style_t *btnh)
void lv_mbox_set_style(lv_obj_t *mbox, lv_mbox_style_t type, lv_style_t *style)
{
lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
lv_obj_set_style(ext->btnh, btnh);
lv_obj_set_style(mbox, bg);
}
lv_mbox_ext_t *ext = lv_obj_get_ext_attr(mbox);
/**
* Set styles of the buttons of a message box in each state
* @param mbox pointer to a message box object
* @param rel pointer to a style for releases state
* @param pr pointer to a style for pressed state
*/
void lv_mbox_set_style_btn(lv_obj_t * mbox, lv_style_t * rel, lv_style_t * pr)
{
lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
ext->style_btn_rel = rel;
ext->style_btn_pr = pr;
if(ext->btnh != NULL) {
lv_obj_t * btn = lv_obj_get_child(ext->btnh, NULL);
while(btn != NULL) {
lv_btn_set_style(btn, rel, pr, NULL, NULL, NULL);
btn = lv_obj_get_child(mbox, btn);
}
switch (type) {
case LV_MBOX_STYLE_BG:
lv_obj_set_style(mbox, style);
break;
case LV_MBOX_STYLE_BTN_BG:
lv_btnm_set_style(ext->btnm, LV_BTNM_STYLE_BG, style);
break;
case LV_MBOX_STYLE_BTN_REL:
lv_btnm_set_style(ext->btnm, LV_BTNM_STYLE_BTN_REL, style);
break;
case LV_MBOX_STYLE_BTN_PR:
lv_btnm_set_style(ext->btnm, LV_BTNM_STYLE_BTN_PR, style);
break;
case LV_MBOX_STYLE_BTN_TGL_REL:
lv_btnm_set_style(ext->btnm, LV_BTNM_STYLE_BTN_TGL_REL, style);
break;
case LV_MBOX_STYLE_BTN_TGL_PR:
lv_btnm_set_style(ext->btnm, LV_BTNM_STYLE_BTN_TGL_PR, style);
break;
case LV_MBOX_STYLE_BTN_INA:
lv_btnm_set_style(ext->btnm, LV_BTNM_STYLE_BTN_INA, style);
break;
}
btnh_resize(mbox);
}
/*=====================
* Getter functions
*====================*/
@@ -295,18 +227,7 @@ const char * lv_mbox_get_text(lv_obj_t * mbox)
{
lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
return lv_label_get_text(ext->txt);
}
/**
* Get width of the buttons
* @param mbox pointer to a message box object
* @return width of the buttons (0: auto fit enabled)
*/
cord_t lv_mbox_get_btn_width(lv_obj_t * mbox)
{
lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
return ext->btn_width;
return lv_label_get_text(ext->text);
}
/**
@@ -335,30 +256,30 @@ uint16_t lv_mbox_get_anim_time(lv_obj_t * mbox )
}
/**
* Get the style of a message box's button holder
* Get a style of a message box
* @param mbox pointer to a message box object
* @return pointer to the message box's background style
* @param type which style should be get
* @return style pointer to a style
*/
lv_style_t * lv_mbox_get_style_btnh(lv_obj_t *mbox)
lv_style_t * lv_mbox_get_style(lv_obj_t *mbox, lv_mbox_style_t type)
{
lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
return lv_obj_get_style(ext->btnh);
lv_mbox_ext_t *ext = lv_obj_get_ext_attr(mbox);
switch (type) {
case LV_MBOX_STYLE_BG: return lv_obj_get_style(mbox);
case LV_MBOX_STYLE_BTN_BG: return lv_btnm_get_style(ext->btnm, LV_BTNM_STYLE_BG);
case LV_MBOX_STYLE_BTN_REL: return lv_btnm_get_style(ext->btnm, LV_BTNM_STYLE_BTN_REL);
case LV_MBOX_STYLE_BTN_PR: return lv_btnm_get_style(ext->btnm, LV_BTNM_STYLE_BTN_PR);
case LV_MBOX_STYLE_BTN_TGL_REL: return lv_btnm_get_style(ext->btnm, LV_BTNM_STYLE_BTN_TGL_REL);
case LV_MBOX_STYLE_BTN_TGL_PR: return lv_btnm_get_style(ext->btnm, LV_BTNM_STYLE_BTN_TGL_PR);
case LV_MBOX_STYLE_BTN_INA: return lv_btnm_get_style(ext->btnm, LV_BTNM_STYLE_BTN_INA);
default: return NULL;
}
/*To avoid warning*/
return NULL;
}
/**
* Get the style of the buttons on a message box
* @param mbox pointer to a message box object
* @param state a state from 'lv_btn_state_t' in which style should be get
* @return pointer to the style in the given state
*/
lv_style_t * lv_mbox_get_style_btn(lv_obj_t * mbox, lv_btn_state_t state)
{
lv_btn_ext_t * ext = lv_obj_get_ext_attr(mbox);
if(ext->styles[state] == NULL) return lv_obj_get_style(mbox);
return ext->styles[state];
}
/**********************
* STATIC FUNCTIONS
@@ -382,142 +303,35 @@ static lv_res_t lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param)
lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
if(sign == LV_SIGNAL_CORD_CHG) {
if(lv_obj_get_width(mbox) != area_get_width(param)) {
btnh_resize(mbox);
mbox_realign(mbox);
}
}
if(sign == LV_SIGNAL_LONG_PRESS) {
lv_mbox_start_auto_close(mbox, 0);
lv_indev_wait_release(param);
res = LV_RES_INV;
}
else if(sign == LV_SIGNAL_STYLE_CHG) {
/*Refresh all the buttons*/
if(ext->btnh != NULL) {
lv_obj_t * btn;
btn = lv_obj_get_child(ext->btnh, NULL);
while(btn != NULL) {
/*Refresh the next button's style*/
lv_btn_set_style(btn, ext->style_btn_rel, ext->style_btn_pr, NULL, NULL, NULL);
btn = lv_obj_get_child(ext->btnh, btn);
}
}
mbox_realign(mbox);
}
else if(sign == LV_SIGNAL_FOCUS) {
/*Get the first button*/
if(ext->btnh != NULL) {
lv_obj_t * btn = NULL;
lv_obj_t * btn_prev = NULL;
btn = lv_obj_get_child(ext->btnh, btn);
while(btn != NULL) {
btn_prev = btn;
btn = lv_obj_get_child(ext->btnh, btn);
}
if(btn_prev != NULL) {
lv_btn_set_state(btn_prev, LV_BTN_STATE_PRESSED);
}
}
}
else if(sign == LV_SIGNAL_DEFOCUS) {
/*Get the 'pressed' button*/
if(ext->btnh != NULL) {
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_PRESSED) break;
btn = lv_obj_get_child(ext->btnh, btn);
}
if(btn != NULL) {
lv_btn_set_state(btn, LV_BTN_STATE_RELEASED);
}
}
}
else if(sign == LV_SIGNAL_CONTROLL) {
lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
char c = *((char*)param);
if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_UP) {
/*Get the last pressed button*/
if(ext->btnh != NULL) {
lv_obj_t * btn = NULL;
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_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_RELEASED);
lv_btn_set_state(btn_prev, LV_BTN_STATE_PRESSED);
}
}
}
else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_DOWN) {
/*Get the last pressed button*/
if(ext->btnh != NULL) {
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_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_RELEASED);
lv_btn_set_state(btn_prev, LV_BTN_STATE_PRESSED);
}
}
}
}
else if(c == LV_GROUP_KEY_ENTER) {
/*Get the 'pressed' button*/
if(ext->btnh != NULL) {
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_PRESSED) break;
btn = lv_obj_get_child(ext->btnh, btn);
}
if(btn != NULL) {
lv_action_t rel_action;
rel_action = lv_btn_get_action(btn, LV_BTN_ACTION_RELEASE);
if(rel_action != NULL) rel_action(btn);
}
}
else if(sign == LV_SIGNAL_FOCUS || sign == LV_SIGNAL_DEFOCUS || sign == LV_SIGNAL_CONTROLL) {
if(ext->btnm) {
ext->btnm->signal_func(ext->btnm, sign, param);
}
}
return LV_RES_OK;
return res;
}
/**
* Resize the button holder to fit
* @param mbox pointer to message box object
*/
static void btnh_resize(lv_obj_t *mbox)
static void mbox_realign(lv_obj_t *mbox)
{
lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
if(ext->btnh == NULL) return;
lv_style_t *btnh_style = lv_mbox_get_style_bg(ext->btnh);
cord_t btnh_req_w = 2 * btnh_style->body.padding.hor;
lv_obj_t *btn = lv_obj_get_child(ext->btnh, NULL);
while(btn != NULL) {
btnh_req_w += lv_obj_get_width(btn) + btnh_style->body.padding.inner;
btn = lv_obj_get_child(ext->btnh, btn);
}
btnh_req_w -= btnh_style->body.padding.inner; /*Trim the last inner padding*/
cord_t txt_w = lv_obj_get_width(ext->txt);
lv_obj_set_width(ext->btnh, btnh_req_w > txt_w ? btnh_req_w : txt_w);
lv_style_t *style = lv_mbox_get_style(mbox, LV_MBOX_STYLE_BG);
cord_t w = lv_obj_get_width(mbox) - 2 * style->body.padding.hor;
if(ext->btnm) lv_obj_set_width(ext->btnm, w);
if(ext->text) lv_obj_set_width(ext->text, w);
}
#endif

View File

@@ -21,18 +21,18 @@ extern "C" {
#error "lv_mbox: lv_cont is required. Enable it in lv_conf.h (USE_LV_CONT 1) "
#endif
#if USE_LV_BTN == 0
#error "lv_mbox: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) "
#if USE_LV_BTNM == 0
#error "lv_mbox: lv_btnm is required. Enable it in lv_conf.h (USE_LV_BTNM 1) "
#endif
#if USE_LV_LABEL == 0
#error "lv_mbox: lv_rlabel is required. Enable it in lv_conf.h (USE_LV_LABEL 1) "
#error "lv_mbox: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) "
#endif
#include "../lv_obj/lv_obj.h"
#include "lv_cont.h"
#include "lv_btn.h"
#include "lv_btnm.h"
#include "lv_label.h"
/*********************
@@ -48,14 +48,21 @@ typedef struct
{
lv_cont_ext_t bg; /*Ext. of ancestor*/
/*New data for this type */
lv_obj_t * txt; /*Text of the message box*/
lv_obj_t * btnh; /*Holder of the buttons*/
lv_style_t * style_btn_rel; /*Style of the released buttons*/
lv_style_t * style_btn_pr; /*Style of the pressed buttons*/
lv_obj_t *text; /*Text of the message box*/
lv_obj_t *btnm; /*Button matrix for the buttons*/
uint16_t anim_time; /*Duration of close animation [ms] (0: no animation)*/
cord_t btn_width; /*Button width (0: to auto fit)*/
}lv_mbox_ext_t;
typedef enum {
LV_MBOX_STYLE_BG,
LV_MBOX_STYLE_BTN_BG,
LV_MBOX_STYLE_BTN_REL,
LV_MBOX_STYLE_BTN_PR,
LV_MBOX_STYLE_BTN_TGL_REL,
LV_MBOX_STYLE_BTN_TGL_PR,
LV_MBOX_STYLE_BTN_INA,
}lv_mbox_style_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
@@ -76,13 +83,13 @@ lv_obj_t * lv_mbox_create(lv_obj_t * par, lv_obj_t * copy);
lv_res_t lv_mbox_close_action(lv_obj_t * btn);
/**
* Add a button to the message box
* Set button to the message box
* @param mbox pointer to message box object
* @param btn_txt the text of the button
* @param rel_action a function which will be called when the button is released
* @return pointer to the created button (lv_btn)
* @param btn_map button descriptor (button matrix map).
* E.g. a const char *txt[] = {"ok", "close", ""} (Can not be local variable)
* @param action a function which will be called when a button is released
*/
lv_obj_t * lv_mbox_add_btn(lv_obj_t * mbox, const char * btn_txt, lv_action_t rel_action);
void lv_mbox_set_btns(lv_obj_t * mbox, const char **btn_map, lv_btnm_action_t action);
/*=====================
* Setter functions
@@ -95,13 +102,6 @@ lv_obj_t * lv_mbox_add_btn(lv_obj_t * mbox, const char * btn_txt, lv_action_t re
*/
void lv_mbox_set_text(lv_obj_t * mbox, const char * txt);
/**
* Set the width of the buttons
* @param mbox pointer to message box object
* @param w width of the buttons or 0 to use auto fit
*/
void lv_mbox_set_btn_width(lv_obj_t *mbox, cord_t w);
/**
* Set animation duration
* @param mbox pointer to a message box object
@@ -123,20 +123,12 @@ void lv_mbox_start_auto_close(lv_obj_t * mbox, uint16_t delay);
void lv_mbox_stop_auto_close(lv_obj_t * mbox);
/**
* Set the styles of a message box
* Set a style of a message box
* @param mbox pointer to a message box object
* @param bg pointer to the new background style
* @param btnh pointer to the new button holder style
* @param type which style should be set
* @param style pointer to a style
*/
void lv_mbox_set_style(lv_obj_t *mbox, lv_style_t *bg, lv_style_t *btnh);
/**
* Set styles of the buttons of a message box in each state
* @param mbox pointer to a message box object
* @param rel pointer to a style for releases state
* @param pr pointer to a style for pressed state
*/
void lv_mbox_set_style_btn(lv_obj_t * mbox, lv_style_t * rel, lv_style_t * pr);
void lv_mbox_set_style(lv_obj_t *mbox, lv_mbox_style_t type, lv_style_t *style);
/*=====================
* Getter functions
@@ -149,13 +141,6 @@ void lv_mbox_set_style_btn(lv_obj_t * mbox, lv_style_t * rel, lv_style_t * pr);
*/
const char * lv_mbox_get_text(lv_obj_t * mbox);
/**
* Get width of the buttons
* @param mbox pointer to a message box object
* @return width of the buttons (0: auto fit enabled)
*/
cord_t lv_mbox_get_btn_width(lv_obj_t * mbox);
/**
* Get the message box object from one of its button.
* It is useful in the button release actions where only the button is known
@@ -171,30 +156,14 @@ lv_obj_t * lv_mbox_get_from_btn(lv_obj_t * btn);
*/
uint16_t lv_mbox_get_anim_time(lv_obj_t * mbox);
/**
* Get the style of a message box's background
* @param mbox pointer to a message box object
* @return pointer to the message box's background style
*/
static inline lv_style_t * lv_mbox_get_style_bg(lv_obj_t *mbox)
{
return lv_obj_get_style(mbox);
}
/**
* Get the style of a message box's button holder
* Get a style of a message box
* @param mbox pointer to a message box object
* @return pointer to the message box's background style
* @param type which style should be get
* @return style pointer to a style
*/
lv_style_t * lv_mbox_get_style_btnh(lv_obj_t *mbox);
/**
* Get the style of the buttons on a message box
* @param mbox pointer to a message box object
* @param state a state from 'lv_btn_state_t' in which style should be get
* @return pointer to the style in the given state
*/
lv_style_t * lv_mbox_get_style_btn(lv_obj_t * mbox, lv_btn_state_t state);
lv_style_t * lv_mbox_get_style(lv_obj_t *mbox, lv_mbox_style_t type);
/**********************
* MACROS

View File

@@ -87,7 +87,10 @@ lv_obj_t * lv_page_create(lv_obj_t * par, lv_obj_t * copy)
* because everything has to be ready before any signal is received*/
lv_obj_set_signal_func(new_page, lv_page_signal);
lv_obj_set_design_func(new_page, lv_page_design);
lv_page_set_style(new_page, &lv_style_pretty_color, &lv_style_pretty, &lv_style_pretty_color);
lv_page_set_style(new_page, LV_PAGE_STYLE_BG, &lv_style_pretty_color);
lv_page_set_style(new_page, LV_PAGE_STYLE_SCRL, &lv_style_pretty);
lv_page_set_style(new_page, LV_PAGE_STYLE_SB, &lv_style_pretty_color);
lv_page_set_sb_mode(new_page, ext->sb.mode);
} else {
lv_page_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
@@ -97,7 +100,10 @@ lv_obj_t * lv_page_create(lv_obj_t * par, lv_obj_t * copy)
lv_page_set_press_action(new_page, copy_ext->pr_action);
lv_page_set_release_action(new_page, copy_ext->rel_action);
lv_page_set_sb_mode(new_page, copy_ext->sb.mode);
lv_page_set_style(new_page, lv_obj_get_style(copy), lv_obj_get_style(copy_ext->scrl), copy_ext->sb.style);
lv_page_set_style(new_page, LV_PAGE_STYLE_BG, lv_page_get_style(copy, LV_PAGE_STYLE_BG));
lv_page_set_style(new_page, LV_PAGE_STYLE_SCRL, lv_page_get_style(copy, LV_PAGE_STYLE_SCRL));
lv_page_set_style(new_page, LV_PAGE_STYLE_SB, lv_page_get_style(copy, LV_PAGE_STYLE_SB));
/* Add the signal function only if 'scrolling' is created
* because everything has to be ready before any signal is received*/
@@ -155,100 +161,30 @@ void lv_page_set_sb_mode(lv_obj_t * page, lv_page_sb_mode_t sb_mode)
}
/**
* Set a new styles for the page
* Set a style of a page
* @param page pointer to a page object
* @param bg pointer to a style for the background
* @param scrl pointer to a style for the scrollable area
* @param sb pointer to a style for the scroll bars
*/
void lv_page_set_style(lv_obj_t *page, lv_style_t *bg, lv_style_t *scrl, lv_style_t *sb)
* @param type which style should be set
* @param style pointer to a style
* */
void lv_page_set_style(lv_obj_t *page, lv_page_style_t type, lv_style_t *style)
{
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
if(sb != NULL) {
ext->sb.style = sb;
area_set_height(&ext->sb.hor_area, ext->sb.style->body.padding.inner);
area_set_width(&ext->sb.ver_area, ext->sb.style->body.padding.inner);
lv_page_sb_refresh(page);
if(bg == NULL) {
/*If scrollbars are positioned out of page then ext. size is needed to draw it*/
/*Page's style change signal will handle it but if no bg. style specified do it manually*/
switch (type) {
case LV_PAGE_STYLE_BG:
lv_obj_set_style(page, style);
break;
case LV_PAGE_STYLE_SCRL:
lv_obj_set_style(ext->scrl, style);
break;
case LV_PAGE_STYLE_SB:
ext->sb.style = style;
area_set_height(&ext->sb.hor_area, ext->sb.style->body.padding.inner);
area_set_width(&ext->sb.ver_area, ext->sb.style->body.padding.inner);
lv_page_sb_refresh(page);
lv_obj_refresh_ext_size(page);
}
lv_obj_invalidate(page);
}
if(scrl != NULL) lv_obj_set_style(ext->scrl, scrl);
if(bg != NULL) lv_obj_set_style(page, bg);
}
/**
* Glue the object to the page. After it the page can be moved (dragged) with this object too.
* @param obj pointer to an object on a page
* @param glue true: enable glue, false: disable glue
*/
void lv_page_glue_obj(lv_obj_t * obj, bool glue)
{
lv_obj_set_drag_parent(obj, glue);
lv_obj_set_drag(obj, glue);
}
/**
* Focus on an object. It ensures that the object will be visible on the page.
* @param page pointer to a page object
* @param obj pointer to an object to focus (must be on the page)
* @param anim_time scroll animation time in milliseconds (0: no animation)
*/
void lv_page_focus(lv_obj_t * page, lv_obj_t * obj, uint16_t anim_time)
{
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
lv_style_t * style = lv_page_get_style_bg(page);
lv_style_t * style_scrl = lv_page_get_style_scrl(page);
cord_t obj_y = obj->coords.y1 - ext->scrl->coords.y1;
cord_t obj_h = lv_obj_get_height(obj);
cord_t scrlable_y = lv_obj_get_y(ext->scrl);
cord_t page_h = lv_obj_get_height(page);
cord_t top_err = -(scrlable_y + obj_y);
cord_t bot_err = scrlable_y + obj_y + obj_h - page_h;
/*If obj is higher then the page focus where the "error" is smaller*/
/*Out of the page on the top*/
if((obj_h <= page_h && top_err > 0) ||
(obj_h > page_h && top_err < bot_err)) {
/*Calculate a new position and let some space above*/
scrlable_y = -(obj_y - style_scrl->body.padding.ver - style->body.padding.ver);
scrlable_y += style_scrl->body.padding.ver;
}
/*Out of the page on the bottom*/
else if((obj_h <= page_h && bot_err > 0) ||
(obj_h > page_h && top_err >= bot_err)) {
/*Calculate a new position and let some space below*/
scrlable_y = -obj_y;
scrlable_y += page_h - obj_h;
scrlable_y -= style_scrl->body.padding.ver;
} else {
/*Already in focus*/
return;
}
if(anim_time == 0) {
lv_obj_set_y(ext->scrl, scrlable_y);
}
else {
anim_t a;
a.act_time = 0;
a.start = lv_obj_get_y(ext->scrl);
a.end = scrlable_y;
a.time = anim_time;
a.end_cb = NULL;
a.playback = 0;
a.repeat = 0;
a.var = ext->scrl;
a.path = anim_get_path(ANIM_PATH_LIN);
a.fp = (anim_fp_t) lv_obj_set_y;
anim_create(&a);
lv_obj_invalidate(page);
break;
}
}
@@ -280,24 +216,99 @@ lv_page_sb_mode_t lv_page_get_sb_mode(lv_obj_t * page)
}
/**
* Get the style of the scrollable part of a page
* @param page pointer to a page object
* @return pointer to the style of the scrollale part
*/
lv_style_t * lv_page_get_style_scrl(lv_obj_t * page)
* Get a style of a page
* @param page pointer to page object
* @param type which style should be get
* @return style pointer to a style
* */
lv_style_t * lv_page_get_style(lv_obj_t *page, lv_page_style_t type)
{
return lv_obj_get_style(lv_page_get_scrl(page));
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
switch (type) {
case LV_PAGE_STYLE_BG: return lv_obj_get_style(page);
case LV_PAGE_STYLE_SCRL: return lv_obj_get_style(ext->scrl);
case LV_PAGE_STYLE_SB: return ext->sb.style;
default: return NULL;
}
/*To avoid warning*/
return NULL;
}
/*=====================
* Other functions
*====================*/
/**
* Glue the object to the page. After it the page can be moved (dragged) with this object too.
* @param obj pointer to an object on a page
* @param glue true: enable glue, false: disable glue
*/
void lv_page_glue_obj(lv_obj_t * obj, bool glue)
{
lv_obj_set_drag_parent(obj, glue);
lv_obj_set_drag(obj, glue);
}
/**
* Get the style of the scrolbars of a page
* @param page pointer to a page object
* @return pointer to the style of the scrollbars
*/
lv_style_t * lv_page_get_style_sb(lv_obj_t * page)
* Focus on an object. It ensures that the object will be visible on the page.
* @param page pointer to a page object
* @param obj pointer to an object to focus (must be on the page)
* @param anim_time scroll animation time in milliseconds (0: no animation)
*/
void lv_page_focus(lv_obj_t * page, lv_obj_t * obj, uint16_t anim_time)
{
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
return ext->sb.style;
lv_style_t * style = lv_page_get_style(page, LV_PAGE_STYLE_BG);
lv_style_t * style_scrl = lv_page_get_style(page, LV_PAGE_STYLE_SCRL);
cord_t obj_y = obj->coords.y1 - ext->scrl->coords.y1;
cord_t obj_h = lv_obj_get_height(obj);
cord_t scrlable_y = lv_obj_get_y(ext->scrl);
cord_t page_h = lv_obj_get_height(page);
cord_t top_err = -(scrlable_y + obj_y);
cord_t bot_err = scrlable_y + obj_y + obj_h - page_h;
/*If obj is higher then the page focus where the "error" is smaller*/
/*Out of the page on the top*/
if((obj_h <= page_h && top_err > 0) ||
(obj_h > page_h && top_err < bot_err)) {
/*Calculate a new position and let some space above*/
scrlable_y = -(obj_y - style_scrl->body.padding.ver - style->body.padding.ver);
scrlable_y += style_scrl->body.padding.ver;
}
/*Out of the page on the bottom*/
else if((obj_h <= page_h && bot_err > 0) ||
(obj_h > page_h && top_err >= bot_err)) {
/*Calculate a new position and let some space below*/
scrlable_y = -obj_y;
scrlable_y += page_h - obj_h;
scrlable_y -= style_scrl->body.padding.ver;
} else {
/*Already in focus*/
return;
}
if(anim_time == 0) {
lv_obj_set_y(ext->scrl, scrlable_y);
}
else {
anim_t a;
a.act_time = 0;
a.start = lv_obj_get_y(ext->scrl);
a.end = scrlable_y;
a.time = anim_time;
a.end_cb = NULL;
a.playback = 0;
a.repeat = 0;
a.var = ext->scrl;
a.path = anim_get_path(ANIM_PATH_LIN);
a.fp = (anim_fp_t) lv_obj_set_y;
anim_create(&a);
}
}
/**********************
@@ -471,7 +482,7 @@ static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param)
if(page->ext_size < (-ext->sb.style->body.padding.ver)) page->ext_size = -ext->sb.style->body.padding.ver;
}
return LV_RES_OK;
return res;
}
/**
@@ -593,7 +604,7 @@ static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, voi
}
}
return LV_RES_OK;
return res;
}

View File

@@ -59,11 +59,18 @@ typedef struct
}sb;
}lv_page_ext_t;
typedef enum {
LV_PAGE_STYLE_BG,
LV_PAGE_STYLE_SCRL,
LV_PAGE_STYLE_SB,
}lv_page_style_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Create a page objects
* @param par pointer to an object, it will be the parent of the new page
@@ -72,10 +79,6 @@ typedef struct
*/
lv_obj_t * lv_page_create(lv_obj_t * par, lv_obj_t * copy);
/*=====================
* Setter functions
*====================*/
/**
* Get the scrollable object of a page
* @param page pointer to a page object
@@ -83,6 +86,10 @@ lv_obj_t * lv_page_create(lv_obj_t * par, lv_obj_t * copy);
*/
lv_obj_t * lv_page_get_scrl(lv_obj_t * page);
/*=====================
* Setter functions
*====================*/
/**
* Set a release action for the page
* @param page pointer to a page object
@@ -104,30 +111,6 @@ void lv_page_set_press_action(lv_obj_t * page, lv_action_t pr_action);
*/
void lv_page_set_sb_mode(lv_obj_t * page, lv_page_sb_mode_t sb_mode);
/**
* Set a new styles for the page
* @param page pointer to a page object
* @param bg pointer to a style for the background
* @param scrl pointer to a style for the scrollable area
* @param sb pointer to a style for the scroll bars
*/
void lv_page_set_style(lv_obj_t *page, lv_style_t *bg, lv_style_t *scrl, lv_style_t *sb);
/**
* Glue the object to the page. After it the page can be moved (dragged) with this object too.
* @param obj pointer to an object on a page
* @param glue true: enable glue, false: disable glue
*/
void lv_page_glue_obj(lv_obj_t * obj, bool glue);
/**
* Focus on an object. It ensures that the object will be visible on the page.
* @param page pointer to a page object
* @param obj pointer to an object to focus (must be on the page)
* @param anim_time scroll animation time in milliseconds (0: no animation)
*/
void lv_page_focus(lv_obj_t * page, lv_obj_t * obj, uint16_t anim_time);
/**
* Set the fit attribute of the scrollable part of a page.
* It means it can set its size automatically to involve all children.
@@ -172,6 +155,14 @@ static inline void lv_page_set_scrl_layout(lv_obj_t * page, lv_cont_layout_t lay
lv_cont_set_layout(lv_page_get_scrl(page), layout);
}
/**
* Set a style of a page
* @param page pointer to a page object
* @param type which style should be set
* @param style pointer to a style
* */
void lv_page_set_style(lv_obj_t *page, lv_page_style_t type, lv_style_t *style);
/*=====================
* Getter functions
*====================*/
@@ -234,28 +225,31 @@ static inline bool lv_page_get_scrl_fit_ver(lv_obj_t * page)
}
/**
* Get the style of page's background
* @param page pointer to a page object
* @return pointer to the style of background
*/
static inline lv_style_t * lv_page_get_style_bg(lv_obj_t * page)
{
return lv_obj_get_style(page);
}
* Get a style of a page
* @param page pointer to page object
* @param type which style should be get
* @return style pointer to a style
* */
lv_style_t * lv_page_get_style(lv_obj_t *page, lv_page_style_t type);
/*=====================
* Other functions
*====================*/
/**
* Get the style of the scrollable part of a page
* @param page pointer to a page object
* @return pointer to the style of the scrollale part
*/
lv_style_t * lv_page_get_style_scrl(lv_obj_t * page);
* Glue the object to the page. After it the page can be moved (dragged) with this object too.
* @param obj pointer to an object on a page
* @param glue true: enable glue, false: disable glue
*/
void lv_page_glue_obj(lv_obj_t * obj, bool glue);
/**
* Get the style of the scrolbars of a page
* @param page pointer to a page object
* @return pointer to the style of the scrollbars
*/
lv_style_t * lv_page_get_style_sb(lv_obj_t * page);
* Focus on an object. It ensures that the object will be visible on the page.
* @param page pointer to a page object
* @param obj pointer to an object to focus (must be on the page)
* @param anim_time scroll animation time in milliseconds (0: no animation)
*/
void lv_page_focus(lv_obj_t * page, lv_obj_t * obj, uint16_t anim_time);
/**********************
* MACROS

View File

@@ -119,6 +119,24 @@ void lv_roller_set_hor_fit(lv_obj_t *roller, bool fit_en)
lv_cont_set_fit(roller, fit_en ,false);
}
/**
* Set a style of a roller
* @param roller pointer to a roller object
* @param type which style should be set
* @param style pointer to a style
*/
void lv_roller_set_style(lv_obj_t *roller, lv_roller_style_t type, lv_style_t *style)
{
switch (type) {
case LV_ROLLER_STYLE_BG:
lv_obj_set_style(roller, style);
break;
case LV_ROLLER_STYLE_SELECTED:
lv_ddlist_set_style(roller, LV_DDLIST_STYLE_SELECTED, style);
break;
}
}
/*=====================
* Getter functions
*====================*/
@@ -133,6 +151,24 @@ bool lv_roller_get_hor_fit(lv_obj_t *roller)
return lv_page_get_scrl_hor_fit(roller);
}
/**
* Get a style of a roller
* @param roller pointer to a roller object
* @param type which style should be get
* @return style pointer to a style
* */
lv_style_t * lv_roller_get_style(lv_obj_t *roller, lv_roller_style_t type)
{
switch (type) {
case LV_ROLLER_STYLE_BG: return lv_obj_get_style(roller);
case LV_ROLLER_STYLE_SELECTED: return lv_ddlist_get_style(roller, LV_DDLIST_STYLE_SELECTED);
default: return NULL;
}
/*To avoid warning*/
return NULL;
}
/**********************
* STATIC FUNCTIONS
**********************/
@@ -159,7 +195,7 @@ static bool lv_roller_design(lv_obj_t * roller, const area_t * mask, lv_design_m
draw_bg(roller, mask);
lv_style_t *style = lv_ddlist_get_style_bg(roller);
lv_style_t *style = lv_roller_get_style(roller, LV_ROLLER_STYLE_BG);
const font_t * font = style->text.font;
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
cord_t font_h = font_get_height_scale(font);
@@ -281,7 +317,7 @@ static lv_res_t lv_roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign,
*/
static void draw_bg(lv_obj_t *roller, const area_t *mask)
{
lv_style_t *style = lv_ddlist_get_style_bg(roller);
lv_style_t *style = lv_roller_get_style(roller, LV_ROLLER_STYLE_BG);
area_t half_mask;
area_t half_roller;
cord_t h = lv_obj_get_height(roller);

View File

@@ -32,6 +32,11 @@ typedef struct {
/*New data for this type */
}lv_roller_ext_t;
typedef enum {
LV_ROLLER_STYLE_BG,
LV_ROLLER_STYLE_SELECTED,
}lv_roller_style_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
@@ -76,16 +81,6 @@ static inline void lv_roller_set_anim_time(lv_obj_t *roller, uint16_t anim_time)
lv_ddlist_set_anim_time(roller, anim_time);
}
/**
* Set the style of a roller
* @param roller pointer to a roller object
* @param bg pointer to the new style of the background
* @param sel pointer to the new style of the select rectangle
*/
static inline void lv_roller_set_style(lv_obj_t *roller, lv_style_t *bg, lv_style_t *sel)
{
lv_ddlist_set_style(roller, bg, NULL, sel);
}
/**
* Enable/disable to set the width of the roller manually (by lv_obj_Set_width())
* @param roller pointer to a roller object
@@ -93,6 +88,14 @@ static inline void lv_roller_set_style(lv_obj_t *roller, lv_style_t *bg, lv_styl
*/
void lv_roller_set_hor_fit(lv_obj_t *roller, bool fit_en);
/**
* Set a style of a roller
* @param roller pointer to a roller object
* @param type which style should be set
* @param style pointer to a style
*/
void lv_roller_set_style(lv_obj_t *roller, lv_roller_style_t type, lv_style_t *style);
/*=====================
* Getter functions
*====================*/
@@ -155,24 +158,12 @@ static inline uint16_t lv_roller_get_anim_time(lv_obj_t * roller)
bool lv_roller_get_hor_fit(lv_obj_t *roller);
/**
* Get the style of the roller's background
* @param roller pointer to a roller object
* @return pointer to the background's style
*/
static inline lv_style_t * lv_roller_get_style_bg(lv_obj_t *roller)
{
return lv_ddlist_get_style_bg(roller);
}
/**
* Get the style of the roller's selected rectangle
* @param roller pointer to a roller object
* @return pointer to the selected rectangle's style
*/
static inline lv_style_t * lv_roller_get_style_selected(lv_obj_t *roller)
{
return lv_ddlist_get_style_select(roller);
}
* Get a style of a roller
* @param roller pointer to a roller object
* @param type which style should be get
* @return style pointer to a style
* */
lv_style_t * lv_roller_get_style(lv_obj_t *roller, lv_roller_style_t type);
/**********************
* MACROS

View File

@@ -75,7 +75,7 @@ lv_obj_t * lv_slider_create(lv_obj_t * par, lv_obj_t * copy)
/*Init the new slider slider*/
if(copy == NULL) {
lv_obj_set_click(new_slider, true);
lv_slider_set_style(new_slider, NULL, NULL, ext->style_knob);
lv_slider_set_style(new_slider, LV_SLIDER_STYLE_KNOB, ext->style_knob);
}
/*Copy an existing slider*/
else {
@@ -118,22 +118,27 @@ void lv_slider_set_knob_in(lv_obj_t * slider, bool in)
}
/**
* Set the styles of a slider
* Set a style of a slider
* @param slider pointer to a slider object
* @param bg pointer to the background's style (NULL to leave unchanged)
* @param indic pointer to the indicator's style (NULL to leave unchanged)
* @param knob pointer to the knob's style (NULL to leave unchanged)
* @param type which style should be set
* @param style pointer to a style
*/
void lv_slider_set_style(lv_obj_t * slider, lv_style_t *bg, lv_style_t *indic, lv_style_t *knob)
void lv_slider_set_style(lv_obj_t *slider, lv_slider_style_t type, lv_style_t *style)
{
if(knob != NULL) {
lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider);
ext->style_knob = knob;
slider->signal_func(slider, LV_SIGNAL_REFR_EXT_SIZE, NULL);
lv_obj_invalidate(slider);
}
lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider);
lv_bar_set_style(slider, bg, indic);
switch (type) {
case LV_SLIDER_STYLE_BG:
lv_bar_set_style(slider, LV_BAR_STYLE_BG, style);
break;
case LV_SLIDER_STYLE_INDIC:
lv_bar_set_style(slider, LV_BAR_STYLE_INDIC, style);
break;
case LV_SLIDER_STYLE_KNOB:
ext->style_knob = style;
lv_obj_refresh_ext_size(slider);
break;
}
}
/*=====================
@@ -175,6 +180,27 @@ bool lv_slider_get_knob_in(lv_obj_t * slider)
return ext->knob_in == 0 ? false : true;
}
/**
* Get a style of a slider
* @param slider pointer to a slider object
* @param type which style should be get
* @return style pointer to a style
*/
lv_style_t * lv_slider_get_style(lv_obj_t *slider, lv_bar_style_t type)
{
lv_slider_ext_t *ext = lv_obj_get_ext_attr(slider);
switch (type) {
case LV_SLIDER_STYLE_BG: return lv_bar_get_style(slider, LV_BAR_STYLE_BG);
case LV_SLIDER_STYLE_INDIC: return lv_bar_get_style(slider, LV_BAR_STYLE_INDIC);
case LV_SLIDER_STYLE_KNOB: return ext->style_knob;
default: return NULL;
}
/*To avoid warning*/
return NULL;
}
/**********************
* STATIC FUNCTIONS
**********************/
@@ -200,9 +226,9 @@ static bool lv_slider_design(lv_obj_t * slider, const area_t * mask, lv_design_m
else if(mode == LV_DESIGN_DRAW_MAIN) {
lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider);
lv_style_t * style_slider = lv_slider_get_style_bg(slider);
lv_style_t * style_knob = lv_slider_get_style_knob(slider);
lv_style_t * style_indic = lv_slider_get_style_indicator(slider);
lv_style_t * style_slider = lv_slider_get_style(slider, LV_SLIDER_STYLE_BG);
lv_style_t * style_knob = lv_slider_get_style(slider, LV_SLIDER_STYLE_KNOB);
lv_style_t * style_indic = lv_slider_get_style(slider, LV_SLIDER_STYLE_INDIC);
/*Draw the bar*/
area_t area_bar;
@@ -386,6 +412,6 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par
}
}
return LV_RES_OK;
return res;
}
#endif

View File

@@ -40,8 +40,10 @@ typedef struct
/*Built-in styles of slider*/
typedef enum
{
LV_SLIDERS_DEF,
}lv_sliders_builtin_t;
LV_SLIDER_STYLE_BG,
LV_SLIDER_STYLE_INDIC,
LV_SLIDER_STYLE_KNOB,
}lv_slider_style_t;
/**********************
* GLOBAL PROTOTYPES
@@ -107,13 +109,12 @@ void lv_slider_set_action(lv_obj_t * slider, lv_action_t action);
void lv_slider_set_knob_in(lv_obj_t * slider, bool in);
/**
* Set the styles of a slider
* Set a style of a slider
* @param slider pointer to a slider object
* @param bg pointer to the background's style (NULL to leave unchanged)
* @param indic pointer to the indicator's style (NULL to leave unchanged)
* @param knob pointer to the knob's style (NULL to leave unchanged)
* @param type which style should be set
* @param style pointer to a style
*/
void lv_slider_set_style(lv_obj_t * slider, lv_style_t *bg, lv_style_t *indic, lv_style_t *knob);
void lv_slider_set_style(lv_obj_t *slider, lv_slider_style_t type, lv_style_t *style);
/*=====================
* Getter functions
@@ -171,25 +172,14 @@ lv_style_t * lv_slider_get_style_knob(lv_obj_t * slider);
*/
bool lv_slider_get_knob_in(lv_obj_t * slider);
/**
* Get the style of the slider's background
* @param slider pointer to a slider object
* @return pointer to the slider's background style
*/
static inline lv_style_t * lv_slider_get_style_bg(lv_obj_t * slider)
{
return lv_bar_get_style_bg(slider);
}
/**
* Get the style of slider indicator
* @param bar pointer to a slider object
* @return pointer to the slider indicator style
* Get a style of a slider
* @param slider pointer to a slider object
* @param type which style should be get
* @return style pointer to a style
*/
static inline lv_style_t * lv_slider_get_style_indicator(lv_obj_t * slider)
{
return lv_bar_get_style_indicator(slider);
}
lv_style_t * lv_slider_get_style(lv_obj_t *slider, lv_bar_style_t type);
/**********************
* MACROS

View File

@@ -57,6 +57,8 @@ lv_obj_t * lv_sw_create(lv_obj_t * par, lv_obj_t * copy)
/*Initialize the allocated 'ext' */
ext->changed = 0;
ext->style_knob_off = ext->slider.style_knob;
ext->style_knob_on = ext->slider.style_knob;
/*The signal and design functions are not copied so set them here*/
lv_obj_set_signal_func(new_sw, lv_sw_signal);
@@ -70,11 +72,11 @@ lv_obj_t * lv_sw_create(lv_obj_t * par, lv_obj_t * copy)
/*Copy an existing switch*/
else {
lv_sw_ext_t *copy_ext = lv_obj_get_ext_attr(copy);
ext->knob_off_style = copy_ext->knob_off_style;
ext->knob_on_style = copy_ext->knob_on_style;
ext->style_knob_off = copy_ext->style_knob_off;
ext->style_knob_on = copy_ext->style_knob_on;
if(lv_sw_get_state(new_sw)) lv_slider_set_style(new_sw, NULL, NULL, ext->knob_on_style);
else lv_slider_set_style(new_sw, NULL, NULL, ext->knob_off_style);
if(lv_sw_get_state(new_sw)) lv_slider_set_style(new_sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_on);
else lv_slider_set_style(new_sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_off);
/*Refresh the style with new signal function*/
lv_obj_refresh_style(new_sw);
}
@@ -94,7 +96,7 @@ void lv_sw_set_on(lv_obj_t *sw)
{
lv_sw_ext_t *ext = lv_obj_get_ext_attr(sw);
lv_slider_set_value(sw, 1);
lv_slider_set_style(sw, NULL, NULL,ext->knob_on_style);
lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB,ext->style_knob_on);
}
/**
@@ -105,26 +107,35 @@ void lv_sw_set_off(lv_obj_t *sw)
{
lv_sw_ext_t *ext = lv_obj_get_ext_attr(sw);
lv_slider_set_value(sw, 0);
lv_slider_set_style(sw, NULL, NULL,ext->knob_off_style);
lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB,ext->style_knob_off);
}
/**
* Set the styles of a switch
* Set a style of a switch
* @param sw pointer to a switch object
* @param bg pointer to the background's style
* @param indic pointer to the indicator's style
* @param knob_off pointer to the knob's style when the switch is OFF
* @param knob_on pointer to the knob's style when the switch is ON
* @param type which style should be set
* @param style pointer to a style
*/
void lv_sw_set_style(lv_obj_t * sw, lv_style_t *bg, lv_style_t *indic, lv_style_t *knob_off, lv_style_t *knob_on)
void lv_sw_set_style(lv_obj_t *sw, lv_sw_style_t type, lv_style_t *style)
{
lv_sw_ext_t *ext = lv_obj_get_ext_attr(sw);
lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw);
ext->knob_on_style = knob_on;
ext->knob_off_style = knob_off;
if(lv_sw_get_state(sw)) lv_slider_set_style(sw, bg, indic, knob_on);
else lv_slider_set_style(sw, bg, indic, knob_off);
switch (type) {
case LV_SLIDER_STYLE_BG:
lv_slider_set_style(sw, LV_SLIDER_STYLE_BG, style);
break;
case LV_SLIDER_STYLE_INDIC:
lv_bar_set_style(sw, LV_SLIDER_STYLE_INDIC, style);
break;
case LV_SW_STYLE_KNOB_OFF:
ext->style_knob_off = style;
if(lv_sw_get_state(sw) == 0) lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, style);
break;
case LV_SW_STYLE_KNOB_ON:
ext->style_knob_on = style;
if(lv_sw_get_state(sw) != 0) lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, style);
break;
}
}
/*=====================
@@ -132,28 +143,26 @@ void lv_sw_set_style(lv_obj_t * sw, lv_style_t *bg, lv_style_t *indic, lv_style_
*====================*/
/**
* Get the style of the switch's knob when the switch is OFF
* @param sw pointer to a switch object
* @return pointer to the switch's knob OFF style
* Get a style of a switch
* @param sw pointer to a switch object
* @param type which style should be get
* @return style pointer to a style
*/
lv_style_t * lv_sw_get_style_knob_off(lv_obj_t *sw)
lv_style_t * lv_sw_get_style(lv_obj_t *sw, lv_bar_style_t type)
{
lv_sw_ext_t *ext = lv_obj_get_ext_attr(sw);
return ext->knob_off_style;
switch (type) {
case LV_SW_STYLE_BG: return lv_slider_get_style(sw, LV_SLIDER_STYLE_BG);
case LV_SW_STYLE_INDIC: return lv_slider_get_style(sw, LV_SLIDER_STYLE_INDIC);
case LV_SW_STYLE_KNOB_OFF: return ext->style_knob_off;
case LV_SW_STYLE_KNOB_ON: return ext->style_knob_on;
default: return NULL;
}
/*To avoid warning*/
return NULL;
}
/**
* Get the style of the switch's knob when the switch is ON
* @param sw pointer to a switch object
* @return pointer to the switch's knob ON style
*/
lv_style_t * lv_sw_get_style_knob_on(lv_obj_t *sw)
{
lv_sw_ext_t *ext = lv_obj_get_ext_attr(sw);
return ext->knob_on_style;
}
/**********************
* STATIC FUNCTIONS
**********************/
@@ -192,8 +201,8 @@ static lv_res_t lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param)
}
else if(sign == LV_SIGNAL_PRESS_LOST) {
ext->changed = 0;
if(lv_sw_get_state(sw)) lv_slider_set_style(sw, NULL, NULL, ext->knob_on_style);
else lv_slider_set_style(sw, NULL, NULL, ext->knob_off_style);
if(lv_sw_get_state(sw)) lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_on);
else lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_off);
}
else if(sign == LV_SIGNAL_RELEASED) {
if(ext->changed == 0) {
@@ -202,8 +211,8 @@ static lv_res_t lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param)
else lv_slider_set_value(sw, 0);
}
if(lv_sw_get_state(sw)) lv_slider_set_style(sw, NULL, NULL, ext->knob_on_style);
else lv_slider_set_style(sw, NULL, NULL, ext->knob_off_style);
if(lv_sw_get_state(sw)) lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_on);
else lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_off);
if(slider_cb != NULL) slider_cb(sw);

View File

@@ -36,11 +36,18 @@ typedef struct
{
lv_slider_ext_t slider; /*Ext. of ancestor*/
/*New data for this type */
lv_style_t *knob_off_style; /*Style of the knob when the switch is OFF*/
lv_style_t *knob_on_style; /*Style of the knob when the switch is ON (NULL to use the same as OFF)*/
lv_style_t *style_knob_off; /*Style of the knob when the switch is OFF*/
lv_style_t *style_knob_on; /*Style of the knob when the switch is ON (NULL to use the same as OFF)*/
uint8_t changed :1; /*Indicates the switch explicitly changed by drag*/
}lv_sw_ext_t;
typedef enum {
LV_SW_STYLE_BG,
LV_SW_STYLE_INDIC,
LV_SW_STYLE_KNOB_OFF,
LV_SW_STYLE_KNOB_ON,
}lv_sw_style_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
@@ -80,14 +87,12 @@ static inline void lv_sw_set_action(lv_obj_t * sw, lv_action_t action)
}
/**
* Set the styles of a switch
* Set a style of a switch
* @param sw pointer to a switch object
* @param bg pointer to the background's style
* @param indic pointer to the indicator's style
* @param knob_off pointer to the knob's style when the switch is OFF
* @param knob_on pointer to the knob's style when the switch is ON
* @param type which style should be set
* @param style pointer to a style
*/
void lv_sw_set_style(lv_obj_t * sw, lv_style_t *bg, lv_style_t *indic, lv_style_t *knob_off, lv_style_t *knob_on);
void lv_sw_set_style(lv_obj_t *sw, lv_sw_style_t type, lv_style_t *style);
/*=====================
* Getter functions
@@ -114,39 +119,12 @@ static inline lv_action_t lv_sw_get_action(lv_obj_t * slider)
}
/**
* Get the style of the switch's background
* @param sw pointer to a switch object
* @return pointer to the switch's background style
* Get a style of a switch
* @param sw pointer to a switch object
* @param type which style should be get
* @return style pointer to a style
*/
static inline lv_style_t * lv_sw_get_style_bg(lv_obj_t *sw)
{
return lv_slider_get_style_bg(sw);
}
/**
* Get the style of the switch's indicator
* @param sw pointer to a switch object
* @return pointer to the switch's indicator style
*/
static inline lv_style_t * lv_sw_get_style_indicator(lv_obj_t *sw)
{
return lv_slider_get_style_indicator(sw);
}
/**
* Get the style of the switch's knob when the switch is OFF
* @param sw pointer to a switch object
* @return pointer to the switch's knob OFF style
*/
lv_style_t * lv_sw_get_style_knob_off(lv_obj_t *sw);
/**
* Get the style of the switch's knob when the switch is ON
* @param sw pointer to a switch object
* @return pointer to the switch's knob ON style
*/
lv_style_t * lv_sw_get_style_knob_on(lv_obj_t *sw);
lv_style_t * lv_sw_get_style(lv_obj_t *sw, lv_bar_style_t type);
/**********************
* MACROS

View File

@@ -23,7 +23,7 @@
/*Test configuration*/
#ifndef LV_TA_CUR_BLINK_TIME
#define LV_TA_CUR_BLINK_TIME 400 /*ms*/
#define LV_TA_CURSOR_BLINK_TIME 400 /*ms*/
#endif
#ifndef LV_TA_PWD_SHOW_TIME
@@ -123,6 +123,8 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, lv_obj_t * copy)
ext->cursor_valid_x = copy_ext->cursor_valid_x;
if(copy_ext->one_line) lv_ta_set_one_line(new_ta, true);
lv_ta_set_style(new_ta, LV_TA_STYLE_CURSOR, lv_ta_get_style(copy, LV_TA_STYLE_CURSOR));
/*Refresh the style with new signal function*/
lv_obj_refresh_style(new_ta);
}
@@ -131,7 +133,7 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, lv_obj_t * copy)
anim_t a;
a.var = new_ta;
a.fp = (anim_fp_t)cursor_blink_anim;
a.time = LV_TA_CUR_BLINK_TIME;
a.time = LV_TA_CURSOR_BLINK_TIME;
a.act_time = 0;
a.end_cb = NULL;
a.start = 1;
@@ -146,9 +148,9 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, lv_obj_t * copy)
return new_ta;
}
/*=====================
* Setter functions
*====================*/
/*======================
* Add/remove functions
*=====================*/
/**
* Insert a character to the current cursor position
@@ -157,7 +159,7 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, lv_obj_t * copy)
*/
void lv_ta_add_char(lv_obj_t * ta, char c)
{
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
if(ext->pwd_mode != 0) pwd_char_hider(ta); /*Make sure all the current text contains only '*'*/
char letter_buf[2];
@@ -199,7 +201,7 @@ void lv_ta_add_char(lv_obj_t * ta, char c)
*/
void lv_ta_add_text(lv_obj_t * ta, const char * txt)
{
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
if(ext->pwd_mode != 0) pwd_char_hider(ta); /*Make sure all the current text contains only '*'*/
@@ -232,6 +234,48 @@ void lv_ta_add_text(lv_obj_t * ta, const char * txt)
lv_ta_set_cursor_pos(ta, lv_ta_get_cursor_pos(ta) + txt_len(txt));
}
/**
* Delete a the left character from the current cursor position
* @param ta pointer to a text area object
*/
void lv_ta_del_char(lv_obj_t * ta)
{
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
uint16_t cur_pos = ext->cursor_pos;
if(cur_pos == 0) return;
char * label_txt = lv_label_get_text(ext->label);
/*Delete a character*/
txt_cut(label_txt, ext->cursor_pos - 1, 1);
/*Refresh the label*/
lv_label_set_text(ext->label, label_txt);
/*Don't let 'width == 0' because cursor will not be visible*/
if(lv_obj_get_width(ext->label) == 0) {
lv_style_t * style = lv_obj_get_style(ext->label);
lv_obj_set_width(ext->label, style->line.width);
}
if(ext->pwd_mode != 0) {
#if TXT_UTF8 == 0
txt_cut(ext->pwd_tmp, ext->cursor_pos - 1, 1);
#else
uint32_t byte_pos = txt_utf8_get_byte_id(ext->pwd_tmp, ext->cursor_pos - 1);
txt_cut(ext->pwd_tmp, ext->cursor_pos - 1, txt_utf8_size(label_txt[byte_pos]));
#endif
ext->pwd_tmp = dm_realloc(ext->pwd_tmp, strlen(ext->pwd_tmp) + 1);
dm_assert(ext->pwd_tmp);
}
/*Move the cursor to the place of the deleted character*/
lv_ta_set_cursor_pos(ta, ext->cursor_pos - 1);
}
/*=====================
* Setter functions
*====================*/
/**
* Set the text of a text area
* @param ta pointer to a text area
@@ -270,51 +314,12 @@ void lv_ta_set_text(lv_obj_t * ta, const char * txt)
}
}
/**
* Delete a the left character from the current cursor position
* @param ta pointer to a text area object
*/
void lv_ta_del(lv_obj_t * ta)
{
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
uint16_t cur_pos = ext->cursor_pos;
if(cur_pos == 0) return;
char * label_txt = lv_label_get_text(ext->label);
/*Delete a character*/
txt_cut(label_txt, ext->cursor_pos - 1, 1);
/*Refresh the label*/
lv_label_set_text(ext->label, label_txt);
/*Don't let 'width == 0' because cursor will not be visible*/
if(lv_obj_get_width(ext->label) == 0) {
lv_style_t * style = lv_obj_get_style(ext->label);
lv_obj_set_width(ext->label, style->line.width);
}
if(ext->pwd_mode != 0) {
#if TXT_UTF8 == 0
txt_cut(ext->pwd_tmp, ext->cursor_pos - 1, 1);
#else
uint32_t byte_pos = txt_utf8_get_byte_id(ext->pwd_tmp, ext->cursor_pos - 1);
txt_cut(ext->pwd_tmp, ext->cursor_pos - 1, txt_utf8_size(label_txt[byte_pos]));
#endif
ext->pwd_tmp = dm_realloc(ext->pwd_tmp, strlen(ext->pwd_tmp) + 1);
dm_assert(ext->pwd_tmp);
}
/*Move the cursor to the place of the deleted character*/
lv_ta_set_cursor_pos(ta, ext->cursor_pos - 1);
}
/**
* Set the cursor position
* @param obj pointer to a text area object
* @param pos the new cursor position in character index
* < 0 : index from the end of the text
* LV_TA_CUR_LAST: go after the last character
* LV_TA_CURSOR_LAST: go after the last character
*/
void lv_ta_set_cursor_pos(lv_obj_t * ta, int16_t pos)
{
@@ -366,7 +371,7 @@ void lv_ta_set_cursor_pos(lv_obj_t * ta, int16_t pos)
anim_t a;
a.var = ta;
a.fp = (anim_fp_t)cursor_blink_anim;
a.time = LV_TA_CUR_BLINK_TIME;
a.time = LV_TA_CURSOR_BLINK_TIME;
a.act_time = 0;
a.end_cb = NULL;
a.start = 1;
@@ -381,88 +386,6 @@ void lv_ta_set_cursor_pos(lv_obj_t * ta, int16_t pos)
lv_obj_invalidate(ta);
}
/**
* Move the cursor one character right
* @param ta pointer to a text area object
*/
void lv_ta_cursor_right(lv_obj_t * ta)
{
uint16_t cp = lv_ta_get_cursor_pos(ta);
cp++;
lv_ta_set_cursor_pos(ta, cp);
}
/**
* Move the cursor one character left
* @param ta pointer to a text area object
*/
void lv_ta_cursor_left(lv_obj_t * ta)
{
uint16_t cp = lv_ta_get_cursor_pos(ta);
if(cp > 0) {
cp--;
lv_ta_set_cursor_pos(ta, cp);
}
}
/**
* Move the cursor one line down
* @param ta pointer to a text area object
*/
void lv_ta_cursor_down(lv_obj_t * ta)
{
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
point_t pos;
/*Get the position of the current letter*/
lv_label_get_letter_pos(ext->label, lv_ta_get_cursor_pos(ta), &pos);
/*Increment the y with one line and keep the valid x*/
lv_style_t * label_style = lv_obj_get_style(ext->label);
const font_t * font_p = label_style->text.font;
cord_t font_h = font_get_height_scale(font_p);
pos.y += font_h + label_style->text.line_space + 1;
pos.x = ext->cursor_valid_x;
/*Do not go below the last line*/
if(pos.y < lv_obj_get_height(ext->label)) {
/*Get the letter index on the new cursor position and set it*/
uint16_t new_cur_pos = lv_label_get_letter_on(ext->label, &pos);
cord_t cur_valid_x_tmp = ext->cursor_valid_x; /*Cursor position set overwrites the valid positon */
lv_ta_set_cursor_pos(ta, new_cur_pos);
ext->cursor_valid_x = cur_valid_x_tmp;
}
}
/**
* Move the cursor one line up
* @param ta pointer to a text area object
*/
void lv_ta_cursor_up(lv_obj_t * ta)
{
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
point_t pos;
/*Get the position of the current letter*/
lv_label_get_letter_pos(ext->label, lv_ta_get_cursor_pos(ta), &pos);
/*Decrement the y with one line and keep the valid x*/
lv_style_t * label_style = lv_obj_get_style(ext->label);
const font_t * font = label_style->text.font;
cord_t font_h = font_get_height_scale(font);
pos.y -= font_h + label_style->text.line_space - 1;
pos.x = ext->cursor_valid_x;
/*Get the letter index on the new cursor position and set it*/
uint16_t new_cur_pos = lv_label_get_letter_on(ext->label, &pos);
cord_t cur_valid_x_tmp = ext->cursor_valid_x; /*Cursor position set overwrites the valid positon */
lv_ta_set_cursor_pos(ta, new_cur_pos);
ext->cursor_valid_x = cur_valid_x_tmp;
}
/**
* Set the cursor visibility.
* @param ta pointer to a text area object
@@ -556,18 +479,27 @@ void lv_ta_set_one_line(lv_obj_t * ta, bool en)
}
/**
* Set the style of the text area
* Set a style of a text area
* @param ta pointer to a text area object
* @param bg pointer to the new background style (NULL to leave unchanged)
* @param sb pointer to the new scrollbar style (NULL to leave unchanged)
* @param cur pointer to the new cursor style (NULL to use the label's style)
* @param type which style should be set
* @param style pointer to a style
*/
void lv_ta_set_style(lv_obj_t * ta, lv_style_t *bg, lv_style_t *sb, lv_style_t *cur)
void lv_ta_set_style(lv_obj_t *ta, lv_ta_style_t type, lv_style_t *style)
{
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
ext->cursor_style = cur;
lv_page_set_style(ta, bg, &lv_style_transp_tight, sb);
switch (type) {
case LV_TA_STYLE_BG:
lv_page_set_style(ta, LV_PAGE_STYLE_BG, style);
break;
case LV_TA_STYLE_SB:
lv_page_set_style(ta, LV_PAGE_STYLE_SB, style);
break;
case LV_TA_STYLE_CURSOR:
ext->cursor_style = style;
lv_obj_refresh_ext_size(lv_page_get_scrl(ta)); /*Refresh ext. size because of cursor drawing*/
break;
}
}
/*=====================
@@ -639,17 +571,6 @@ lv_ta_cursor_type_t lv_ta_get_cursor_type(lv_obj_t * ta)
return ext->cursor_type;
}
/**
* Get the style of the cursor
* @param ta pointer to a text area object
* @return style pointer to the new cursor style
*/
lv_style_t * lv_ta_get_style_cursor(lv_obj_t * ta)
{
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
return ext->cursor_style;
}
/**
* Get the password mode attribute
* @param ta pointer to a text area object
@@ -672,6 +593,112 @@ bool lv_ta_get_one_line(lv_obj_t * ta)
return ext->one_line == 0 ? false : true;
}
/**
* Get a style of a text area
* @param ta pointer to a text area object
* @param type which style should be get
* @return style pointer to a style
*/
lv_style_t * lv_ta_get_style(lv_obj_t *ta, lv_ta_style_t type)
{
lv_ta_ext_t *ext = lv_obj_get_ext_attr(ta);
switch (type) {
case LV_TA_STYLE_BG: return lv_page_get_style(ta, LV_PAGE_STYLE_BG);
case LV_TA_STYLE_SB: return lv_page_get_style(ta, LV_PAGE_STYLE_SB);
case LV_TA_STYLE_CURSOR: return ext->cursor_style; /*TODO in 'ext' all cursor attributes into a struct*/
default: return NULL;
}
/*To avoid warning*/
return NULL;
}
/*=====================
* Other functions
*====================*/
/**
* Move the cursor one character right
* @param ta pointer to a text area object
*/
void lv_ta_cursor_right(lv_obj_t * ta)
{
uint16_t cp = lv_ta_get_cursor_pos(ta);
cp++;
lv_ta_set_cursor_pos(ta, cp);
}
/**
* Move the cursor one character left
* @param ta pointer to a text area object
*/
void lv_ta_cursor_left(lv_obj_t * ta)
{
uint16_t cp = lv_ta_get_cursor_pos(ta);
if(cp > 0) {
cp--;
lv_ta_set_cursor_pos(ta, cp);
}
}
/**
* Move the cursor one line down
* @param ta pointer to a text area object
*/
void lv_ta_cursor_down(lv_obj_t * ta)
{
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
point_t pos;
/*Get the position of the current letter*/
lv_label_get_letter_pos(ext->label, lv_ta_get_cursor_pos(ta), &pos);
/*Increment the y with one line and keep the valid x*/
lv_style_t * label_style = lv_obj_get_style(ext->label);
const font_t * font_p = label_style->text.font;
cord_t font_h = font_get_height_scale(font_p);
pos.y += font_h + label_style->text.line_space + 1;
pos.x = ext->cursor_valid_x;
/*Do not go below the last line*/
if(pos.y < lv_obj_get_height(ext->label)) {
/*Get the letter index on the new cursor position and set it*/
uint16_t new_cur_pos = lv_label_get_letter_on(ext->label, &pos);
cord_t cur_valid_x_tmp = ext->cursor_valid_x; /*Cursor position set overwrites the valid positon */
lv_ta_set_cursor_pos(ta, new_cur_pos);
ext->cursor_valid_x = cur_valid_x_tmp;
}
}
/**
* Move the cursor one line up
* @param ta pointer to a text area object
*/
void lv_ta_cursor_up(lv_obj_t * ta)
{
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
point_t pos;
/*Get the position of the current letter*/
lv_label_get_letter_pos(ext->label, lv_ta_get_cursor_pos(ta), &pos);
/*Decrement the y with one line and keep the valid x*/
lv_style_t * label_style = lv_obj_get_style(ext->label);
const font_t * font = label_style->text.font;
cord_t font_h = font_get_height_scale(font);
pos.y -= font_h + label_style->text.line_space - 1;
pos.x = ext->cursor_valid_x;
/*Get the letter index on the new cursor position and set it*/
uint16_t new_cur_pos = lv_label_get_letter_on(ext->label, &pos);
cord_t cur_valid_x_tmp = ext->cursor_valid_x; /*Cursor position set overwrites the valid positon */
lv_ta_set_cursor_pos(ta, new_cur_pos);
ext->cursor_valid_x = cur_valid_x_tmp;
}
/**********************
* STATIC FUNCTIONS
**********************/
@@ -880,7 +907,6 @@ static lv_res_t lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param)
}
lv_label_set_text(ext->label, NULL);
lv_obj_refresh_ext_size(scrl); /*Refresh ext. size because of cursor drawing*/
}
} else if(sign == LV_SIGNAL_CORD_CHG) {
/*Set the label width according to the text area width*/
@@ -908,7 +934,7 @@ static lv_res_t lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param)
}
}
return LV_RES_OK;
return res;
}
/**
@@ -935,7 +961,7 @@ static lv_res_t lv_ta_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void
scrl->ext_size = MATH_MAX(scrl->ext_size, style_label->text.line_space + font_h);
}
return LV_RES_OK;
return res;
}
/**

View File

@@ -62,10 +62,17 @@ typedef struct
uint8_t cursor_state :1; /*Indicates that the cursor is visible now or not (Handled by the library)*/
}lv_ta_ext_t;
typedef enum {
LV_TA_STYLE_BG,
LV_TA_STYLE_SB,
LV_TA_STYLE_CURSOR,
}lv_ta_style_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Create a text area objects
* @param par pointer to an object, it will be the parent of the new text area
@@ -74,9 +81,10 @@ typedef struct
*/
lv_obj_t * lv_ta_create(lv_obj_t * par, lv_obj_t * copy);
/*=====================
* Setter functions
*====================*/
/*======================
* Add/remove functions
*=====================*/
/**
* Insert a character to the current cursor position
@@ -92,6 +100,16 @@ void lv_ta_add_char(lv_obj_t * ta, char c);
*/
void lv_ta_add_text(lv_obj_t * ta, const char * txt);
/**
* Delete a the left character from the current cursor position
* @param ta pointer to a text area object
*/
void lv_ta_del_char(lv_obj_t * ta);
/*=====================
* Setter functions
*====================*/
/**
* Set the text of a text area
* @param ta pointer to a text area
@@ -99,44 +117,15 @@ void lv_ta_add_text(lv_obj_t * ta, const char * txt);
*/
void lv_ta_set_text(lv_obj_t * ta, const char * txt);
/**
* Delete a the left character from the current cursor position
* @param ta pointer to a text area object
*/
void lv_ta_del(lv_obj_t * ta);
/**
* Set the cursor position
* @param obj pointer to a text area object
* @param pos the new cursor position in character index
* < 0 : index from the end of the text
* LV_TA_CUR_LAST: go after the last character
* LV_TA_CURSOR_LAST: go after the last character
*/
void lv_ta_set_cursor_pos(lv_obj_t * ta, int16_t pos);
/**
* Move the cursor one character right
* @param ta pointer to a text area object
*/
void lv_ta_cursor_right(lv_obj_t * ta);
/**
* Move the cursor one character left
* @param ta pointer to a text area object
*/
void lv_ta_cursor_left(lv_obj_t * ta);
/**
* Move the cursor one line down
* @param ta pointer to a text area object
*/
void lv_ta_cursor_down(lv_obj_t * ta);
/**
* Move the cursor one line up
* @param ta pointer to a text area object
*/
void lv_ta_cursor_up(lv_obj_t * ta);
/**
* Set the cursor visibility.
* @param ta pointer to a text area object
@@ -150,7 +139,6 @@ void lv_ta_set_cursor_show(lv_obj_t * ta, bool show);
* @param cur_type: element of 'lv_ta_cursor_type_t'
*/
void lv_ta_set_cursor_type(lv_obj_t * ta, lv_ta_cursor_type_t cur_type);
/**
* Enable/Disable password mode
* @param ta pointer to a text area object
@@ -176,13 +164,12 @@ static inline void lv_ta_set_sb_mode(lv_obj_t * ta, lv_page_sb_mode_t mode)
}
/**
* Set the style of the text area
* Set a style of a text area
* @param ta pointer to a text area object
* @param bg pointer to the new background style (NULL to leave unchanged)
* @param sb pointer to the new scrollbar style (NULL to leave unchanged)
* @param cur pointer to the new cursor style (NULL to use the label's style)
* @param type which style should be set
* @param style pointer to a style
*/
void lv_ta_set_style(lv_obj_t * ta, lv_style_t *bg, lv_style_t *sb, lv_style_t *cur);
void lv_ta_set_style(lv_obj_t *ta, lv_ta_style_t type, lv_style_t *style);
/*=====================
* Getter functions
@@ -202,7 +189,6 @@ const char * lv_ta_get_text(lv_obj_t * ta);
*/
lv_obj_t * lv_ta_get_label(lv_obj_t * ta);
/**
* Get the current cursor position in character index
* @param ta pointer to a text area object
@@ -249,31 +235,40 @@ static inline lv_page_sb_mode_t lv_ta_get_sb_mode(lv_obj_t * ta)
}
/**
* Get the style of the text area background
* @param ta pointer to a text area object
* @return pointer to the style of the background
*/
static inline lv_style_t * lv_ta_get_style_bg(lv_obj_t * ta)
{
return lv_page_get_style_bg(ta);
}
/**
* Get the style of the scrollbars of a text area
* @param ta pointer to a text area object
* @return pointer to the style of the scrollbars
*/
static inline lv_style_t * lv_ta_get_style_sb(lv_obj_t * ta)
{
return lv_page_get_style_sb(ta);
}
/**
* Get the style of the cursor
* Get a style of a text area
* @param ta pointer to a text area object
* @return style pointer to the new cursor style
* @param type which style should be get
* @return style pointer to a style
*/
lv_style_t * lv_ta_get_style_cursor(lv_obj_t * ta);
lv_style_t * lv_ta_get_style(lv_obj_t *ta, lv_ta_style_t type);
/*=====================
* Other functions
*====================*/
/**
* Move the cursor one character right
* @param ta pointer to a text area object
*/
void lv_ta_cursor_right(lv_obj_t * ta);
/**
* Move the cursor one character left
* @param ta pointer to a text area object
*/
void lv_ta_cursor_left(lv_obj_t * ta);
/**
* Move the cursor one line down
* @param ta pointer to a text area object
*/
void lv_ta_cursor_down(lv_obj_t * ta);
/**
* Move the cursor one line up
* @param ta pointer to a text area object
*/
void lv_ta_cursor_up(lv_obj_t * ta);
/**********************
* MACROS

View File

@@ -24,13 +24,15 @@
/**********************
* STATIC PROTOTYPES
**********************/
static bool tabpage_signal(lv_obj_t * tab_page, lv_signal_t sign, void * param);
static bool tabscrl_signal(lv_obj_t * tab_scrl, lv_signal_t sign, void * param);
static lv_res_t lv_tabview_signal(lv_obj_t * tabview, lv_signal_t sign, void * param);
static lv_res_t tabpage_signal(lv_obj_t * tab_page, lv_signal_t sign, void * param);
static lv_res_t tabpage_scrl_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_res_t tab_btnm_action(lv_obj_t * tab_btnm, const char * tab_name);
static void tabview_realign(lv_obj_t * tabview);
/**********************
* STATIC VARIABLES
@@ -39,6 +41,7 @@ static lv_signal_func_t ancestor_signal;
static lv_signal_func_t page_signal;
static lv_signal_func_t page_scrl_signal;
static const char * tab_def[] = {""};
/**********************
* MACROS
**********************/
@@ -47,10 +50,6 @@ static const char * tab_def[] = {""};
* GLOBAL FUNCTIONS
**********************/
/*-----------------
* Create function
*-----------------*/
/**
* Create a Tab view object
* @param par pointer to an object, it will be the parent of the new tab
@@ -76,7 +75,7 @@ lv_obj_t * lv_tabview_create(lv_obj_t * par, lv_obj_t * copy)
ext->point_last.y = 0;
ext->content = NULL;
ext->indic = NULL;
ext->tabs = NULL;
ext->btns = NULL;
ext->tab_load_action = NULL;
ext->anim_time = LV_TABVIEW_ANIM_TIME;
ext->tab_name_ptr = dm_alloc(sizeof(char*));
@@ -88,48 +87,57 @@ lv_obj_t * lv_tabview_create(lv_obj_t * par, lv_obj_t * copy)
/*Init the new tab tab*/
if(copy == NULL) {
lv_obj_set_size(new_tabview, LV_HOR_RES, LV_VER_RES);
lv_obj_set_style(new_tabview, &lv_style_plain);
lv_obj_set_style(new_tabview, &lv_style_pretty);
ext->tabs = lv_btnm_create(new_tabview, NULL);
lv_obj_set_height(ext->tabs, 3 * LV_DPI / 4);
lv_obj_set_style(ext->tabs, &lv_style_transp_tight);
lv_btnm_set_map(ext->tabs, tab_def);
lv_btnm_set_action(ext->tabs, tab_btnm_action);
lv_btnm_set_toggle(ext->tabs, true, 0);
ext->btns = lv_btnm_create(new_tabview, NULL);
lv_obj_set_height(ext->btns, 3 * LV_DPI / 4);
lv_btnm_set_map(ext->btns, tab_def);
lv_btnm_set_action(ext->btns, tab_btnm_action);
lv_btnm_set_toggle(ext->btns, true, 0);
ext->indic = lv_obj_create(ext->tabs, NULL);
lv_obj_set_size(ext->indic, LV_DPI, LV_DPI / 10);
lv_obj_align(ext->indic, ext->tabs, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
ext->indic = lv_obj_create(ext->btns, NULL);
lv_obj_set_width(ext->indic, LV_DPI);
lv_obj_align(ext->indic, ext->btns, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
lv_obj_set_click(ext->indic, false);
ext->content = lv_cont_create(new_tabview, NULL);
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_fit);
lv_obj_align(ext->content, ext->tabs, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
lv_cont_set_style(ext->content, &lv_style_transp_tight);
lv_obj_set_height(ext->content, LV_VER_RES - lv_obj_get_height(ext->btns));
lv_obj_align(ext->content, ext->btns, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_BG, &lv_style_transp);
lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_INDIC, &lv_style_plain_color);
}
/*Copy an existing tab*/
else {
lv_tabview_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
ext->point_last.x = 0;
ext->point_last.y = 0;
ext->tabs = lv_btnm_create(new_tabview, copy_ext->tabs);
ext->indic = lv_obj_create(ext->tabs, copy_ext->indic);
ext->btns = lv_btnm_create(new_tabview, copy_ext->btns);
ext->indic = lv_obj_create(ext->btns, 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] = "";
lv_btnm_set_map(ext->tabs, ext->tab_name_ptr);
lv_btnm_set_map(ext->btns, ext->tab_name_ptr);
uint16_t i;
lv_obj_t *new_tab;
lv_obj_t *copy_tab;
for (i = 0; i < copy_ext->tab_cnt; i++) {
lv_tabview_add_tab(new_tabview, copy_ext->tab_name_ptr[i]);
new_tab = lv_tabview_add_tab(new_tabview, copy_ext->tab_name_ptr[i]);
copy_tab = lv_tabview_get_tab(copy, i);
lv_page_set_style(new_tab, LV_PAGE_STYLE_BG, lv_page_get_style(copy_tab, LV_PAGE_STYLE_BG));
lv_page_set_style(new_tab, LV_PAGE_STYLE_SCRL, lv_page_get_style(copy_tab, LV_PAGE_STYLE_SCRL));
lv_page_set_style(new_tab, LV_PAGE_STYLE_SB, lv_page_get_style(copy_tab, LV_PAGE_STYLE_SB));
}
/*Refresh the style with new signal function*/
lv_obj_refresh_style(new_tabview);
}
@@ -137,40 +145,6 @@ lv_obj_t * lv_tabview_create(lv_obj_t * par, lv_obj_t * copy)
return new_tabview;
}
/**
* Signal function of the Tab view
* @param tabview pointer to a Tab view object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return true: the object is still valid (not deleted), false: the object become invalid
*/
bool lv_tabview_signal(lv_obj_t * tabview, lv_signal_t sign, void * param)
{
bool valid;
/* Include the ancient signal function */
valid = ancestor_signal(tabview, sign, param);
/* The object can be deleted so check its validity and then
* make the object specific signal handling */
if(valid != false) {
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
if(sign == LV_SIGNAL_CLEANUP) {
dm_free(ext->tab_name_ptr);
ext->tab_name_ptr = NULL;
} else if(sign == LV_SIGNAL_CORD_CHG) {
if(ext->content != NULL &&
(lv_obj_get_width(tabview) != area_get_width(param) ||
lv_obj_get_height(tabview) != area_get_height(param)))
{
lv_tabview_realign(tabview);
}
}
}
return valid;
}
/*======================
* Add/remove functions
*=====================*/
@@ -179,7 +153,7 @@ bool lv_tabview_signal(lv_obj_t * tabview, lv_signal_t sign, void * param)
* Add a new tab with the given name
* @param tabview pointer to Tab view object where to ass the new tab
* @param name the text on the tab button
* @return pointer to page object (lv_page) which is the containter of the contet
* @return pointer to the created page object (lv_page). You can create your content here
*/
lv_obj_t * lv_tabview_add_tab(lv_obj_t * tabview, const char * name)
{
@@ -187,26 +161,35 @@ lv_obj_t * lv_tabview_add_tab(lv_obj_t * tabview, const char * name)
/*Create the container page*/
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_transp_fit);
lv_obj_set_style(lv_page_get_scrl(h), &lv_style_transp_fit);
lv_obj_set_size(h, lv_obj_get_width(tabview), lv_obj_get_height(ext->content));
lv_page_set_style(h, LV_PAGE_STYLE_BG, &lv_style_transp);
lv_page_set_style(h, LV_PAGE_STYLE_SCRL, &lv_style_transp_tight);
lv_page_set_sb_mode(h, LV_PAGE_SB_MODE_AUTO);
if(page_signal == NULL) page_signal = lv_obj_get_signal_func(h);
if(page_scrl_signal == NULL) page_scrl_signal = lv_obj_get_signal_func(lv_page_get_scrl(h));
lv_obj_set_signal_func(h, tabpage_signal);
lv_obj_set_signal_func(lv_page_get_scrl(h), tabscrl_signal);
lv_obj_set_signal_func(lv_page_get_scrl(h), tabpage_scrl_signal);
/*Extend the button matrix map with the new name*/
char *name_dm;
if((name[0] & LV_BTNM_CTRL_MASK) == LV_BTNM_CTRL_CODE) { /*If control byte presented let is*/
name_dm = dm_alloc(strlen(name) + 1); /*+1 for the the closing '\0' */
strcpy(name_dm, name);
} else { /*Set a no long press control byte is not presented*/
name_dm = dm_alloc(strlen(name) + 2); /*+1 for the the closing '\0' and +1 for the control byte */
name_dm[0] = '\221';
strcpy(&name_dm[1], name);
}
ext->tab_cnt++;
ext->tab_name_ptr = dm_realloc(ext->tab_name_ptr, sizeof(char *) * (ext->tab_cnt + 1));
ext->tab_name_ptr[ext->tab_cnt - 1] = name;
ext->tab_name_ptr[ext->tab_cnt - 1] = name_dm;
ext->tab_name_ptr[ext->tab_cnt] = "";
lv_btnm_set_map(ext->tabs, ext->tab_name_ptr);
lv_btnm_set_map(ext->btns, ext->tab_name_ptr);
/*Modify the indicator size*/
lv_style_t * style_tabs = lv_obj_get_style(ext->tabs);
lv_style_t * style_tabs = lv_obj_get_style(ext->btns);
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_cur + style_tabs->body.padding.inner * ext->tab_cur + style_tabs->body.padding.hor);
@@ -214,7 +197,7 @@ lv_obj_t * lv_tabview_add_tab(lv_obj_t * tabview, const char * name)
/*Set the first tab as active*/
if(ext->tab_cnt == 1) {
ext->tab_cur = 0;
lv_tabview_set_act(tabview, 0, false);
lv_tabview_set_current_tab(tabview, 0, false);
}
return h;
@@ -230,7 +213,7 @@ lv_obj_t * lv_tabview_add_tab(lv_obj_t * tabview, const char * name)
* @param id index of a tab to load
* @param anim_en true: set with sliding animation; false: set immediately
*/
void lv_tabview_set_act(lv_obj_t * tabview, uint16_t id, bool anim_en)
void lv_tabview_set_current_tab(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);
@@ -262,7 +245,7 @@ void lv_tabview_set_act(lv_obj_t * tabview, uint16_t id, bool anim_en)
/*Move the indicator*/
cord_t indic_width = lv_obj_get_width(ext->indic);
lv_style_t * tabs_style = lv_obj_get_style(ext->tabs);
lv_style_t * tabs_style = lv_obj_get_style(ext->btns);
cord_t indic_x = indic_width * id + tabs_style->body.padding.inner * id + tabs_style->body.padding.hor;
if(ext->anim_time == 0 || anim_en == false ) {
@@ -284,7 +267,7 @@ 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_cur);
lv_btnm_set_toggle(ext->btns, true, ext->tab_cur);
}
/**
@@ -311,6 +294,52 @@ void lv_tabview_set_anim_time(lv_obj_t * tabview, uint16_t anim_time_ms)
ext->anim_time = anim_time_ms;
}
/**
* Set the height of the tab buttons
* @param tabview pointer to a tabview object
* @param h the new height
*/
void lv_tabview_set_btn_height(lv_obj_t *tabview, cord_t h)
{
lv_tabview_ext_t *ext = lv_obj_get_ext_attr(tabview);
lv_obj_set_height(ext->btns, h);
tabview_realign(tabview);
}
void lv_tabview_set_style(lv_obj_t *tabview, lv_tabview_style_t type, lv_style_t *style)
{
lv_tabview_ext_t *ext = lv_obj_get_ext_attr(tabview);
switch(type) {
case LV_TABVIEW_STYLE_BG:
lv_obj_set_style(tabview, style);
break;
case LV_TABVIEW_STYLE_BTN_BG:
lv_btnm_set_style(ext->btns, LV_BTNM_STYLE_BG, style);
break;
case LV_TABVIEW_STYLE_BTN_REL:
lv_btnm_set_style(ext->btns, LV_BTNM_STYLE_BTN_REL, style);
break;
case LV_TABVIEW_STYLE_BTN_PR:
lv_btnm_set_style(ext->btns, LV_BTNM_STYLE_BTN_PR, style);
break;
case LV_TABVIEW_STYLE_BTN_TGL_REL:
lv_btnm_set_style(ext->btns, LV_BTNM_STYLE_BTN_TGL_REL, style);
break;
case LV_TABVIEW_STYLE_BTN_TGL_PR:
lv_btnm_set_style(ext->btns, LV_BTNM_STYLE_BTN_TGL_PR, style);
break;
case LV_TABVIEW_STYLE_BTN_INA:
lv_btnm_set_style(ext->btns, LV_BTNM_STYLE_BTN_INA, style);
break;
case LV_TABVIEW_STYLE_INDIC:
lv_obj_set_style(ext->indic, style);
lv_obj_set_height(ext->indic, style->body.padding.inner);
tabview_realign(tabview);
break;
}
}
/*=====================
* Getter functions
@@ -321,7 +350,7 @@ void lv_tabview_set_anim_time(lv_obj_t * tabview, uint16_t anim_time_ms)
* @param tabview pointer to Tab view object
* @return the active tab index
*/
uint16_t lv_tabview_get_tab_act(lv_obj_t * tabview)
uint16_t lv_tabview_get_current_tab(lv_obj_t * tabview)
{
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
return ext->tab_cur;
@@ -332,7 +361,7 @@ uint16_t lv_tabview_get_tab_act(lv_obj_t * tabview)
* @param tabview pointer to Tab view object
* @return tab count
*/
uint16_t lv_tabview_get_tab_cnt(lv_obj_t * tabview)
uint16_t lv_tabview_get_tab_count(lv_obj_t * tabview)
{
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
return ext->tab_cnt;
@@ -344,7 +373,7 @@ uint16_t lv_tabview_get_tab_cnt(lv_obj_t * tabview)
* @param id index of the tab (>= 0)
* @return pointer to page (lv_page) object
*/
lv_obj_t * lv_tabview_get_tab_page(lv_obj_t * tabview, uint16_t id)
lv_obj_t * lv_tabview_get_tab(lv_obj_t * tabview, uint16_t id)
{
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
uint16_t i = 0;
@@ -360,28 +389,6 @@ lv_obj_t * lv_tabview_get_tab_page(lv_obj_t * tabview, uint16_t id)
return NULL;
}
/**
* Get the tab button matrix (lv_btnm) of a Tab view
* @param tabview pointer to Tab view object
* @return pointer to button matrix (lv_btnm) object which is the tab buttons
*/
lv_obj_t * lv_tabview_get_tabs(lv_obj_t * tabview)
{
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
return ext->tabs;
}
/**
* Get the indicator rectangle (lv_obj) of a Tab view
* @param tabview pointer to Tab view object
* @return pointer to Base object (lv_obj) which is the indicator rectangle on the tab buttons
*/
lv_obj_t * lv_tabview_get_indic(lv_obj_t * tabview)
{
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
return ext->indic;
}
/**
* Get the tab load action
* @param tabview pointer to a tabview object
@@ -404,139 +411,128 @@ uint16_t lv_tabview_get_anim_time(lv_obj_t * tabview, uint16_t anim_time_ms)
return ext->anim_time;
}
/*=====================
* Other functions
*====================*/
/**
* Realign and resize the elements of Tab view
* @param tabview pointer to a Tab view object
* Get a style of a tab view
* @param tabview pointer to a ab view object
* @param type which style should be get
* @return style pointer to a style
*/
void lv_tabview_realign(lv_obj_t * tabview)
lv_style_t * lv_tabview_get_style(lv_obj_t *tabview, lv_tabview_style_t type)
{
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
lv_tabview_ext_t *ext = lv_obj_get_ext_attr(tabview);
lv_obj_set_width(ext->tabs, lv_obj_get_width(tabview));
lv_obj_set_height(ext->content, lv_obj_get_height(tabview) - lv_obj_get_height(ext->tabs));
lv_obj_align(ext->content, ext->tabs, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
lv_obj_t * pages = lv_obj_get_child(ext->content, NULL);
while(pages != NULL) {
lv_obj_set_size(pages, lv_obj_get_width(tabview), 200);//lv_obj_get_height(tabview) - lv_obj_get_height(ext->tabs));
pages = lv_obj_get_child(ext->content, pages);
switch (type) {
case LV_TABVIEW_STYLE_BG: return lv_obj_get_style(tabview);
case LV_TABVIEW_STYLE_BTN_BG: return lv_btnm_get_style(ext->btns, LV_BTNM_STYLE_BG);
case LV_TABVIEW_STYLE_BTN_REL: return lv_btnm_get_style(ext->btns, LV_BTNM_STYLE_BTN_REL);
case LV_TABVIEW_STYLE_BTN_PR: return lv_btnm_get_style(ext->btns, LV_BTNM_STYLE_BTN_PR);
case LV_TABVIEW_STYLE_BTN_TGL_REL: return lv_btnm_get_style(ext->btns, LV_BTNM_STYLE_BTN_TGL_REL);
case LV_TABVIEW_STYLE_BTN_TGL_PR: return lv_btnm_get_style(ext->btns, LV_BTNM_STYLE_BTN_TGL_PR);
case LV_TABVIEW_STYLE_BTN_INA: return lv_btnm_get_style(ext->btns, LV_BTNM_STYLE_BTN_INA);
default: return NULL;
}
if(ext->tab_cnt != 0) {
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_align(ext->indic, ext->tabs, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
lv_tabview_set_act(tabview, ext->tab_cur, false);
/*To avoid warning*/
return NULL;
}
/**********************
* STATIC FUNCTIONS
**********************/
#if 0 /*Unused*/
/**
* Handle the drawing related tasks of the tabs
* @param tab pointer to an object
* @param mask the object will be drawn only in this area
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
* (return 'true' if yes)
* LV_DESIGN_DRAW: draw the object (always return 'true')
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
* @param return true/false, depends on 'mode'
* Signal function of the Tab view
* @param tabview pointer to a Tab view object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
*/
static bool lv_tab_design(lv_obj_t * tab, const area_t * mask, lv_design_mode_t mode)
static lv_res_t lv_tabview_signal(lv_obj_t * tabview, lv_signal_t sign, void * param)
{
/*Return false if the object is not covers the mask_p area*/
if(mode == LV_DESIGN_COVER_CHK) {
return false;
}
/*Draw the object*/
else if(mode == LV_DESIGN_DRAW_MAIN) {
lv_res_t res;
}
/*Post draw when the children are drawn*/
else if(mode == LV_DESIGN_DRAW_POST) {
/* Include the ancient signal function */
res = ancestor_signal(tabview, sign, param);
if(res != LV_RES_OK) return res;
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
if(sign == LV_SIGNAL_CLEANUP) {
uint8_t i;
for(i = 0; ext->tab_name_ptr[i][0] != '\0'; i++) dm_free(ext->tab_name_ptr[i]);
dm_free(ext->tab_name_ptr);
ext->tab_name_ptr = NULL;
} else if(sign == LV_SIGNAL_CORD_CHG) {
if(ext->content != NULL &&
(lv_obj_get_width(tabview) != area_get_width(param) ||
lv_obj_get_height(tabview) != area_get_height(param)))
{
tabview_realign(tabview);
}
}
return true;
return res;
}
#endif
/**
* Signal function of a tab's page
* @param tab pointer to a tab page object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return true: the object is still valid (not deleted), false: the object become invalid
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
*/
static bool tabpage_signal(lv_obj_t * tab_page, lv_signal_t sign, void * param)
static lv_res_t tabpage_signal(lv_obj_t * tab_page, lv_signal_t sign, void * param)
{
bool valid;
lv_res_t res;
/* Include the ancient signal function */
valid = page_signal(tab_page, sign, param);
/* The object can be deleted so check its validity and then
* make the object specific signal handling */
if(valid != false) {
lv_obj_t * cont = lv_obj_get_parent(tab_page);
lv_obj_t * tab = lv_obj_get_parent(cont);
if(sign == LV_SIGNAL_PRESSED) {
tabpage_pressed_hadler(tab, tab_page);
}
else if(sign == LV_SIGNAL_PRESSING) {
tabpage_pressing_hadler(tab, tab_page);
}
else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) {
tabpage_press_lost_hadler(tab, tab_page);
}
res = page_signal(tab_page, sign, param);
if(res != LV_RES_OK) return res;
lv_obj_t * cont = lv_obj_get_parent(tab_page);
lv_obj_t * tab = lv_obj_get_parent(cont);
if(sign == LV_SIGNAL_PRESSED) {
tabpage_pressed_hadler(tab, tab_page);
}
else if(sign == LV_SIGNAL_PRESSING) {
tabpage_pressing_hadler(tab, tab_page);
}
else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) {
tabpage_press_lost_hadler(tab, tab_page);
}
return valid;
return res;
}
/**
* Signal function of the tab page's scrollable object
* @param tab_scrl pointer to a tab page's scrollable object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return true: the object is still valid (not deleted), false: the object become invalid
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
*/
static bool tabscrl_signal(lv_obj_t * tab_scrl, lv_signal_t sign, void * param)
static lv_res_t tabpage_scrl_signal(lv_obj_t * tab_scrl, lv_signal_t sign, void * param)
{
bool valid;
lv_res_t res;
/* Include the ancient signal function */
valid = page_scrl_signal(tab_scrl, sign, param);
/* The object can be deleted so check its validity and then
* make the object specific signal handling */
if(valid != false) {
lv_obj_t * tab_page = lv_obj_get_parent(tab_scrl);
lv_obj_t * cont = lv_obj_get_parent(tab_page);
lv_obj_t * tab = lv_obj_get_parent(cont);
if(sign == LV_SIGNAL_PRESSED) {
tabpage_pressed_hadler(tab, tab_page);
}
else if(sign == LV_SIGNAL_PRESSING) {
tabpage_pressing_hadler(tab, tab_page);
}
else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) {
tabpage_press_lost_hadler(tab, tab_page);
}
res = page_scrl_signal(tab_scrl, sign, param);
if(res != LV_RES_OK) return res;
lv_obj_t * tab_page = lv_obj_get_parent(tab_scrl);
lv_obj_t * cont = lv_obj_get_parent(tab_page);
lv_obj_t * tab = lv_obj_get_parent(cont);
if(sign == LV_SIGNAL_PRESSED) {
tabpage_pressed_hadler(tab, tab_page);
}
else if(sign == LV_SIGNAL_PRESSING) {
tabpage_pressing_hadler(tab, tab_page);
}
else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) {
tabpage_press_lost_hadler(tab, tab_page);
}
return valid;
return res;
}
/**
@@ -582,7 +578,7 @@ static void tabpage_pressing_hadler(lv_obj_t * tabview, lv_obj_t * tabpage)
/*Move the indicator*/
cord_t indic_width = lv_obj_get_width(ext->indic);
lv_style_t * tabs_style = lv_obj_get_style(ext->tabs);
lv_style_t * tabs_style = lv_obj_get_style(ext->btns);
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);
@@ -614,18 +610,18 @@ static void tabpage_press_lost_hadler(lv_obj_t * tabview, lv_obj_t * tabpage)
x_diff = x_diff * (100 - LV_INDEV_DRAG_THROW) / 100;
}
cord_t page_x1 = tabpage->coords.x1 + x_predict;
cord_t page_x2 = tabpage->coords.x2 + x_predict;
cord_t page_x1 = tabpage->coords.x1 - tabview->coords.x1 + x_predict;
cord_t page_x2 = page_x1 + lv_obj_get_width(tabpage);
cord_t treshold = lv_obj_get_width(tabview) / 2;
uint16_t tab_cur = ext->tab_cur;
if(page_x1 > (tabview->coords.x2 - tabview->coords.x1) / 2) {
if(page_x1 > treshold) {
if(tab_cur != 0) tab_cur--;
} else if(page_x2 < (tabview->coords.x2 - tabview->coords.x1) / 2) {
} else if(page_x2 < treshold) {
if(tab_cur < ext->tab_cnt - 1) tab_cur++;
}
lv_tabview_set_act(tabview, tab_cur, true);
lv_tabview_set_current_tab(tabview, tab_cur, true);
}
/**
@@ -642,13 +638,41 @@ static lv_res_t tab_btnm_action(lv_obj_t * tab_btnm, const char * tab_name)
uint8_t i = 0;
while(tabs_map[i][0] != '\0') {
if(strcmp(tabs_map[i], tab_name) == 0) break;
if(strcmp(&tabs_map[i][1], tab_name) == 0) break; /*[1] to skip the control byte*/
i++;
}
lv_tabview_set_act(tab, i, true);
lv_tabview_set_current_tab(tab, i, true);
return LV_RES_OK;
}
/**
* Realign and resize the elements of Tab view
* @param tabview pointer to a Tab view object
*/
static void tabview_realign(lv_obj_t * tabview)
{
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
lv_obj_set_width(ext->btns, lv_obj_get_width(tabview));
lv_obj_set_height(ext->content, lv_obj_get_height(tabview) - lv_obj_get_height(ext->btns));
lv_obj_align(ext->content, ext->btns, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
lv_obj_t * pages = lv_obj_get_child(ext->content, NULL);
while(pages != NULL) {
lv_obj_set_size(pages, lv_obj_get_width(tabview), lv_obj_get_height(ext->content));
pages = lv_obj_get_child(ext->content, pages);
}
if(ext->tab_cnt != 0) {
lv_style_t * style_tabs = lv_obj_get_style(ext->btns);
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_align(ext->indic, ext->btns, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
lv_tabview_set_current_tab(tabview, ext->tab_cur, false);
}
#endif

View File

@@ -46,7 +46,7 @@ typedef struct
{
/*Ext. of ancestor*/
/*New data for this type */
lv_obj_t * tabs;
lv_obj_t * btns;
lv_obj_t * indic;
lv_obj_t * content; /*A rectangle to show the current tab*/
const char ** tab_name_ptr;
@@ -59,39 +59,53 @@ typedef struct
lv_tabview_action_t tab_load_action;
}lv_tabview_ext_t;
typedef enum {
LV_TABVIEW_STYLE_BG,
LV_TABVIEW_STYLE_BTN_BG,
LV_TABVIEW_STYLE_BTN_REL,
LV_TABVIEW_STYLE_BTN_PR,
LV_TABVIEW_STYLE_BTN_TGL_REL,
LV_TABVIEW_STYLE_BTN_TGL_PR,
LV_TABVIEW_STYLE_BTN_INA,
LV_TABVIEW_STYLE_INDIC,
}lv_tabview_style_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Create a Tab view objects
* Create a Tab view object
* @param par pointer to an object, it will be the parent of the new tab
* @param copy pointer to a tab object, if not NULL then the new object will be copied from it
* @return pointer to the created tab
*/
lv_obj_t * lv_tabview_create(lv_obj_t * par, lv_obj_t * copy);
/**
* Signal function of the Tab view
* @param tab pointer to a tab object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return true: the object is still valid (not deleted), false: the object become invalid
*/
bool lv_tabview_signal(lv_obj_t * tab, lv_signal_t sign, void * param);
/*======================
* Add/remove functions
*=====================*/
/**
* Realign and resize the elements of Tab view
* @param tabview pointer to a Tab view object
* Add a new tab with the given name
* @param tabview pointer to Tab view object where to ass the new tab
* @param name the text on the tab button
* @return pointer to the created page object (lv_page). You can create your content here
*/
void lv_tabview_realign(lv_obj_t * tabview);
lv_obj_t * lv_tabview_add_tab(lv_obj_t * tabview, const char * name);
/*=====================
* Setter functions
*====================*/
/**
* Set a new tab
* @param tabview pointer to Tab view object
* @param id index of a tab to load
* @param anim_en true: set with sliding animation; false: set immediately
*/
void lv_tabview_set_act(lv_obj_t * tabview, uint16_t id, bool anim_en);
void lv_tabview_set_current_tab(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)
@@ -99,7 +113,7 @@ void lv_tabview_set_act(lv_obj_t * tabview, uint16_t id, bool anim_en);
* @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);
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
@@ -108,48 +122,40 @@ void lv_tabview_set_tab_load_action(lv_obj_t *tabview,lv_tabview_action_t action
*/
void lv_tabview_set_anim_time(lv_obj_t * tabview, uint16_t anim_time_ms);
/**
* Set the height of the tab buttons
* @param tabview pointer to a tabview object
* @param h the new height
*/
void lv_tabview_set_btn_height(lv_obj_t *tabview, cord_t h);
void lv_tabview_set_style(lv_obj_t *tabview, lv_tabview_style_t type, lv_style_t *style);
/*=====================
* Getter functions
*====================*/
/**
* 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);
uint16_t lv_tabview_get_current_tab(lv_obj_t * tabview);
/**
* Get the number of tabs
* @param tabview pointer to Tab view object
* @return tab count
*/
uint16_t lv_tabview_get_tab_cnt(lv_obj_t * tabview);
uint16_t lv_tabview_get_tab_count(lv_obj_t * tabview);
/**
* Get the page (content area) of a tab
* @param tabview pointer to Tab view object
* @param id index of the tab (>= 0)
* @return pointer to page (lv_page) object
*/
lv_obj_t * lv_tabview_get_tab_page(lv_obj_t * tabview, uint16_t id);
/**
* Get the tab button matrix (lv_btnm) of a Tab view
* @param tabview pointer to Tab view object
* @return pointer to button matrix (lv_btnm) object which is the tab buttons
*/
lv_obj_t * lv_tabview_get_tabs(lv_obj_t * tabview);
/**
* Get the indicator rectangle (lv_obj) of a Tab view
* @param tabview pointer to Tab view object
* @return pointer to Base object (lv_obj) which is the indicator rectangle on the tab buttons
*/
lv_obj_t * lv_tabview_get_indic(lv_obj_t * tabview);
/**
* Add a new tab with the given name
* @param tabview pointer to Tab view object where to ass the new tab
* @param name the text on the tab button
* @return pointer to page object (lv_page) which is the containter of the contet
*/
lv_obj_t * lv_tabview_add_tab(lv_obj_t * tabview, const char * name);
lv_obj_t * lv_tabview_get_tab(lv_obj_t * tabview, uint16_t id);
/**
* Get the tab load action
@@ -157,6 +163,7 @@ lv_obj_t * lv_tabview_add_tab(lv_obj_t * tabview, const char * name);
* @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
@@ -164,6 +171,15 @@ lv_tabview_action_t lv_tabview_get_tab_load_action(lv_obj_t *tabview);
*/
uint16_t lv_tabview_get_anim_time(lv_obj_t * tabview, uint16_t anim_time_ms);
/**
* Get a style of a tab view
* @param tabview pointer to a ab view object
* @param type which style should be get
* @return style pointer to a style
*/
lv_style_t * lv_tabview_get_style(lv_obj_t *tabview, lv_tabview_style_t type);
/**********************
* MACROS
**********************/