diff --git a/lv_hal/lv_hal_indev.c b/lv_hal/lv_hal_indev.c index 85cb1f42f..861ae8c42 100644 --- a/lv_hal/lv_hal_indev.c +++ b/lv_hal/lv_hal_indev.c @@ -42,7 +42,7 @@ static lv_indev_t *indev_list = NULL; * @param driver Input Device driver structure * @return pointer to the new input device */ -lv_indev_t * lv_indev_drv_register(lv_hal_indev_drv_t *driver) +lv_indev_t * lv_indev_register(lv_hal_indev_drv_t *driver) { lv_indev_t *node; @@ -88,7 +88,7 @@ lv_indev_t * lv_indev_next(lv_indev_t * indev) * @param data input device will write its data here * @return false: no more data; true: there more data to read (buffered) */ -bool lv_indev_get(lv_indev_t * indev, lv_hal_indev_data_t *data) +bool lv_indev_read(lv_indev_t * indev, lv_hal_indev_data_t *data) { bool cont = false; diff --git a/lv_hal/lv_hal_indev.h b/lv_hal/lv_hal_indev.h index 025ae607f..4b82f93ed 100644 --- a/lv_hal/lv_hal_indev.h +++ b/lv_hal/lv_hal_indev.h @@ -17,8 +17,8 @@ extern "C" { *********************/ #include #include +#include "lv_hal.h" #include "misc/gfx/area.h" -#include /********************* * DEFINES @@ -99,15 +99,15 @@ typedef struct _lv_indev_t { * @param driver Input Device driver structure * @return 0 on success, -ve on error */ -lv_indev_t * lv_indev_drv_register(lv_hal_indev_drv_t *driver); +lv_indev_t * lv_indev_register(lv_hal_indev_drv_t *driver); /** - * Ask data fro man input device. + * Ask data from an input device. * @param data input device data * @return false: no more data; true: there more data to read (buffered) */ -bool lv_indev_get(lv_indev_t * indev, lv_hal_indev_data_t *data); +bool lv_indev_read(lv_indev_t * indev, lv_hal_indev_data_t *data); /** * Get the next input device. diff --git a/lv_obj/lv_indev.c b/lv_obj/lv_indev.c index 7a3df403d..7d23e8249 100644 --- a/lv_obj/lv_indev.c +++ b/lv_obj/lv_indev.c @@ -201,7 +201,7 @@ static void indev_proc_task(void * param) if(i->state.disable == 0) { /*Read the data*/ - lv_indev_get(i, &data); + lv_indev_read(i, &data); i->state.pressed = data.state; /*Move the cursor if set and moved*/ @@ -283,12 +283,12 @@ static void indev_proc_press(lv_indev_state_t * state) /*If there is no last object then search*/ if(state->act_obj == NULL) { pr_obj = indev_search_obj(state, lv_layer_top()); - if(pr_obj == NULL) pr_obj = indev_search_obj(state, lv_screen_act()); + if(pr_obj == NULL) pr_obj = indev_search_obj(state, lv_scr_act()); } /*If there is last object but it is not dragged also search*/ else if(state->drag_in_prog == 0) {/*Now act_obj != NULL*/ pr_obj = indev_search_obj(state, lv_layer_top()); - if(pr_obj == NULL) pr_obj = indev_search_obj(state, lv_screen_act()); + if(pr_obj == NULL) pr_obj = indev_search_obj(state, lv_scr_act()); } /*If a dragable object was the last then keep it*/ else { @@ -520,7 +520,6 @@ static void indev_drag_throw(lv_indev_state_t * state) lv_obj_t * drag_obj = state->last_obj; /*If drag parent is active check recursively the drag_parent attribute*/ - while(lv_obj_get_drag_parent(drag_obj) != false && drag_obj != NULL) { drag_obj = lv_obj_get_parent(drag_obj); diff --git a/lv_obj/lv_obj.c b/lv_obj/lv_obj.c index 2a2705823..f96c20b28 100644 --- a/lv_obj/lv_obj.c +++ b/lv_obj/lv_obj.c @@ -364,7 +364,7 @@ void lv_obj_invalidate(lv_obj_t * obj) { /*Invalidate the object only if it belongs to the 'act_scr'*/ lv_obj_t * obj_scr = lv_obj_get_screen(obj); - if(obj_scr == lv_screen_act() || + if(obj_scr == lv_scr_act() || obj_scr == lv_layer_top() || obj_scr == lv_layer_sys()) { /*Truncate recursively to the parents*/ @@ -404,7 +404,7 @@ void lv_obj_invalidate(lv_obj_t * obj) * Load a new screen * @param scr pointer to a screen */ -void lv_screen_load(lv_obj_t * scr) +void lv_scr_load(lv_obj_t * scr) { act_scr = scr; @@ -496,10 +496,10 @@ void lv_obj_set_pos(lv_obj_t * obj, cord_t x, cord_t y) /** * Set relative the position of an object (relative to the parent). - * The coordinates will be upscaled with LV_DOWNSCALE. + * The coordinates will be up scaled LV_ANTIALIAS is enabled. * @param obj pointer to an object - * @param x new distance from the left side of the parent. (will be multiplied with LV_DOWNSCALE) - * @param y new distance from the top of the parent. (will be multiplied with LV_DOWNSCALE) + * @param x new distance from the left side of the parent. + * @param y new distance from the top of the parent. */ void lv_obj_set_pos_scale(lv_obj_t * obj, cord_t x, cord_t y) { @@ -518,9 +518,9 @@ void lv_obj_set_x(lv_obj_t * obj, cord_t x) /** * Set the x coordinate of a object. - * The coordinate will be upscaled with LV_DOWNSCALE. + * The coordinate will be up scaled LV_ANTIALIAS is enabled. * @param obj pointer to an object - * @param x new distance from the left side from the parent. (will be multiplied with LV_DOWNSCALE) + * @param x new distance from the left side from the parent. */ void lv_obj_set_x_scale(lv_obj_t * obj, cord_t x) { @@ -539,9 +539,9 @@ void lv_obj_set_y(lv_obj_t * obj, cord_t y) /** * Set the y coordinate of a object. - * The coordinate will be upscaled with LV_DOWNSCALE. + * The coordinate will be up scaled LV_ANTIALIAS is enabled. * @param obj pointer to an object - * @param y new distance from the top of the parent. (will be multiplied with LV_DOWNSCALE) + * @param y new distance from the top of the parent. */ void lv_obj_set_y_scale(lv_obj_t * obj, cord_t y) { @@ -588,10 +588,11 @@ void lv_obj_set_size(lv_obj_t * obj, cord_t w, cord_t h) } /** - * Set the size of an object. The coordinates will be upscaled with LV_DOWNSCALE. + * Set the size of an object. + * The coordinates will be up scaled LV_ANTIALIAS is enabled. * @param obj pointer to an object - * @param w new width (will be multiplied with LV_DOWNSCALE) - * @param h new height (will be multiplied with LV_DOWNSCALE) + * @param w new width + * @param h new height */ void lv_obj_set_size_scale(lv_obj_t * obj, cord_t w, cord_t h) { @@ -609,9 +610,10 @@ void lv_obj_set_width(lv_obj_t * obj, cord_t w) } /** - * Set the width of an object. The width will be upscaled with LV_DOWNSCALE + * Set the width of an object. + * The coordinates will be up scaled LV_ANTIALIAS is enabled. * @param obj pointer to an object - * @param w new width (will be multiplied with LV_DOWNSCALE) + * @param w new width */ void lv_obj_set_width_scale(lv_obj_t * obj, cord_t w) { @@ -629,9 +631,10 @@ void lv_obj_set_height(lv_obj_t * obj, cord_t h) } /** - * Set the height of an object. The height will be upscaled with LV_DOWNSCALE + * Set the height of an object. + * The coordinate will be up scaled LV_ANTIALIAS is enabled. * @param obj pointer to an object - * @param h new height (will be multiplied with LV_DOWNSCALE) + * @param h new height */ void lv_obj_set_height_scale(lv_obj_t * obj, cord_t h) { @@ -777,30 +780,19 @@ void lv_obj_align(lv_obj_t * obj,lv_obj_t * base, lv_align_t align, cord_t x_mod /** - * Align an object to an other object. The coordinates will be upscaled with LV_DOWNSCALE. + * Align an object to an other object. + * The coordinates will be up scaled LV_ANTIALIAS is enabled. * @param obj pointer to an object to align * @param base pointer to an object (if NULL the parent is used). 'obj' will be aligned to it. * @param align type of alignment (see 'lv_align_t' enum) - * @param x_mod x coordinate shift after alignment (will be multiplied with LV_DOWNSCALE) - * @param y_mod y coordinate shift after alignment (will be multiplied with LV_DOWNSCALE) + * @param x_mod x coordinate shift after alignment + * @param y_mod y coordinate shift after alignment */ void lv_obj_align_scale(lv_obj_t * obj,lv_obj_t * base, lv_align_t align, cord_t x_mod, cord_t y_mod) { lv_obj_align(obj, base, align, x_mod << LV_ANTIALIAS, y_mod << LV_ANTIALIAS); } -/** - * Set the extended size of an object - * @param obj pointer to an object - * @param ext_size the extended size - */ -void lv_obj_set_ext_size(lv_obj_t * obj, cord_t ext_size) -{ - obj->ext_size = ext_size; - - lv_obj_invalidate(obj); -} - /*--------------------- * Appearance set *--------------------*/ @@ -1108,7 +1100,7 @@ void lv_obj_animate(lv_obj_t * obj, lv_anim_builtin_t type, uint16_t time, uint1 * Return with the actual screen * @return pointer to the actual screen object */ -lv_obj_t * lv_screen_act(void) +lv_obj_t * lv_scr_act(void) { return act_scr; } diff --git a/lv_obj/lv_obj.h b/lv_obj/lv_obj.h index b5f9001c9..1cc991004 100644 --- a/lv_obj/lv_obj.h +++ b/lv_obj/lv_obj.h @@ -223,7 +223,7 @@ void lv_obj_invalidate(lv_obj_t * obj); * Load a new screen * @param scr pointer to a screen */ -void lv_screen_load(lv_obj_t * scr); +void lv_scr_load(lv_obj_t * scr); /** * Set a new parent for an object. Its relative position will be the same. @@ -457,7 +457,7 @@ void * lv_obj_allocate_ext_attr(lv_obj_t * obj, uint16_t ext_size); */ void lv_obj_refresh_ext_size(lv_obj_t * obj); -#if LV_OBJ_FREE_NUMBER != 0 +#if LV_OBJ_FREE_NUM != 0 /** * Set an application specific number for an object. * It can help to identify objects in the application. @@ -467,7 +467,7 @@ void lv_obj_refresh_ext_size(lv_obj_t * obj); void lv_obj_set_free_number(lv_obj_t * obj, uint8_t free_number); #endif -#if LV_OBJ_FREE_POINTER != 0 +#if LV_OBJ_FREE_PTR != 0 /** * Set an application specific pointer for an object. * It can help to identify objects in the application. @@ -491,7 +491,7 @@ void lv_obj_animate(lv_obj_t * obj, lv_anim_builtin_t type, uint16_t time, uint1 * Return with the actual screen * @return pointer to to the actual screen object */ -lv_obj_t * lv_screen_act(void);lv_obj_t * lv_layer_top(void); +lv_obj_t * lv_scr_act(void);lv_obj_t * lv_layer_top(void); /** * Return with the system layer. (Same on every screen and it is above the all other layers) @@ -667,7 +667,7 @@ void * lv_obj_get_ext_attr(lv_obj_t * obj); uint8_t lv_obj_get_free_num(lv_obj_t * obj); #endif -#if LV_OBJ_FREE_P != 0 +#if LV_OBJ_FREE_PTR != 0 /** * Get the free pointer * @param obj pointer to an object @@ -684,9 +684,11 @@ void * lv_obj_get_free_p(lv_obj_t * obj); */ void * lv_obj_get_group(lv_obj_t * obj); #endif + /********************** * MACROS **********************/ +#define LV_SCALE(x) (x << LV_ANTIALIAS) #ifdef __cplusplus diff --git a/lv_obj/lv_refr.c b/lv_obj/lv_refr.c index 6008a35ff..6e404d154 100644 --- a/lv_obj/lv_refr.c +++ b/lv_obj/lv_refr.c @@ -98,7 +98,7 @@ void lv_inv_area(const area_t * area_p) /*The area is truncated to the screen*/ if(suc != false) { -#if LV_DOWNSCALE == 2 +#if LV_ANTIALIAS == 1 /*Rounding*/ com_area.x1 = com_area.x1 & (~0x1); com_area.y1 = com_area.y1 & (~0x1); @@ -242,7 +242,7 @@ static void lv_refr_area_no_vdb(const area_t * area_p) lv_obj_t * top_p; /*Get top object which is not covered by others*/ - top_p = lv_refr_get_top_obj(area_p, lv_screen_act()); + top_p = lv_refr_get_top_obj(area_p, lv_scr_act()); /*Do the refreshing*/ lv_refr_make(top_p, area_p); @@ -261,7 +261,7 @@ static void lv_refr_area_with_vdb(const area_t * area_p) if(max_row > area_get_height(area_p)) max_row = area_get_height(area_p); /*Round the row number with downscale*/ -#if LV_DOWNSCALE == 2 +#if LV_ANTIALIAS == 1 max_row &= (~0x1); #endif @@ -310,7 +310,7 @@ static void lv_refr_area_part_vdb(const area_t * area_p) area_union(&start_mask, area_p, &vdb_p->area); /*Get the most top object which is not covered by others*/ - top_p = lv_refr_get_top_obj(&start_mask, lv_screen_act()); + top_p = lv_refr_get_top_obj(&start_mask, lv_scr_act()); /*Do the refreshing from the top object*/ lv_refr_make(top_p, &start_mask); @@ -372,7 +372,7 @@ static void lv_refr_make(lv_obj_t * top_p, const area_t * mask_p) /* Normally always will be a top_obj (at least the screen) * but in special cases (e.g. if the screen has alpha) it won't. * In this case use the screen directly */ - if(top_p == NULL) top_p = lv_screen_act(); + if(top_p == NULL) top_p = lv_scr_act(); /*Refresh the top object and its children*/ lv_refr_obj(top_p, mask_p); diff --git a/lv_objx/lv_bar.c b/lv_objx/lv_bar.c index ccc561fb0..0e5424093 100644 --- a/lv_objx/lv_bar.c +++ b/lv_objx/lv_bar.c @@ -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->style_indic = lv_style_get(LV_STYLE_PRETTY_COLOR); + ext->indicator_style = lv_style_get(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->style_indic = ext_copy->style_indic; + ext->indicator_style = ext_copy->indicator_style; /*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_style_indic(bar); + lv_style_t * style_indic = lv_bar_get_indicator_style(bar); if(style_indic->body.shadow.width > bar->ext_size) bar->ext_size = style_indic->body.shadow.width; } @@ -196,11 +196,11 @@ void lv_bar_set_range(lv_obj_t * bar, int16_t min, int16_t max) * @param bar pointer to a bar object * @param style pointer to a style */ -void lv_bar_set_style_indic(lv_obj_t * bar, lv_style_t * style) +void lv_bar_set_indicator_style(lv_obj_t * bar, lv_style_t * style) { lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); - ext->style_indic = style; + ext->indicator_style = style; bar->signal_func(bar, LV_SIGNAL_REFR_EXT_SIZE, NULL); @@ -249,13 +249,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_style_indic(lv_obj_t * bar) +lv_style_t * lv_bar_get_indicator_style(lv_obj_t * bar) { lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); - if(ext->style_indic == NULL) return lv_obj_get_style(bar); + if(ext->indicator_style == NULL) return lv_obj_get_style(bar); - return ext->style_indic; + return ext->indicator_style; } /********************** @@ -282,7 +282,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_style_indic(bar); + lv_style_t * style_indic = lv_bar_get_indicator_style(bar); area_t indic_area; area_cpy(&indic_area, &bar->coords); indic_area.x1 += style_indic->body.padding.horizontal; diff --git a/lv_objx/lv_bar.h b/lv_objx/lv_bar.h index f42b942e9..3a4bcf722 100644 --- a/lv_objx/lv_bar.h +++ b/lv_objx/lv_bar.h @@ -32,12 +32,12 @@ extern "C" { /*Data of bar*/ typedef struct { - /*No inherited ext*/ /*Ext. of ancestor*/ + /*No inherited ext*/ /*Ext. of ancestor*/ /*New data for this type */ - 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 * style_indic; /*Style of the indicator*/ + 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_bar_ext_t; /********************** @@ -88,7 +88,7 @@ void lv_bar_set_range(lv_obj_t * bar, int16_t min, int16_t max); * @param bar pointer to a bar object * @param style pointer to a style */ -void lv_bar_set_style_indic(lv_obj_t * bar, lv_style_t * style); +void lv_bar_set_indicator_style(lv_obj_t * bar, lv_style_t * style); /** * Get the value of a bar @@ -116,7 +116,7 @@ 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_style_indic(lv_obj_t * bar); +lv_style_t * lv_bar_get_indicator_style(lv_obj_t * bar); /********************** * MACROS diff --git a/lv_objx/lv_btn.c b/lv_objx/lv_btn.c index 029e5a0de..1c98d9542 100644 --- a/lv_objx/lv_btn.c +++ b/lv_objx/lv_btn.c @@ -8,15 +8,14 @@ *********************/ #include "lv_conf.h" -#if USE_LV_BUTTON != 0 +#if USE_LV_BTN != 0 +#include #include "lv_btn.h" #include "../lv_obj/lv_group.h" #include "../lv_draw/lv_draw.h" #include "misc/gfx/area.h" #include "misc/gfx/color.h" -#include -#include /********************* * DEFINES @@ -240,6 +239,22 @@ void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state) } } +/** + * Toggle the state of the button (ON->OFF, OFF->ON) + * @param btn pointer to a button object + */ +void lv_btn_toggle(lv_obj_t * btn) +{ + lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn); + switch(ext->state) { + case LV_BTN_STATE_OFF_RELEASED: lv_btn_set_state(btn, LV_BTN_STATE_ON_RELEASED); break; + case LV_BTN_STATE_OFF_PRESSED: lv_btn_set_state(btn, LV_BTN_STATE_ON_PRESSED); break; + case LV_BTN_STATE_ON_RELEASED: lv_btn_set_state(btn, LV_BTN_STATE_OFF_RELEASED); break; + case LV_BTN_STATE_ON_PRESSED: lv_btn_set_state(btn, LV_BTN_STATE_OFF_PRESSED); break; + default: break; + } +} + /** * Set a function to call when the button is pressed * @param btn pointer to a button object diff --git a/lv_objx/lv_btn.h b/lv_objx/lv_btn.h index f24469829..2acc2a963 100644 --- a/lv_objx/lv_btn.h +++ b/lv_objx/lv_btn.h @@ -1,10 +1,10 @@ /** - * @file lv_button.h + * @file lv_btn.h * */ -#ifndef lv_btn_H -#define lv_btn_H +#ifndef LV_BTN_H +#define LV_BTN_H #ifdef __cplusplus extern "C" { @@ -14,7 +14,7 @@ extern "C" { * INCLUDES *********************/ #include "lv_conf.h" -#if USE_LV_BUTTON != 0 +#if USE_LV_BTN != 0 /*Testing of dependencies*/ #if USE_LV_CONT == 0 @@ -22,7 +22,7 @@ extern "C" { #endif #include "lv_cont.h" -#include +#include "../lv_obj/lv_indev.h" /********************* * DEFINES @@ -100,6 +100,12 @@ void lv_btn_set_toggle(lv_obj_t * btn, bool tgl); */ void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state); +/** + * Toggle the state of the button (ON->OFF, OFF->ON) + * @param btn pointer to a button object + */ +void lv_btn_toggle(lv_obj_t * btn); + /** * Set a function to call when the button is pressed * @param btn pointer to a button object @@ -108,7 +114,7 @@ void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state); 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 + * Set styles of a button is each state. Use NULL for any style which are not be changed. * @param btn pointer to button object * @param rel pointer to a style for releases state * @param pr pointer to a style for pressed state @@ -118,7 +124,6 @@ void lv_btn_set_action(lv_obj_t * btn, lv_btn_action_t type, lv_action_t action) */ void lv_btn_set_style(lv_obj_t * btn, lv_btn_state_t state, lv_style_t * style); -void lv_btn_set_style_all(lv_obj_t * btn, lv_style_t ** style_array); /** * Get the current state of the button * @param btn pointer to a button object @@ -141,12 +146,11 @@ bool lv_btn_get_toggle(lv_obj_t * btn); lv_action_t lv_btn_get_action(lv_obj_t * btn, lv_btn_action_t type); /** - * Get the press action of a button + * Get the style of a button in a given state * @param btn pointer to a button object - * @return pointer to the press action function + * @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_action_t lv_btn_get_pr_action(lv_obj_t * btn); - lv_style_t * lv_btn_get_style(lv_obj_t * btn, lv_btn_state_t state); /********************** diff --git a/lv_objx/lv_btnm.c b/lv_objx/lv_btnm.c index 5cd827869..3d59ecc60 100644 --- a/lv_objx/lv_btnm.c +++ b/lv_objx/lv_btnm.c @@ -28,10 +28,13 @@ * STATIC PROTOTYPES **********************/ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_t mode); -static uint8_t lv_btnm_get_width_unit(const char * btn_str); -static uint16_t lv_btnm_get_btn_from_point(lv_obj_t * btnm, point_t * p); -static uint16_t lv_btnm_get_btn_txt(lv_obj_t * btnm, uint16_t btn_id); -static void lv_btnm_create_btns(lv_obj_t * btnm, const char ** map); +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); +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); +static void create_buttons(lv_obj_t * btnm, const char ** map); /********************** * STATIC VARIABLES @@ -68,17 +71,18 @@ lv_obj_t * lv_btnm_create(lv_obj_t * par, lv_obj_t * copy) /*Allocate the object type specific extended data*/ lv_btnm_ext_t * ext = lv_obj_allocate_ext_attr(new_btnm, sizeof(lv_btnm_ext_t)); dm_assert(ext); - ext->btn_cnt = 0; - ext->btn_pr = LV_BTNM_PR_NONE; - ext->btn_tgl = LV_BTNM_PR_NONE; - ext->btn_areas = NULL; - ext->cb = NULL; + ext->button_cnt = 0; + ext->button_id_pressed = LV_BTNM_PR_NONE; + ext->button_id_toggled = LV_BTNM_PR_NONE; + ext->button_areas = NULL; + ext->action = NULL; ext->map_p = NULL; - ext->style_btn_rel = lv_style_get(LV_STYLE_BUTTON_OFF_RELEASED); - ext->style_btn_pr = lv_style_get(LV_STYLE_BUTTON_OFF_PRESSED); - ext->style_btn_trel = lv_style_get(LV_STYLE_BUTTON_ON_RELEASED); - ext->style_btn_tpr = lv_style_get(LV_STYLE_BUTTON_ON_PRESSED); - ext->tgl = 0; + ext->toggle = 0; + ext->button_styles[LV_BTN_STATE_OFF_RELEASED] = lv_style_get(LV_STYLE_BUTTON_OFF_RELEASED); + ext->button_styles[LV_BTN_STATE_OFF_PRESSED] = lv_style_get(LV_STYLE_BUTTON_OFF_PRESSED); + ext->button_styles[LV_BTN_STATE_ON_RELEASED] = lv_style_get(LV_STYLE_BUTTON_ON_RELEASED); + ext->button_styles[LV_BTN_STATE_ON_PRESSED] = lv_style_get(LV_STYLE_BUTTON_ON_PRESSED); + ext->button_styles[LV_BTN_STATE_INACTIVE] = lv_style_get(LV_STYLE_BUTTON_INACTIVE); if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_func(new_btnm); @@ -94,10 +98,9 @@ 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); - ext->style_btn_rel = copy_ext->style_btn_rel; - ext->style_btn_pr = copy_ext->style_btn_pr; + memcpy(ext->button_styles, copy_ext->button_styles, sizeof(ext->button_styles)); + ext->action = copy_ext->action; lv_btnm_set_map(new_btnm, lv_btnm_get_map(copy)); - ext->cb = copy_ext->cb; } return new_btnm; @@ -125,7 +128,7 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) area_t btn_area; point_t p; if(sign == LV_SIGNAL_CLEANUP) { - dm_free(ext->btn_areas); + dm_free(ext->button_areas); } else if(sign == LV_SIGNAL_STYLE_CHG || sign == LV_SIGNAL_CORD_CHG) { lv_btnm_set_map(btnm, ext->map_p); @@ -134,13 +137,13 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) uint16_t btn_pr; /*Search the pressed area*/ lv_indev_get_point(param, &p); - btn_pr = lv_btnm_get_btn_from_point(btnm, &p); + btn_pr = get_button_from_point(btnm, &p); /*Invalidate to old and the new areas*/; lv_obj_get_coords(btnm, &btnm_area); - if(btn_pr != ext->btn_pr) { + if(btn_pr != ext->button_id_pressed) { lv_indev_reset_lpr(param); - if(ext->btn_pr != LV_BTNM_PR_NONE) { - area_cpy(&btn_area, &ext->btn_areas[ext->btn_pr]); + if(ext->button_id_pressed != LV_BTNM_PR_NONE) { + area_cpy(&btn_area, &ext->button_areas[ext->button_id_pressed]); btn_area.x1 += btnm_area.x1; btn_area.y1 += btnm_area.y1; btn_area.x2 += btnm_area.x1; @@ -148,7 +151,7 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) lv_inv_area(&btn_area); } if(btn_pr != LV_BTNM_PR_NONE) { - area_cpy(&btn_area, &ext->btn_areas[btn_pr]); + area_cpy(&btn_area, &ext->button_areas[btn_pr]); btn_area.x1 += btnm_area.x1; btn_area.y1 += btnm_area.y1; btn_area.x2 += btnm_area.x1; @@ -157,75 +160,75 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) } } - ext->btn_pr = btn_pr; + ext->button_id_pressed = btn_pr; } else if(sign == LV_SIGNAL_LONG_PRESS_REP) { - if(ext->cb != NULL && ext->btn_pr != LV_BTNM_PR_NONE) { - uint16_t txt_i = lv_btnm_get_btn_txt(btnm, ext->btn_pr); + 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((ext->map_p[txt_i][0] & LV_BTNM_CTRL_MASK) == LV_BTNM_CTRL_CODE) { /*If there is control byte check for "no long press"*/ - if((ext->map_p[txt_i][0] & LV_BTNM_NO_LPR_MASK) == 0) ext->cb(btnm, txt_i); - } else { /*If no control byte then call the action unconditionally*/ - ext->cb(btnm, txt_i); + if(button_is_repeat_disabled(ext->map_p[txt_i]) == false) { + ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i])); } } } } else if(sign == LV_SIGNAL_RELEASED) { - if(ext->btn_pr != LV_BTNM_PR_NONE) { - if(ext->cb) { - uint16_t txt_i = lv_btnm_get_btn_txt(btnm, ext->btn_pr); + 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) { - ext->cb(btnm, txt_i); + ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i])); } } /*Invalidate to old pressed area*/; lv_obj_get_coords(btnm, &btnm_area); - area_cpy(&btn_area, &ext->btn_areas[ext->btn_pr]); + area_cpy(&btn_area, &ext->button_areas[ext->button_id_pressed]); btn_area.x1 += btnm_area.x1; btn_area.y1 += btnm_area.y1; btn_area.x2 += btnm_area.x1; btn_area.y2 += btnm_area.y1; lv_inv_area(&btn_area); - if(ext->tgl != 0) { + if(ext->toggle != 0) { /*Invalidate to old toggled area*/; - area_cpy(&btn_area, &ext->btn_areas[ext->btn_tgl]); + area_cpy(&btn_area, &ext->button_areas[ext->button_id_toggled]); btn_area.x1 += btnm_area.x1; btn_area.y1 += btnm_area.y1; btn_area.x2 += btnm_area.x1; btn_area.y2 += btnm_area.y1; lv_inv_area(&btn_area); - ext->btn_tgl = ext->btn_pr; + ext->button_id_toggled = ext->button_id_pressed; } - ext->btn_pr = LV_BTNM_PR_NONE; + ext->button_id_pressed = LV_BTNM_PR_NONE; } } else if(sign == LV_SIGNAL_PRESS_LOST || sign == LV_SIGNAL_DEFOCUS) { - ext->btn_pr = LV_BTNM_PR_NONE; + ext->button_id_pressed = LV_BTNM_PR_NONE; lv_obj_invalidate(btnm); } else if(sign == LV_SIGNAL_FOCUS) { - ext->btn_pr = 0; + ext->button_id_pressed = 0; lv_obj_invalidate(btnm); } else if(sign == LV_SIGNAL_CONTROLL) { lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); char c = *((char*)param); if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_UP) { - if(ext->btn_pr == LV_BTNM_PR_NONE) ext->btn_pr = 0; - else ext->btn_pr++; - if(ext->btn_pr >= ext->btn_cnt - 1) ext->btn_pr = ext->btn_cnt - 1; + if(ext->button_id_pressed == LV_BTNM_PR_NONE) ext->button_id_pressed = 0; + else ext->button_id_pressed++; + if(ext->button_id_pressed >= ext->button_cnt - 1) ext->button_id_pressed = ext->button_cnt - 1; lv_obj_invalidate(btnm); } else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_DOWN) { - if(ext->btn_pr == LV_BTNM_PR_NONE) ext->btn_pr = 0; - if(ext->btn_pr > 0) ext->btn_pr--; + if(ext->button_id_pressed == LV_BTNM_PR_NONE) ext->button_id_pressed = 0; + if(ext->button_id_pressed > 0) ext->button_id_pressed--; lv_obj_invalidate(btnm); } else if(c == LV_GROUP_KEY_ENTER) { - if(ext->cb != NULL) { - uint16_t txt_i = lv_btnm_get_btn_txt(btnm, ext->btn_pr); - if(txt_i != LV_BTNM_PR_NONE) ext->cb(btnm, txt_i); + if(ext->action != NULL) { + uint16_t txt_i = get_button_text(btnm, ext->button_id_pressed); + if(txt_i != LV_BTNM_PR_NONE) { + ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i])); + } } } } @@ -247,7 +250,7 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) * - bit 7: always 1 * - bit 6: always 0 * - bit 5: reserved - * - bit 4: no long press + * - bit 4: no repeat (on long press) * - bit 3: hidden * - bit 2..0: button relative width * Example (practically use octal numbers): "\224abc": "abc" text with 4 width and no long press @@ -260,7 +263,7 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map) ext->map_p = map; /*Analyze the map and create the required number of buttons*/ - lv_btnm_create_btns(btnm, map); + create_buttons(btnm, map); /*Set size and positions of the buttons*/ lv_style_t * btnms = lv_obj_get_style(btnm); @@ -294,7 +297,7 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map) /*Count the buttons in a line*/ while(strcmp(map_p_tmp[btn_cnt], "\n") != 0 && strlen(map_p_tmp[btn_cnt]) != 0) { /*Check a line*/ - unit_cnt += lv_btnm_get_width_unit(map_p_tmp[btn_cnt]); + unit_cnt += get_button_width(map_p_tmp[btn_cnt]); btn_cnt ++; } @@ -312,17 +315,17 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map) /* one_unit_w = all_unit_w / unit_cnt * act_unit_w = one_unit_w * button_width * do this two operation but the multiply first to divide a greater number */ - act_unit_w = (all_unit_w * lv_btnm_get_width_unit(map_p_tmp[i])) / unit_cnt; + act_unit_w = (all_unit_w * get_button_width(map_p_tmp[i])) / unit_cnt; /*Always recalculate act_x because of rounding errors */ act_x = (unit_act_cnt * all_unit_w) / unit_cnt + i * btnms->body.padding.inner + btnms->body.padding.horizontal; - area_set(&ext->btn_areas[btn_i], act_x, + area_set(&ext->button_areas[btn_i], act_x, act_y, act_x + act_unit_w, act_y + btn_h); - unit_act_cnt += lv_btnm_get_width_unit(map_p_tmp[i]); + unit_act_cnt += get_button_width(map_p_tmp[i]); i_tot ++; btn_i ++; @@ -342,10 +345,10 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map) * @param btnm: pointer to button matrix object * @param cb pointer to a callback function */ -void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_callback_t cb) +void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_action_t cb) { lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); - ext->cb = cb; + ext->action = cb; } /** @@ -354,16 +357,16 @@ void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_callback_t cb) * @param en true: enable toggling; false: disable toggling * @param id index of the currently toggled button (ignored if 'en' == false) */ -void lv_btnm_set_tgl(lv_obj_t * btnm, bool en, uint16_t id) +void lv_btnm_set_toggle(lv_obj_t * btnm, bool en, uint16_t id) { lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); - ext->tgl = en == false ? 0 : 1; - if(ext->tgl != 0) { - if(id > ext->btn_cnt) id = LV_BTNM_PR_NONE; - ext->btn_tgl = id; + ext->toggle = en == false ? 0 : 1; + if(ext->toggle != 0) { + if(id > ext->button_cnt) id = LV_BTNM_PR_NONE; + ext->button_id_toggled = id; } else { - ext->btn_tgl = LV_BTNM_PR_NONE; + ext->button_id_toggled = LV_BTNM_PR_NONE; } lv_obj_invalidate(btnm); @@ -378,15 +381,12 @@ void lv_btnm_set_tgl(lv_obj_t * btnm, bool en, uint16_t id) * @param tpr pointer to a style for toggled pressed state (NULL to leave it unchanged) * @param ina pointer to a style for inactive state (NULL to leave it unchanged) */ -void lv_btnm_set_styles_btn(lv_obj_t *btnm, lv_style_t *rel, lv_style_t *pr, - lv_style_t *trel, lv_style_t *tpr, lv_style_t *ina) +void lv_btnm_set_button_style(lv_obj_t *btnm, lv_btn_state_t state, lv_style_t *style) { + if(state >= LV_BTN_STATE_NUM) return; + lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); - if(rel != NULL) ext->style_btn_rel = rel; - if(pr != NULL) ext->style_btn_pr = pr; - if(trel != NULL) ext->style_btn_trel = trel; - if(tpr != NULL) ext->style_btn_tpr = tpr; - if(ina != NULL) ext->style_btn_ina = ina; + ext->button_styles[state] = style; lv_obj_invalidate(btnm); } @@ -411,10 +411,10 @@ const char ** lv_btnm_get_map(lv_obj_t * btnm) * @param btnm: pointer to button matrix object * @return pointer to the callback function */ -lv_btnm_callback_t lv_btnm_get_action(lv_obj_t * btnm) +lv_btnm_action_t lv_btnm_get_action(lv_obj_t * btnm) { lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); - return ext->cb; + return ext->action; } /** @@ -423,27 +423,12 @@ lv_btnm_callback_t lv_btnm_get_action(lv_obj_t * btnm) * @param state style in this state (LV_BTN_STATE_PR or LV_BTN_STATE_REL) * @return pointer the button style in the given state */ -lv_style_t * lv_btnm_get_style_btn(lv_obj_t * btnm, lv_btn_state_t state) +lv_style_t * lv_btnm_get_button_style(lv_obj_t * btnm, lv_btn_state_t state) { - lv_style_t * style; - lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); + if(state >= LV_BTN_STATE_NUM) return lv_obj_get_style(btnm); - switch(state) { - case LV_BTN_STATE_OFF_PRESSED: - style = ext->style_btn_pr; - break; - case LV_BTN_STATE_OFF_RELEASED: - style = ext->style_btn_rel; - break; - case LV_BTN_STATE_ON_PRESSED: - style = ext->style_btn_tpr; - break; - case LV_BTN_STATE_ON_RELEASED: - style = ext->style_btn_trel; - break; - default: - style = NULL; - } + lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); + lv_style_t * style = ext->button_styles[state]; if(style == NULL) style = lv_obj_get_style(btnm); @@ -484,20 +469,16 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_ uint16_t btn_i = 0; uint16_t txt_i = 0; - for(btn_i = 0; btn_i < ext->btn_cnt; btn_i ++, txt_i ++) { + for(btn_i = 0; btn_i < ext->button_cnt; btn_i ++, txt_i ++) { /*Search the next valid text in the map*/ while(strcmp(ext->map_p[txt_i], "\n") == 0) txt_i ++; /*Skip hidden buttons*/ - if((ext->map_p[txt_i][0] & LV_BTNM_CTRL_MASK) == LV_BTNM_CTRL_CODE && - (ext->map_p[txt_i][0] & LV_BTNM_HIDDEN_MASK)) - { - continue; - } + if(button_is_hidden(ext->map_p[txt_i])) continue; lv_obj_get_coords(btnm, &area_btnm); - area_cpy(&area_tmp, &ext->btn_areas[btn_i]); + area_cpy(&area_tmp, &ext->button_areas[btn_i]); area_tmp.x1 += area_btnm.x1; area_tmp.y1 += area_btnm.y1; area_tmp.x2 += area_btnm.x1; @@ -507,10 +488,10 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_ btn_h = area_get_height(&area_tmp); /*Load the style*/ - if(btn_i != ext->btn_pr && btn_i != ext->btn_tgl) btn_style = lv_btnm_get_style_btn(btnm, LV_BTN_STATE_OFF_RELEASED); - else if(btn_i == ext->btn_pr && btn_i != ext->btn_tgl) btn_style = lv_btnm_get_style_btn(btnm, LV_BTN_STATE_OFF_PRESSED); - else if(btn_i != ext->btn_pr && btn_i == ext->btn_tgl) btn_style = lv_btnm_get_style_btn(btnm, LV_BTN_STATE_ON_RELEASED); - else if(btn_i == ext->btn_pr && btn_i == ext->btn_tgl) btn_style = lv_btnm_get_style_btn(btnm, LV_BTN_STATE_ON_PRESSED); + if(btn_i != ext->button_id_pressed && btn_i != ext->button_id_toggled) btn_style = lv_btnm_get_button_style(btnm, LV_BTN_STATE_OFF_RELEASED); + else if(btn_i == ext->button_id_pressed && btn_i != ext->button_id_toggled) btn_style = lv_btnm_get_button_style(btnm, LV_BTN_STATE_OFF_PRESSED); + else if(btn_i != ext->button_id_pressed && btn_i == ext->button_id_toggled) btn_style = lv_btnm_get_button_style(btnm, LV_BTN_STATE_ON_RELEASED); + else if(btn_i == ext->button_id_pressed && btn_i == ext->button_id_toggled) btn_style = lv_btnm_get_button_style(btnm, LV_BTN_STATE_ON_PRESSED); lv_draw_rect(&area_tmp, mask, btn_style); @@ -537,7 +518,7 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_ * @param btnm pointer to button matrix object * @param map_p pointer to a string array */ -static void lv_btnm_create_btns(lv_obj_t * btnm, const char ** map) +static void create_buttons(lv_obj_t * btnm, const char ** map) { /*Count the buttons in the map*/ uint16_t btn_cnt = 0; @@ -551,13 +532,13 @@ static void lv_btnm_create_btns(lv_obj_t * btnm, const char ** map) lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); - if(ext->btn_areas != NULL) { - dm_free(ext->btn_areas); - ext->btn_areas = NULL; + if(ext->button_areas != NULL) { + dm_free(ext->button_areas); + ext->button_areas = NULL; } - ext->btn_areas = dm_alloc(sizeof(area_t) * btn_cnt); - ext->btn_cnt = btn_cnt; + ext->button_areas = dm_alloc(sizeof(area_t) * btn_cnt); + ext->button_cnt = btn_cnt; } /** @@ -565,7 +546,7 @@ static void lv_btnm_create_btns(lv_obj_t * btnm, const char ** map) * @param btn_str The descriptor string of a button. E.g. "apple" or "\004banana" * @return the width of the button in units */ -static uint8_t lv_btnm_get_width_unit(const char * btn_str) +static uint8_t get_button_width(const char * btn_str) { if((btn_str[0] & LV_BTNM_CTRL_MASK) == LV_BTNM_CTRL_CODE){ return btn_str[0] & LV_BTNM_WIDTH_MASK; @@ -574,13 +555,42 @@ static uint8_t lv_btnm_get_width_unit(const char * btn_str) return 1; /*Default width is 1*/ } +static bool button_is_hidden(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_HIDE_MASK)) { + return true; + } + + return false; +} + +static bool button_is_repeat_disabled(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_REPEAT_DISABLE_MASK)) { + return true; + } + + return false; +} + +const char * cut_ctrl_byte(const char * btn_str) +{ + /*Cut the control byte if present*/ + if((btn_str[0] & LV_BTNM_CTRL_MASK) == LV_BTNM_CTRL_CODE) return &btn_str[1]; + else return btn_str; +} + /** * Gives the button id of a button under a given point * @param btnm pointer to a button matrix object * @param p a point with absolute coordinates * @return the id of the button or LV_BTNM_PR_NONE. */ -static uint16_t lv_btnm_get_btn_from_point(lv_obj_t * btnm, point_t * p) +static uint16_t get_button_from_point(lv_obj_t * btnm, point_t * p) { area_t btnm_cords; area_t btn_area; @@ -588,8 +598,8 @@ static uint16_t lv_btnm_get_btn_from_point(lv_obj_t * btnm, point_t * p) uint16_t i; lv_obj_get_coords(btnm, &btnm_cords); - for(i = 0; i < ext->btn_cnt; i++) { - area_cpy(&btn_area, &ext->btn_areas[i]); + for(i = 0; i < ext->button_cnt; i++) { + area_cpy(&btn_area, &ext->button_areas[i]); btn_area.x1 += btnm_cords.x1; btn_area.y1 += btnm_cords.y1; btn_area.x2 += btnm_cords.x1; @@ -599,7 +609,7 @@ static uint16_t lv_btnm_get_btn_from_point(lv_obj_t * btnm, point_t * p) } } - if(i == ext->btn_cnt) i = LV_BTNM_PR_NONE; + if(i == ext->button_cnt) i = LV_BTNM_PR_NONE; return i; } @@ -610,10 +620,10 @@ static uint16_t lv_btnm_get_btn_from_point(lv_obj_t * btnm, point_t * p) * @param btn_id button id * @return text id in ext->map_p or LV_BTNM_PR_NONE if 'btn_id' was invalid */ -static uint16_t lv_btnm_get_btn_txt(lv_obj_t * btnm, uint16_t btn_id) +static uint16_t get_button_text(lv_obj_t * btnm, uint16_t btn_id) { lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); - if(btn_id > ext->btn_cnt) return LV_BTNM_PR_NONE; + if(btn_id > ext->button_cnt) return LV_BTNM_PR_NONE; uint16_t txt_i = 0; uint16_t btn_i = 0; @@ -626,7 +636,7 @@ static uint16_t lv_btnm_get_btn_txt(lv_obj_t * btnm, uint16_t btn_id) if(strcmp(ext->map_p[txt_i], "\n") == 0) txt_i ++; } - if(btn_i == ext->btn_cnt) return LV_BTNM_PR_NONE; + if(btn_i == ext->button_cnt) return LV_BTNM_PR_NONE; return txt_i; } diff --git a/lv_objx/lv_btnm.h b/lv_objx/lv_btnm.h index 2a0918b43..8a7dd6a1f 100644 --- a/lv_objx/lv_btnm.h +++ b/lv_objx/lv_btnm.h @@ -29,42 +29,39 @@ 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_HIDDEN_MASK 0x08 -#define LV_BTNM_NO_LPR_MASK 0x10 +#define LV_BTNM_HIDE_MASK 0x08 +#define LV_BTNM_REPEAT_DISABLE_MASK 0x10 #define LV_BTNM_RESERVED_MASK 0x20 /********************** * TYPEDEFS **********************/ -/* Type of callback function which is called when a button is released on the button matrix - * Parameters: button matrix, released button index in the map string - * return LV_ACTION_RES_INV: the button matrix is deleted else LV_ACTION_RES_OK*/ -typedef lv_action_res_t (*lv_btnm_callback_t) (lv_obj_t *, uint16_t); +/* Type of callback function which is called when a button is released or long pressed on the button matrix + * Parameters: button matrix, text of the released button + * return LV_ACTION_RES_INV if the button matrix is deleted else LV_ACTION_RES_OK*/ +typedef lv_action_res_t (*lv_btnm_action_t) (lv_obj_t *, const char *txt); /*Data of button matrix*/ typedef struct { lv_cont_ext_t bg; /*Ext. of ancestor*/ /*New data for this type */ - const char ** map_p; /*Pointer to the current map*/ - area_t * btn_areas; /*Array of areas for the buttons (Handled by the library)*/ - uint16_t btn_cnt; /*Number of button in 'map_p'(Handled by the library)*/ - uint16_t btn_pr; /*Index of the currently pressed button or LV_BTNM_PR_NONE (Handled by the library)*/ - uint16_t btn_tgl; /*Index of the currently toggled button or LV_BTNM_PR_NONE (Handled by the library)*/ - lv_btnm_callback_t cb; /*A function to call when a button is releases*/ - lv_style_t * style_btn_rel; /*Style of the released buttons*/ - lv_style_t * style_btn_pr; /*Style of the pressed buttons*/ - lv_style_t * style_btn_trel; /*Style of the toggled released buttons*/ - lv_style_t * style_btn_tpr; /*Style of the toggled pressed buttons*/ - lv_style_t * style_btn_ina; /*Style of the inactive buttons*/ - uint8_t tgl :1; /*Enable toggling*/ + const char ** map_p; /*Pointer to the current map*/ + 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*/ + 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 */ + uint8_t toggle :1; /*Enable toggling*/ }lv_btnm_ext_t; /********************** * GLOBAL PROTOTYPES **********************/ + /** * Create a button matrix objects * @param par pointer to an object, it will be the parent of the new button matrix @@ -87,10 +84,14 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param); * @param btnm pointer to a button matrix object * @param map pointer a string array. The last string has to be: "". * Use "\n" to begin a new line. - * Use octal numbers (e.g. "\003") to set the relative - * width of a button. (max. 9 -> \011) - * (e.g. const char * str[] = {"a", "b", "\n", "\004c", "d", ""}). - * The button do not copy the array so it can not be a local variable. + * The first byte can be a control data: + * - bit 7: always 1 + * - bit 6: always 0 + * - bit 5: reserved + * - bit 4: no repeat (on long press) + * - bit 3: hidden + * - bit 2..0: button relative width + * Example (practically use octal numbers): "\224abc": "abc" text with 4 width and no long press */ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map); @@ -99,7 +100,7 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map); * @param btnm: pointer to button matrix object * @param cb pointer to a callback function */ -void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_callback_t cb); +void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_action_t cb); /** * Enable or disable button toggling @@ -107,20 +108,18 @@ void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_callback_t cb); * @param en true: enable toggling; false: disable toggling * @param id index of the currently toggled button (ignored if 'en' == false) */ -void lv_btnm_set_tgl(lv_obj_t * btnm, bool en, uint16_t id); - +void lv_btnm_set_toggle(lv_obj_t * btnm, bool en, uint16_t id); /** * Set the styles of the buttons of the button matrix * @param btnm pointer to a button matrix object - * @param rel pointer to a style for releases state - * @param pr pointer to a style for pressed state - * @param trel pointer to a style for toggled releases state - * @param tpr pointer to a style for toggled pressed state - * @param ina pointer to a style for inactive state + * @param rel pointer to a style for releases state (NULL to leave it unchanged) + * @param pr pointer to a style for pressed state (NULL to leave it unchanged) + * @param trel pointer to a style for toggled releases state (NULL to leave it unchanged) + * @param tpr pointer to a style for toggled pressed state (NULL to leave it unchanged) + * @param ina pointer to a style for inactive state (NULL to leave it unchanged) */ -void lv_btnm_set_styles_btn(lv_obj_t * btnm, lv_style_t * rel, lv_style_t * pr, - lv_style_t * trel, lv_style_t * tpr, lv_style_t * ina); +void lv_btnm_set_button_style(lv_obj_t *btnm, lv_btn_state_t state, lv_style_t *style); /** * Get the current map of a button matrix @@ -134,7 +133,7 @@ const char ** lv_btnm_get_map(lv_obj_t * btnm); * @param btnm: pointer to button matrix object * @return pointer to the callback function */ -lv_btnm_callback_t lv_btnm_get_action(lv_obj_t * btnm); +lv_btnm_action_t lv_btnm_get_action(lv_obj_t * btnm); /** * Get the style of buttons in button matrix @@ -142,7 +141,7 @@ lv_btnm_callback_t lv_btnm_get_action(lv_obj_t * btnm); * @param state style in this state (LV_BTN_STATE_PR or LV_BTN_STATE_REL) * @return pointer the button style in the given state */ -lv_style_t * lv_btnm_get_style_btn(lv_obj_t * btnm, lv_btn_state_t state); +lv_style_t * lv_btnm_get_button_style(lv_obj_t * btnm, lv_btn_state_t state); /********************** * MACROS diff --git a/lv_objx/lv_cb.h b/lv_objx/lv_cb.h index 9764e4734..b39021e93 100644 --- a/lv_objx/lv_cb.h +++ b/lv_objx/lv_cb.h @@ -17,7 +17,7 @@ extern "C" { #if USE_LV_CB != 0 /*Testing of dependencies*/ -#if USE_LV_BUTTON == 0 +#if USE_LV_BTN == 0 #error "lv_cb: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) " #endif diff --git a/lv_objx/lv_img.c b/lv_objx/lv_img.c index a1a43c5cd..add0245d9 100644 --- a/lv_objx/lv_img.c +++ b/lv_objx/lv_img.c @@ -238,7 +238,7 @@ void lv_img_set_auto_size(lv_obj_t * img, bool en) /** - * Enable the upscaling with LV_DOWNSCALE. + * Enable the upscaling if LV_ANTIALIAS is enabled. * If enabled the object size will be same as the picture size. * @param img pointer to an image * @param en true: upscale enable, false: upscale disable @@ -250,9 +250,9 @@ void lv_img_set_upscale(lv_obj_t * img, bool en) /*Upscale works only if antialiassing is enabled*/ #if LV_ANTIALIAS == 0 en = false; -#endif +#else ext->upscale = (en == false ? 0 : 1); - +#endif /*Refresh the image with the new size*/ lv_img_set_file(img, ext->fn); } diff --git a/lv_objx/lv_line.c b/lv_objx/lv_line.c index 67e050bac..089fc1c0e 100644 --- a/lv_objx/lv_line.c +++ b/lv_objx/lv_line.c @@ -180,7 +180,7 @@ void lv_line_set_y_inv(lv_obj_t * line, bool yinv) } /** - * Enable (or disable) the point coordinate upscaling (compensate LV_DOWNSCALE). + * Enable (or disable) the points' coordinate upscaling (if LV_ANTIALIAS is enabled). * @param line pointer to a line object * @param unscale true: enable the point coordinate upscaling */ diff --git a/lv_objx/lv_list.h b/lv_objx/lv_list.h index 5c75d0ae1..08255843f 100644 --- a/lv_objx/lv_list.h +++ b/lv_objx/lv_list.h @@ -21,7 +21,7 @@ extern "C" { #error "lv_list: lv_page is required. Enable it in lv_conf.h (USE_LV_PAGE 1) " #endif -#if USE_LV_BUTTON == 0 +#if USE_LV_BTN == 0 #error "lv_list: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) " #endif diff --git a/lv_objx/lv_mbox.h b/lv_objx/lv_mbox.h index 202b838fe..b814d11a0 100644 --- a/lv_objx/lv_mbox.h +++ b/lv_objx/lv_mbox.h @@ -21,7 +21,7 @@ extern "C" { #error "lv_mbox: lv_cont is required. Enable it in lv_conf.h (USE_LV_CONT 1) " #endif -#if USE_LV_BUTTON == 0 +#if USE_LV_BTN == 0 #error "lv_mbox: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) " #endif diff --git a/lv_objx/lv_slider.c b/lv_objx/lv_slider.c index eb222535f..d754101bb 100644 --- a/lv_objx/lv_slider.c +++ b/lv_objx/lv_slider.c @@ -284,7 +284,7 @@ static bool lv_slider_design(lv_obj_t * slider, const area_t * mask, lv_design_m lv_style_t * style_slider = lv_obj_get_style(slider); lv_style_t * style_knob = lv_slider_get_style_knob(slider); - lv_style_t * style_indic = lv_bar_get_style_indic(slider); + lv_style_t * style_indic = lv_bar_get_indicator_style(slider); /*Draw the bar*/ area_t area_bar; diff --git a/lv_objx/lv_tabview.c b/lv_objx/lv_tabview.c index 0e6fc4f09..9b6d2c2b0 100644 --- a/lv_objx/lv_tabview.c +++ b/lv_objx/lv_tabview.c @@ -93,7 +93,7 @@ lv_obj_t * lv_tabview_create(lv_obj_t * par, lv_obj_t * copy) lv_btnm_set_map(ext->tabs, tab_def); lv_obj_set_height(ext->tabs, 3 * LV_DPI / 4); lv_btnm_set_action(ext->tabs, tab_btnm_action); - lv_btnm_set_tgl(ext->tabs, true, 0); + lv_btnm_set_toggle(ext->tabs, true, 0); ext->indic = lv_obj_create(ext->tabs, NULL); lv_style_t * style_indic = lv_obj_get_style(ext->indic); @@ -279,7 +279,7 @@ void lv_tabview_set_act(lv_obj_t * tabview, uint16_t id, bool anim_en) anim_create(&a); } - lv_btnm_set_tgl(ext->tabs, true, ext->tab_act); + lv_btnm_set_toggle(ext->tabs, true, ext->tab_act); } /*===================== diff --git a/lv_objx/lv_win.h b/lv_objx/lv_win.h index f3790fdc0..d4b651c65 100644 --- a/lv_objx/lv_win.h +++ b/lv_objx/lv_win.h @@ -17,7 +17,7 @@ extern "C" { #if USE_LV_WIN != 0 /*Testing of dependencies*/ -#if USE_LV_BUTTON == 0 +#if USE_LV_BTN == 0 #error "lv_win: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) " #endif