2021-04-12 18:19:04 +02:00
# Tabview (lv_tabview)
## Overview
The Tab view object can be used to organize content in tabs.
2021-06-09 15:10:35 +02:00
The Tab view is built from other widgets:
2021-05-19 13:51:22 +02:00
- Main container: [lv_obj ](/widgets/obj ))
2022-07-27 10:50:32 +02:00
- Tab buttons: [lv_btnmatrix ](/widgets/btnmatrix )
2021-05-19 13:51:22 +02:00
- Container for the tabs: [lv_obj ](/widgets/obj )
- Content of the tabs: [lv_obj ](/widgets/obj )
2021-04-12 18:19:04 +02:00
2022-03-21 18:25:51 +08:00
The tab buttons can be positioned on the top, bottom, left and right side of the Tab view.
2021-04-12 18:19:04 +02:00
2021-06-09 15:10:35 +02:00
A new tab can be selected either by clicking on a tab button or by sliding horizontally on the content.
2021-04-12 18:19:04 +02:00
2021-05-19 13:51:22 +02:00
## Parts and Styles
2021-06-09 15:10:35 +02:00
There are no special parts on the Tab view but the `lv_obj` and `lv_btnnmatrix` widgets are used to create the Tab view.
2021-04-12 18:19:04 +02:00
2021-05-19 13:51:22 +02:00
## Usage
2021-04-12 18:19:04 +02:00
2021-05-19 13:51:22 +02:00
### Create a Tab view
2021-04-12 18:19:04 +02:00
2022-03-21 18:25:51 +08:00
`lv_tabview_create(parent, tab_pos, tab_size);` creates a new empty Tab view. `tab_pos` can be `LV_DIR_TOP/BOTTOM/LEFT/RIGHT` to position the tab buttons to a side.
2021-05-19 13:51:22 +02:00
`tab_size` is the height (in case of `LV_DIR_TOP/BOTTOM` ) or width (in case of `LV_DIR_LEFT/RIGHT` ) tab buttons.
2021-04-12 18:19:04 +02:00
2021-05-19 13:51:22 +02:00
### Add tabs
2021-04-12 18:19:04 +02:00
2021-06-09 15:10:35 +02:00
New tabs can be added with `lv_tabview_add_tab(tabview, "Tab name")` . This will return a pointer to an [lv_obj ](/widgets/obj ) object where the tab's content can be created.
2021-04-12 18:19:04 +02:00
2022-06-13 12:56:37 +01:00
### Rename tabs
2022-06-13 13:00:23 +01:00
A tab can be renamed with `lv_tabview_rename_tab(tabview, tab_id, "New Name")` .
2022-06-13 12:56:37 +01:00
2021-04-12 18:19:04 +02:00
### Change tab
To select a new tab you can:
2021-05-19 13:51:22 +02:00
- Click on its tab button
- Slide horizontally
- Use `lv_tabview_set_act(tabview, id, LV_ANIM_ON/OFF)` function
2021-04-12 18:19:04 +02:00
2021-05-19 13:51:22 +02:00
### Get the parts
2021-04-12 18:19:04 +02:00
2022-07-27 10:50:32 +02:00
`lv_tabview_get_content(tabview)` returns the container for the tabs, `lv_tabview_get_tab_btns(tabview)` returns the Tab buttons object which is a [Button matrix ](/widgets/btnmatrix ).
2021-04-12 18:19:04 +02:00
## Events
2021-05-19 13:51:22 +02:00
- `LV_EVENT_VALUE_CHANGED` Sent when a new tab is selected by sliding or clicking the tab button. `lv_tabview_get_tab_act(tabview)` returns the zero based index of the current tab.
2021-04-12 18:19:04 +02:00
Learn more about [Events ](/overview/event ).
## Keys
2021-06-09 15:10:35 +02:00
Keys have effect only on the tab buttons (Button matrix). Add manually to a group if required.
2021-04-12 18:19:04 +02:00
Learn more about [Keys ](/overview/indev ).
## Example
```eval_rst
2022-08-15 09:27:00 -04:00
.. include:: ../../examples/widgets/tabview/index.rst
2021-04-12 18:19:04 +02:00
```
## API
```eval_rst
.. doxygenfile:: lv_tabview.h
:project: lvgl
```