Roller (lv_roller)

Overview

Roller allows the end user to select an item from a list by scrolling it. The item in the middle is the selected item and normally stands out from the other items due to different styles applied to it.

Parts and Styles

  • LV_PART_MAIN The background of the roller uses the typical background and text style properties.

    • Style text_line_space adjusts the space between list items. Use lv_obj_set_style_text_line_space() to set this value.

    • When the Roller is scrolled and doesn't stop exactly on an item, it will automatically scroll to the nearest valid item in anim_time milliseconds as specified in the anim_duration style. Use lv_obj_set_style_anim_duration() to set this value.

  • LV_PART_SELECTED The selected item (displayed in the middle of the Roller). Besides the typical background properties, it uses text style properties to change the appearance of the text of the selected item.

Usage

Setting the list items

List items are passed to the Roller as a string with lv_roller_set_options(roller, string_list, LV_ROLLER_MODE_NORMAL). The items should be separated by \n. For example: "First\nSecond\nThird".

LV_ROLLER_MODE_INFINITE makes the Roller circular.

You can select an option programmatically with lv_roller_set_selected(roller, id, LV_ANIM_ON), where id is the zero-based index of the list item to be selected.

If you don't know the index of an option can also select an item with lv_roller_set_selected_str(roller, str, LV_ANIM_ON), where str is the string equal to one of the list items.

Get selected option

To get the index of the currently selected item use lv_roller_get_selected(roller).

lv_roller_get_selected_str(roller, buf, buf_size) will copy the name of the selected item to buf.

Visible rows

The number of visible rows can be adjusted with lv_roller_set_visible_row_count(roller, num).

This function calculates the height with the current style. If the font, line space, border width, etc. of the Roller changes, this function needs to be called again.

Events

Further Reading

Learn more about Base-Widget Events emitted by all Widgets.

Learn more about Events.

Keys

  • LV_KEY_RIGHT/DOWN Select next option

  • LV_KEY_LEFT/UP Select previous option

  • LY_KEY_ENTER Accept the selected option (sends LV_EVENT_VALUE_CHANGED event)

Further Reading

Learn more about Keys.

Example

Simple Roller


Styling the roller


add fade mask to roller


API

lv_api_map_v8.h

lv_obj_property_names.h

lv_observer.h

lv_roller.h

lv_roller_private.h