Barcode
The LVGL Barcode utility enables you to generate Code-128 bar codes. It uses the code128 library by fhunleth.
Usage
Set LV_USE_BARCODE
to 1
in lv_conf.h
.
Use lv_barcode_create()
to create a barcode object, and use
lv_barcode_update()
to generate a barcode.
Call lv_barcode_set_scale()
to adjust scaling,
call lv_barcode_set_dark_color()
and lv_barcode_set_light_color()
adjust colors. Call lv_barcode_set_direction()
to set the bar code's
orientation. After any of a bar code's settings have changed, call
lv_barcode_update()
again to regenerate it.
Notes
It is best not to manually set the width of the barcode, because when the width of the Widget is lower than the width of the barcode, the display will be incomplete due to truncation.
The scale adjustment can only be an integer multiple, for example, lv_barcode_set_scale(barcode, 2) means 2x scaling.
The direction setting can be
LV_DIR_HOR
orLV_DIR_VER
.
Example
Create a Barcode
C code
View on GitHub#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_screen_active());
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);
/*Set data*/
lv_barcode_update(barcode, "https://lvgl.io");
}
#endif