Roller (lv_roller)
A wheel-like list where the centered item is the selection.
Overview
The Roller lets the user pick one item from a list by scrolling it like a wheel. The centered item is the selected one and is usually styled to stand out from the rest.
Learn more in the LVGL Open documentation.
/**
* @file lv_example_roller.c
*/
#include "../lv_examples.h"
/**
* @title Roller
* @brief Infinite scrolling, a visible row count, and subject binding.
*
* `options` takes the list plus a mode parameter (`options-mode="infinite"`)
* so it loops endlessly. `visible_row_count` sets how many rows are shown,
* and `bind_value="subject_index"` keeps the selection in a subject that the
* label below mirrors.
*/
void lv_example_roller(void)
{
static lv_style_t style_roller;
static lv_style_t style_roller_sel;
static lv_subject_t subject_index;
static bool inited = false;
if (!inited) {
/*Init all styles*/
lv_style_init(&style_roller);
lv_style_init(&style_roller_sel);
lv_style_set_bg_color(&style_roller, lv_color_hex(0x0f172a));
lv_style_set_bg_opa(&style_roller, (255 * 100 / 100));
lv_style_set_text_color(&style_roller, lv_color_hex(0x94a3b8));
lv_style_set_radius(&style_roller, 8);
lv_style_set_pad_all(&style_roller, 6);
lv_style_set_bg_color(&style_roller_sel, lv_color_hex(0x3b82f6));
lv_style_set_text_color(&style_roller_sel, lv_color_hex(0xffffff));
lv_subject_init_int(&subject_index, 0);
inited = true;
}
lv_obj_t * screen = lv_screen_active();
lv_obj_t * lv_roller_0 = lv_roller_create(screen);
lv_obj_set_align(lv_roller_0, LV_ALIGN_CENTER);
lv_roller_set_options(lv_roller_0, "January\nFebruary\nMarch\nApril\nMay\nJune\nJuly\nAugust\nSeptember\nOctober\nNovember", LV_ROLLER_MODE_INFINITE);
lv_roller_set_visible_row_count(lv_roller_0, 3);
lv_roller_bind_value(lv_roller_0, &subject_index);
lv_obj_add_style(lv_roller_0, &style_roller, 0);
lv_obj_add_style(lv_roller_0, &style_roller_sel, LV_PART_SELECTED);
lv_obj_t * lv_label_0 = lv_label_create(screen);
lv_obj_set_align(lv_label_0, LV_ALIGN_CENTER);
lv_obj_set_y(lv_label_0, -70);
lv_label_bind_text(lv_label_0, &subject_index, "Month index: %d");
}
<!--
@title Roller
@brief Infinite scrolling, a visible row count, and subject binding.
`options` takes the list plus a mode parameter (`options-mode="infinite"`)
so it loops endlessly. `visible_row_count` sets how many rows are shown,
and `bind_value="subject_index"` keeps the selection in a subject that the
label below mirrors.
-->
<screen>
<styles>
<style name="style_roller" bg_color="0x0f172a" bg_opa="100%" text_color="0x94a3b8" radius="8" pad_all="6" />
<!-- The centered (selected) row -->
<style name="style_roller_sel" bg_color="0x3b82f6" text_color="0xffffff" />
</styles>
<view>
<lv_roller
align="center"
options="January February March April May June July August September October November"
options-mode="infinite"
visible_row_count="3"
bind_value="subject_index"
>
<style name="style_roller" />
<style name="style_roller_sel" selector="selected" />
</lv_roller>
<lv_label align="center" y="-70" bind_text="subject_index" bind_text-fmt="Month index: %d" />
</view>
</screen>
Enumerations
lv_roller_mode — How the roller scrolls
| Value | Description |
|---|---|
normal | Stop at first and last option |
infinite | Scroll endlessly in a loop |
Properties
Parts
Style parts of the widget with local style (e.g. style_bg_color-knob="0xff0000") or with style sheets (e.g. <style name="style_knob" selector="knob">). See Styles to learn more.
| Part | Description |
|---|---|
main | The background and option list: background and text properties. text_line_space sets the row spacing (and the height of the selected band); anim_duration sets the scroll animation time. |
selected | The option in the middle band: text and background properties to highlight the selected row. Can use different font than main |
Properties below are the widget's XML <api>; see API for how properties, parameters and elements work.
| Property | Type | Description |
|---|---|---|
options | string | Set the roller options |
options-mode | enum:lv_roller_mode | Set the roller mode (reference as options-mode) (default: normal) |
options_translation_tag | string | Set the options from a translation tag. They follow the active language. |
options_translation_tag-mode | enum:lv_roller_mode | Set the roller mode (reference as options_translation_tag-mode) (default: normal) |
selected | int | Set the selected option |
selected-animated | bool | Animate the selection (reference as selected-animated) (default: false) |
visible_row_count | int | Show this many rows at once |
bind_value | subject | Bind the selected option to a subject |
Last updated on