mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-21 22:52:46 +08:00
feat(qrcode): add new set_data helper function (#8950)
This commit is contained in:
committed by
GitHub
parent
235090d715
commit
ea71792568
@@ -204,6 +204,12 @@ lv_result_t lv_qrcode_update(lv_obj_t * obj, const void * data, uint32_t data_le
|
||||
return LV_RESULT_OK;
|
||||
}
|
||||
|
||||
void lv_qrcode_set_data(lv_obj_t * obj, const char * data)
|
||||
{
|
||||
if(data == NULL) return;
|
||||
lv_qrcode_update(obj, data, lv_strlen(data));
|
||||
}
|
||||
|
||||
void lv_qrcode_set_quiet_zone(lv_obj_t * obj, bool enable)
|
||||
{
|
||||
lv_qrcode_t * qrcode = (lv_qrcode_t *)obj;
|
||||
|
||||
@@ -72,6 +72,13 @@ void lv_qrcode_set_light_color(lv_obj_t * obj, lv_color_t color);
|
||||
*/
|
||||
lv_result_t lv_qrcode_update(lv_obj_t * obj, const void * data, uint32_t data_len);
|
||||
|
||||
/**
|
||||
* Helper function to set the data of a QR code object
|
||||
* @param obj pointer to a QR code object
|
||||
* @param data data to display as a string
|
||||
*/
|
||||
void lv_qrcode_set_data(lv_obj_t * obj, const char * data);
|
||||
|
||||
/**
|
||||
* Enable or disable quiet zone.
|
||||
* Quiet zone is the area around the QR code where no data is encoded.
|
||||
|
||||
@@ -49,9 +49,6 @@ void lv_xml_qrcode_apply(lv_xml_parser_state_t * state, const char ** attrs)
|
||||
void * item = lv_xml_state_get_item(state);
|
||||
lv_xml_obj_apply(state, attrs); /*Apply the common properties, e.g. width, height, styles flags etc*/
|
||||
|
||||
/* QR needs data after size/colors, so capture `data` while looping and apply at the end */
|
||||
const char * data_txt = NULL;
|
||||
|
||||
for(int i = 0; attrs[i]; i += 2) {
|
||||
const char * name = attrs[i];
|
||||
const char * value = attrs[i + 1];
|
||||
@@ -59,16 +56,9 @@ void lv_xml_qrcode_apply(lv_xml_parser_state_t * state, const char ** attrs)
|
||||
if(lv_streq("size", name)) lv_qrcode_set_size(item, lv_xml_atoi(value));
|
||||
else if(lv_streq("dark_color", name)) lv_qrcode_set_dark_color(item, lv_xml_to_color(value));
|
||||
else if(lv_streq("light_color", name)) lv_qrcode_set_light_color(item, lv_xml_to_color(value));
|
||||
else if(lv_streq("data", name)) data_txt = value;
|
||||
else if(lv_streq("data", name)) lv_qrcode_set_data(item, value);
|
||||
else if(lv_streq("quiet_zone", name)) lv_qrcode_set_quiet_zone(item, lv_xml_to_bool(value));
|
||||
}
|
||||
|
||||
if(data_txt) {
|
||||
lv_result_t r = lv_qrcode_update(item, data_txt, (uint32_t)lv_strlen(data_txt));
|
||||
if(r != LV_RESULT_OK) {
|
||||
LV_LOG_WARN("lv_qrcode_update() failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**********************
|
||||
|
||||
@@ -33,8 +33,8 @@ void test_xml_qrcode_with_attrs(void)
|
||||
"size", "150",
|
||||
"dark_color", "0x000000",
|
||||
"light_color", "0xFFFFFF",
|
||||
"data", "https://lvgl.io",
|
||||
"quiet_zone", "true",
|
||||
"data", "https://lvgl.io",
|
||||
"style_border_width", "1",
|
||||
"style_border_color", "0x000000",
|
||||
NULL, NULL,
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ Example
|
||||
<prop name="size" type="int" help="QR canvas edge length in px (use this instead of width/height)"/>
|
||||
<prop name="dark_color" type="color" help="Foreground color for QR modules"/>
|
||||
<prop name="light_color" type="color" help="Background color"/>
|
||||
<prop name="data" type="string" help="UTF-8 payload encoded into the QR code"/>
|
||||
<prop name="data" type="string" help="UTF-8 payload encoded into the QR code. Must be called as last property"/>
|
||||
<prop name="quiet_zone" type="bool" help="Add quiet zone (border) around the QR code"/>
|
||||
</api>
|
||||
</widget>
|
||||
|
||||
Reference in New Issue
Block a user