fix(buttonmatrix): use const arrays (#6765)
Co-authored-by: Julian Foad <julian@foad.me.uk>
This commit is contained in:
@@ -51,7 +51,7 @@ static bool button_is_popover(lv_buttonmatrix_ctrl_t ctrl_bits);
|
||||
static bool button_is_checkable(lv_buttonmatrix_ctrl_t ctrl_bits);
|
||||
static bool button_get_checked(lv_buttonmatrix_ctrl_t ctrl_bits);
|
||||
static uint32_t get_button_from_point(lv_obj_t * obj, lv_point_t * p);
|
||||
static void allocate_button_areas_and_controls(const lv_obj_t * obj, const char ** map);
|
||||
static void allocate_button_areas_and_controls(const lv_obj_t * obj, const char * const * map);
|
||||
static void invalidate_button_area(const lv_obj_t * obj, uint32_t btn_idx);
|
||||
static void make_one_button_checked(lv_obj_t * obj, uint32_t btn_idx);
|
||||
static bool has_popovers_in_top_row(lv_obj_t * obj);
|
||||
@@ -60,7 +60,7 @@ static bool has_popovers_in_top_row(lv_obj_t * obj);
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
#if LV_WIDGETS_HAS_DEFAULT_VALUE
|
||||
static const char * lv_buttonmatrix_def_map[] = {"Btn1", "Btn2", "Btn3", "\n", "Btn4", "Btn5", ""};
|
||||
static const char * const lv_buttonmatrix_def_map[] = {"Btn1", "Btn2", "Btn3", "\n", "Btn4", "Btn5", ""};
|
||||
#endif
|
||||
|
||||
const lv_obj_class_t lv_buttonmatrix_class = {
|
||||
@@ -96,7 +96,7 @@ lv_obj_t * lv_buttonmatrix_create(lv_obj_t * parent)
|
||||
* Setter functions
|
||||
*====================*/
|
||||
|
||||
void lv_buttonmatrix_set_map(lv_obj_t * obj, const char * map[])
|
||||
void lv_buttonmatrix_set_map(lv_obj_t * obj, const char * const map[])
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
if(map == NULL) return;
|
||||
@@ -125,7 +125,7 @@ void lv_buttonmatrix_set_map(lv_obj_t * obj, const char * map[])
|
||||
*(A button can be 1,2,3... unit wide)*/
|
||||
uint32_t txt_tot_i = 0; /*Act. index in the str map*/
|
||||
uint32_t btn_tot_i = 0; /*Act. index of button areas*/
|
||||
const char ** map_row = map;
|
||||
const char * const * map_row = map;
|
||||
|
||||
/*Count the units and the buttons in a line*/
|
||||
uint32_t row;
|
||||
@@ -295,7 +295,7 @@ void lv_buttonmatrix_set_one_checked(lv_obj_t * obj, bool en)
|
||||
* Getter functions
|
||||
*====================*/
|
||||
|
||||
const char ** lv_buttonmatrix_get_map(const lv_obj_t * obj)
|
||||
const char * const * lv_buttonmatrix_get_map(const lv_obj_t * obj)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
|
||||
@@ -813,7 +813,7 @@ static void draw_main(lv_event_t * e)
|
||||
* @param obj pointer to button matrix object
|
||||
* @param map_p pointer to a string array
|
||||
*/
|
||||
static void allocate_button_areas_and_controls(const lv_obj_t * obj, const char ** map)
|
||||
static void allocate_button_areas_and_controls(const lv_obj_t * obj, const char * const * map)
|
||||
{
|
||||
lv_buttonmatrix_t * btnm = (lv_buttonmatrix_t *)obj;
|
||||
btnm->row_cnt = 1;
|
||||
@@ -1029,7 +1029,7 @@ static bool has_popovers_in_top_row(lv_obj_t * obj)
|
||||
return false;
|
||||
}
|
||||
|
||||
const char ** map_row = btnm->map_p;
|
||||
const char * const * map_row = btnm->map_p;
|
||||
uint32_t btn_cnt = 0;
|
||||
|
||||
while(map_row[btn_cnt] && lv_strcmp(map_row[btn_cnt], "\n") != 0 && map_row[btn_cnt][0] != '\0') {
|
||||
|
||||
@@ -73,7 +73,7 @@ lv_obj_t * lv_buttonmatrix_create(lv_obj_t * parent);
|
||||
* @param obj pointer to a button matrix object
|
||||
* @param map pointer a string array. The last string has to be: "". Use "\n" to make a line break.
|
||||
*/
|
||||
void lv_buttonmatrix_set_map(lv_obj_t * obj, const char * map[]);
|
||||
void lv_buttonmatrix_set_map(lv_obj_t * obj, const char * const map[]);
|
||||
|
||||
/**
|
||||
* Set the button control map (hidden, disabled etc.) for a button matrix.
|
||||
@@ -155,7 +155,7 @@ void lv_buttonmatrix_set_one_checked(lv_obj_t * obj, bool en);
|
||||
* @param obj pointer to a button matrix object
|
||||
* @return the current map
|
||||
*/
|
||||
const char ** lv_buttonmatrix_get_map(const lv_obj_t * obj);
|
||||
const char * const * lv_buttonmatrix_get_map(const lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get the index of the lastly "activated" button by the user (pressed, released, focused etc)
|
||||
|
||||
@@ -30,7 +30,7 @@ extern "C" {
|
||||
/** Data of button matrix */
|
||||
struct lv_buttonmatrix_t {
|
||||
lv_obj_t obj;
|
||||
const char ** map_p; /**< Pointer to the current map */
|
||||
const char * const * map_p; /**< Pointer to the current map */
|
||||
lv_area_t * button_areas; /**< Array of areas of buttons */
|
||||
lv_buttonmatrix_ctrl_t * ctrl_bits; /**< Array of control bytes */
|
||||
uint32_t btn_cnt; /**< Number of button in 'map_p'(Handled by the library) */
|
||||
|
||||
@@ -176,19 +176,19 @@ static const lv_buttonmatrix_ctrl_t default_kb_ctrl_num_map[] = {
|
||||
1, 1, 1, 1, 1
|
||||
};
|
||||
|
||||
static const char * * kb_map[10] = {
|
||||
(const char * *)default_kb_map_lc,
|
||||
(const char * *)default_kb_map_uc,
|
||||
(const char * *)default_kb_map_spec,
|
||||
(const char * *)default_kb_map_num,
|
||||
(const char * *)default_kb_map_lc,
|
||||
(const char * *)default_kb_map_lc,
|
||||
(const char * *)default_kb_map_lc,
|
||||
(const char * *)default_kb_map_lc,
|
||||
static const char * const * kb_map[10] = {
|
||||
default_kb_map_lc,
|
||||
default_kb_map_uc,
|
||||
default_kb_map_spec,
|
||||
default_kb_map_num,
|
||||
default_kb_map_lc,
|
||||
default_kb_map_lc,
|
||||
default_kb_map_lc,
|
||||
default_kb_map_lc,
|
||||
#if LV_USE_ARABIC_PERSIAN_CHARS == 1
|
||||
(const char * *)default_kb_map_ar,
|
||||
default_kb_map_ar,
|
||||
#endif
|
||||
(const char * *)NULL
|
||||
NULL
|
||||
};
|
||||
static const lv_buttonmatrix_ctrl_t * kb_ctrl[10] = {
|
||||
default_kb_ctrl_lc_map,
|
||||
@@ -269,7 +269,7 @@ void lv_keyboard_set_popovers(lv_obj_t * obj, bool en)
|
||||
lv_keyboard_update_ctrl_map(obj);
|
||||
}
|
||||
|
||||
void lv_keyboard_set_map(lv_obj_t * obj, lv_keyboard_mode_t mode, const char * map[],
|
||||
void lv_keyboard_set_map(lv_obj_t * obj, lv_keyboard_mode_t mode, const char * const map[],
|
||||
const lv_buttonmatrix_ctrl_t ctrl_map[])
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
@@ -410,7 +410,7 @@ void lv_keyboard_def_event_cb(lv_event_t * e)
|
||||
}
|
||||
}
|
||||
|
||||
const char ** lv_keyboard_get_map_array(const lv_obj_t * kb)
|
||||
const char * const * lv_keyboard_get_map_array(const lv_obj_t * kb)
|
||||
{
|
||||
return lv_buttonmatrix_get_map(kb);
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ void lv_keyboard_set_popovers(lv_obj_t * kb, bool en);
|
||||
* @param ctrl_map See 'lv_buttonmatrix_set_ctrl_map()' for more info.
|
||||
|
||||
*/
|
||||
void lv_keyboard_set_map(lv_obj_t * kb, lv_keyboard_mode_t mode, const char * map[],
|
||||
void lv_keyboard_set_map(lv_obj_t * kb, lv_keyboard_mode_t mode, const char * const map[],
|
||||
const lv_buttonmatrix_ctrl_t ctrl_map[]);
|
||||
|
||||
/*=====================
|
||||
@@ -140,7 +140,7 @@ bool lv_keyboard_get_popovers(const lv_obj_t * obj);
|
||||
* @param kb pointer to a keyboard object
|
||||
* @return the current map
|
||||
*/
|
||||
const char ** lv_keyboard_get_map_array(const lv_obj_t * kb);
|
||||
const char * const * lv_keyboard_get_map_array(const lv_obj_t * kb);
|
||||
|
||||
/**
|
||||
* Get the index of the lastly "activated" button by the user (pressed, released, focused etc)
|
||||
|
||||
@@ -25,7 +25,7 @@ void tearDown(void)
|
||||
|
||||
void test_button_matrix_creation(void)
|
||||
{
|
||||
const char ** map;
|
||||
const char * const * map;
|
||||
|
||||
/* Verify the default map. */
|
||||
map = lv_buttonmatrix_get_map(btnm);
|
||||
@@ -39,7 +39,7 @@ void test_button_matrix_creation(void)
|
||||
|
||||
void test_button_matrix_set_map_works(void)
|
||||
{
|
||||
const char ** ret_map;
|
||||
const char * const * ret_map;
|
||||
static const char * exp_map[] = {"A", "B", "\n", "C", "D", ""};
|
||||
|
||||
lv_buttonmatrix_set_map(btnm, exp_map);
|
||||
|
||||
Reference in New Issue
Block a user