Tabview (lv_tabview)

Overview

The Tab view object can be used to organize content in tabs.

Parts and Styles

The Tab view object has several parts. The main is LV_TABVIEW_PART_BG. It a rectangle-like container which holds the other parts of the Tab view.

On the background 2 important real parts are created:

  • LV_TABVIEW_PART_BG_SCRL: it's the scrollable part of Page. It holds the content of the tabs next to each other. The background of the Page is always transparent and can't be accessed externally.

  • LV_TABVIEW_PART_TAB_BG: The tab buttons which is a Button matrix. Clicking on a button will scroll LV_TABVIEW_PART_BG_SCRL to the related tab's content. The tab buttons can be accessed via LV_TABVIEW_PART_TAB_BTN. The height of the tab's button matrix is calculated from the font height plus padding of the background's and the button's style.

All the listed parts supports the typical background style properties and padding.

LV_TABVIEW_PART_TAB_BG has an additional real part, an indicator, called LV_TABVIEW_PART_INDIC. It's a thin rectangle-like object under the currently selected tab. When the tab view is animated to an other tab the indicator will be animated too. It can be styles using the typical background style properties. The size style property will set the its thickness.

When a new tab is added a Page is create for them on LV_TABVIEW_PART_BG_SCRL and a new button is added to LV_TABVIEW_PART_TAB_BG Button matrix. The created Pages can be used as normal Pages and they have the usual Page parts.

Usage

Adding tab

New tabs can be added with lv_tabview_add_tab(tabview, "Tab name"). It will return with a pointer to a Page object where the tab's content can be created.

Change tab

To select a new tab you can:

  • Click on it on the Button matrix part

  • Slide

  • Use lv_tabview_set_tab_act(tabview, id, LV_ANIM_ON/OFF) function

Tab button's position

By default, the tab selector buttons are placed on the top of the Tab view. It can be changed with lv_tabview_set_btns_pos(tabview, LV_TABVIEW_TAB_POS_TOP/BOTTOM/LEFT/RIGHT/NONE)

LV_TABVIEW_TAB_POS_NONE will hide the tabs.

Note that, you can't change the tab position from top or bottom to left or right when tabs are already added.

Animation time

The animation time is adjusted by lv_tabview_set_anim_time(tabview, anim_time_ms). It is used when the new tab is loaded.

Scroll propagation

As the tabs' content object is a Page it can receive scroll propagation from an other Page-like object. For example, if a text area is created on the tab's content and that Text area is scrolled but it reached the end the scroll can be propagated to the content Page. It can be enabled with lv_page/textarea_set_scroll_propagation(obj, true).

By default the tab's content Pages have enabled scroll propagation, therefore when they are scrolled horizontally the scroll is propagated to LV_TABVIEW_PART_BG_SCRL and this way the Pages will be scrolled.

The manual sliding can be disabled with lv_page_set_scroll_propagation(tab_page, false).

Events

Besides the Generic events the following Special events are sent by the Slider:

  • LV_EVENT_VALUE_CHANGED Sent when a new tab is selected by sliding or clicking the tab button

Learn more about Events.

Keys

The following Keys are processed by the Tabview:

  • LV_KEY_RIGHT/LEFT Select a tab

  • LV_KEY_ENTER Change to the selected tab

Learn more about Keys.

Example

C

Simple Tabview

Tabview example in LittlevGL

code

#include "../../../lv_examples.h"
#if LV_USE_TABVIEW

void lv_ex_tabview_1(void)
{
    /*Create a Tab view object*/
    lv_obj_t *tabview;
    tabview = lv_tabview_create(lv_scr_act(), NULL);

    /*Add 3 tabs (the tabs are page (lv_page) and can be scrolled*/
    lv_obj_t *tab1 = lv_tabview_add_tab(tabview, "Tab 1");
    lv_obj_t *tab2 = lv_tabview_add_tab(tabview, "Tab 2");
    lv_obj_t *tab3 = lv_tabview_add_tab(tabview, "Tab 3");


    /*Add content to the tabs*/
    lv_obj_t * label = lv_label_create(tab1, NULL);
    lv_label_set_text(label, "This the first tab\n\n"
                             "If the content\n"
                             "of a tab\n"
                             "become too long\n"
                             "the it \n"
                             "automatically\n"
                             "become\n"
                             "scrollable.");

    label = lv_label_create(tab2, NULL);
    lv_label_set_text(label, "Second tab");

    label = lv_label_create(tab3, NULL);
    lv_label_set_text(label, "Third tab");
}
#endif

