Overview

Roller allow you to simply select one option from more with scrolling. Its functionalities are similar to Drop down list

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

You can select an option manually with lv_roller_set_selected(roller, id), where id is the index of an option.

A callback function can be specified with lv_roller_set_action(roller, my_action) to call when a new option is selected.

The roller's height can be adjusted with lv_roller_set_visible_row_count(roller, row_cnt)to set number of visible options.

The width is adjusted automatically. To prevent this apply lv_roller_set_hor_fit(roller, false) and set the width manually by lv_obj_set_width(roller, width)

The Roller's open/close animation time is adjusted by lv_roller_set_anim_time(roller, anim_time). Zero animation time means no animation.

Style usage

The lv_roller_set_style(roller, LV_ROLLER_STYLE_..., &style) set the styles of a Roller

  • LV_ROLLER_STYLE_BG Style of the background. All style.body properties are used. It is used for the label's style from style.text. Gradient is applied on the top and bottom as well. Default: lv_style_pretty
  • LV_DDLIST_STYLE_SEL Style of the selected option. The style.body properties are used. The selected option will be recolored with text.color. Default: lv_style_plain_color

Notes

Example of Roller in Littlev Graphics Library

						/*Create a default roller*/
lv_obj_t *roller1 = lv_roller_create(lv_scr_act(), NULL);
lv_roller_set_options(roller1, "Apple\n"
                               "Broccoli\n"
                               "Cabbage\n"
                               "Dewberry\n"
                               "Eggplant\n"
                               "Fig\n"
                               "Grapefruit");
lv_obj_set_pos(roller1, 50, 80);


/*Create styles*/
static lv_style_t bg_style;
lv_style_copy(&bg_style, &lv_style_pretty);
bg_style.body.main_color = LV_COLOR_WHITE;
bg_style.body.grad_color = LV_COLOR_HEX3(0xddd);
bg_style.body.border.width = 0;
bg_style.text.line_space = 20;
bg_style.text.opa = LV_OPA_40;

static lv_style_t sel_style;
lv_style_copy(&sel_style, &lv_style_pretty);
sel_style.body.empty = 1;
sel_style.body.radius = LV_RADIUS_CIRCLE;
sel_style.text.color = LV_COLOR_BLUE;

/*Create a roller and apply the new styles*/
lv_obj_t *roller2 = lv_roller_create(lv_scr_act(), NULL);
lv_roller_set_options(roller2, "0\n"
                               "1\n"
                               "2\n"
                               "3\n"
                               "4\n"
                               "5\n"
                               "6\n"
                               "7\n"
                               "8\n"
                               "9");
lv_roller_set_style(roller2, LV_ROLLER_STYLE_BG, &bg_style);
lv_roller_set_selected(roller2, 3, false);
lv_roller_set_style(roller2, LV_ROLLER_STYLE_SEL, &sel_style);
lv_roller_set_visible_row_count(roller2, 3);
lv_roller_set_hor_fit(roller2, false);
lv_obj_set_width(roller2, 40);
lv_obj_set_pos(roller2, 220, 50);

lv_obj_t *

lv_roller_create

(lv_obj_t * par, lv_obj_t * copy);

Create a roller object

par pointer to an object, it will be the parent of the new roller

copy pointer to a roller object, if not NULL then the new object will be copied from it

return pointer to the created roller

void

lv_roller_set_options

(lv_obj_t * roller, const char * options);

Set the options on a roller

roller pointer to roller object

options a string with '\n' separated options. E.g. "One\nTwo\nThree"

void

lv_roller_set_selected

(lv_obj_t *roller, uint16_t sel_opt, bool anim_en);

Set the selected option

roller pointer to a roller object

sel_opt id of the selected option (0 ... number of option - 1);

anim_en true: set with animation; false set immediately

void

lv_roller_set_action

(lv_obj_t * roller, lv_action_t action);

Set a function to call when a new option is chosen

roller pointer to a roller

action pointer to a callback function

void

lv_roller_set_visible_row_count

(lv_obj_t *roller, uint8_t row_cnt);

Set the height to show the given number of rows (options)

roller pointer to a roller object

row_cnt number of desired visible rows

void

lv_roller_set_hor_fit

(lv_obj_t * roller, bool fit_en);

Enable or disable the horizontal fit to the content

roller pointer to a roller

fit en true: enable auto fit; false: disable auto fit

void

lv_roller_set_anim_time

(lv_obj_t *roller, uint16_t anim_time);

Set the open/close animation time.

roller pointer to a roller object

anim_time: open/close animation time [ms]

void

lv_roller_set_style

(lv_obj_t *roller, lv_roller_style_t type, lv_style_t *style);

Set a style of a roller

roller pointer to a roller object

type which style should be set

style pointer to a style

const

char

* lv_roller_get_options(lv_obj_t *roller);

Get the options of a roller

roller pointer to roller object

return the options separated by '\n'-s (E.g. "Option1\nOption2\nOption3")

uint16_t

lv_roller_get_selected

(lv_obj_t *roller);

Get the id of the selected option

roller pointer to a roller object

return id of the selected option (0 ... number of option - 1);

void

lv_roller_get_selected_str

(lv_obj_t * roller, char * buf);

Get the current selected option as a string

roller pointer to roller object

buf pointer to an array to store the string

lv_action_t

lv_roller_get_action

(lv_obj_t * roller);

Get the "option selected" callback function

roller pointer to a roller

return pointer to the call back function

uint16_t

lv_roller_get_anim_time

(lv_obj_t * roller);

Get the open/close animation time.

roller pointer to a roller

return open/close animation time [ms]

bool

lv_roller_get_hor_fit

(lv_obj_t *roller);

Get the auto width set attribute

roller pointer to a roller object

return true: auto size enabled; false: manual width settings enabled

lv_style_t *

lv_roller_get_style

(lv_obj_t *roller, lv_roller_style_t type);

Get a style of a roller

roller pointer to a roller object

type which style should be get

return style pointer to a style

LittlevGL - Open-source Embedded GUI Library

LittlevGL is a free and open-source graphics library providing everything you need to create embedded GUI with easy-to-use graphical elements, beautiful visual effects and low memory footprint.

If you like LittlevGL, please
support its deveopment!


The founder of Littlev Graphics Library (LittlevGL) and related software modules is:
Gábor Kiss-Vámosi
All Rights Reserved ©  2018 Hungary