Roller (lv_roller)
Roller allows the end user to select an item from a list by scrolling through it. The item in the middle is the selected item and normally stands out from the other items due to different styles ap...
Overview
Roller allows the end user to select an item from a list by scrolling through 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_MAINThe background of the roller uses the typical background and text style properties.-
Style
text_line_spaceadjusts the space between list items. Uselv_obj_set_style_text_line_spaceto 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_timemilliseconds as specified in theanim_durationstyle. Uselv_obj_set_style_anim_durationto set this value.
-
-
LV_PART_SELECTEDThe 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.
Data binding
To get familiar with observers, subjects, and data bindings in general visit the Observer page.
This method of subscribing to an integer Subject affects a Roller Widget's integer value directly. Note that this is a two-way binding (Subject <===> Widget) so an end user's direct interaction with the Roller Widget updates the Subject's value and vice versa.
It supports only integer subjects.
Events
LV_EVENT_VALUE_CHANGEDSent when a new list item is selected.
Keys
LV_KEY_RIGHT/DOWNSelect next optionLV_KEY_LEFT/UPSelect previous optionLY_KEY_ENTERAccept the selected option (sendsLV_EVENT_VALUE_CHANGEDevent)
Further Reading
Learn more about Keys.
Examples
Simple Roller
Styling the roller
add fade mask to roller
API
How is this guide?
Last updated on