2024-01-04 07:25:13 +01:00
|
|
|
.. _lv_table:
|
|
|
|
|
|
|
|
================
|
2023-04-27 06:42:02 -06:00
|
|
|
Table (lv_table)
|
|
|
|
================
|
|
|
|
|
2024-11-17 21:51:24 -07:00
|
|
|
|
2023-04-27 06:42:02 -06:00
|
|
|
Overview
|
|
|
|
********
|
|
|
|
|
2024-11-17 21:51:24 -07:00
|
|
|
Tables are built from rows, columns, and cells containing text.
|
2023-04-27 06:42:02 -06:00
|
|
|
|
2024-11-17 21:51:24 -07:00
|
|
|
The Table Widget is very lightweight because only the text strings are stored.
|
|
|
|
No real Widgets are created for cells --- they are just drawn on the fly.
|
2023-04-27 06:42:02 -06:00
|
|
|
|
2024-11-17 21:51:24 -07:00
|
|
|
The Table is added to the default group (if one is set).
|
|
|
|
Table is an editable Widget, allow selecting a cell with encoder and keyboard
|
2024-10-23 12:53:33 -06:00
|
|
|
navigation as well.
|
2023-04-27 06:42:02 -06:00
|
|
|
|
2024-11-17 21:51:24 -07:00
|
|
|
|
|
|
|
|
2024-01-04 07:25:13 +01:00
|
|
|
.. _lv_table_parts_and_styles:
|
|
|
|
|
2023-04-27 06:42:02 -06:00
|
|
|
Parts and Styles
|
|
|
|
****************
|
|
|
|
|
2024-11-17 21:51:24 -07:00
|
|
|
- :cpp:enumerator:`LV_PART_MAIN` The background of the Table; uses the :ref:`typical
|
|
|
|
background style properties <typical bg props>`.
|
|
|
|
- :cpp:enumerator:`LV_PART_ITEMS` The cells of the Table also use the
|
|
|
|
:ref:`typical background style properties <typical bg props>` as well as text
|
|
|
|
style properties.
|
|
|
|
|
|
|
|
|
2023-04-27 06:42:02 -06:00
|
|
|
|
2024-01-04 07:25:13 +01:00
|
|
|
.. _lv_table_usage:
|
|
|
|
|
2023-04-27 06:42:02 -06:00
|
|
|
Usage
|
|
|
|
*****
|
|
|
|
|
|
|
|
Set cell value
|
|
|
|
--------------
|
|
|
|
|
2024-11-17 21:51:24 -07:00
|
|
|
Cells can store only text so numbers need to be converted to text
|
|
|
|
before displaying them in a Table.
|
2023-04-27 06:42:02 -06:00
|
|
|
|
|
|
|
:cpp:expr:`lv_table_set_cell_value(table, row, col, "Content")`. The text is
|
2024-11-17 21:51:24 -07:00
|
|
|
saved by the Table so the buffer containing the string can be a local variable.
|
2023-04-27 06:42:02 -06:00
|
|
|
|
|
|
|
Line breaks can be used in the text like ``"Value\n60.3"``.
|
|
|
|
|
2024-11-17 21:51:24 -07:00
|
|
|
New rows and columns are automatically added as required.
|
2023-04-27 06:42:02 -06:00
|
|
|
|
|
|
|
Rows and Columns
|
|
|
|
----------------
|
|
|
|
|
|
|
|
To explicitly set number of rows and columns use
|
2023-11-15 22:38:24 +01:00
|
|
|
:cpp:expr:`lv_table_set_row_count(table, row_cnt)` and
|
2024-11-17 21:51:24 -07:00
|
|
|
:cpp:expr:`lv_table_set_column_count(table, col_cnt)`.
|
2023-04-27 06:42:02 -06:00
|
|
|
|
|
|
|
Width and Height
|
|
|
|
----------------
|
|
|
|
|
2024-11-17 21:51:24 -07:00
|
|
|
Column width can be set with
|
2023-12-04 22:57:47 +01:00
|
|
|
:cpp:expr:`lv_table_set_column_width(table, col_id, width)`. The overall width of
|
2024-11-17 21:51:24 -07:00
|
|
|
the Table Widget will be set to the sum of all column widths.
|
2023-04-27 06:42:02 -06:00
|
|
|
|
2024-11-17 21:51:24 -07:00
|
|
|
Height is calculated automatically from the cell styles (font,
|
2023-04-27 06:42:02 -06:00
|
|
|
padding etc) and the number of rows.
|
|
|
|
|
|
|
|
Merge cells
|
|
|
|
-----------
|
|
|
|
|
|
|
|
Cells can be merged horizontally with
|
|
|
|
:cpp:expr:`lv_table_add_cell_ctrl(table, row, col, LV_TABLE_CELL_CTRL_MERGE_RIGHT)`.
|
2024-11-17 21:51:24 -07:00
|
|
|
To merge more adjacent cells, call this function for each cell.
|
2023-04-27 06:42:02 -06:00
|
|
|
|
2024-11-17 21:51:24 -07:00
|
|
|
Scrolling
|
|
|
|
---------
|
2023-04-27 06:42:02 -06:00
|
|
|
|
2024-11-17 21:51:24 -07:00
|
|
|
If a Table's width or height is set to :c:macro:`LV_SIZE_CONTENT` that size
|
|
|
|
will be used to show the whole Table in the respective direction. E.g.
|
2023-04-27 06:42:02 -06:00
|
|
|
:cpp:expr:`lv_obj_set_size(table, LV_SIZE_CONTENT, LV_SIZE_CONTENT)`
|
2024-11-17 21:51:24 -07:00
|
|
|
automatically sets the Table size to show all columns and rows.
|
2023-04-27 06:42:02 -06:00
|
|
|
|
2024-11-17 21:51:24 -07:00
|
|
|
If the width or height is set to a smaller number than its "intrinsic"
|
|
|
|
size then the Table becomes scrollable.
|
2023-04-27 06:42:02 -06:00
|
|
|
|
2024-10-23 12:53:33 -06:00
|
|
|
|
|
|
|
|
2024-01-04 07:25:13 +01:00
|
|
|
.. _lv_table_events:
|
|
|
|
|
2023-04-27 06:42:02 -06:00
|
|
|
Events
|
|
|
|
******
|
|
|
|
|
|
|
|
- :cpp:enumerator:`LV_EVENT_VALUE_CHANGED` Sent when a new cell is selected with
|
|
|
|
keys.
|
|
|
|
|
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_table_keys:
|
|
|
|
|
2023-04-27 06:42:02 -06:00
|
|
|
Keys
|
|
|
|
****
|
|
|
|
|
2024-11-17 21:51:24 -07:00
|
|
|
The following *Keys* are processed by Table Widgets:
|
|
|
|
|
|
|
|
- ``LV_KEY_RIGHT/LEFT/UP/DOWN/`` Select a cell.
|
2023-04-27 06:42:02 -06:00
|
|
|
|
|
|
|
Note that, as usual, the state of :cpp:enumerator:`LV_KEY_ENTER` is translated to
|
|
|
|
``LV_EVENT_PRESSED/PRESSING/RELEASED`` etc.
|
|
|
|
|
|
|
|
:cpp:expr:`lv_table_get_selected_cell(table, &row, &col)` can be used to get the
|
|
|
|
currently selected cell. Row and column will be set to
|
2024-11-17 21:51:24 -07:00
|
|
|
:c:macro:`LV_TABLE_CELL_NONE` if no cell 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:`indev_keys`.
|
|
|
|
|
|
|
|
|
2023-04-27 06:42:02 -06:00
|
|
|
|
2024-01-04 07:25:13 +01:00
|
|
|
.. _lv_table_example:
|
|
|
|
|
2023-04-27 06:42:02 -06:00
|
|
|
Example
|
|
|
|
*******
|
|
|
|
|
2024-10-23 12:53:33 -06:00
|
|
|
.. include:: ../../examples/widgets/table/index.rst
|
2023-04-27 06:42:02 -06:00
|
|
|
|
|
|
|
MicroPython
|
|
|
|
-----------
|
|
|
|
|
|
|
|
No examples yet.
|
|
|
|
|
2024-10-23 12:53:33 -06:00
|
|
|
|
|
|
|
|
2024-01-04 07:25:13 +01:00
|
|
|
.. _lv_table_api:
|
|
|
|
|
2023-04-27 06:42:02 -06:00
|
|
|
API
|
|
|
|
***
|