# lv_barcode.h (/api/public/widgets/lv_barcode_h)



<RelatedHeaders name="lv_barcode_private.h" isPrivate="false" />

<ApiSummary functions="16" enums="2" variables="1" />

Functions [#functions]

<ApiTabs items="[&#x22;Setters (7)&#x22;,&#x22;Getters (5)&#x22;,&#x22;Other (4)&#x22;]">
  <ApiTab value="Setters (7)">
    <ApiMember kind="function" name="lv_barcode_set_dark_color" file="public/widgets/lv_barcode.h" line="72" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_barcode.h#L72">
      lv_barcode_set_dark_color [#lv_barcode_set_dark_color]

      Set the dark color of a barcode object. Only rewrites the palette, so it takes effect before or after the data and never regenerates the bars.

      ```c title=" " lineNumbers=1
      void lv_barcode_set_dark_color(lv_obj_t *obj, lv_color_t color)
      ```

      <span className="sr-only">
        Parameters
      </span>

      | Name    | Type                                             | Description               |
      | ------- | ------------------------------------------------ | ------------------------- |
      | `obj`   | <ApiLink name="lv_obj_t" display="lv_obj_t *" /> | pointer to barcode object |
      | `color` | <ApiLink name="lv_color_t" />                    | dark color of the barcode |
    </ApiMember>

    <ApiMember kind="function" name="lv_barcode_set_light_color" file="public/widgets/lv_barcode.h" line="81" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_barcode.h#L81">
      lv_barcode_set_light_color [#lv_barcode_set_light_color]

      Set the light color of a barcode object. Only rewrites the palette, so it takes effect before or after the data and never regenerates the bars.

      ```c title=" " lineNumbers=1
      void lv_barcode_set_light_color(lv_obj_t *obj, lv_color_t color)
      ```

      <span className="sr-only">
        Parameters
      </span>

      | Name    | Type                                             | Description                |
      | ------- | ------------------------------------------------ | -------------------------- |
      | `obj`   | <ApiLink name="lv_obj_t" display="lv_obj_t *" /> | pointer to barcode object  |
      | `color` | <ApiLink name="lv_color_t" />                    | light color of the barcode |
    </ApiMember>

    <ApiMember kind="function" name="lv_barcode_set_scale" file="public/widgets/lv_barcode.h" line="89" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_barcode.h#L89">
      lv_barcode_set_scale [#lv_barcode_set_scale]

      Set the scale of a barcode object, i.e. the pixel width of a single bar. The stored data is re-generated, so this may be called before or after the data.

      ```c title=" " lineNumbers=1
      void lv_barcode_set_scale(lv_obj_t *obj, uint16_t scale)
      ```

      <span className="sr-only">
        Parameters
      </span>

      | Name    | Type                                             | Description                      |
      | ------- | ------------------------------------------------ | -------------------------------- |
      | `obj`   | <ApiLink name="lv_obj_t" display="lv_obj_t *" /> | pointer to barcode object        |
      | `scale` | `uint16_t`                                       | scale factor; must be at least 1 |
    </ApiMember>

    <ApiMember kind="function" name="lv_barcode_set_direction" file="public/widgets/lv_barcode.h" line="97" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_barcode.h#L97">
      lv_barcode_set_direction [#lv_barcode_set_direction]

      Set the direction of a barcode object. The stored data is re-generated, so this may be called before or after the data.

      ```c title=" " lineNumbers=1
      void lv_barcode_set_direction(lv_obj_t *obj, lv_dir_t direction)
      ```

      <span className="sr-only">
        Parameters
      </span>

      | Name        | Type                                             | Description                                   |
      | ----------- | ------------------------------------------------ | --------------------------------------------- |
      | `obj`       | <ApiLink name="lv_obj_t" display="lv_obj_t *" /> | pointer to barcode object                     |
      | `direction` | <ApiLink name="lv_dir_t" />                      | draw direction (`LV_DIR_HOR` or `LV_DIR_VER`) |
    </ApiMember>

    <ApiMember kind="function" name="lv_barcode_set_tiled" file="public/widgets/lv_barcode.h" line="105" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_barcode.h#L105">
      lv_barcode_set_tiled [#lv_barcode_set_tiled]

      Set the tiled mode of a barcode object. The stored data is re-generated, so this may be called before or after the data.

      ```c title=" " lineNumbers=1
      void lv_barcode_set_tiled(lv_obj_t *obj, bool tiled)
      ```

      <span className="sr-only">
        Parameters
      </span>

      | Name    | Type                                             | Description                                    |
      | ------- | ------------------------------------------------ | ---------------------------------------------- |
      | `obj`   | <ApiLink name="lv_obj_t" display="lv_obj_t *" /> | pointer to barcode object                      |
      | `tiled` | `bool`                                           | true: tiled mode, false: normal mode (default) |
    </ApiMember>

    <ApiMember kind="function" name="lv_barcode_set_encoding" file="public/widgets/lv_barcode.h" line="113" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_barcode.h#L113">
      lv_barcode_set_encoding [#lv_barcode_set_encoding]

      Set the encoding of a barcode object. The stored data is re-generated, so this may be called before or after the data.

      ```c title=" " lineNumbers=1
      void lv_barcode_set_encoding(lv_obj_t *obj, lv_barcode_encoding_t encoding)
      ```

      <span className="sr-only">
        Parameters
      </span>

      | Name       | Type                                             | Description                                             |
      | ---------- | ------------------------------------------------ | ------------------------------------------------------- |
      | `obj`      | <ApiLink name="lv_obj_t" display="lv_obj_t *" /> | pointer to barcode object                               |
      | `encoding` | <ApiLink name="lv_barcode_encoding_t" />         | encoding (default is `LV_BARCODE_ENCODING_CODE128_GS1`) |
    </ApiMember>

    <ApiMember kind="function" name="lv_barcode_set_update_mode" file="public/widgets/lv_barcode.h" line="149" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_barcode.h#L149">
      lv_barcode_set_update_mode [#lv_barcode_set_update_mode]

      Set when a change is turned into a new barcode bitmap. Applies to the data and to the scale, direction, tiled mode and encoding; the colors are never affected.

      ```c title=" " lineNumbers=1
      void lv_barcode_set_update_mode(lv_obj_t *obj, lv_barcode_update_mode_t mode)
      ```

      <span className="sr-only">
        Parameters
      </span>

      | Name   | Type                                             | Description               |
      | ------ | ------------------------------------------------ | ------------------------- |
      | `obj`  | <ApiLink name="lv_obj_t" display="lv_obj_t *" /> | pointer to barcode object |
      | `mode` | <ApiLink name="lv_barcode_update_mode_t" />      | the mode to use           |

      <Callout type="info">
        Only the fill is deferred. The canvas is resized in the setter in both modes, because the draw pass cannot reallocate it.
      </Callout>

      <Callout type="info">
        Deferred mode expects an explicit <ApiLink name="lv_barcode_render" display="lv_barcode_render()" />, which returns the result. Forgetting it still gives the right bitmap, but the redraw does the work and warns, and no caller is left to see a failure.
      </Callout>

      <Callout type="info">
        Switching back to IMMEDIATE while out of date also regenerates, but this returns void, so a failure is only logged. Render first to get the result.
      </Callout>
    </ApiMember>
  </ApiTab>

  <ApiTab value="Getters (5)">
    <ApiMember kind="function" name="lv_barcode_get_update_mode" file="public/widgets/lv_barcode.h" line="156" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_barcode.h#L156">
      lv_barcode_get_update_mode [#lv_barcode_get_update_mode]

      Get when a property change is turned into a new barcode bitmap.

      ```c title=" " lineNumbers=1
      lv_barcode_update_mode_t lv_barcode_get_update_mode(lv_obj_t *obj)
      ```

      <span className="sr-only">
        Parameters
      </span>

      | Name  | Type                                             | Description               |
      | ----- | ------------------------------------------------ | ------------------------- |
      | `obj` | <ApiLink name="lv_obj_t" display="lv_obj_t *" /> | pointer to barcode object |

      **Returns:** <ApiLink name="lv_barcode_update_mode_t" /> — the update mode currently in use
    </ApiMember>

    <ApiMember kind="function" name="lv_barcode_get_dark_color" file="public/widgets/lv_barcode.h" line="176" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_barcode.h#L176">
      lv_barcode_get_dark_color [#lv_barcode_get_dark_color]

      Get the dark color of a barcode object

      ```c title=" " lineNumbers=1
      lv_color_t lv_barcode_get_dark_color(lv_obj_t *obj)
      ```

      <span className="sr-only">
        Parameters
      </span>

      | Name  | Type                                             | Description               |
      | ----- | ------------------------------------------------ | ------------------------- |
      | `obj` | <ApiLink name="lv_obj_t" display="lv_obj_t *" /> | pointer to barcode object |

      **Returns:** <ApiLink name="lv_color_t" /> — dark color of the barcode
    </ApiMember>

    <ApiMember kind="function" name="lv_barcode_get_light_color" file="public/widgets/lv_barcode.h" line="183" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_barcode.h#L183">
      lv_barcode_get_light_color [#lv_barcode_get_light_color]

      Get the light color of a barcode object

      ```c title=" " lineNumbers=1
      lv_color_t lv_barcode_get_light_color(lv_obj_t *obj)
      ```

      <span className="sr-only">
        Parameters
      </span>

      | Name  | Type                                             | Description               |
      | ----- | ------------------------------------------------ | ------------------------- |
      | `obj` | <ApiLink name="lv_obj_t" display="lv_obj_t *" /> | pointer to barcode object |

      **Returns:** <ApiLink name="lv_color_t" /> — light color of the barcode
    </ApiMember>

    <ApiMember kind="function" name="lv_barcode_get_scale" file="public/widgets/lv_barcode.h" line="190" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_barcode.h#L190">
      lv_barcode_get_scale [#lv_barcode_get_scale]

      Get the scale of a barcode object

      ```c title=" " lineNumbers=1
      uint16_t lv_barcode_get_scale(lv_obj_t *obj)
      ```

      <span className="sr-only">
        Parameters
      </span>

      | Name  | Type                                             | Description               |
      | ----- | ------------------------------------------------ | ------------------------- |
      | `obj` | <ApiLink name="lv_obj_t" display="lv_obj_t *" /> | pointer to barcode object |

      **Returns:** `uint16_t` — scale factor
    </ApiMember>

    <ApiMember kind="function" name="lv_barcode_get_encoding" file="public/widgets/lv_barcode.h" line="197" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_barcode.h#L197">
      lv_barcode_get_encoding [#lv_barcode_get_encoding]

      Get the encoding of a barcode object

      ```c title=" " lineNumbers=1
      lv_barcode_encoding_t lv_barcode_get_encoding(const lv_obj_t *obj)
      ```

      <span className="sr-only">
        Parameters
      </span>

      | Name  | Type                                                   | Description               |
      | ----- | ------------------------------------------------------ | ------------------------- |
      | `obj` | <ApiLink name="lv_obj_t" display="const lv_obj_t *" /> | pointer to barcode object |

      **Returns:** <ApiLink name="lv_barcode_encoding_t" /> — encoding
    </ApiMember>
  </ApiTab>

  <ApiTab value="Other (4)">
    <ApiMember kind="function" name="lv_barcode_create" file="public/widgets/lv_barcode.h" line="63" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_barcode.h#L63">
      lv_barcode_create [#lv_barcode_create]

      Create an empty barcode (an `lv_canvas`) object.

      ```c title=" " lineNumbers=1
      lv_obj_t * lv_barcode_create(lv_obj_t *parent)
      ```

      <span className="sr-only">
        Parameters
      </span>

      | Name     | Type                                             | Description                                                                                                        |
      | -------- | ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ |
      | `parent` | <ApiLink name="lv_obj_t" display="lv_obj_t *" /> | pointer to a parent widget **May** be `NULL`.. When NULL, the widget is created as a screen on the active display. |

      **Returns:** <ApiLink name="lv_obj_t" display="lv_obj_t *" /> — pointer to the created barcode object
    </ApiMember>

    <ApiMember kind="function" name="lv_barcode_update" file="public/widgets/lv_barcode.h" line="125" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_barcode.h#L125">
      lv_barcode_update [#lv_barcode_update]

      Set the data of a barcode object and generate the bitmap. A copy is stored, so a later property change or resize can regenerate it; the properties may be set before or after the data, in any order.

      ```c title=" " lineNumbers=1
      lv_result_t lv_barcode_update(lv_obj_t *obj, const char *data)
      ```

      <span className="sr-only">
        Parameters
      </span>

      | Name   | Type                                             | Description                                |
      | ------ | ------------------------------------------------ | ------------------------------------------ |
      | `obj`  | <ApiLink name="lv_obj_t" display="lv_obj_t *" /> | pointer to barcode object                  |
      | `data` | `const char *`                                   | data to display as a NUL terminated string |

      **Returns:** <ApiLink name="lv_result_t" /> — LV\_RESULT\_OK: if no error; LV\_RESULT\_INVALID: on error

      <Callout type="info">
        Obeys the update mode. In DEFERRED the canvas is only resized here, so the return value reports that resize, not the bars.
      </Callout>
    </ApiMember>

    <ApiMember kind="function" name="lv_barcode_render" file="public/widgets/lv_barcode.h" line="134" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_barcode.h#L134">
      lv_barcode_render [#lv_barcode_render]

      (Re)generate the barcode bitmap from the stored data, whether or not anything changed. Needs no data argument, which is how deferred changes are applied.

      ```c title=" " lineNumbers=1
      lv_result_t lv_barcode_render(lv_obj_t *obj)
      ```

      <span className="sr-only">
        Parameters
      </span>

      | Name  | Type                                             | Description               |
      | ----- | ------------------------------------------------ | ------------------------- |
      | `obj` | <ApiLink name="lv_obj_t" display="lv_obj_t *" /> | pointer to barcode object |

      **Returns:** <ApiLink name="lv_result_t" /> — LV\_RESULT\_OK: if no error; LV\_RESULT\_INVALID: on error (e.g. no data set, or the bars do not fit the current object size)
    </ApiMember>

    <ApiMember kind="function" name="lv_barcode_is_render_valid" file="public/widgets/lv_barcode.h" line="169" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_barcode.h#L169">
      lv_barcode_is_render_valid [#lv_barcode_is_render_valid]

      Check whether the bitmap is free of a known generation failure. <ApiLink name="lv_barcode_render" display="lv_barcode_render()" />, and <ApiLink name="lv_barcode_update" display="lv_barcode_update()" /> in IMMEDIATE mode, return their result directly; the rest cannot - they run in a void setter, the resize handler, or a deferred fill in the draw pass. Use this for those, e.g. after shrinking the object below the size its data needs.

      ```c title=" " lineNumbers=1
      bool lv_barcode_is_render_valid(lv_obj_t *obj)
      ```

      <span className="sr-only">
        Parameters
      </span>

      | Name  | Type                                             | Description               |
      | ----- | ------------------------------------------------ | ------------------------- |
      | `obj` | <ApiLink name="lv_obj_t" display="lv_obj_t *" /> | pointer to barcode object |

      **Returns:** `bool` — true: no generation attempt is known to have failed. A change re-arms the Widget, so this is also true while a deferred regeneration is still pending; false: the last generation attempt failed, or no data has been set yet

      <Callout type="info">
        A failure is not retried every redraw; only a change makes the Widget try again.
      </Callout>
    </ApiMember>
  </ApiTab>
</ApiTabs>

Enums [#enums]

<ApiMember kind="enum" name="lv_barcode_encoding_t" file="public/widgets/lv_barcode.h" line="31" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_barcode.h#L31">
  lv_barcode_encoding_t [#lv_barcode_encoding_t]

  | Name                              | Description                                             |
  | --------------------------------- | ------------------------------------------------------- |
  | `LV_BARCODE_ENCODING_CODE128_GS1` | Code 128 with GS1 encoding. Strips `[FCN1]` and spaces. |
  | `LV_BARCODE_ENCODING_CODE128_RAW` | Code 128 with raw encoding.                             |
</ApiMember>

<TypeUsedBy name="lv_barcode_encoding_t" count="1">
  * `lv_barcode_set_encoding` — param `encoding`
</TypeUsedBy>

<ApiMember kind="enum" name="lv_barcode_update_mode_t" file="public/widgets/lv_barcode.h" line="46" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_barcode.h#L46">
  lv_barcode_update_mode_t [#lv_barcode_update_mode_t]

  Controls when a change is turned into a new barcode bitmap. Applies to the data too. The colors are always a palette-only write, so they are never affected.

  | Name                               | Value | Description                                                               |
  | ---------------------------------- | ----- | ------------------------------------------------------------------------- |
  | `LV_BARCODE_UPDATE_MODE_IMMEDIATE` | `0`   | Re-generate as soon as a property changes (default)                       |
  | `LV_BARCODE_UPDATE_MODE_DEFERRED`  |       | Only mark the bitmap out of date and re-generate once, on the next redraw |
</ApiMember>

<TypeUsedBy name="lv_barcode_update_mode_t" count="1">
  * `lv_barcode_set_update_mode` — param `mode`
</TypeUsedBy>

Variables [#variables]

<ApiMember kind="variable" name="lv_barcode_class" file="public/widgets/lv_barcode.h" line="51" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_barcode.h#L51">
  lv_barcode_class [#lv_barcode_class]

  ```c title=" " lineNumbers=1
  const lv_obj_class_t lv_barcode_class
  ```
</ApiMember>

Dependencies [#dependencies]

<FileIncludes includes="[&#x22;lv_conf_internal.h&#x22;, &#x22;lv_types.h&#x22;, &#x22;lv_color.h&#x22;, &#x22;lv_canvas.h&#x22;]" includedBy="[&#x22;lvgl.h&#x22;]" transitiveIncludes="[&#x22;lv_anim.h&#x22;, &#x22;lv_area.h&#x22;, &#x22;lv_assert.h&#x22;, &#x22;lv_bidi.h&#x22;, &#x22;lv_color_op.h&#x22;, &#x22;lv_display.h&#x22;, &#x22;lv_draw.h&#x22;, &#x22;lv_draw_arc.h&#x22;, &#x22;lv_draw_blur.h&#x22;, &#x22;lv_draw_buf.h&#x22;, &#x22;lv_draw_image.h&#x22;, &#x22;lv_draw_label.h&#x22;, &#x22;lv_draw_line.h&#x22;, &#x22;lv_draw_rect.h&#x22;, &#x22;lv_draw_triangle.h&#x22;, &#x22;lv_event.h&#x22;, &#x22;lv_ext_data.h&#x22;, &#x22;lv_flex.h&#x22;, &#x22;lv_font.h&#x22;, &#x22;lv_fs.h&#x22;, &#x22;lv_grad.h&#x22;, &#x22;lv_grid.h&#x22;, &#x22;lv_group.h&#x22;, &#x22;lv_image.h&#x22;, &#x22;lv_image_decoder.h&#x22;, &#x22;lv_image_dsc.h&#x22;, &#x22;lv_indev.h&#x22;, &#x22;lv_layout.h&#x22;, &#x22;lv_ll.h&#x22;, &#x22;lv_log.h&#x22;, &#x22;lv_math.h&#x22;, &#x22;lv_matrix.h&#x22;, &#x22;lv_mem.h&#x22;, &#x22;lv_obj.h&#x22;, &#x22;lv_obj_class.h&#x22;, &#x22;lv_obj_draw.h&#x22;, &#x22;lv_obj_event.h&#x22;, &#x22;lv_obj_pos.h&#x22;, &#x22;lv_obj_property.h&#x22;, &#x22;lv_obj_scroll.h&#x22;, &#x22;lv_obj_style.h&#x22;, &#x22;lv_obj_style_gen.h&#x22;, &#x22;lv_obj_tree.h&#x22;, &#x22;lv_observer.h&#x22;, &#x22;lv_palette.h&#x22;, &#x22;lv_profiler.h&#x22;, &#x22;lv_profiler_builtin.h&#x22;, &#x22;lv_sprintf.h&#x22;, &#x22;lv_string.h&#x22;, &#x22;lv_style.h&#x22;, &#x22;lv_style_gen.h&#x22;, &#x22;lv_symbol_def.h&#x22;, &#x22;lv_text.h&#x22;, &#x22;lv_timer.h&#x22;]" />
