refactor(btn, img): rename btn to button and img to image

This commit is contained in:
Gabor Kiss-Vamosi
2023-09-14 20:12:31 +02:00
parent e91786ce49
commit 09c12d0f9c
366 changed files with 3271 additions and 3222 deletions

View File

@@ -6,8 +6,8 @@ static void event_handler(lv_event_t * e)
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * obj = lv_event_get_target(e);
if(code == LV_EVENT_VALUE_CHANGED) {
uint32_t id = lv_btnmatrix_get_selected_btn(obj);
const char * txt = lv_btnmatrix_get_btn_text(obj, id);
uint32_t id = lv_buttonmatrix_get_selected_button(obj);
const char * txt = lv_buttonmatrix_get_button_text(obj, id);
LV_UNUSED(txt);
LV_LOG_USER("%s was pressed\n", txt);
}
@@ -19,13 +19,13 @@ static const char * btnm_map[] = {"1", "2", "3", "4", "5", "\n",
"Action1", "Action2", ""
};
void lv_example_btnmatrix_1(void)
void lv_example_buttonmatrix_1(void)
{
lv_obj_t * btnm1 = lv_btnmatrix_create(lv_scr_act());
lv_btnmatrix_set_map(btnm1, btnm_map);
lv_btnmatrix_set_btn_width(btnm1, 10, 2); /*Make "Action1" twice as wide as "Action2"*/
lv_btnmatrix_set_btn_ctrl(btnm1, 10, LV_BTNMATRIX_CTRL_CHECKABLE);
lv_btnmatrix_set_btn_ctrl(btnm1, 11, LV_BTNMATRIX_CTRL_CHECKED);
lv_obj_t * btnm1 = lv_buttonmatrix_create(lv_scr_act());
lv_buttonmatrix_set_map(btnm1, btnm_map);
lv_buttonmatrix_set_button_width(btnm1, 10, 2); /*Make "Action1" twice as wide as "Action2"*/
lv_buttonmatrix_set_button_ctrl(btnm1, 10, LV_BUTTONMATRIX_CTRL_CHECKABLE);
lv_buttonmatrix_set_button_ctrl(btnm1, 11, LV_BUTTONMATRIX_CTRL_CHECKED);
lv_obj_align(btnm1, LV_ALIGN_CENTER, 0, 0);
lv_obj_add_event(btnm1, event_handler, LV_EVENT_ALL, NULL);
}

View File

