2024-01-04 07:25:13 +01:00
|
|
|
.. _lv_roller:
|
|
|
|
|
|
|
|
==================
|
2023-04-27 06:42:02 -06:00
|
|
|
Roller (lv_roller)
|
|
|
|
==================
|
|
|
|
|
2024-11-25 08:20:26 -07:00
|
|
|
|
2023-04-27 06:42:02 -06:00
|
|
|
Overview
|
|
|
|
********
|
|
|
|
|
2024-11-25 08:20:26 -07:00
|
|
|
Roller allows the end user to select an item from a list by scrolling it.
|
2024-12-08 15:13:21 -07:00
|
|
|
The item in the middle is the selected item and normally stands out from
|
|
|
|
the other items due to different styles applied to it.
|
|
|
|
|
|
|
|
|
2024-11-25 08:20:26 -07:00
|
|
|
|
2023-04-27 06:42:02 -06:00
|
|
|
|
2024-01-04 07:25:13 +01:00
|
|
|
.. _lv_roller_parts_and_styles:
|
|
|
|
|
2023-04-27 06:42:02 -06:00
|
|
|
Parts and Styles
|
|
|
|
****************
|
|
|
|
|
2024-12-08 15:13:21 -07:00
|
|
|
- :cpp:enumerator:`LV_PART_MAIN` The background of the roller uses the :ref:`typical
|
|
|
|
background <typical bg props>` and text style properties.
|
2024-11-25 08:20:26 -07:00
|
|
|
|
|
|
|
- Style ``text_line_space`` adjusts the space between list items.
|
|
|
|
Use :cpp:func:`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
|
|
|
|
:cpp:func:`lv_obj_set_style_anim_duration` to set this value.
|
|
|
|
|
|
|
|
- :cpp:enumerator:`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.
|
|
|
|
|
2023-04-27 06:42:02 -06:00
|
|
|
|
2024-12-08 15:13:21 -07:00
|
|
|
|
2024-01-04 07:25:13 +01:00
|
|
|
.. _lv_roller_usage:
|
|
|
|
|
2023-04-27 06:42:02 -06:00
|
|
|
Usage
|
|
|
|
*****
|
|
|
|
|
2024-11-25 08:20:26 -07:00
|
|
|
Setting the list items
|
|
|
|
----------------------
|
2023-04-27 06:42:02 -06:00
|
|
|
|
2024-11-25 08:20:26 -07:00
|
|
|
List items are passed to the Roller as a string with
|
|
|
|
:cpp:expr:`lv_roller_set_options(roller, string_list, LV_ROLLER_MODE_NORMAL)`.
|
|
|
|
The items should be separated by ``\n``. For example:
|
2023-04-27 06:42:02 -06:00
|
|
|
``"First\nSecond\nThird"``.
|
|
|
|
|
2024-11-25 08:20:26 -07:00
|
|
|
:cpp:enumerator:`LV_ROLLER_MODE_INFINITE` makes the Roller circular.
|
2023-04-27 06:42:02 -06:00
|
|
|
|
2024-11-25 08:20:26 -07:00
|
|
|
You can select an option programmatically with
|
2023-04-27 06:42:02 -06:00
|
|
|
:cpp:expr:`lv_roller_set_selected(roller, id, LV_ANIM_ON)`,
|
2024-11-25 08:20:26 -07:00
|
|
|
where *id* is the zero-based index of the list item to be selected.
|
2023-04-27 06:42:02 -06:00
|
|
|
|
2024-11-25 08:20:26 -07:00
|
|
|
If you don't know the index of an option can also select an item with
|
2024-10-28 10:27:38 +01:00
|
|
|
:cpp:expr:`lv_roller_set_selected_str(roller, str, LV_ANIM_ON)`,
|
2024-11-25 08:20:26 -07:00
|
|
|
where *str* is the string equal to one of the list items.
|
2024-10-28 10:27:38 +01:00
|
|
|
|
2023-04-27 06:42:02 -06:00
|
|
|
Get selected option
|
|
|
|
-------------------
|
|
|
|
|
2024-11-25 08:20:26 -07:00
|
|
|
To get the *index* of the currently selected item use :cpp:expr:`lv_roller_get_selected(roller)`.
|
2023-04-27 06:42:02 -06:00
|
|
|
|
2024-11-25 08:20:26 -07:00
|
|
|
:cpp:expr:`lv_roller_get_selected_str(roller, buf, buf_size)` will copy the name of the selected item to ``buf``.
|
2023-04-27 06:42:02 -06:00
|
|
|
|
|
|
|
Visible rows
|
|
|
|
------------
|
|
|
|
|
|
|
|
The number of visible rows can be adjusted with :cpp:expr:`lv_roller_set_visible_row_count(roller, num)`.
|
|
|
|
|
|
|
|
This function calculates the height with the current style. If the font,
|
2024-11-25 08:20:26 -07:00
|
|
|
line space, border width, etc. of the Roller changes, this function needs
|
2023-04-27 06:42:02 -06:00
|
|
|
to be called again.
|
|
|
|
|
2024-10-23 12:53:33 -06:00
|
|
|
|
|
|
|
|
2024-01-04 07:25:13 +01:00
|
|
|
.. _lv_roller_events:
|
|
|
|
|
2023-04-27 06:42:02 -06:00
|
|
|
Events
|
|
|
|
******
|
|
|
|
|
2024-11-25 08:20:26 -07:00
|
|
|
- :cpp:enumerator:`LV_EVENT_VALUE_CHANGED` Sent when a new list item is selected.
|
2023-04-27 06:42:02 -06:00
|
|
|
|
2024-10-23 12:53:33 -06:00
|
|
|
.. admonition:: Further Reading
|
|
|
|
|
|
|
|
Learn more about :ref:`lv_obj_events` emitted by all Widgets.
|
|
|
|
|
|
|
|
Learn more about :ref:`events`.
|
|
|
|
|
2023-04-27 06:42:02 -06:00
|
|
|
|
|
|
|
|
2024-01-04 07:25:13 +01:00
|
|
|
.. _lv_roller_keys:
|
|
|
|
|
2023-04-27 06:42:02 -06:00
|
|
|
Keys
|
|
|
|
****
|
|
|
|
|
2024-11-25 08:20:26 -07:00
|
|
|
- ``LV_KEY_RIGHT/DOWN`` Select next option
|
|
|
|
- ``LV_KEY_LEFT/UP`` Select previous option
|
|
|
|
- :cpp:enumerator:`LY_KEY_ENTER` Accept the selected option (sends :cpp:enumerator:`LV_EVENT_VALUE_CHANGED` event)
|
2023-04-27 06:42:02 -06:00
|
|
|
|
2024-10-23 12:53:33 -06:00
|
|
|
.. admonition:: Further Reading
|
|
|
|
|
|
|
|
Learn more about :ref:`indev_keys`.
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-01-04 07:25:13 +01:00
|
|
|
.. _lv_roller_example:
|
|
|
|
|
2023-04-27 06:42:02 -06:00
|
|
|
Example
|
|
|
|
*******
|
|
|
|
|
2024-10-23 12:53:33 -06:00
|
|
|
.. include:: ../../examples/widgets/roller/index.rst
|
|
|
|
|
|
|
|
|
2023-04-27 06:42:02 -06:00
|
|
|
|
2024-01-04 07:25:13 +01:00
|
|
|
.. _lv_roller_api:
|
|
|
|
|
2023-04-27 06:42:02 -06:00
|
|
|
API
|
|
|
|
***
|