1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

btnm fixes

This commit is contained in:
Gabor Kiss-Vamosi 2019-02-27 06:17:37 +01:00
parent 1efb3d87c8
commit 53b8056502
3 changed files with 55 additions and 22 deletions

View File

@ -28,10 +28,10 @@
**********************/
static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param);
static bool lv_btnm_design(lv_obj_t * btnm, const lv_area_t * mask, lv_design_mode_t mode);
static uint8_t get_button_width(lv_btn_ctrl_t ctrl_bits);
static bool button_is_hidden(lv_btn_ctrl_t ctrl_bits);
static bool button_is_repeat_disabled(lv_btn_ctrl_t ctrl_bits);
static bool button_is_inactive(lv_btn_ctrl_t ctrl_bits);
static uint8_t get_button_width(lv_btnm_ctrl_t ctrl_bits);
static bool button_is_hidden(lv_btnm_ctrl_t ctrl_bits);
static bool button_is_repeat_disabled(lv_btnm_ctrl_t ctrl_bits);
static bool button_is_inactive(lv_btnm_ctrl_t ctrl_bits);
const char * cut_ctrl_byte(const char * btn_str);
static uint16_t get_button_from_point(lv_obj_t * btnm, lv_point_t * p);
static uint16_t get_button_text(lv_obj_t * btnm, uint16_t btn_id);
@ -284,10 +284,10 @@ void lv_btnm_set_map(const lv_obj_t * btnm, const char ** map)
* - bit 2..0: Relative width compared to the buttons in the
* same row. [1..7]
*/
void lv_btnm_set_ctrl_map(const lv_obj_t * btnm, lv_btn_ctrl_t * ctrl_map)
void lv_btnm_set_ctrl_map(const lv_obj_t * btnm, const lv_btnm_ctrl_t * ctrl_map)
{
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
memcpy(ext->ctrl_bits, ctrl_map, sizeof(lv_btn_ctrl_t) * ext->btn_cnt);
memcpy(ext->ctrl_bits, ctrl_map, sizeof(lv_btnm_ctrl_t) * ext->btn_cnt);
lv_btnm_set_map(btnm, ext->map_p);
}
@ -692,8 +692,6 @@ static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
if(res != LV_RES_OK) return res;
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
//lv_area_t btnm_area;
lv_area_t btn_area;
lv_point_t p;
if(sign == LV_SIGNAL_CLEANUP) {
lv_mem_free(ext->button_areas);
@ -708,7 +706,6 @@ static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
/*Invalidate to old and the new areas*/;
//lv_obj_get_coords(btnm, &btnm_area);
if(btn_pr != ext->btn_id_pr) {
lv_disp_t * disp = lv_obj_get_disp(btnm);
lv_indev_reset_lpr(param);
if(ext->btn_id_pr != LV_BTNM_PR_NONE) {
invalidate_button_area(btnm, ext->btn_id_pr);
@ -737,8 +734,6 @@ static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
if(button_is_inactive(ext->ctrl_bits[ext->btn_id_pr]) == false && txt_i != LV_BTNM_PR_NONE) { /*Ignore the inactive buttons and clicks between the buttons*/
if(ext->action) res = ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i]));
if(res == LV_RES_OK) {
lv_disp_t * disp = lv_obj_get_disp(btnm);
/*Invalidate to old pressed area*/;
invalidate_button_area(btnm, ext->btn_id_pr);
@ -892,7 +887,7 @@ static void allocate_btn_areas_and_controls(const lv_obj_t * btnm, const char **
ext->button_areas = lv_mem_alloc(sizeof(lv_area_t) * btn_cnt);
lv_mem_assert(ext->button_areas);
ext->ctrl_bits = lv_mem_alloc(sizeof(lv_btn_ctrl_t) * btn_cnt);
ext->ctrl_bits = lv_mem_alloc(sizeof(lv_btnm_ctrl_t) * btn_cnt);
lv_mem_assert(ext->ctrl_bits);
if(ext->button_areas == NULL || ext->ctrl_bits == NULL) btn_cnt = 0;
@ -921,22 +916,22 @@ static void parse_control_bytes(const lv_obj_t * btnm, const char ** map)
* @param ctrl_bits least significant 3 bits used (1..7 valid values)
* @return the width of the button in units
*/
static uint8_t get_button_width(lv_btn_ctrl_t ctrl_bits)
static uint8_t get_button_width(lv_btnm_ctrl_t ctrl_bits)
{
return ctrl_bits ? ctrl_bits & LV_BTNM_WIDTH_MASK : 1;
}
static bool button_is_hidden(lv_btn_ctrl_t ctrl_bits)
static bool button_is_hidden(lv_btnm_ctrl_t ctrl_bits)
{
return ctrl_bits & LV_BTNM_HIDE_MASK;
}
static bool button_is_repeat_disabled(lv_btn_ctrl_t ctrl_bits)
static bool button_is_repeat_disabled(lv_btnm_ctrl_t ctrl_bits)
{
return ctrl_bits & LV_BTNM_REPEAT_DISABLE_MASK;
}
static bool button_is_inactive(lv_btn_ctrl_t ctrl_bits)
static bool button_is_inactive(lv_btnm_ctrl_t ctrl_bits)
{
return ctrl_bits & LV_BTNM_INACTIVE_MASK;
}
@ -1021,7 +1016,7 @@ static void invalidate_button_area(const lv_obj_t * btnm, uint16_t btn_idx)
btn_area.x2 += btnm_area.x1;
btn_area.y2 += btnm_area.y1;
lv_inv_area(&btn_area);
lv_inv_area(lv_obj_get_disp(btnm), &btn_area);
}
/**
@ -1041,6 +1036,7 @@ static bool maps_are_identical(const char ** map1, const char ** map2)
while (map1[i][0] != '\0' && map2[i][0] != '\0') {
if (strcmp(map1[i], map2[i]) !=0 )
return false;
i++;
}
return map1[i][0] == '\0' && map2[i][0] == '\0';
}

View File

@ -53,7 +53,7 @@ extern "C" {
typedef lv_res_t (*lv_btnm_action_t) (lv_obj_t *, const char *txt);
/* Type to store button control bits (disabled, hidden etc.) */
typedef uint8_t lv_btn_ctrl_t;
typedef uint8_t lv_btnm_ctrl_t;
/*Data of button matrix*/
typedef struct
@ -62,7 +62,7 @@ typedef struct
/*New data for this type */
const char ** map_p; /*Pointer to the current map*/
lv_area_t *button_areas; /*Array of areas of buttons*/
lv_btn_ctrl_t *ctrl_bits; /*Array of control bytes*/
lv_btnm_ctrl_t *ctrl_bits; /*Array of control bytes*/
lv_btnm_action_t action; /*A function to call when a button is releases*/
lv_style_t *styles_btn[LV_BTN_STATE_NUM]; /*Styles of buttons in each state*/
uint16_t btn_cnt; /*Number of button in 'map_p'(Handled by the library)*/
@ -132,7 +132,7 @@ void lv_btnm_set_map(const lv_obj_t * btnm, const char ** map);
* - bit 2..0: Relative width compared to the buttons in the
* same row. [1..7]
*/
void lv_btnm_set_ctrl_map(const lv_obj_t * btnm, lv_btn_ctrl_t * ctrl_map);
void lv_btnm_set_ctrl_map(const lv_obj_t * btnm, const lv_btnm_ctrl_t * ctrl_map);
/**
* Set a new callback function for the buttons (It will be called when a button is released)

View File

@ -39,6 +39,13 @@ static const char * kb_map_lc[] = {
"\202"SYMBOL_CLOSE, "\202"SYMBOL_LEFT, "\206 ", "\202"SYMBOL_RIGHT, "\202"SYMBOL_OK, ""
};
static const lv_btnm_ctrl_t kb_ctrl_lc_map[] = {
5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 7,
(6 | LV_BTNM_REPEAT_DISABLE_MASK), 3, 3, 3, 3, 3, 3, 3, 3, 3, 7,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 6, 2, 2
};
static const char * kb_map_uc[] = {
"\2051#", "\204Q", "\204W", "\204E", "\204R", "\204T", "\204Y", "\204U", "\204I", "\204O", "\204P", "\207Bksp", "\n",
"\226abc", "\203A", "\203S", "\203D", "\203F", "\203G", "\203H", "\203J", "\203K", "\203L", "\207Enter", "\n",
@ -46,6 +53,13 @@ static const char * kb_map_uc[] = {
"\202"SYMBOL_CLOSE, "\202"SYMBOL_LEFT, "\206 ", "\202"SYMBOL_RIGHT, "\202"SYMBOL_OK, ""
};
static const lv_btnm_ctrl_t kb_ctrl_uc_map[] = {
5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 7,
(6 | LV_BTNM_REPEAT_DISABLE_MASK), 3, 3, 3, 3, 3, 3, 3, 3, 3, 7,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 6, 2, 2
};
static const char * kb_map_spec[] = {
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "\202Bksp", "\n",
"\222abc", "+", "-", "/", "*", "=", "%", "!", "?", "#", "<", ">", "\n",
@ -53,12 +67,25 @@ static const char * kb_map_spec[] = {
"\202"SYMBOL_CLOSE, "\202"SYMBOL_LEFT, "\206 ", "\202"SYMBOL_RIGHT, "\202"SYMBOL_OK, ""
};
static const lv_btnm_ctrl_t kb_ctrl_spec_map[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
(2 | LV_BTNM_REPEAT_DISABLE_MASK), 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 6, 2, 2
};
static const char * kb_map_num[] = {
"1", "2", "3", "\202"SYMBOL_CLOSE, "\n",
"4", "5", "6", "\202"SYMBOL_OK, "\n",
"7", "8", "9", "\202Bksp", "\n",
"+/-", "0", ".", SYMBOL_LEFT, SYMBOL_RIGHT, ""
};
static const lv_btnm_ctrl_t kb_ctrl_num_map[] = {
1, 1, 1, 2,
1, 1, 1, 2,
1, 1, 1, 1, 1
};
/**********************
* MACROS
**********************/
@ -106,6 +133,7 @@ lv_obj_t * lv_kb_create(lv_obj_t * par, const lv_obj_t * copy)
lv_obj_align(new_kb, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
lv_btnm_set_action(new_kb, lv_kb_def_action);
lv_btnm_set_map(new_kb, kb_map_lc);
lv_btnm_set_ctrl_map(new_kb, kb_ctrl_lc_map);
/*Set the default styles*/
lv_theme_t * th = lv_theme_get_current();
@ -181,8 +209,14 @@ void lv_kb_set_mode(lv_obj_t * kb, lv_kb_mode_t mode)
if(ext->mode == mode) return;
ext->mode = mode;
if(mode == LV_KB_MODE_TEXT) lv_btnm_set_map(kb, kb_map_lc);
else if(mode == LV_KB_MODE_NUM) lv_btnm_set_map(kb, kb_map_num);
if(mode == LV_KB_MODE_TEXT) {
lv_btnm_set_map(kb, kb_map_lc);
lv_btnm_set_ctrl_map(kb, kb_ctrl_lc_map);
}
else if(mode == LV_KB_MODE_NUM) {
lv_btnm_set_map(kb, kb_map_num);
lv_btnm_set_ctrl_map(kb, kb_ctrl_num_map);
}
}
@ -406,12 +440,15 @@ static lv_res_t lv_kb_def_action(lv_obj_t * kb, const char * txt)
/*Do the corresponding action according to the text of the button*/
if(strcmp(txt, "abc") == 0) {
lv_btnm_set_map(kb, kb_map_lc);
lv_btnm_set_ctrl_map(kb, kb_ctrl_lc_map);
return LV_RES_OK;
} else if(strcmp(txt, "ABC") == 0) {
lv_btnm_set_map(kb, kb_map_uc);
lv_btnm_set_ctrl_map(kb, kb_ctrl_uc_map);
return LV_RES_OK;
} else if(strcmp(txt, "1#") == 0) {
lv_btnm_set_map(kb, kb_map_spec);
lv_btnm_set_ctrl_map(kb, kb_ctrl_spec_map);
return LV_RES_OK;
} else if(strcmp(txt, SYMBOL_CLOSE) == 0) {
if(ext->hide_action) res = ext->hide_action(kb);