@@ -3,22 +3,22 @@ def event_handler(e):
obj = e.get_target_obj()
if code == lv.EVENT.VALUE_CHANGED :
id = obj.get_selected_btn()
txt = obj.get_btn_text(id)
id = obj.get_selected_button()
txt = obj.get_button_text(id)
print("%s was pressed"%txt)
btnm_map = ["1", "2", "3", "4", "5", "\n",
buttonm_map = ["1", "2", "3", "4", "5", "\n",
"6", "7", "8", "9", "0", "\n",
"Action1", "Action2", ""]
btnm1 = lv.btnmatrix(lv.scr_act())
btnm1.set_map(btnm_map)
btnm1.set_btn_width(10, 2) # Make "Action1" twice as wide as "Action2"
btnm1.set_btn_ctrl(10, lv.btnmatrix.CTRL.CHECKABLE)
btnm1.set_btn_ctrl(11, lv.btnmatrix.CTRL.CHECKED)
btnm1.align(lv.ALIGN.CENTER, 0, 0)
btnm1.add_event(event_handler, lv.EVENT.ALL, None)
buttonm1 = lv.buttonmatrix(lv.scr_act())
buttonm1.set_map(buttonm_map)
buttonm1.set_button_width(10, 2) # Make "Action1" twice as wide as "Action2"
buttonm1.set_button_ctrl(10, lv.buttonmatrix.CTRL.CHECKABLE)
buttonm1.set_button_ctrl(11, lv.buttonmatrix.CTRL.CHECKED)
buttonm1.align(lv.ALIGN.CENTER, 0, 0)
buttonm1.add_event(event_handler, lv.EVENT.ALL, None)
#endif

View File

@@ -10,7 +10,7 @@ static void event_cb(lv_event_t * e)
/*When the button matrix draws the buttons...*/
if(base_dsc->part == LV_PART_ITEMS) {
bool pressed = false;
if(lv_btnmatrix_get_selected_btn(obj) == base_dsc->id1 && lv_obj_has_state(obj, LV_STATE_PRESSED)) {
if(lv_buttonmatrix_get_selected_button(obj) == base_dsc->id1 && lv_obj_has_state(obj, LV_STATE_PRESSED)) {
pressed = true;
}
@@ -46,9 +46,9 @@ static void event_cb(lv_event_t * e)
label_draw_dsc->opa = 0;
}
if(draw_task->type == LV_DRAW_TASK_TYPE_FILL) {
LV_IMG_DECLARE(img_star);
lv_img_header_t header;
lv_res_t res = lv_img_decoder_get_info(&img_star, &header);
LV_IMAGE_DECLARE(img_star);
lv_image_header_t header;
lv_res_t res = lv_image_decoder_get_info(&img_star, &header);
if(res != LV_RES_OK) return;
lv_area_t a;
@@ -58,13 +58,13 @@ static void event_cb(lv_event_t * e)
a.y2 = header.h - 1;
lv_area_align(&draw_task->area, &a, LV_ALIGN_CENTER, 0, 0);
lv_draw_img_dsc_t img_draw_dsc;
lv_draw_img_dsc_init(&img_draw_dsc);
lv_draw_image_dsc_t img_draw_dsc;
lv_draw_image_dsc_init(&img_draw_dsc);
img_draw_dsc.src = &img_star;
img_draw_dsc.recolor = lv_color_black();
if(pressed) img_draw_dsc.recolor_opa = LV_OPA_30;
lv_draw_img(base_dsc->layer, &img_draw_dsc, &a);
lv_draw_image(base_dsc->layer, &img_draw_dsc, &a);
}
}
@@ -74,9 +74,9 @@ static void event_cb(lv_event_t * e)
/**
* Add custom drawer to the button matrix to customize buttons one by one
*/
void lv_example_btnmatrix_2(void)
void lv_example_buttonmatrix_2(void)
{
lv_obj_t * btnm = lv_btnmatrix_create(lv_scr_act());
lv_obj_t * btnm = lv_buttonmatrix_create(lv_scr_act());
lv_obj_add_event(btnm, event_cb, LV_EVENT_DRAW_TASK_ADDED, NULL);
lv_obj_add_flag(btnm, LV_OBJ_FLAG_SEND_DRAW_TASK_EVENTS);
lv_obj_center(btnm);

View File

@@ -4,27 +4,27 @@
static void event_cb(lv_event_t * e)
{
lv_obj_t * obj = lv_event_get_target(e);
uint32_t id = lv_btnmatrix_get_selected_btn(obj);
uint32_t id = lv_buttonmatrix_get_selected_button(obj);
bool prev = id == 0;
bool next = id == 6;
if(prev || next) {
/*Find the checked button*/
uint32_t i;
for(i = 1; i < 7; i++) {
if(lv_btnmatrix_has_btn_ctrl(obj, i, LV_BTNMATRIX_CTRL_CHECKED)) break;
if(lv_buttonmatrix_has_button_ctrl(obj, i, LV_BUTTONMATRIX_CTRL_CHECKED)) break;
}
if(prev && i > 1) i--;
else if(next && i < 5) i++;
lv_btnmatrix_set_btn_ctrl(obj, i, LV_BTNMATRIX_CTRL_CHECKED);
lv_buttonmatrix_set_button_ctrl(obj, i, LV_BUTTONMATRIX_CTRL_CHECKED);
}
}
/**
* Make a button group (pagination)
*/
void lv_example_btnmatrix_3(void)
void lv_example_buttonmatrix_3(void)
{
static lv_style_t style_bg;
lv_style_init(&style_bg);
@@ -46,20 +46,20 @@ void lv_example_btnmatrix_3(void)
static const char * map[] = {LV_SYMBOL_LEFT, "1", "2", "3", "4", "5", LV_SYMBOL_RIGHT, ""};
lv_obj_t * btnm = lv_btnmatrix_create(lv_scr_act());
lv_btnmatrix_set_map(btnm, map);
lv_obj_t * btnm = lv_buttonmatrix_create(lv_scr_act());
lv_buttonmatrix_set_map(btnm, map);
lv_obj_add_style(btnm, &style_bg, 0);
lv_obj_add_style(btnm, &style_btn, LV_PART_ITEMS);
lv_obj_add_event(btnm, event_cb, LV_EVENT_VALUE_CHANGED, NULL);
lv_obj_set_size(btnm, 225, 35);
/*Allow selecting on one number at time*/
lv_btnmatrix_set_btn_ctrl_all(btnm, LV_BTNMATRIX_CTRL_CHECKABLE);
lv_btnmatrix_clear_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKABLE);
lv_btnmatrix_clear_btn_ctrl(btnm, 6, LV_BTNMATRIX_CTRL_CHECKABLE);
lv_buttonmatrix_set_button_ctrl_all(btnm, LV_BUTTONMATRIX_CTRL_CHECKABLE);
lv_buttonmatrix_clear_button_ctrl(btnm, 0, LV_BUTTONMATRIX_CTRL_CHECKABLE);
lv_buttonmatrix_clear_button_ctrl(btnm, 6, LV_BUTTONMATRIX_CTRL_CHECKABLE);
lv_btnmatrix_set_one_checked(btnm, true);
lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKED);
lv_buttonmatrix_set_one_checked(btnm, true);
lv_buttonmatrix_set_button_ctrl(btnm, 1, LV_BUTTONMATRIX_CTRL_CHECKED);
lv_obj_center(btnm);

View File

@@ -1,6 +1,6 @@
def event_cb(e):
obj = e.get_target_obj()
id = obj.get_selected_btn()
id = obj.get_selected_button()
if id == 0:
prev = True
else:
@@ -12,14 +12,14 @@ def event_cb(e):
if prev or next:
# Find the checked butto
for i in range(7):
if obj.has_btn_ctrl(i, lv.btnmatrix.CTRL.CHECKED):
if obj.has_button_ctrl(i, lv.buttonmatrix.CTRL.CHECKED):
break
if prev and i > 1:
i-=1
elif next and i < 5:
i+=1
obj.set_btn_ctrl(i, lv.btnmatrix.CTRL.CHECKED)
obj.set_button_ctrl(i, lv.buttonmatrix.CTRL.CHECKED)
#
# Make a button group
@@ -34,31 +34,31 @@ style_bg.set_radius(lv.RADIUS_CIRCLE)
style_bg.set_border_width(0)
style_btn = lv.style_t()
style_btn.init()
style_btn.set_radius(0)
style_btn.set_border_width(1)
style_btn.set_border_opa(lv.OPA._50)
style_btn.set_border_color(lv.palette_main(lv.PALETTE.GREY))
style_btn.set_border_side(lv.BORDER_SIDE.INTERNAL)
style_btn.set_radius(0)
style_button = lv.style_t()
style_button.init()
style_button.set_radius(0)
style_button.set_border_width(1)
style_button.set_border_opa(lv.OPA._50)
style_button.set_border_color(lv.palette_main(lv.PALETTE.GREY))
style_button.set_border_side(lv.BORDER_SIDE.INTERNAL)
style_button.set_radius(0)
map = [lv.SYMBOL.LEFT,"1","2", "3", "4", "5",lv.SYMBOL.RIGHT, ""]
btnm = lv.btnmatrix(lv.scr_act())
btnm.set_map(map)
btnm.add_style(style_bg, 0)
btnm.add_style(style_btn, lv.PART.ITEMS)
btnm.add_event(event_cb, lv.EVENT.VALUE_CHANGED, None)
btnm.set_size(225, 35)
buttonm = lv.buttonmatrix(lv.scr_act())
buttonm.set_map(map)
buttonm.add_style(style_bg, 0)
buttonm.add_style(style_button, lv.PART.ITEMS)
buttonm.add_event(event_cb, lv.EVENT.VALUE_CHANGED, None)
buttonm.set_size(225, 35)
# Allow selecting on one number at time
btnm.set_btn_ctrl_all(lv.btnmatrix.CTRL.CHECKABLE)
btnm.clear_btn_ctrl(0, lv.btnmatrix.CTRL.CHECKABLE)
btnm.clear_btn_ctrl(6, lv.btnmatrix.CTRL.CHECKABLE)
buttonm.set_button_ctrl_all(lv.buttonmatrix.CTRL.CHECKABLE)
buttonm.clear_button_ctrl(0, lv.buttonmatrix.CTRL.CHECKABLE)
buttonm.clear_button_ctrl(6, lv.buttonmatrix.CTRL.CHECKABLE)
btnm.set_one_checked(True)
btnm.set_btn_ctrl(1, lv.btnmatrix.CTRL.CHECKED)
buttonm.set_one_checked(True)
buttonm.set_button_ctrl(1, lv.buttonmatrix.CTRL.CHECKED)
btnm.center()
buttonm.center()