MicroPython

No examples yet.

API

Typedefs

typedef uint8_t lv_tabview_btns_pos_t
typedef uint8_t lv_tabview_part_t

Enums

enum [anonymous]

Position of tabview buttons.

Values:

enumerator LV_TABVIEW_TAB_POS_NONE
enumerator LV_TABVIEW_TAB_POS_TOP
enumerator LV_TABVIEW_TAB_POS_BOTTOM
enumerator LV_TABVIEW_TAB_POS_LEFT
enumerator LV_TABVIEW_TAB_POS_RIGHT
enum [anonymous]

Values:

enumerator LV_TABVIEW_PART_BG = LV_OBJ_PART_MAIN
enumerator _LV_TABVIEW_PART_VIRTUAL_LAST = _LV_OBJ_PART_VIRTUAL_LAST
enumerator LV_TABVIEW_PART_BG_SCRLLABLE = _LV_OBJ_PART_REAL_LAST
enumerator LV_TABVIEW_PART_TAB_BG
enumerator LV_TABVIEW_PART_TAB_BTN
enumerator LV_TABVIEW_PART_INDIC
enumerator _LV_TABVIEW_PART_REAL_LAST

Functions

lv_obj_t *lv_tabview_create(lv_obj_t *par, const lv_obj_t *copy)

Create a Tab view object

Return

pointer to the created tab

Parameters
  • par: pointer to an object, it will be the parent of the new tab

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

lv_obj_t *lv_tabview_add_tab(lv_obj_t *tabview, const char *name)

Add a new tab with the given name

Return

pointer to the created page object (lv_page). You can create your content here

Parameters
  • tabview: pointer to Tab view object where to ass the new tab

  • name: the text on the tab button

void lv_tabview_clean_tab(lv_obj_t *tab)

Delete all children of a tab created by lv_tabview_add_tab.

Parameters
  • tab: pointer to a tab

void lv_tabview_set_tab_act(lv_obj_t *tabview, uint16_t id, lv_anim_enable_t anim)

Set a new tab

Parameters
  • tabview: pointer to Tab view object

  • id: index of a tab to load

  • anim: LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately

void lv_tabview_set_anim_time(lv_obj_t *tabview, uint16_t anim_time)

Set the animation time of tab view when a new tab is loaded

Parameters
  • tabview: pointer to Tab view object

  • anim_time: time of animation in milliseconds

void lv_tabview_set_btns_pos(lv_obj_t *tabview, lv_tabview_btns_pos_t btns_pos)

Set the position of tab select buttons

Parameters
  • tabview: pointer to a tab view object

  • btns_pos: which button position

uint16_t lv_tabview_get_tab_act(const lv_obj_t *tabview)

Get the index of the currently active tab

Return

the active tab index

Parameters
  • tabview: pointer to Tab view object

uint16_t lv_tabview_get_tab_count(const lv_obj_t *tabview)

Get the number of tabs

Return

tab count

Parameters
  • tabview: pointer to Tab view object

lv_obj_t *lv_tabview_get_tab(const lv_obj_t *tabview, uint16_t id)

Get the page (content area) of a tab

Return

pointer to page (lv_page) object

Parameters
  • tabview: pointer to Tab view object

  • id: index of the tab (>= 0)

uint16_t lv_tabview_get_anim_time(const lv_obj_t *tabview)

Get the animation time of tab view when a new tab is loaded

Return

time of animation in milliseconds

Parameters
  • tabview: pointer to Tab view object

lv_tabview_btns_pos_t lv_tabview_get_btns_pos(const lv_obj_t *tabview)

Get position of tab select buttons

Parameters
  • tabview: pointer to a ab view object

struct lv_tabview_ext_t

Public Members

lv_obj_t *btns
lv_obj_t *indic
lv_obj_t *content
const char **tab_name_ptr
lv_point_t point_last
uint16_t tab_cur
uint16_t tab_cnt
uint16_t anim_time
lv_tabview_btns_pos_t btns_pos