Minor fixes

This commit is contained in:
Gabor
2016-12-15 10:31:30 +01:00
parent 320a5b524c
commit 2eefe1a231
21 changed files with 238 additions and 128 deletions

View File

@@ -126,10 +126,10 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
/**
* Set a new map. Buttons will be created/deleted according to the map.
* @param btnm pointer to a button matrix object
* @param map pointer a string array. Tha last string hast be: "".
* @param map pointer a string array. The last string has to be: "".
* Use "\n" to begin a new line.
* Use "\003" octal numbers to set relative
* the width of a button. (max. 9 -> \011)
* 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", ""}).
*/
void lv_btnm_set_map(lv_obj_t * btnm, const char ** map)
@@ -143,10 +143,9 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map)
/*Set size and positions of the buttons*/
lv_btnms_t * btnms = lv_obj_get_style(btnm);
cord_t max_w = lv_obj_get_width(btnm) - 2 * btnms->bg.hpad;
cord_t max_h = lv_obj_get_height(btnm) - 2 * btnms->bg.vpad;
cord_t act_y = btnms->bg.vpad;
uint8_t btn_cnt_tot = 0; /*Used to set free number of the buttons*/
cord_t max_w = lv_obj_get_width(btnm) - 2 * btnms->rects.hpad;
cord_t max_h = lv_obj_get_height(btnm) - 2 * btnms->rects.vpad;
cord_t act_y = btnms->rects.vpad;
/*Count the lines to calculate button height*/
uint8_t line_cnt = 1;
@@ -155,13 +154,14 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map)
if(strcmp(map[li], "\n") == 0) line_cnt ++;
}
cord_t btn_h = max_h - ((line_cnt - 1) * btnms->bg.opad);
cord_t btn_h = max_h - ((line_cnt - 1) * btnms->rects.opad);
btn_h = btn_h / line_cnt;
/* Count the units and the buttons in a line
* (A button can be 1,2,3... unit wide)*/
uint16_t unit_cnt;
uint16_t btn_cnt;
uint16_t btn_cnt; /*Number of buttons in a row*/
uint16_t i_tot = 0; /*Act. index in the str map*/
const char ** map_p_tmp = map;
lv_obj_t * btn;
btn = ll_get_head(&btnm->child_ll);
@@ -170,6 +170,7 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map)
while(1) {
unit_cnt = 0;
btn_cnt = 0;
/*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]);
@@ -179,31 +180,32 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map)
/*Only deal with the non empty lines*/
if(btn_cnt != 0) {
/*Calculate the unit width*/
cord_t unit_w = max_w - ((btn_cnt-1) * btnms->bg.opad);
cord_t unit_w = max_w - ((btn_cnt-1) * btnms->rects.opad);
unit_w = unit_w / unit_cnt;
/*Set the button size and positions and set the texts*/
uint16_t i;
lv_obj_t * label;
cord_t act_x = btnms->bg.hpad;
cord_t act_x = btnms->rects.hpad;
for(i = 0; i < btn_cnt; i++) {
lv_obj_set_size(btn, unit_w * lv_btnm_get_width_unit(map_p_tmp[i]), btn_h);
lv_obj_align(btn, NULL, LV_ALIGN_IN_TOP_LEFT, act_x, act_y);
lv_obj_set_free_num(btn, btn_cnt_tot);
lv_obj_set_style(btn, &btnms->btn);
act_x += lv_obj_get_width(btn) + btnms->bg.opad;
lv_obj_set_free_num(btn, i_tot);
lv_obj_set_style(btn, &btnms->btns);
act_x += lv_obj_get_width(btn) + btnms->rects.opad;
label = lv_obj_get_child(btn, NULL); /*Get the label on the button (the only child)*/
lv_obj_set_style(label, &btnms->btn_label);
lv_obj_set_style(label, &btnms->labels);
lv_label_set_text(label, map_p_tmp[i]);
btn = ll_get_next(&btnm->child_ll, btn); /*Go to the next button*/
btn_cnt_tot ++;
i_tot++;
}
}
act_y += btn_h + btnms->bg.opad;
act_y += btn_h + btnms->rects.opad;
if(strlen(map_p_tmp[btn_cnt]) == 0) break; /*Break on end of map*/
map_p_tmp = &map_p_tmp[btn_cnt + 1]; /*Set the map to the next line*/
i_tot ++; /*Skip the '\n'*/
}
}
@@ -312,9 +314,9 @@ static bool lv_btnm_design(lv_obj_t * obj, const area_t * mask, lv_design_mode_t
static void lv_btnms_init(void)
{
/*Default style*/
lv_rects_get(LV_RECTS_DEF, &lv_btnms_def.bg); /*Background rectangle style*/
lv_btns_get(LV_BTNS_DEF, &lv_btnms_def.btn); /*Button style*/
lv_labels_get(LV_LABELS_BTN, &lv_btnms_def.btn_label); /*BUtton label style*/
lv_rects_get(LV_RECTS_DEF, &lv_btnms_def.rects); /*Background rectangle style*/
lv_btns_get(LV_BTNS_DEF, &lv_btnms_def.btns); /*Button style*/
lv_labels_get(LV_LABELS_BTN, &lv_btnms_def.labels); /*BUtton label style*/
}
/**