Skip to content

Commit 3b32d36

Browse files
clydebarrowCopilotbdraco
authored
[lvgl] Document text: option for button (#5637)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: J. Nick Koston <nick@koston.org>
1 parent 3fff36b commit 3b32d36

File tree

1 file changed

+40
-15
lines changed

1 file changed

+40
-15
lines changed

content/components/lvgl/widgets.md

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,17 @@ Simple push (momentary) or toggle (two-states) button.
429429

430430
{{< img src="lvgl_button.png" alt="Image" class="align-center" >}}
431431

432+
A button has no inherent content so requires child widgets to be added. As a shorthand for a button with a single text label,
433+
the `text:` option may be used to add a single `label` child, otherwise the `widgets:` key must be used to add other
434+
widgets inside the button.
435+
436+
A button is momentary by default, which has a `pressed` state. If the `checkable` flag is set, it becomes a toggle button, which also has a `checked` state.
437+
432438
**Configuration variables:**
433439

434-
- **checkable** (*Optional*, boolean): A significant [flag](#lvgl-widget-flags) to make a toggle button (which remains pressed in `checked` state). Defaults to `false`.
440+
- **checkable** (*Optional*, boolean): A significant [flag](#lvgl-widget-flags) to make a toggle button (which reports its `checked` state). Defaults to `false`.
441+
- **text** (*Optional*, string): Text to be displayed on the button. This will create and add a single label widget to the button. May not be used
442+
with the `widgets:` key.
435443
- Style options from [Style properties](/components/lvgl#lvgl-styling) for the background of the button. Uses the typical background style properties.
436444

437445
A notable state is `checked` (boolean) which can have different styles applied.
@@ -445,30 +453,22 @@ A notable state is `checked` (boolean) which can have different styles applied.
445453
**Example:**
446454

447455
```yaml
448-
# Example widget:
456+
# Example widget with text:
449457
- button:
450-
x: 10
451-
y: 10
452-
width: 50
453-
height: 30
454458
id: btn_id
459+
text: "Click me!"
455460
```
456461

457-
To have a button with a text label on it, add a child [`label`](#lvgl-widget-label) widget to it:
462+
To create an image button, add a child [`image`](#lvgl-widget-image) widget to it:
458463

459464
```yaml
460-
# Example toggle button with text:
465+
# Example toggle button with image:
461466
- button:
462-
x: 10
463-
y: 10
464-
width: 70
465-
height: 30
466467
id: btn_id
467468
checkable: true
468469
widgets:
469-
- label:
470-
align: center
471-
text: "Light"
470+
- image:
471+
src: my_image_id
472472
473473
# Example trigger:
474474
- button:
@@ -478,12 +478,37 @@ To have a button with a text label on it, add a child [`label`](#lvgl-widget-lab
478478
- logger.log:
479479
format: "Button checked state: %d"
480480
args: [ x ]
481+
481482
```
482483

483484
The `button` can be also integrated as a {{< docref "/components/binary_sensor/lvgl" "Binary Sensor" >}} or as a {{< docref "/components/switch/lvgl" "Switch" >}} component.
485+
> [!NOTE]
486+
> A binary sensor linked to a button reports its `pressed` state, while a switch linked to a button reports its `checked` state.
484487

485488
See [Remote light button](/cookbook/lvgl#lvgl-cookbook-binent) for an example which demonstrates how to use a checkable button to act on a Home Assistant service.
486489

490+
**Actions:**
491+
492+
- `lvgl.button.update` [action](/automations/actions#actions-action) may be used to update the button styles at runtime. If
493+
the button has a `text:` option then it may also be updated with this action.
494+
- **id** (**Required**): The ID or a list of IDs of button widgets to be updated.
495+
- **text** (*Optional*, string): Update the button's text (only if the button was configured with the `text:` option).
496+
- Style options from [Style properties](/components/lvgl#lvgl-styling) for the background of the button.
497+
498+
> [!NOTE]
499+
> Where other widgets are added as children, they must be updated directly.
500+
501+
```yaml
502+
# Text update example
503+
- button:
504+
id: btn_id
505+
text: "Click me!"
506+
on_click:
507+
lvgl.button.update:
508+
id: btn_id
509+
text: "Clicked"
510+
```
511+
487512
{{< anchor "lvgl-widget-buttonmatrix" >}}
488513

489514
## `buttonmatrix`

0 commit comments

Comments
 (0)