Parts and States

Widgets are built from multiple parts. For example, a Base Widget has "main" and "scrollbar" parts, while a Slider has "main", "indicator", and "knob" parts.

Edit on GitHub

Parts

Widgets are built from multiple parts. For example, a Base Widget has "main" and "scrollbar" parts, while a Slider has "main", "indicator", and "knob" parts. Parts are similar to pseudo-elements in CSS.

The following predefined parts exist in LVGL:

The main purpose of parts is to allow styling individual "components" of a widget. They are described in more detail in the Style overview section.

States

A widget can be in a combination of the following states:

States are usually changed automatically by the library as the user interacts with a widget (e.g., pressing, releasing, focusing). However, states can also be modified manually. To set or clear a given state (while leaving other states untouched), use:

In both cases, you can bit-wise OR multiple state values. For example:

lv_obj_add_state(widget, LV_STATE_PRESSED | LV_STATE_CHECKED)

Every state also has a dedicated setter and getter for a single state, which is usually more convenient:

 
lv_obj_set_checked(widget, true);
if(lv_obj_is_disabled(widget)) { ... }

lv_obj_set_<state>() and lv_obj_is_<state>() exist for all states, e.g. lv_obj_set_alt, lv_obj_set_focused, lv_obj_set_pressed, lv_obj_is_edited. The custom states are named lv_obj_set_state_user_1...lv_obj_set_state_user_4() and lv_obj_is_state_user_1...lv_obj_is_state_user_4().

To learn more about states, see the related section in Styles Overview.

Last updated on

On this page