feat(libs): add barcode widget (#3778)
Signed-off-by: pengyiqiang <pengyiqiang@xiaomi.com> Co-authored-by: pengyiqiang <pengyiqiang@xiaomi.com>
This commit is contained in:
6
examples/libs/barcode/index.rst
Normal file
6
examples/libs/barcode/index.rst
Normal file
@@ -0,0 +1,6 @@
|
||||
Create a Barcode
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: libs/barcode/lv_example_barcode_1
|
||||
:language: c
|
||||
|
||||
38
examples/libs/barcode/lv_example_barcode.h
Normal file
38
examples/libs/barcode/lv_example_barcode.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @file lv_example_barcode.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_EXAMPLE_BARCODE_H
|
||||
#define LV_EXAMPLE_BARCODE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void lv_example_barcode_1(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_EXAMPLE_BARCODE_H*/
|
||||
28
examples/libs/barcode/lv_example_barcode_1.c
Normal file
28
examples/libs/barcode/lv_example_barcode_1.c
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_BARCODE && LV_BUILD_EXAMPLES
|
||||
|
||||
/**
|
||||
* Create a Barcode
|
||||
*/
|
||||
void lv_example_barcode_1(void)
|
||||
{
|
||||
lv_color_t bg_color = lv_palette_lighten(LV_PALETTE_LIGHT_BLUE, 5);
|
||||
lv_color_t fg_color = lv_palette_darken(LV_PALETTE_BLUE, 4);
|
||||
|
||||
lv_obj_t * barcode = lv_barcode_create(lv_scr_act());
|
||||
lv_obj_set_height(barcode, 50);
|
||||
lv_obj_center(barcode);
|
||||
|
||||
/*Set color*/
|
||||
lv_barcode_set_dark_color(barcode, fg_color);
|
||||
lv_barcode_set_light_color(barcode, bg_color);
|
||||
|
||||
/*Add a border with bg_color*/
|
||||
lv_obj_set_style_border_color(barcode, bg_color, 0);
|
||||
lv_obj_set_style_border_width(barcode, 5, 0);
|
||||
|
||||
/*Set data*/
|
||||
lv_barcode_update(barcode, "https://lvgl.io");
|
||||
}
|
||||
|
||||
#endif
|
||||
21
examples/libs/barcode/lv_example_barcode_1.py
Executable file
21
examples/libs/barcode/lv_example_barcode_1.py
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/opt/bin/lv_micropython -i
|
||||
import lvgl as lv
|
||||
import display_driver
|
||||
|
||||
bg_color = lv.palette_lighten(lv.PALETTE.LIGHT_BLUE, 5)
|
||||
fg_color = lv.palette_darken(lv.PALETTE.BLUE, 4)
|
||||
|
||||
barcode = lv.barcode(lv.scr_act())
|
||||
barcode.set_height(50)
|
||||
barcode.center()
|
||||
|
||||
# Set color
|
||||
barcode.set_dark_color(fg_color)
|
||||
barcode.set_light_color(bg_color)
|
||||
|
||||
# Add a border with bg_color
|
||||
barcode.set_style_border_color(bg_color, 0)
|
||||
barcode.set_style_border_width(5, 0)
|
||||
|
||||
# Set data
|
||||
barcode.update("https://lvgl.io")
|
||||
@@ -13,6 +13,7 @@ extern "C" {
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "barcode/lv_example_barcode.h"
|
||||
#include "bmp/lv_example_bmp.h"
|
||||
#include "ffmpeg/lv_example_ffmpeg.h"
|
||||
#include "freetype/lv_example_freetype.h"
|
||||
|
||||
Reference in New Issue
Block a user