anyuianyui
Home
Getting Started
Documentation
Download
  • English
  • 简体中文
Home
Getting Started
Documentation
Download
  • English
  • 简体中文
  • Setup

    • Installation
  • Core Concepts

    • Introduction
    • Design
    • Hide and Lock
    • Resource Management
  • Higher Order Component

    • State Button
    • Label Slider
    • Value Slider
    • Check Group & Radio Group
    • StatusBar
    • NavigateBar
    • Drawer
  • Advanced Features

    • Use External Image File as Source
    • GIF Animated Image
    • Template Component
    • Global Components
    • Screen Management
    • Communication Commands and Events
    • Lottie Animation
  • Development

    • Build Mode
    • Build Toolchain Configuration
    • Code Transplant
  • Technical Support

    • FAQ

Introduction

The State Button is a Higher Order Component that provides multi-state functionality for button-like interactions.

A common requirement involves buttons with multiple states that cycle upon user interaction. For example, an air conditioner control might cycle through volume settings: Low → Medium → High → Auto → Low → ... Each state requires distinct visual representations. Standard LVGL components such as Button or Image Button cannot achieve this behavior without extensive custom code development.

The State Button addresses this limitation by enabling configuration of multiple states, with each state supporting distinct images and labels. As the state transitions, the configured visual elements update automatically.

Component Structure

The State Button encapsulates the following components:

  • Container (x1): Provides the background for the HoC
  • Images (x3): Display images for each state
  • Labels (x3): Display labels for each state
  • Button (x1): Handles user interactions with transparent styling to ensure only images, labels, and background are visible

Attributes

The State Button provides the following configurable attributes:

States Configure the number of states for the HoC, with each state supporting:

  • Up to 3 configurable images
  • Up to 3 configurable labels

Current State Represents the active state of the HoC. This value can be modified to observe visual changes.

State Button Configuration

By default, the State Button displays one image and one label. To display additional images and labels, right-click the HoC and select Edit to access the HoC editor for configuration modifications.

The default State Button configuration appears as follows: statebtn-default

The default settings are displayed as: statebtn-attrs-default

Layout adjustments can be made through the HoC editor, where encapsulated components can be repositioned similar to standard components.

Components that are not required can be hidden. Conversely, default hidden components can be unhidden to enable additional images and labels.

Hidden components are excluded from code generation and build processes, effectively treating them as non-existent.

A fully configured State Button with all components visible appears as: statebtn-full

The corresponding settings are displayed as: statebtn-setting-full

For alternative styling such as a square shape with rounded corners, right-click the component and select Edit to modify the appearance:

statebtn-edit

While this example may not represent optimal aesthetics, users can customize the design according to their preferences.

After creating a customized State Button, right-click to save it as a Template Component for reuse throughout the project.

Next
Label Slider