mirror of
https://github.com/lvgl/lvgl.git
synced 2024-11-24 02:03:53 +08:00
add static inline function to clraify API (bar, slider, sw, cb, btn, btnm)
This commit is contained in:
parent
5325a93990
commit
c517d73a71
@ -64,7 +64,7 @@ lv_obj_t * lv_bar_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
ext->min_value = 0;
|
||||
ext->max_value = 100;
|
||||
ext->act_value = 0;
|
||||
ext->indicator_style = &lv_style_pretty_color;
|
||||
ext->style_inicator = &lv_style_pretty_color;
|
||||
|
||||
/* Save the ancient design function.
|
||||
* It will be used in the bar design function*/
|
||||
@ -84,7 +84,7 @@ lv_obj_t * lv_bar_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
ext->min_value = ext_copy->min_value;
|
||||
ext->max_value = ext_copy->max_value;
|
||||
ext->act_value = ext_copy->act_value;
|
||||
ext->indicator_style = ext_copy->indicator_style;
|
||||
ext->style_inicator = ext_copy->style_inicator;
|
||||
/*Refresh the style with new signal function*/
|
||||
lv_obj_refresh_style(new_bar);
|
||||
|
||||
@ -110,7 +110,7 @@ bool lv_bar_signal(lv_obj_t * bar, lv_signal_t sign, void * param)
|
||||
* make the object specific signal handling */
|
||||
if(valid != false) {
|
||||
if(sign == LV_SIGNAL_REFR_EXT_SIZE) {
|
||||
lv_style_t * style_indic = lv_bar_get_indicator_style(bar);
|
||||
lv_style_t * style_indic = lv_bar_get_style_indicator(bar);
|
||||
if(style_indic->body.shadow.width > bar->ext_size) bar->ext_size = style_indic->body.shadow.width;
|
||||
}
|
||||
|
||||
@ -171,7 +171,7 @@ void lv_bar_set_value_anim(lv_obj_t * bar, int16_t value, uint16_t anim_time)
|
||||
|
||||
/**
|
||||
* Set minimum and the maximum values of a bar
|
||||
* @param bar pointer to he bar object
|
||||
* @param bar pointer to the bar object
|
||||
* @param min minimum value
|
||||
* @param max maximum value
|
||||
*/
|
||||
@ -192,19 +192,23 @@ void lv_bar_set_range(lv_obj_t * bar, int16_t min, int16_t max)
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the style of bar indicator
|
||||
* Set the styles of a bar
|
||||
* @param bar pointer to a bar object
|
||||
* @param style pointer to a style
|
||||
* @param bg pointer to the background's style (NULL to leave unchanged)
|
||||
* @param indic pointer to the indicator's style (NULL to leave unchanged)
|
||||
*/
|
||||
void lv_bar_set_indicator_style(lv_obj_t * bar, lv_style_t * style)
|
||||
void lv_bar_set_styles(lv_obj_t * bar, lv_style_t * bg, lv_style_t * indic)
|
||||
{
|
||||
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
||||
|
||||
ext->indicator_style = style;
|
||||
if(indic != NULL) {
|
||||
ext->style_inicator = indic;
|
||||
bar->signal_func(bar, LV_SIGNAL_REFR_EXT_SIZE, NULL);
|
||||
}
|
||||
|
||||
bar->signal_func(bar, LV_SIGNAL_REFR_EXT_SIZE, NULL);
|
||||
|
||||
lv_obj_invalidate(bar);
|
||||
if(bg != NULL) {
|
||||
lv_obj_set_style(bar, bg);
|
||||
}
|
||||
}
|
||||
|
||||
/*=====================
|
||||
@ -249,13 +253,13 @@ int16_t lv_bar_get_max_value(lv_obj_t * bar)
|
||||
* @param bar pointer to a bar object
|
||||
* @return pointer to the bar indicator style
|
||||
*/
|
||||
lv_style_t * lv_bar_get_indicator_style(lv_obj_t * bar)
|
||||
lv_style_t * lv_bar_get_style_indicator(lv_obj_t * bar)
|
||||
{
|
||||
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
||||
|
||||
if(ext->indicator_style == NULL) return lv_obj_get_style(bar);
|
||||
if(ext->style_inicator == NULL) return lv_obj_get_style(bar);
|
||||
|
||||
return ext->indicator_style;
|
||||
return ext->style_inicator;
|
||||
}
|
||||
|
||||
/**********************
|
||||
@ -282,7 +286,7 @@ static bool lv_bar_design(lv_obj_t * bar, const area_t * mask, lv_design_mode_t
|
||||
|
||||
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
||||
|
||||
lv_style_t * style_indic = lv_bar_get_indicator_style(bar);
|
||||
lv_style_t * style_indic = lv_bar_get_style_indicator(bar);
|
||||
area_t indic_area;
|
||||
area_cpy(&indic_area, &bar->coords);
|
||||
indic_area.x1 += style_indic->body.padding.hor;
|
||||
|
@ -37,7 +37,7 @@ typedef struct
|
||||
int16_t act_value; /*Current value of the bar*/
|
||||
int16_t min_value; /*Minimum value of the bar*/
|
||||
int16_t max_value; /*Maximum value of the bar*/
|
||||
lv_style_t *indicator_style; /*Style of the indicator*/
|
||||
lv_style_t *style_inicator; /*Style of the indicator*/
|
||||
}lv_bar_ext_t;
|
||||
|
||||
/**********************
|
||||
@ -83,12 +83,14 @@ 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 style of bar indicator
|
||||
* Set the styles of a bar
|
||||
* @param bar pointer to a bar object
|
||||
* @param style pointer to a style
|
||||
* @param bg pointer to the background's style
|
||||
* @param indic pointer to the indicator's style
|
||||
*/
|
||||
void lv_bar_set_indicator_style(lv_obj_t * bar, lv_style_t * style);
|
||||
void lv_bar_set_styles(lv_obj_t * bar, lv_style_t * bg, lv_style_t * indic);
|
||||
|
||||
/**
|
||||
* Get the value of a bar
|
||||
@ -116,7 +118,21 @@ int16_t lv_bar_get_max_value(lv_obj_t * bar);
|
||||
* @param bar pointer to a bar object
|
||||
* @return pointer to the bar indicator style
|
||||
*/
|
||||
lv_style_t * lv_bar_get_indicator_style(lv_obj_t * bar);
|
||||
lv_style_t * lv_bar_get_style_indicator(lv_obj_t * bar);
|
||||
|
||||
/****************************
|
||||
* TRANSPARENT API FUNCTIONS
|
||||
***************************/
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
|
@ -256,9 +256,9 @@ void lv_btn_toggle(lv_obj_t * btn)
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a function to call when the button is pressed
|
||||
* Set a function to call when the button event happens
|
||||
* @param btn pointer to a button object
|
||||
* @param pr_action pointer to function
|
||||
* @param action type of event form 'lv_action_t' (press, release, long press, long press repeat)
|
||||
*/
|
||||
void lv_btn_set_action(lv_obj_t * btn, lv_btn_action_t type, lv_action_t action)
|
||||
{
|
||||
@ -271,37 +271,29 @@ 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_style pointer to a style for releases state
|
||||
* @param pr_style pointer to a style for pressed state
|
||||
* @param tgl_rel_style pointer to a style for toggled releases state
|
||||
* @param tgl_pr_style pointer to a style for toggled pressed state
|
||||
* @param inactive_style pointer to a style for inactive state
|
||||
* @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_styles(lv_obj_t * btn, lv_style_t *rel_style, lv_style_t *pr_style,
|
||||
lv_style_t *tgl_rel_style, lv_style_t *tgl_pr_style,
|
||||
lv_style_t *inactive_style)
|
||||
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)
|
||||
{
|
||||
lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn);
|
||||
|
||||
if(rel_style != NULL) ext->styles[LV_BTN_STATE_RELEASED] = rel_style;
|
||||
if(pr_style != NULL) ext->styles[LV_BTN_STATE_PRESSED] = pr_style;
|
||||
if(tgl_rel_style != NULL) ext->styles[LV_BTN_STATE_TGL_RELEASED] = tgl_rel_style;
|
||||
if(tgl_pr_style != NULL) ext->styles[LV_BTN_STATE_TGL_PRESSED] = tgl_pr_style;
|
||||
if(inactive_style != NULL) ext->styles[LV_BTN_STATE_INACTIVE] = inactive_style;
|
||||
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;
|
||||
|
||||
/*Refresh the object with the new style*/
|
||||
lv_obj_set_style(btn, ext->styles[ext->state]);
|
||||
}
|
||||
|
||||
|
||||
void lv_btn_set_style_all(lv_obj_t * btn, lv_style_t ** style_array)
|
||||
{
|
||||
lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn);
|
||||
memcpy(ext->styles, style_array, sizeof(ext->styles));
|
||||
|
||||
lv_obj_set_style(btn, ext->styles[ext->state]);
|
||||
}
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
|
@ -107,24 +107,24 @@ void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state);
|
||||
void lv_btn_toggle(lv_obj_t * btn);
|
||||
|
||||
/**
|
||||
* Set a function to call when the button is pressed
|
||||
* Set a function to call when the button event happens
|
||||
* @param btn pointer to a button object
|
||||
* @param pr_action pointer to function
|
||||
* @param action type of event form 'lv_action_t' (press, release, long press, long press repeat)
|
||||
*/
|
||||
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_style pointer to a style for releases state
|
||||
* @param pr_style pointer to a style for pressed state
|
||||
* @param tgl_rel_style pointer to a style for toggled releases state
|
||||
* @param tgl_pr_style pointer to a style for toggled pressed state
|
||||
* @param inactive_style pointer to a style for inactive state
|
||||
* @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 inactive pointer to a style for inactive state
|
||||
*/
|
||||
void lv_btn_set_styles(lv_obj_t * btn, lv_style_t *rel_style, lv_style_t *pr_style,
|
||||
lv_style_t *tgl_rel_style, lv_style_t *tgl_pr_style,
|
||||
lv_style_t *inactive_style);
|
||||
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);
|
||||
|
||||
/**
|
||||
* Get the current state of the button
|
||||
@ -155,6 +155,63 @@ lv_action_t lv_btn_get_action(lv_obj_t * btn, lv_btn_action_t type);
|
||||
*/
|
||||
lv_style_t * lv_btn_get_style(lv_obj_t * btn, lv_btn_state_t state);
|
||||
|
||||
|
||||
/****************************
|
||||
* TRANSPARENT API FUNCTIONS
|
||||
***************************/
|
||||
|
||||
/**
|
||||
* Set the layout on a button
|
||||
* @param btn pointer to a button object
|
||||
* @param layout a layout from 'lv_cont_layout_t'
|
||||
*/
|
||||
static inline void lv_btn_set_layout(lv_obj_t * btn, lv_cont_layout_t layout)
|
||||
{
|
||||
lv_cont_set_layout(btn, layout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the horizontal or vertical fit.
|
||||
* The button size will be set to involve the children horizontally or vertically.
|
||||
* @param btn pointer to a button object
|
||||
* @param hor_en true: enable the horizontal fit
|
||||
* @param ver_en true: enable the vertical fit
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the layout of a button
|
||||
* @param btn pointer to button object
|
||||
* @return the layout from 'lv_cont_layout_t'
|
||||
*/
|
||||
static inline lv_cont_layout_t lv_btn_get_layout(lv_obj_t * btn)
|
||||
{
|
||||
return lv_cont_get_layout(btn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get horizontal fit enable attribute of a button
|
||||
* @param btn pointer to a button object
|
||||
* @return true: horizontal fit is enabled; false: disabled
|
||||
*/
|
||||
static inline bool lv_btn_get_hor_fit(lv_obj_t * btn)
|
||||
{
|
||||
return lv_cont_get_fit_hor(btn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get vertical fit enable attribute of a container
|
||||
* @param btn pointer to a button object
|
||||
* @return true: vertical fit is enabled; false: disabled
|
||||
*/
|
||||
static inline bool lv_btn_get_ver_fit(lv_obj_t * btn)
|
||||
{
|
||||
return lv_cont_get_fit_ver(btn);
|
||||
}
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
@ -31,6 +31,7 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_
|
||||
static uint8_t get_button_width(const char * btn_str);
|
||||
static bool button_is_hidden(const char * btn_str);
|
||||
static bool button_is_repeat_disabled(const char * btn_str);
|
||||
static bool button_is_inactive(const char * btn_str);
|
||||
const char * cut_ctrl_byte(const char * btn_str);
|
||||
static uint16_t get_button_from_point(lv_obj_t * btnm, point_t * p);
|
||||
static uint16_t get_button_text(lv_obj_t * btnm, uint16_t btn_id);
|
||||
@ -65,7 +66,7 @@ static lv_design_func_t ancestor_design_f;
|
||||
lv_obj_t * lv_btnm_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
{
|
||||
/*Create the ancestor object*/
|
||||
lv_obj_t * new_btnm = lv_cont_create(par, copy);
|
||||
lv_obj_t * new_btnm = lv_obj_create(par, copy);
|
||||
dm_assert(new_btnm);
|
||||
|
||||
/*Allocate the object type specific extended data*/
|
||||
@ -78,11 +79,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->button_styles[LV_BTN_STATE_RELEASED] = &lv_style_btn_off_released;
|
||||
ext->button_styles[LV_BTN_STATE_PRESSED] = &lv_style_btn_off_pressed;
|
||||
ext->button_styles[LV_BTN_STATE_TGL_RELEASED] = &lv_style_btn_on_released;
|
||||
ext->button_styles[LV_BTN_STATE_TGL_PRESSED] = &lv_style_btn_on_pressed;
|
||||
ext->button_styles[LV_BTN_STATE_INACTIVE] = &lv_style_btn_inactive;
|
||||
ext->styles_btn[LV_BTN_STATE_RELEASED] = &lv_style_btn_off_released;
|
||||
ext->styles_btn[LV_BTN_STATE_PRESSED] = &lv_style_btn_off_pressed;
|
||||
ext->styles_btn[LV_BTN_STATE_TGL_RELEASED] = &lv_style_btn_on_released;
|
||||
ext->styles_btn[LV_BTN_STATE_TGL_PRESSED] = &lv_style_btn_on_pressed;
|
||||
ext->styles_btn[LV_BTN_STATE_INACTIVE] = &lv_style_btn_inactive;
|
||||
|
||||
if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_func(new_btnm);
|
||||
|
||||
@ -98,7 +99,7 @@ lv_obj_t * lv_btnm_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
/*Copy an existing object*/
|
||||
else {
|
||||
lv_btnm_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
|
||||
memcpy(ext->button_styles, copy_ext->button_styles, sizeof(ext->button_styles));
|
||||
memcpy(ext->styles_btn, copy_ext->styles_btn, sizeof(ext->styles_btn));
|
||||
ext->action = copy_ext->action;
|
||||
lv_btnm_set_map(new_btnm, lv_btnm_get_map(copy));
|
||||
}
|
||||
@ -118,7 +119,7 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
|
||||
bool valid;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
valid = lv_cont_signal(btnm, sign, param);
|
||||
valid = lv_obj_signal(btnm, sign, param);
|
||||
|
||||
/* The object can be deleted so check its validity and then
|
||||
* make the object specific signal handling */
|
||||
@ -167,7 +168,8 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
|
||||
if(ext->action && ext->button_id_pressed != LV_BTNM_PR_NONE) {
|
||||
uint16_t txt_i = get_button_text(btnm, ext->button_id_pressed);
|
||||
if(txt_i != LV_BTNM_PR_NONE) {
|
||||
if(button_is_repeat_disabled(ext->map_p[txt_i]) == false) {
|
||||
if(button_is_repeat_disabled(ext->map_p[txt_i]) == false &&
|
||||
button_is_inactive(ext->map_p[txt_i]) == false) {
|
||||
ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i]));
|
||||
}
|
||||
}
|
||||
@ -177,7 +179,7 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
|
||||
if(ext->button_id_pressed != LV_BTNM_PR_NONE) {
|
||||
if(ext->action) {
|
||||
uint16_t txt_i = get_button_text(btnm, ext->button_id_pressed);
|
||||
if(txt_i != LV_BTNM_PR_NONE) {
|
||||
if(txt_i != LV_BTNM_PR_NONE && button_is_inactive(ext->map_p[txt_i]) == false) {
|
||||
ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i]));
|
||||
}
|
||||
}
|
||||
@ -249,7 +251,7 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
|
||||
* The first byte can be a control data:
|
||||
* - bit 7: always 1
|
||||
* - bit 6: always 0
|
||||
* - bit 5: reserved
|
||||
* - bit 5: inactive (disabled)
|
||||
* - bit 4: no repeat (on long press)
|
||||
* - bit 3: hidden
|
||||
* - bit 2..0: button relative width
|
||||
@ -375,24 +377,24 @@ 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_style pointer to a style for releases state
|
||||
* @param pr_style pointer to a style for pressed state
|
||||
* @param tgl_rel_style pointer to a style for toggled releases state
|
||||
* @param tgl_pr_style pointer to a style for toggled pressed state
|
||||
* @param inactive_style pointer to a style for inactive state
|
||||
* @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_button_style(lv_obj_t *btnm, lv_style_t *rel_style, lv_style_t *pr_style,
|
||||
lv_style_t *tgl_rel_style, lv_style_t *tgl_pr_style,
|
||||
lv_style_t *inactive_style)
|
||||
void lv_btnm_set_style(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)
|
||||
|
||||
{
|
||||
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
|
||||
|
||||
if(rel_style != NULL) ext->button_styles[LV_BTN_STATE_RELEASED] = rel_style;
|
||||
if(pr_style != NULL) ext->button_styles[LV_BTN_STATE_PRESSED] = pr_style;
|
||||
if(tgl_rel_style != NULL) ext->button_styles[LV_BTN_STATE_TGL_RELEASED] = tgl_rel_style;
|
||||
if(tgl_pr_style != NULL) ext->button_styles[LV_BTN_STATE_TGL_PRESSED] = tgl_pr_style;
|
||||
if(inactive_style != NULL) ext->button_styles[LV_BTN_STATE_INACTIVE] = inactive_style;
|
||||
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);
|
||||
}
|
||||
@ -434,7 +436,7 @@ lv_style_t * lv_btnm_get_button_style(lv_obj_t * btnm, lv_btn_state_t state)
|
||||
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->button_styles[state];
|
||||
lv_style_t * style = ext->styles_btn[state];
|
||||
|
||||
if(style == NULL) style = lv_obj_get_style(btnm);
|
||||
|
||||
@ -495,12 +497,12 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_
|
||||
btn_h = area_get_height(&area_tmp);
|
||||
|
||||
/*Load the style*/
|
||||
if(btn_i != ext->button_id_pressed && btn_i != ext->button_id_toggled) btn_style = lv_btnm_get_button_style(btnm, LV_BTN_STATE_RELEASED);
|
||||
if(button_is_inactive(ext->map_p[txt_i])) btn_style = lv_btnm_get_button_style(btnm, LV_BTN_STATE_INACTIVE);
|
||||
else if(btn_i != ext->button_id_pressed && btn_i != ext->button_id_toggled) btn_style = lv_btnm_get_button_style(btnm, LV_BTN_STATE_RELEASED);
|
||||
else if(btn_i == ext->button_id_pressed && btn_i != ext->button_id_toggled) btn_style = lv_btnm_get_button_style(btnm, LV_BTN_STATE_PRESSED);
|
||||
else if(btn_i != ext->button_id_pressed && btn_i == ext->button_id_toggled) btn_style = lv_btnm_get_button_style(btnm, LV_BTN_STATE_TGL_RELEASED);
|
||||
else if(btn_i == ext->button_id_pressed && btn_i == ext->button_id_toggled) btn_style = lv_btnm_get_button_style(btnm, LV_BTN_STATE_TGL_PRESSED);
|
||||
|
||||
lv_draw_rect(&area_tmp, mask, btn_style);
|
||||
lv_draw_rect(&area_tmp, mask, btn_style);
|
||||
|
||||
/*Calculate the size of the text*/
|
||||
const font_t * font = btn_style->text.font;
|
||||
@ -586,6 +588,18 @@ static bool button_is_repeat_disabled(const char * btn_str)
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool button_is_inactive(const char * btn_str)
|
||||
{
|
||||
/*If control byte presents and hidden bit is '1' then the button is hidden*/
|
||||
if(((btn_str[0] & LV_BTNM_CTRL_MASK) == LV_BTNM_CTRL_CODE) &&
|
||||
(btn_str[0] & LV_BTNM_INACTIVE_MASK)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const char * cut_ctrl_byte(const char * btn_str)
|
||||
{
|
||||
/*Cut the control byte if present*/
|
||||
|
@ -29,9 +29,9 @@ extern "C" {
|
||||
#define LV_BTNM_CTRL_CODE 0x80 /*The control byte has to begin (if present) with 0b10xxxxxx*/
|
||||
#define LV_BTNM_CTRL_MASK 0xC0
|
||||
#define LV_BTNM_WIDTH_MASK 0x07
|
||||
#define LV_BTNM_HIDE_MASK 0x08
|
||||
#define LV_BTNM_HIDE_MASK 0x08
|
||||
#define LV_BTNM_REPEAT_DISABLE_MASK 0x10
|
||||
#define LV_BTNM_RESERVED_MASK 0x20
|
||||
#define LV_BTNM_INACTIVE_MASK 0x20
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
@ -45,12 +45,12 @@ typedef lv_res_t (*lv_btnm_action_t) (lv_obj_t *, const char *txt);
|
||||
/*Data of button matrix*/
|
||||
typedef struct
|
||||
{
|
||||
lv_cont_ext_t bg; /*Ext. of ancestor*/
|
||||
/*No inherited ext.*/ /*Ext. of ancestor*/
|
||||
/*New data for this type */
|
||||
const char ** map_p; /*Pointer to the current map*/
|
||||
area_t * button_areas; /*Array of areas of buttons*/
|
||||
area_t *button_areas; /*Array of areas of buttons*/
|
||||
lv_btnm_action_t action; /*A function to call when a button is releases*/
|
||||
lv_style_t * button_styles[LV_BTN_STATE_NUM]; /*Styles of buttons in each state*/
|
||||
lv_style_t *styles_btn[LV_BTN_STATE_NUM]; /*Styles of buttons in each state*/
|
||||
uint16_t button_cnt; /*Number of button in 'map_p'(Handled by the library)*/
|
||||
uint16_t button_id_pressed; /*Index of the currently pressed button or LV_BTNM_PR_NONE*/
|
||||
uint16_t button_id_toggled; /*Index of the currently toggled button or LV_BTNM_PR_NONE */
|
||||
@ -87,7 +87,7 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param);
|
||||
* The first byte can be a control data:
|
||||
* - bit 7: always 1
|
||||
* - bit 6: always 0
|
||||
* - bit 5: reserved
|
||||
* - bit 5: inactive (disabled)
|
||||
* - bit 4: no repeat (on long press)
|
||||
* - bit 3: hidden
|
||||
* - bit 2..0: button relative width
|
||||
@ -120,9 +120,9 @@ void lv_btnm_set_toggle(lv_obj_t * btnm, bool en, uint16_t id);
|
||||
* @param tgl_pr_style pointer to a style for toggled pressed state
|
||||
* @param inactive_style pointer to a style for inactive state
|
||||
*/
|
||||
void lv_btnm_set_button_style(lv_obj_t *btnm, lv_style_t *rel_style, lv_style_t *pr_style,
|
||||
lv_style_t *tgl_rel_style, lv_style_t *tgl_pr_style,
|
||||
lv_style_t *inactive_style);
|
||||
void lv_btnm_set_style(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);
|
||||
/**
|
||||
* Get the current map of a button matrix
|
||||
* @param btnm pointer to a button matrix object
|
||||
|
@ -69,7 +69,7 @@ lv_obj_t * lv_cb_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
/*Init the new checkbox object*/
|
||||
if(copy == NULL) {
|
||||
ext->bullet = lv_btn_create(new_cb, NULL);
|
||||
lv_btn_set_styles(new_cb, &lv_style_transp, &lv_style_transp,
|
||||
lv_btn_set_style(new_cb, &lv_style_transp, &lv_style_transp,
|
||||
&lv_style_transp, &lv_style_transp,
|
||||
&lv_style_transp);
|
||||
|
||||
@ -80,7 +80,7 @@ lv_obj_t * lv_cb_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
if(ancestor_bullet_design_f == NULL) ancestor_bullet_design_f = lv_obj_get_design_func(ext->bullet);
|
||||
|
||||
lv_obj_set_click(ext->bullet, false);
|
||||
lv_btn_set_styles(ext->bullet, &lv_style_pretty, &lv_style_pretty_color,
|
||||
lv_btn_set_style(ext->bullet, &lv_style_pretty, &lv_style_pretty_color,
|
||||
&lv_style_btn_on_released, &lv_style_btn_on_pressed,
|
||||
NULL);
|
||||
|
||||
@ -125,17 +125,17 @@ bool lv_cb_signal(lv_obj_t * cb, lv_signal_t sign, void * param)
|
||||
if(valid != false) {
|
||||
if(sign == LV_SIGNAL_STYLE_CHG) {
|
||||
lv_obj_set_size(ext->bullet, font_get_height(style->text.font), font_get_height(style->text.font));
|
||||
lv_btn_set_state(lv_cb_get_bullet(cb), lv_btn_get_state(cb));
|
||||
lv_btn_set_state(ext->bullet, lv_btn_get_state(cb));
|
||||
} else if(sign == LV_SIGNAL_PRESSED ||
|
||||
sign == LV_SIGNAL_RELEASED ||
|
||||
sign == LV_SIGNAL_PRESS_LOST) {
|
||||
lv_btn_set_state(lv_cb_get_bullet(cb), lv_btn_get_state(cb));
|
||||
lv_btn_set_state(ext->bullet, lv_btn_get_state(cb));
|
||||
} else if(sign == LV_SIGNAL_CONTROLL) {
|
||||
char c = *((char*)param);
|
||||
if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_DOWN ||
|
||||
c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_UP ||
|
||||
c == LV_GROUP_KEY_ENTER) {
|
||||
lv_btn_set_state(lv_cb_get_bullet(cb), lv_btn_get_state(cb));
|
||||
lv_btn_set_state(ext->bullet, lv_btn_get_state(cb));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -159,6 +159,23 @@ void lv_cb_set_text(lv_obj_t * cb, const char * txt)
|
||||
lv_label_set_text(ext->label, txt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set styles of a checkbox's bullet 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
|
||||
*/
|
||||
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)
|
||||
{
|
||||
lv_cb_ext_t * ext = lv_obj_get_ext_attr(cb);
|
||||
lv_btn_set_style(ext->bullet, rel, pr, tgl_rel, tgl_pr, ina);
|
||||
}
|
||||
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
@ -175,17 +192,6 @@ const char * lv_cb_get_text(lv_obj_t * cb)
|
||||
return lv_label_get_text(ext->label);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bullet (lv_btn) of a check box
|
||||
* @param cb pointer to check box object
|
||||
* @return pointer to the bullet of the check box (lv_btn)
|
||||
*/
|
||||
lv_obj_t * lv_cb_get_bullet(lv_obj_t * cb)
|
||||
{
|
||||
lv_cb_ext_t * ext = lv_obj_get_ext_attr(cb);
|
||||
return ext->bullet;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
@ -73,6 +73,20 @@ bool lv_cb_signal(lv_obj_t * cb, lv_signal_t sign, void * param);
|
||||
*/
|
||||
void lv_cb_set_text(lv_obj_t * cb, const char * txt);
|
||||
|
||||
|
||||
/**
|
||||
* Set styles of a checkbox's bullet is each state. Use NULL for any style to leave it unchanged
|
||||
* @param cb pointer to checkbox 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);
|
||||
|
||||
/**
|
||||
* Get the text of a check box
|
||||
* @param cb pointer to check box object
|
||||
@ -80,12 +94,86 @@ void lv_cb_set_text(lv_obj_t * cb, const char * txt);
|
||||
*/
|
||||
const char * lv_cb_get_text(lv_obj_t * cb);
|
||||
|
||||
/******************************
|
||||
* TRANSPARENT API FUNCTIONS
|
||||
******************************/
|
||||
|
||||
/**
|
||||
* Get the bullet (lv_btn) of a check box
|
||||
* @param cb pointer to check box object
|
||||
* @return pointer to the bullet of the check box (lv_btn)
|
||||
* Set the state of the check box
|
||||
* @param cb pointer to a check box object
|
||||
* @param checked true: make the check box checked; false: make it unchecked
|
||||
*/
|
||||
lv_obj_t * lv_cb_get_bullet(lv_obj_t * cb);
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the check box inactive (disabled)
|
||||
* @param cb pointer to a check box object
|
||||
*/
|
||||
static inline void lv_cb_set_inactive(lv_obj_t * cb)
|
||||
{
|
||||
lv_btn_set_state(cb, LV_BTN_STATE_INACTIVE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a function to call when the button is pressed
|
||||
* @param cb pointer to a check box object
|
||||
*/
|
||||
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_bg(lv_obj_t *cb, lv_style_t *bg)
|
||||
{
|
||||
lv_btn_set_style(cb, bg, bg, bg, bg, bg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the current state of the check box
|
||||
* @param cb pointer to a check box object
|
||||
* @return true: checked; false: not checked
|
||||
*/
|
||||
static inline bool lv_cb_is_checked(lv_obj_t * cb)
|
||||
{
|
||||
return lv_btn_get_state(cb) == LV_BTN_STATE_RELEASED ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the action of a check box
|
||||
* @param cb pointer to a button object
|
||||
* @return pointer to the action function
|
||||
*/
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
|
@ -157,8 +157,8 @@ void lv_cont_set_layout(lv_obj_t * cont, lv_cont_layout_t layout)
|
||||
* Enable the horizontal or vertical fit.
|
||||
* The container size will be set to involve the children horizontally or vertically.
|
||||
* @param cont pointer to a container object
|
||||
* @param hor_en true: enable the horizontal padding
|
||||
* @param ver_en true: enable the vertical padding
|
||||
* @param hor_en true: enable the horizontal fit
|
||||
* @param ver_en true: enable the vertical fit
|
||||
*/
|
||||
void lv_cont_set_fit(lv_obj_t * cont, bool hor_en, bool ver_en)
|
||||
{
|
||||
@ -189,9 +189,9 @@ lv_cont_layout_t lv_cont_get_layout(lv_obj_t * cont)
|
||||
/**
|
||||
* Get horizontal fit enable attribute of a container
|
||||
* @param cont pointer to a container object
|
||||
* @return true: horizontal padding is enabled
|
||||
* @return true: horizontal fit is enabled; false: disabled
|
||||
*/
|
||||
bool lv_cont_get_hor_fit(lv_obj_t * cont)
|
||||
bool lv_cont_get_fit_hor(lv_obj_t * cont)
|
||||
{
|
||||
lv_cont_ext_t * ext = lv_obj_get_ext_attr(cont);
|
||||
return ext->hor_fit == 0 ? false : true;
|
||||
@ -200,9 +200,9 @@ bool lv_cont_get_hor_fit(lv_obj_t * cont)
|
||||
/**
|
||||
* Get vertical fit enable attribute of a container
|
||||
* @param cont pointer to a container object
|
||||
* @return true: vertical padding is enabled
|
||||
* @return true: vertical fit is enabled; false: disabled
|
||||
*/
|
||||
bool lv_cont_get_ver_fit(lv_obj_t * cont)
|
||||
bool lv_cont_get_fit_ver(lv_obj_t * cont)
|
||||
{
|
||||
lv_cont_ext_t * ext = lv_obj_get_ext_attr(cont);
|
||||
return ext->ver_fit == 0 ? false : true;
|
||||
|
@ -97,16 +97,16 @@ lv_cont_layout_t lv_cont_get_layout(lv_obj_t * cont);
|
||||
/**
|
||||
* Get horizontal fit enable attribute of a container
|
||||
* @param cont pointer to a container object
|
||||
* @return true: horizontal padding is enabled
|
||||
* @return true: horizontal fit is enabled; false: disabled
|
||||
*/
|
||||
bool lv_cont_get_hor_fit(lv_obj_t * cont);
|
||||
bool lv_cont_get_fit_hor(lv_obj_t * cont);
|
||||
|
||||
/**
|
||||
* Get vertical fit enable attribute of a container
|
||||
* @param cont pointer to a container object
|
||||
* @return true: vertical padding is enabled
|
||||
* Get vertical fit enable attribute of a button
|
||||
* @param btn pointer to a button object
|
||||
* @return true: vertical padding is enabled; false: disabled
|
||||
*/
|
||||
bool lv_cont_get_ver_fit(lv_obj_t * cont);
|
||||
bool lv_cont_get_fit_ver(lv_obj_t * cont);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
|
@ -213,7 +213,9 @@ 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_all(liste, ext->styles_btn);
|
||||
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_action(liste, LV_BTN_ACTION_RELEASE, rel_action);
|
||||
lv_page_glue_obj(liste, true);
|
||||
@ -372,7 +374,7 @@ void lv_list_set_btn_styles(lv_obj_t * list, lv_style_t * rel, lv_style_t * pr,
|
||||
lv_obj_t * liste = lv_list_get_next_btn(list, NULL);
|
||||
while(liste != NULL)
|
||||
{
|
||||
lv_btn_set_styles(liste, rel, pr, trel, tpr, ina);
|
||||
lv_btn_set_style(liste, rel, pr, trel, tpr, ina);
|
||||
liste = lv_list_get_next_btn(list, liste);
|
||||
}
|
||||
}
|
||||
|
@ -48,8 +48,8 @@ typedef struct
|
||||
{
|
||||
lv_page_ext_t page; /*Ext. of ancestor*/
|
||||
/*New data for this type */
|
||||
lv_style_t * styles_btn[LV_BTN_STATE_NUM]; /*Styles of the list element buttons*/
|
||||
lv_style_t * style_img; /*Style of the list element images on buttons*/
|
||||
lv_style_t *styles_btn[LV_BTN_STATE_NUM]; /*Styles of the list element buttons*/
|
||||
lv_style_t *style_img; /*Style of the list element images on buttons*/
|
||||
uint8_t sb_out :1; /*1: Keep space for the scrollbar*/
|
||||
}lv_list_ext_t;
|
||||
|
||||
|
@ -142,7 +142,7 @@ bool lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param)
|
||||
btn = lv_obj_get_child(ext->btnh, NULL);
|
||||
while(btn != NULL) {
|
||||
/*Refresh the next button's style*/
|
||||
lv_btn_set_styles(btn, ext->style_btn_rel, ext->style_btn_pr, NULL, NULL, NULL);
|
||||
lv_btn_set_style(btn, ext->style_btn_rel, ext->style_btn_pr, NULL, NULL, NULL);
|
||||
btn = lv_obj_get_child(ext->btnh, btn);
|
||||
}
|
||||
}
|
||||
@ -273,7 +273,7 @@ lv_obj_t * lv_mbox_add_btn(lv_obj_t * mbox, const char * btn_txt, lv_action_t re
|
||||
lv_obj_t * btn;
|
||||
btn = lv_btn_create(ext->btnh, NULL);
|
||||
lv_btn_set_action(btn, LV_BTN_ACTION_RELEASE, rel_action);
|
||||
lv_btn_set_styles(btn, ext->style_btn_rel, ext->style_btn_pr, NULL, NULL, NULL);
|
||||
lv_btn_set_style(btn, ext->style_btn_rel, ext->style_btn_pr, NULL, NULL, NULL);
|
||||
lv_cont_set_fit(btn, true, true);
|
||||
|
||||
lv_obj_t * label;
|
||||
@ -322,7 +322,7 @@ void lv_mbox_set_styles_btn(lv_obj_t * mbox, lv_style_t * rel, lv_style_t * pr)
|
||||
lv_obj_t * btn = lv_obj_get_child(ext->btnh, NULL);
|
||||
|
||||
while(btn != NULL) {
|
||||
lv_btn_set_styles(btn, rel, pr, NULL, NULL, NULL);
|
||||
lv_btn_set_style(btn, rel, pr, NULL, NULL, NULL);
|
||||
btn = lv_obj_get_child(mbox, btn);
|
||||
}
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param)
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_STYLE_CHG) {
|
||||
lv_style_t * style = lv_obj_get_style(page);
|
||||
if(lv_cont_get_hor_fit(ext->scrl) == false) {
|
||||
if(lv_cont_get_fit_hor(ext->scrl) == false) {
|
||||
lv_obj_set_width(ext->scrl, lv_obj_get_width(page) - 2 * style->body.padding.hor);
|
||||
} else {
|
||||
ext->scrl->signal_func(ext->scrl, LV_SIGNAL_CORD_CHG, &ext->scrl->coords);
|
||||
@ -177,7 +177,7 @@ bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param)
|
||||
(lv_obj_get_width(page) != area_get_width(param) ||
|
||||
lv_obj_get_height(page) != area_get_height(param))) {
|
||||
|
||||
if(lv_cont_get_hor_fit(ext->scrl) == false) {
|
||||
if(lv_cont_get_fit_hor(ext->scrl) == false) {
|
||||
lv_obj_set_width(ext->scrl, lv_obj_get_width(page) - 2 * style->body.padding.hor);
|
||||
}
|
||||
|
||||
@ -228,7 +228,7 @@ bool lv_page_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param)
|
||||
if(sign == LV_SIGNAL_CORD_CHG) {
|
||||
|
||||
/*Be sure the width of the scrollable is correct*/
|
||||
if(lv_cont_get_hor_fit(scrl) == false) {
|
||||
if(lv_cont_get_fit_hor(scrl) == false) {
|
||||
lv_obj_set_width(scrl, lv_obj_get_width(page) - 2 * page_style->body.padding.hor);
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ lv_obj_t * lv_slider_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
dm_assert(ext);
|
||||
|
||||
/*Initialize the allocated 'ext' */
|
||||
ext->cb = NULL;
|
||||
ext->action = NULL;
|
||||
ext->tmp_value = ext->bar.min_value;
|
||||
ext->style_knob = &lv_style_pretty;
|
||||
ext->knob_in = 0;
|
||||
@ -78,13 +78,13 @@ 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_knob_style(new_slider, ext->style_knob);
|
||||
lv_slider_set_style(new_slider, NULL, NULL, ext->style_knob);
|
||||
}
|
||||
/*Copy an existing slider*/
|
||||
else {
|
||||
lv_slider_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
|
||||
ext->style_knob = copy_ext->style_knob;
|
||||
ext->cb = copy_ext->cb;
|
||||
ext->action = copy_ext->action;
|
||||
ext->knob_in = copy_ext->knob_in;
|
||||
/*Refresh the style with new signal function*/
|
||||
lv_obj_refresh_style(new_slider);
|
||||
@ -140,7 +140,7 @@ bool lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * param)
|
||||
else if (sign == LV_SIGNAL_RELEASED) {
|
||||
ext->tmp_value = lv_bar_get_value(slider);
|
||||
lv_bar_set_value(slider, ext->tmp_value);
|
||||
if(ext->cb != NULL) ext->cb(slider);
|
||||
if(ext->action != NULL) ext->action(slider);
|
||||
}
|
||||
else if(sign == LV_SIGNAL_CORD_CHG) {
|
||||
/* The knob size depends on slider size.
|
||||
@ -167,10 +167,10 @@ bool lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * param)
|
||||
char c = *((char*)param);
|
||||
if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_UP) {
|
||||
lv_bar_set_value(slider, lv_bar_get_value(slider) + 1);
|
||||
if(ext->cb != NULL) ext->cb(slider);
|
||||
if(ext->action != NULL) ext->action(slider);
|
||||
} else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_DOWN) {
|
||||
lv_bar_set_value(slider, lv_bar_get_value(slider) - 1);
|
||||
if(ext->cb != NULL) ext->cb(slider);
|
||||
if(ext->action != NULL) ext->action(slider);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -185,27 +185,32 @@ bool lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * param)
|
||||
/**
|
||||
* Set a function which will be called when a new value is set on the slider
|
||||
* @param slider pointer to slider object
|
||||
* @param cb a callback function
|
||||
* @param action a callback function
|
||||
*/
|
||||
void lv_slider_set_action(lv_obj_t * slider, lv_action_t cb)
|
||||
void lv_slider_set_action(lv_obj_t * slider, lv_action_t action)
|
||||
{
|
||||
lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider);
|
||||
ext->cb = cb;
|
||||
ext->action = action;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the style of knob on a slider
|
||||
* @param slider pointer to slider object
|
||||
* @param style pointer the new knob style
|
||||
* Set the styles of a slider
|
||||
* @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 knob pointer to the knob's style (NULL to leave unchanged)
|
||||
*/
|
||||
void lv_slider_set_knob_style(lv_obj_t * slider, lv_style_t * style)
|
||||
void lv_slider_set_style(lv_obj_t * slider, lv_style_t *bg, lv_style_t *indic, lv_style_t *knob)
|
||||
{
|
||||
lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider);
|
||||
ext->style_knob = 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);
|
||||
}
|
||||
|
||||
slider->signal_func(slider, LV_SIGNAL_REFR_EXT_SIZE, NULL);
|
||||
|
||||
lv_obj_invalidate(slider);
|
||||
lv_bar_set_styles(slider, bg, indic);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -225,24 +230,26 @@ void lv_slider_set_knob_in(lv_obj_t * slider, bool in)
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Get the slider callback function
|
||||
* Get the slider action function
|
||||
* @param slider pointer to slider object
|
||||
* @return the callback function
|
||||
*/
|
||||
lv_action_t lv_slider_get_action(lv_obj_t * slider)
|
||||
{
|
||||
lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider);
|
||||
return ext->cb;
|
||||
return ext->action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the style of knob on a slider
|
||||
* @param slider pointer to slider object
|
||||
* @return pointer the new knob style
|
||||
* Set the styles of a slider
|
||||
* @param slider pointer to a bar object
|
||||
* @return pointer to the knob's style
|
||||
*/
|
||||
lv_style_t * lv_slider_get_style_knob(lv_obj_t * slider)
|
||||
lv_style_t * lv_slider_get_style_knob(lv_obj_t * slider)
|
||||
{
|
||||
lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider);
|
||||
return ext->style_knob;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -282,9 +289,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_obj_get_style(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_bar_get_indicator_style(slider);
|
||||
lv_style_t * style_indic = lv_slider_get_style_indicator(slider);
|
||||
|
||||
/*Draw the bar*/
|
||||
area_t area_bar;
|
||||
|
@ -31,8 +31,8 @@ typedef struct
|
||||
{
|
||||
lv_bar_ext_t bar; /*Ext. of ancestor*/
|
||||
/*New data for this type */
|
||||
lv_action_t cb; /*Function to call when a new value is set*/
|
||||
lv_style_t * style_knob; /*Style of the knob*/
|
||||
lv_action_t action; /*Function to call when a new value is set*/
|
||||
lv_style_t *style_knob; /*Style of the knob*/
|
||||
int16_t tmp_value; /*Store a temporal value during press until release (Handled by the library)*/
|
||||
uint8_t knob_in :1; /*1: Draw the knob inside the bar*/
|
||||
}lv_slider_ext_t;
|
||||
@ -72,11 +72,13 @@ bool lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * param);
|
||||
void lv_slider_set_action(lv_obj_t * slider, lv_action_t cb);
|
||||
|
||||
/**
|
||||
* Set the style of knob on a slider
|
||||
* @param slider pointer to slider object
|
||||
* @param style pointer the new knob style
|
||||
* Set the styles of a slider
|
||||
* @param bar pointer to a bar object
|
||||
* @param bg pointer to the background's style
|
||||
* @param indic pointer to the indicator's style
|
||||
* @param knob pointer to the knob's style
|
||||
*/
|
||||
void lv_slider_set_knob_style(lv_obj_t * slider, lv_style_t * style);
|
||||
void lv_slider_set_style(lv_obj_t * slider, lv_style_t *bg, lv_style_t *indic, lv_style_t *knob);
|
||||
|
||||
/**
|
||||
* Set the 'knob in' attribute of a slider
|
||||
@ -93,12 +95,13 @@ void lv_slider_set_knob_in(lv_obj_t * slider, bool in);
|
||||
*/
|
||||
lv_action_t lv_slider_get_action(lv_obj_t * slider);
|
||||
|
||||
|
||||
/**
|
||||
* Get the style of knob on a slider
|
||||
* @param slider pointer to slider object
|
||||
* @return pointer the new knob style
|
||||
* Set the styles of a slider
|
||||
* @param slider pointer to a bar object
|
||||
* @return pointer to the knob's style
|
||||
*/
|
||||
lv_style_t * lv_slider_get_style_knob(lv_obj_t * slider);
|
||||
lv_style_t * lv_slider_get_style_knob(lv_obj_t * slider);
|
||||
|
||||
/**
|
||||
* Get the 'knob in' attribute of a slider
|
||||
@ -108,6 +111,94 @@ lv_style_t * lv_slider_get_style_knob(lv_obj_t * slider);
|
||||
*/
|
||||
bool lv_slider_get_knob_in(lv_obj_t * slider);
|
||||
|
||||
|
||||
/******************************
|
||||
* TRANSPARENT API FUNCTIONS
|
||||
******************************/
|
||||
|
||||
/**
|
||||
* Set a new value on the slider
|
||||
* @param slider pointer to a slider object
|
||||
* @param value new value
|
||||
*/
|
||||
static inline void lv_slider_set_value(lv_obj_t * slider, int16_t value)
|
||||
{
|
||||
lv_bar_set_value(slider, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new value with animation on a slider
|
||||
* @param slider pointer to a slider object
|
||||
* @param value new value
|
||||
* @param anim_time animation time in milliseconds
|
||||
*/
|
||||
static inline void lv_slider_set_value_anim(lv_obj_t * slider, int16_t value, uint16_t anim_time)
|
||||
{
|
||||
lv_bar_set_value_anim(slider, value, anim_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set minimum and the maximum values of a bar
|
||||
* @param slider pointer to the slider object
|
||||
* @param min minimum value
|
||||
* @param max maximum value
|
||||
*/
|
||||
static inline void lv_slider_set_range(lv_obj_t *slider, int16_t min, int16_t max)
|
||||
{
|
||||
lv_bar_set_range(slider, min, max);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a slider
|
||||
* @param slider pointer to a slider object
|
||||
* @return the value of the slider
|
||||
*/
|
||||
static inline int16_t lv_slider_get_value(lv_obj_t * slider)
|
||||
{
|
||||
return lv_slider_get_value(slider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the minimum value of a slider
|
||||
* @param slider pointer to a slider object
|
||||
* @return the minimum value of the slider
|
||||
*/
|
||||
static inline int16_t lv_slider_slider_min_value(lv_obj_t * slider)
|
||||
{
|
||||
return lv_bar_get_min_value(slider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the maximum value of a slider
|
||||
* @param slider pointer to a slider object
|
||||
* @return the maximum value of the slider
|
||||
*/
|
||||
static inline int16_t lv_slider_get_max_value(lv_obj_t * slider)
|
||||
{
|
||||
return lv_bar_get_max_value(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
|
||||
*/
|
||||
static inline lv_style_t * lv_slider_get_style_indicator(lv_obj_t * slider)
|
||||
{
|
||||
return lv_bar_get_style_indicator(slider);
|
||||
}
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
@ -94,8 +94,8 @@ bool lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param)
|
||||
lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw);
|
||||
int16_t old_val = lv_bar_get_value(sw);
|
||||
|
||||
lv_action_t slider_cb = ext->slider.cb;
|
||||
ext->slider.cb = NULL; /*Do not let the slider to call the callback. The Switch will do it*/
|
||||
lv_action_t slider_cb = ext->slider.action;
|
||||
ext->slider.action = NULL; /*Do not let the slider to call the callback. The Switch will do it*/
|
||||
|
||||
/* Include the ancient signal function */
|
||||
valid = lv_slider_signal(sw, sign, param);
|
||||
@ -126,7 +126,7 @@ bool lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param)
|
||||
}
|
||||
|
||||
/*Restore the callback*/
|
||||
ext->slider.cb = slider_cb;
|
||||
ext->slider.action = slider_cb;
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
@ -60,6 +60,99 @@ lv_obj_t * lv_sw_create(lv_obj_t * par, lv_obj_t * copy);
|
||||
*/
|
||||
bool lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param);
|
||||
|
||||
/******************************
|
||||
* TRANSPARENT API FUNCTIONS
|
||||
******************************/
|
||||
|
||||
/**
|
||||
* Set the styles 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 pointer to the knob's style
|
||||
*/
|
||||
static inline void lv_sw_set_style(lv_obj_t * sw, lv_style_t *bg, lv_style_t *indic, lv_style_t *knob)
|
||||
{
|
||||
lv_slider_set_style(sw, bg, indic, knob);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn ON the switch
|
||||
* @param sw pointer to a switch object
|
||||
*/
|
||||
static inline void lv_sw_set_on(lv_obj_t *sw)
|
||||
{
|
||||
lv_bar_set_value(sw, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn OFF the switch
|
||||
* @param sw pointer to a switch object
|
||||
*/
|
||||
static inline void lv_sw_set_off(lv_obj_t *sw)
|
||||
{
|
||||
lv_bar_set_value(sw, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a function which will be called when the switch is toggled by the user
|
||||
* @param sw pointer to switch object
|
||||
* @param action a callback function
|
||||
*/
|
||||
static inline void lv_sw_set_action(lv_obj_t * sw, lv_action_t action)
|
||||
{
|
||||
lv_slider_set_action(sw, action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the state of a switch
|
||||
* @param sw pointer to a switch object
|
||||
* @return false: OFF; true: ON
|
||||
*/
|
||||
static inline bool lv_sw_get_state(lv_obj_t *sw)
|
||||
{
|
||||
return lv_bar_get_value(sw) == 0 ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the switch action function
|
||||
* @param slider pointer to a switch object
|
||||
* @return the callback function
|
||||
*/
|
||||
static inline lv_action_t lv_sw_get_action(lv_obj_t * slider)
|
||||
{
|
||||
return lv_slider_get_action(slider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the style of the switch's background
|
||||
* @param sw pointer to a switch object
|
||||
* @return pointer to the switch's background style
|
||||
*/
|
||||
static inline bool 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 bool lv_sw_get_style_indicator(lv_obj_t *sw)
|
||||
{
|
||||
return lv_slider_get_style_indicator(sw);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the style of the switch's knob
|
||||
* @param sw pointer to a switch object
|
||||
* @return pointer to the switch's knob style
|
||||
*/
|
||||
static inline bool lv_sw_get_style_knob(lv_obj_t *sw)
|
||||
{
|
||||
return lv_slider_get_style_knob(sw);
|
||||
}
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
|
@ -209,7 +209,7 @@ lv_obj_t * lv_win_add_cbtn(lv_obj_t * win, const char * img_path, lv_action_t re
|
||||
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
|
||||
|
||||
lv_obj_t * btn = lv_btn_create(ext->btnh, NULL);
|
||||
lv_btn_set_styles(btn, ext->style_cbtn_rel, ext->style_cbtn_pr, NULL, NULL, NULL);
|
||||
lv_btn_set_style(btn, ext->style_cbtn_rel, ext->style_cbtn_pr, NULL, NULL, NULL);
|
||||
lv_obj_set_size(btn, ext->cbtn_size, ext->cbtn_size);
|
||||
lv_btn_set_action(btn, LV_BTN_ACTION_RELEASE, rel_action);
|
||||
|
||||
@ -276,7 +276,7 @@ void lv_win_set_styles_cbtn(lv_obj_t * win, lv_style_t * rel, lv_style_t * pr)
|
||||
lv_obj_t * cbtn;
|
||||
cbtn = lv_obj_get_child(ext->btnh, NULL);
|
||||
while(cbtn != NULL) {
|
||||
lv_btn_set_styles(cbtn, ext->style_cbtn_rel, ext->style_cbtn_pr, NULL, NULL, NULL);
|
||||
lv_btn_set_style(cbtn, ext->style_cbtn_rel, ext->style_cbtn_pr, NULL, NULL, NULL);
|
||||
|
||||
cbtn = lv_obj_get_child(ext->btnh, cbtn);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user