From 3543d5f094db09e2381cb9f3da58c1d7d33c8002 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Sun, 16 Jan 2022 10:23:35 +0100 Subject: [PATCH] LVGL add support for set_text_fmt --- .../lv_berry/generate/be_lv_c_mapping.h | 4 +- lib/libesp32_lvgl/lv_berry/tools/convert.py | 57 +++++++++++-------- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/lib/libesp32_lvgl/lv_berry/generate/be_lv_c_mapping.h b/lib/libesp32_lvgl/lv_berry/generate/be_lv_c_mapping.h index 8cacaa260..78fae0221 100644 --- a/lib/libesp32_lvgl/lv_berry/generate/be_lv_c_mapping.h +++ b/lib/libesp32_lvgl/lv_berry/generate/be_lv_c_mapping.h @@ -830,7 +830,7 @@ const be_ntv_func_def_t lv_label_func[] = { { "set_long_mode", (void*) &lv_label_set_long_mode, "", "(lv.lv_obj)i" }, { "set_recolor", (void*) &lv_label_set_recolor, "", "(lv.lv_obj)b" }, { "set_text", (void*) &lv_label_set_text, "", "(lv.lv_obj)s" }, - { "set_text_fmt", (void*) &lv_label_set_text_fmt, "", "(lv.lv_obj)s" }, + { "set_text_fmt", (void*) &lv_label_set_text_fmt, "", "(lv.lv_obj)s[......]" }, { "set_text_sel_end", (void*) &lv_label_set_text_sel_end, "", "(lv.lv_obj)i" }, { "set_text_sel_start", (void*) &lv_label_set_text_sel_start, "", "(lv.lv_obj)i" }, { "set_text_static", (void*) &lv_label_set_text_static, "", "(lv.lv_obj)s" }, @@ -893,7 +893,7 @@ const be_ntv_func_def_t lv_table_func[] = { { "get_selected_cell", (void*) &lv_table_get_selected_cell, "", "(lv.lv_obj)(lv.uint16)(lv.uint16)" }, { "has_cell_ctrl", (void*) &lv_table_has_cell_ctrl, "b", "(lv.lv_obj)ii(lv.lv_table_cell_ctrl)" }, { "set_cell_value", (void*) &lv_table_set_cell_value, "", "(lv.lv_obj)iis" }, - { "set_cell_value_fmt", (void*) &lv_table_set_cell_value_fmt, "", "(lv.lv_obj)iis" }, + { "set_cell_value_fmt", (void*) &lv_table_set_cell_value_fmt, "", "(lv.lv_obj)iis[......]" }, { "set_col_cnt", (void*) &lv_table_set_col_cnt, "", "(lv.lv_obj)i" }, { "set_col_width", (void*) &lv_table_set_col_width, "", "(lv.lv_obj)ii" }, { "set_row_cnt", (void*) &lv_table_set_row_cnt, "", "(lv.lv_obj)i" }, diff --git a/lib/libesp32_lvgl/lv_berry/tools/convert.py b/lib/libesp32_lvgl/lv_berry/tools/convert.py index 129f0e9b9..2b5811bfb 100644 --- a/lib/libesp32_lvgl/lv_berry/tools/convert.py +++ b/lib/libesp32_lvgl/lv_berry/tools/convert.py @@ -211,6 +211,7 @@ with open(lv_widgets_file) as f: g = parse_func_def.search(l_raw) if g: + # print(l_raw, g.group(3)) # if match, we parse the line # Ex: 'void lv_obj_set_parent(lv_obj_t * obj, lv_obj_t * parent);' ret_type = g.group(1) # return type of the function @@ -230,37 +231,43 @@ with open(lv_widgets_file) as f: # convert arguments c_args = "" args_raw = [ x.strip(" \t\n\r") for x in g.group(3).split(",") ] # split by comma and strip + # print(args_raw) for arg_raw in args_raw: # Ex: 'const lv_obj_t * parent' -> 'const ', 'lv_obj_t', ' * ', 'parent', '' # Ex: 'bool auto_fit' -> '', 'bool', ' ', 'auto_fit', '' # Ex: 'const lv_coord_t value[]' -> 'const', 'lv_coord_t', '', 'value', '[]' ga = parse_arg.search(arg_raw) - if ga: # parsing ok? - ga_type = ga.group(2) - ga_ptr = ( ga.group(3).strip(" \t\n\r") == "*" ) # boolean - ga_name = ga.group(4) - ga_array = ga.group(5) - ga_type_ptr = ga_type - if ga_ptr: ga_type_ptr += " *" - if ga_array: ga_type_ptr += " []" - if ga_type_ptr in return_types: - ga_type = return_types[ga_type_ptr] - else: - # remove the trailing '_t' of type name if any - ga_type = re.sub(r"_t$", "", ga_type) - - # if the type is a single letter, we just add it - if len(ga_type) == 1 and ga_type != 'c': # callbacks are different - c_args += ga_type - else: - if ga_type.endswith("_cb"): - # it's a callback type, we encode it differently - if ga_type not in lv_cb_types: - lv_cb_types.append(ga_type) - c_args += "^" + ga_type + "^" + # print(f"g={g} ga={ga}") + if ga or arg_raw == '...': # parsing ok? Special case for '...' which can't be captured easily in regex + if arg_raw != '...': + ga_type = ga.group(2) + ga_ptr = ( ga.group(3).strip(" \t\n\r") == "*" ) # boolean + ga_name = ga.group(4) + ga_array = ga.group(5) + ga_type_ptr = ga_type + if ga_ptr: ga_type_ptr += " *" + if ga_array: ga_type_ptr += " []" + if ga_type_ptr in return_types: + ga_type = return_types[ga_type_ptr] else: - # we have a high-level type that we treat as a class name, enclose in parenthesis - c_args += "(" + "lv." + ga_type + ")" + # remove the trailing '_t' of type name if any + ga_type = re.sub(r"_t$", "", ga_type) + + # if the type is a single letter, we just add it + if len(ga_type) == 1 and ga_type != 'c': # callbacks are different + c_args += ga_type + else: + if ga_type.endswith("_cb"): + # it's a callback type, we encode it differently + if ga_type not in lv_cb_types: + lv_cb_types.append(ga_type) + c_args += "^" + ga_type + "^" + else: + # we have a high-level type that we treat as a class name, enclose in parenthesis + c_args += "(" + "lv." + ga_type + ")" + else: + # '...' + c_args += "[......]" # allow 6 additional parameters # analyze function name and determine if it needs to be assigned to a specific class func_name = g.group(2)