Skip to content

Commit

Permalink
LVGL cookbook (#4110)
Browse files Browse the repository at this point in the history
Co-authored-by: Keith Burzinski <[email protected]>
Co-authored-by: clydebarrow <[email protected]>
Co-authored-by: Jesse Hills <[email protected]>
  • Loading branch information
4 people committed Sep 15, 2024
1 parent 0f6122e commit 3003276
Show file tree
Hide file tree
Showing 24 changed files with 2,276 additions and 6 deletions.
9 changes: 8 additions & 1 deletion components/lvgl/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The graphic display should be configured with ``auto_clear_enabled: false`` and

For interactivity, a :doc:`Touchscreen </components/touchscreen/index>` (capacitive highly preferred), a :doc:`/components/sensor/rotary_encoder` or a custom keypad made up from discrete :doc:`Binary Sensors </components/binary_sensor/index>` can be used.

Check out the detailed examples in :ref:`the Cookbook <lvgl-cookbook>` which demonstrate a number of ways you can integrate your environment with LVGL and ESPHome.

Basics
------
Expand Down Expand Up @@ -146,6 +147,7 @@ The following configuration variables apply to the main ``lvgl`` component, in o
align: CENTER
text: 'Hello World!'
See :ref:`lvgl-cookbook-navigator` in the Cookbook for an example which demonstrates how to implement a page navigation bar at the bottom of the screen.

.. _lvgl-color:

Expand Down Expand Up @@ -176,6 +178,7 @@ You can use :ref:`fonts configured normally<display-fonts>`, the glyphs will be

For best results, set ``bpp: 4`` to get the glyphs rendered with proper anti-aliasing.

Check out :ref:`lvgl-cookbook-icontext`, :ref:`lvgl-cookbook-iconstat` and :ref:`lvgl-cookbook-iconbatt` in the Cookbook for examples which demonstrate how to use icons and text with TrueType/OpenType fonts.

**Library fonts**

Expand Down Expand Up @@ -378,6 +381,7 @@ So the precedence happens like this: state based styles override the locally spe

Feel free to experiment to discover inheritance and precedence of the styles based on states between the nested widgets.

:ref:`lvgl-cookbook-theme` The Cookbook contains an example which demonstrates how to implement a gradient style for your widgets.

.. _lvgl-layouts:

Expand All @@ -388,6 +392,7 @@ Layouts aim to position widgets automatically, eliminating the need to specify `

The layout configuration options are applied to any parent widget or page, influencing the appearance of the children. The position and size calculated by the layout overwrites the *normal* ``x``, ``y``, ``width``, and ``height`` settings of the children.

Check out :ref:`lvgl-cookbook-flex`, :ref:`lvgl-cookbook-grid` and :ref:`lvgl-cookbook-weather` in the Cookbook for examples which demonstrate how to automate widget positioning, potentially reducing the size of your device's YAML configuration, and saving you from lots of manual calculations.

The ``hidden``, ``ignore_layout`` and ``floating`` :ref:`flags <lvgl-widget-flags>` can be used on widgets to ignore them in layout calculations.

Expand Down Expand Up @@ -594,7 +599,7 @@ This :ref:`action <actions-action>` redraws the entire screen, or optionally onl

This :ref:`action <actions-action>` pauses the activity of LVGL, including rendering.

- **show_snow** (*Optional*, boolean): When paused, display random colored pixels across the entire screen in order to minimize screen burn-in, to relief the tension put on each individual pixel.
- **show_snow** (*Optional*, boolean): When paused, display random colored pixels across the entire screen in order to minimize screen burn-in, to relief the tension put on each individual pixel. See :ref:`lvgl-cookbook-antiburn` for an example which demonstrates how to use this.

.. code-block:: yaml
Expand Down Expand Up @@ -801,6 +806,7 @@ The ``on_idle`` :ref:`triggers <automation>` are activated when inactivity time
- light.turn_off: display_backlight
- lvgl.pause:
See :ref:`lvgl-cookbook-idlescreen` for an example which demonstrates how to implement screen saving with idle settings.

See Also
--------
Expand All @@ -811,6 +817,7 @@ See Also

*

- :doc:`LVGL Examples in the Cookbook </cookbook/lvgl>`
- :doc:`/components/display/index`
- :doc:`/components/touchscreen/index`
- :doc:`/components/sensor/rotary_encoder`
Expand Down
29 changes: 24 additions & 5 deletions components/lvgl/widgets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ To apply styles to the states, you need to specify them one level above, for exa
The state itself can be can be changed by interacting with the widget, or through :ref:`actions <lvgl-automation-actions>` with ``lvgl.widget.update``.

See :ref:`lvgl-cookbook-cover` for a cookbook example which demonstrates how to use styling and properties to show different states of a Home Assistant entity.

.. _lvgl-widget-flags:

In addition to visual styling, each widget supports some boolean **flags** to influence the behavior:
Expand Down Expand Up @@ -114,7 +116,7 @@ In addition to visual styling, each widget supports some boolean **flags** to in

.. note::

LVGL only supports **integers** for numeric ``value``. Visualizer widgets can't display floats directly, but they allow scaling by 10s.
LVGL only supports **integers** for numeric ``value``. Visualizer widgets can't display floats directly, but they allow scaling by 10s. Some examples in the :doc:`Cookbook </cookbook/lvgl>` cover how to do that.

.. _lvgl-widget-parts:

Expand Down Expand Up @@ -264,6 +266,8 @@ The animation image is similar to the normal ``image`` widget. The main differen
repeat_count: 100
duration: 300ms
See :ref:`lvgl-cookbook-animbatt` in the Cookbook for a more detailed example.

.. _lvgl-widget-arc:

``arc``
Expand Down Expand Up @@ -345,7 +349,9 @@ If the ``adv_hittest`` :ref:`flag <lvgl-widget-flags>` is enabled the arc can be

The ``on_value`` trigger is sent as the arc knob is dragged or changed with keys. The event is sent *continuously* while the arc knob is being dragged; this generally has a negative effect on performance. To mitigate this, consider using a :ref:`universal interaction trigger <lvgl-automation-triggers>` like ``on_release``, to get the ``x`` variable once after the interaction has completed.

The ``arc`` can be also integrated as :doc:`Number </components/number/lvgl>` or :doc:`Sensor </components/sensor/lvgl>` component.
The ``arc`` can be also integrated as a :doc:`Number </components/number/lvgl>` or :doc:`Sensor </components/sensor/lvgl>` component.

See :ref:`lvgl-cookbook-bright` and :ref:`lvgl-cookbook-volume` for examples which demonstrate how to use a slider (or an arc) to control entities in Home Assistant.

.. _lvgl-widget-bar:

Expand Down Expand Up @@ -466,6 +472,8 @@ To have a button with a text label on it, add a child :ref:`lvgl-widget-label` w
The ``button`` can be also integrated as a :doc:`Binary Sensor </components/binary_sensor/lvgl>` or as a :doc:`Switch </components/switch/lvgl>` component.

See :ref:`lvgl-cookbook-binent` for an example which demonstrates how to use a checkable button to act on a Home Assistant service.

.. _lvgl-widget-buttonmatrix:

``buttonmatrix``
Expand Down Expand Up @@ -596,7 +604,7 @@ The button matrix widget is a lightweight way to display multiple buttons in row
.. tip::

The Button Matrix widget supports the :ref:`key_collector` to collect the button presses as key press sequences for further automations.
The Button Matrix widget supports the :ref:`key_collector` to collect the button presses as key press sequences for further automations. Check out :ref:`lvgl-cookbook-keypad` for an example.

.. _lvgl-widget-checkbox:

Expand Down Expand Up @@ -656,7 +664,7 @@ The checkbox widget is made internally from a *tick box* and a label. When the c
.. note::

In case you configure ``default_font`` in the main section to a custom font, the checkmark will not be shown correctly when the checkbox is in the checked state.
In case you configure ``default_font`` in the main section to a custom font, the checkmark will not be shown correctly when the checkbox is in the checked state. See :ref:`lvgl-cookbook-ckboxmark` for how to easily resolve this.

The ``checkbox`` can be also integrated as a :doc:`Switch </components/switch/lvgl>` component.

Expand Down Expand Up @@ -988,6 +996,8 @@ The ``led`` can be also integrated as :doc:`Light </components/light/lvgl>` comp

If configured as a light component, ``color`` and ``brightness`` are overridden by the light at startup, according to its ``restore_mode`` setting.

Check out :ref:`lvgl-cookbook-keypad` in the Cookbook for an example which demonstrates how to change the ``led`` styling properties from an automation.

.. _lvgl-widget-line:

``line``
Expand Down Expand Up @@ -1139,6 +1149,8 @@ The meter widget can visualize data in very flexible ways. It can use arcs, need
id: temperature_needle
value: 3
See :ref:`lvgl-cookbook-gauge`, :ref:`lvgl-cookbook-thermometer` and :ref:`lvgl-cookbook-clock` in the Cookbook for examples which demonstrate how to effectively use this widget.

.. _lvgl-widget-msgbox:

``msgboxes``
Expand Down Expand Up @@ -1362,6 +1374,8 @@ Normally, the slider can be adjusted either by dragging the knob, or by clicking

The ``slider`` can be also integrated as :doc:`Number </components/number/lvgl>` or :doc:`Sensor </components/sensor/lvgl>` component.

See :ref:`lvgl-cookbook-bright` and :ref:`lvgl-cookbook-volume` for examples which demonstrate how to use a slider to control entities in Home Assistant.

.. _lvgl-widget-spinbox:

``spinbox``
Expand Down Expand Up @@ -1437,7 +1451,9 @@ The spinbox contains a numeric value (as text) which can be increased or decreas
format: "Spinbox value is %f"
args: [ x ]
The ``spinbox`` can be also integrated as :doc:`Number </components/number/lvgl>` or :doc:`Sensor </components/sensor/lvgl>` component.
The ``spinbox`` can be also integrated as a :doc:`Number </components/number/lvgl>` or :doc:`Sensor </components/sensor/lvgl>` component.

See :ref:`lvgl-cookbook-climate` for an example which demonstrates how to implement a thermostat control using the spinbox.

.. _lvgl-widget-spinner:

Expand Down Expand Up @@ -1531,6 +1547,8 @@ The switch looks like a little slider and can be used to turn something on and o
The ``switch`` can be also integrated as a :doc:`Switch </components/switch/lvgl>` component.

See :ref:`lvgl-cookbook-relay` for an example which demonstrates how to use a switch to act on a local component.

.. _lvgl-widget-tabview:

``tabview``
Expand Down Expand Up @@ -1781,6 +1799,7 @@ This powerful :ref:`action <actions-action>` allows changing/updating any widget
id: my_label_id
hidden: true
Check out in the Cookbook :ref:`lvgl-cookbook-binent` for an example which demonstrates how to use a template to update the state.

.. _lvgl-automation-shorthands:

Expand Down
Binary file added cookbook/images/lvgl_cook_animimg_batt.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cookbook/images/lvgl_cook_climate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cookbook/images/lvgl_cook_clock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cookbook/images/lvgl_cook_cover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cookbook/images/lvgl_cook_flex_layout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cookbook/images/lvgl_cook_font_batt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cookbook/images/lvgl_cook_font_binstat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cookbook/images/lvgl_cook_font_roboto_mdi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cookbook/images/lvgl_cook_gauge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cookbook/images/lvgl_cook_gradient_styles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cookbook/images/lvgl_cook_keypad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cookbook/images/lvgl_cook_pagenav.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cookbook/images/lvgl_cook_remligbut.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cookbook/images/lvgl_cook_statico.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cookbook/images/lvgl_cook_thermometer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cookbook/images/lvgl_cook_thermometer_gauge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cookbook/images/lvgl_cook_titlebar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cookbook/images/lvgl_cook_volume.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cookbook/images/lvgl_cook_weather.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3003276

Please sign in to comment.