1# Roller (lv_roller)
2
3## Overview
4
5Roller allows you to simply select one option from a list by scrolling.
6
7## Parts and Styles
8- `LV_PART_MAIN` The background of the roller uses all the typical background properties and text style properties. `style_text_line_space` adjusts the space between the options.
9When the Roller is scrolled and doesn't stop exactly on an option it will scroll to the nearest valid option automatically in `anim_time` milliseconds as specified in the style.
10- `LV_PART_SELECTED` The selected option in the middle. Besides the typical background properties it uses the text style properties to change the appearance of the text in the selected area.
11
12## Usage
13
14### Set options
15Options are passed to the Roller as a string with `lv_roller_set_options(roller, options, LV_ROLLER_MODE_NORMAL/INFINITE)`. The options should be separated by `\n`. For example: `"First\nSecond\nThird"`.
16
17`LV_ROLLER_MODE_INFINITE` makes the roller circular.
18
19You can select an option manually with `lv_roller_set_selected(roller, id, LV_ANIM_ON/OFF)`, where *id* is the index of an option.
20
21If the roller has a lot of options then especially in infinite mode the rendered options of the display might look scrambled. In this case `LV_USE_LARGE_COORD` should be enabled in `lv_conf.h`
22
23### Get selected option
24To get the *index* of the currently selected option use `lv_roller_get_selected(roller)`.
25
26`lv_roller_get_selected_str(roller, buf, buf_size)` will copy the name of the selected option to `buf`.
27
28### Visible rows
29The number of visible rows can be adjusted with `lv_roller_set_visible_row_count(roller, num)`.
30
31This 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.
32
33## Events
34- `LV_EVENT_VALUE_CHANGED` Sent when a new option is selected.
35
36See the events of the [Base object](/widgets/obj) too.
37
38Learn more about [Events](/overview/event).
39
40## Keys
41- `LV_KEY_RIGHT/DOWN` Select the next option
42- `LV_KEY_LEFT/UP` Select the previous option
43- `LY_KEY_ENTER` Apply the selected option (Send `LV_EVENT_VALUE_CHANGED` event)
44
45## Example
46
47```eval_rst
48
49.. include:: ../../../examples/widgets/roller/index.rst
50
51```
52
53## API
54
55```eval_rst
56
57.. doxygenfile:: lv_roller.h
58  :project: lvgl
59
60```
61