2017-08-23 14:24:34 +02:00
|
|
|
/**
|
|
|
|
* @file lv_tab.c
|
2018-06-19 09:49:58 +02:00
|
|
|
*
|
2017-08-23 14:24:34 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
2018-07-07 11:53:22 +02:00
|
|
|
#include "lv_tabview.h"
|
2020-02-15 00:33:26 +01:00
|
|
|
#if LV_USE_TABVIEW != 0
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2020-02-14 12:44:15 +01:00
|
|
|
#include "lv_btnmatrix.h"
|
2019-09-24 16:30:38 +02:00
|
|
|
#include "../lv_core/lv_debug.h"
|
2017-11-16 15:32:33 +01:00
|
|
|
#include "../lv_themes/lv_theme.h"
|
2017-11-23 20:42:14 +01:00
|
|
|
#include "../lv_misc/lv_anim.h"
|
2019-04-09 15:24:20 +02:00
|
|
|
#include "../lv_core/lv_disp.h"
|
2017-08-23 14:24:34 +02:00
|
|
|
|
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
2019-09-26 10:51:54 +02:00
|
|
|
#define LV_OBJX_NAME "lv_tabview"
|
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_ANIMATION
|
2020-02-26 19:48:27 +01:00
|
|
|
#ifndef LV_TABVIEW_DEF_ANIM_TIME
|
|
|
|
#define LV_TABVIEW_DEF_ANIM_TIME 300 /*Animation time of focusing to the a list element [ms] (0: no animation) */
|
|
|
|
#endif
|
2017-11-27 17:48:54 +01:00
|
|
|
#else
|
2020-02-26 19:48:27 +01:00
|
|
|
#undef LV_TABVIEW_DEF_ANIM_TIME
|
|
|
|
#define LV_TABVIEW_DEF_ANIM_TIME 0 /*No animations*/
|
2017-11-27 17:48:54 +01:00
|
|
|
#endif
|
2017-08-23 14:24:34 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC PROTOTYPES
|
|
|
|
**********************/
|
2017-11-15 15:50:33 +01:00
|
|
|
static lv_res_t lv_tabview_signal(lv_obj_t * tabview, lv_signal_t sign, void * param);
|
2019-10-02 16:35:02 +02:00
|
|
|
static lv_res_t tabview_scrl_signal(lv_obj_t * tabview_scrl, lv_signal_t sign, void * param);
|
2020-01-16 14:26:36 +01:00
|
|
|
static lv_style_list_t * lv_tabview_get_style(lv_obj_t * tabview, uint8_t part);
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2019-03-12 06:20:45 +01:00
|
|
|
static void tab_btnm_event_cb(lv_obj_t * tab_btnm, lv_event_t event);
|
2017-11-15 15:50:33 +01:00
|
|
|
static void tabview_realign(lv_obj_t * tabview);
|
2019-09-19 14:58:07 +02:00
|
|
|
static void refr_indic_size(lv_obj_t * tabview);
|
|
|
|
static void refr_btns_size(lv_obj_t * tabview);
|
|
|
|
static void refr_content_size(lv_obj_t * tabview);
|
|
|
|
static void refr_align(lv_obj_t * tabview);
|
2017-08-23 14:24:34 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC VARIABLES
|
|
|
|
**********************/
|
2019-02-26 09:25:46 +01:00
|
|
|
static lv_signal_cb_t ancestor_signal;
|
2019-09-19 14:58:07 +02:00
|
|
|
static lv_signal_cb_t ancestor_scrl_signal;
|
2019-02-26 09:25:46 +01:00
|
|
|
static lv_signal_cb_t page_signal;
|
2017-08-23 14:24:34 +02:00
|
|
|
static const char * tab_def[] = {""};
|
2017-11-15 15:50:33 +01:00
|
|
|
|
2017-08-23 14:24:34 +02:00
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* GLOBAL FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a Tab view object
|
|
|
|
* @param par pointer to an object, it will be the parent of the new tab
|
|
|
|
* @param copy pointer to a tab object, if not NULL then the new object will be copied from it
|
|
|
|
* @return pointer to the created tab
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
lv_obj_t * lv_tabview_create(lv_obj_t * par, const lv_obj_t * copy)
|
2017-08-23 14:24:34 +02:00
|
|
|
{
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_TRACE("tab view create started");
|
2018-07-25 17:57:08 +02:00
|
|
|
|
2017-08-23 14:24:34 +02:00
|
|
|
/*Create the ancestor of tab*/
|
2020-01-18 23:34:34 +01:00
|
|
|
lv_obj_t * tabview = lv_obj_create(par, copy);
|
|
|
|
LV_ASSERT_MEM(tabview);
|
|
|
|
if(tabview == NULL) return NULL;
|
|
|
|
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(tabview);
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2017-08-23 14:24:34 +02:00
|
|
|
/*Allocate the tab type specific extended data*/
|
2020-01-18 23:34:34 +01:00
|
|
|
lv_tabview_ext_t * ext = lv_obj_allocate_ext_attr(tabview, sizeof(lv_tabview_ext_t));
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(ext);
|
2019-12-03 18:16:14 +01:00
|
|
|
if(ext == NULL) {
|
2020-01-18 23:34:34 +01:00
|
|
|
lv_obj_del(tabview);
|
2019-12-03 18:16:14 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2017-08-23 14:24:34 +02:00
|
|
|
|
|
|
|
/*Initialize the allocated 'ext' */
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->tab_cur = 0;
|
2020-01-20 16:11:38 +01:00
|
|
|
ext->tab_cnt = 0;
|
2017-08-23 14:24:34 +02:00
|
|
|
ext->point_last.x = 0;
|
|
|
|
ext->point_last.y = 0;
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->content = NULL;
|
|
|
|
ext->indic = NULL;
|
|
|
|
ext->btns = NULL;
|
|
|
|
ext->btns_pos = LV_TABVIEW_BTNS_POS_TOP;
|
2019-05-20 09:22:09 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2019-06-06 06:05:40 +02:00
|
|
|
ext->anim_time = LV_TABVIEW_DEF_ANIM_TIME;
|
2019-05-20 09:22:09 -07:00
|
|
|
#endif
|
2017-08-23 14:24:34 +02:00
|
|
|
|
|
|
|
/*The signal and design functions are not copied so set them here*/
|
2020-01-18 23:34:34 +01:00
|
|
|
lv_obj_set_signal_cb(tabview, lv_tabview_signal);
|
2017-08-23 14:24:34 +02:00
|
|
|
/*Init the new tab tab*/
|
|
|
|
if(copy == NULL) {
|
2018-10-05 17:22:49 +02:00
|
|
|
ext->tab_name_ptr = lv_mem_alloc(sizeof(char *));
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(ext->tab_name_ptr);
|
2018-10-05 17:22:49 +02:00
|
|
|
if(ext->tab_name_ptr == NULL) return NULL;
|
|
|
|
ext->tab_name_ptr[0] = "";
|
2018-07-25 13:33:53 +02:00
|
|
|
|
2019-04-09 15:24:20 +02:00
|
|
|
/* Set a size which fits into the parent.
|
2019-04-10 06:21:54 +02:00
|
|
|
* Don't use `par` directly because if the tabview is created on a page it is moved to the
|
|
|
|
* scrollable so the parent has changed */
|
2020-01-30 05:48:49 +01:00
|
|
|
lv_coord_t w;
|
|
|
|
lv_coord_t h;
|
|
|
|
if(par) {
|
2020-02-05 15:12:45 +01:00
|
|
|
w = lv_obj_get_width_fit(lv_obj_get_parent(tabview));
|
|
|
|
h = lv_obj_get_height_fit(lv_obj_get_parent(tabview));
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else {
|
2020-01-30 05:48:49 +01:00
|
|
|
w = lv_disp_get_hor_res(NULL);
|
|
|
|
h = lv_disp_get_ver_res(NULL);
|
|
|
|
}
|
|
|
|
|
2020-02-05 15:12:45 +01:00
|
|
|
lv_obj_set_size(tabview, w, h);
|
2017-11-15 15:50:33 +01:00
|
|
|
|
2020-01-18 23:34:34 +01:00
|
|
|
ext->content = lv_page_create(tabview, NULL);
|
2020-02-14 12:36:44 +01:00
|
|
|
ext->btns = lv_btnmatrix_create(tabview, NULL);
|
2019-06-06 06:05:40 +02:00
|
|
|
ext->indic = lv_obj_create(ext->btns, NULL);
|
2019-04-18 18:00:11 +03:00
|
|
|
|
2019-09-19 14:58:07 +02:00
|
|
|
if(ancestor_scrl_signal == NULL) ancestor_scrl_signal = lv_obj_get_signal_cb(lv_page_get_scrl(ext->content));
|
|
|
|
lv_obj_set_signal_cb(lv_page_get_scrl(ext->content), tabview_scrl_signal);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_btnmatrix_set_map(ext->btns, tab_def);
|
2019-03-12 06:20:45 +01:00
|
|
|
lv_obj_set_event_cb(ext->btns, tab_btnm_event_cb);
|
2019-06-06 06:05:40 +02:00
|
|
|
|
2017-08-23 14:24:34 +02:00
|
|
|
lv_obj_set_click(ext->indic, false);
|
2020-02-21 16:33:42 +01:00
|
|
|
lv_obj_set_drag_dir(lv_page_get_scrl(ext->content), LV_DRAG_DIR_ONE);
|
2019-06-06 06:05:40 +02:00
|
|
|
|
2020-02-14 13:38:48 +01:00
|
|
|
lv_page_set_scrl_fit2(ext->content, LV_FIT_TIGHT, LV_FIT_PARENT);
|
|
|
|
lv_page_set_scrl_layout(ext->content, LV_LAYOUT_ROW_TOP);
|
2020-03-06 13:14:25 +01:00
|
|
|
lv_page_set_scrlbar_mode(ext->content, LV_SB_MODE_OFF);
|
2017-11-15 15:50:33 +01:00
|
|
|
|
2020-02-21 16:33:42 +01:00
|
|
|
lv_obj_clean_style_list(ext->content, LV_PAGE_PART_BG);
|
2020-01-10 18:16:20 +01:00
|
|
|
|
2020-01-18 23:34:34 +01:00
|
|
|
lv_theme_apply(tabview, LV_THEME_TABVIEW);
|
2020-01-01 18:46:22 +01:00
|
|
|
|
2017-08-23 14:24:34 +02:00
|
|
|
}
|
2017-11-16 15:32:33 +01:00
|
|
|
/*Copy an existing tab view*/
|
2017-08-23 14:24:34 +02:00
|
|
|
else {
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_tabview_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->point_last.x = 0;
|
|
|
|
ext->point_last.y = 0;
|
2020-02-14 12:36:44 +01:00
|
|
|
ext->btns = lv_btnmatrix_create(tabview, copy_ext->btns);
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->indic = lv_obj_create(ext->btns, copy_ext->indic);
|
2020-01-18 23:34:34 +01:00
|
|
|
ext->content = lv_page_create(tabview, copy_ext->content);
|
2019-05-20 09:22:09 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2019-06-06 06:05:40 +02:00
|
|
|
ext->anim_time = copy_ext->anim_time;
|
2019-05-20 09:22:09 -07:00
|
|
|
#endif
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
ext->tab_name_ptr = lv_mem_alloc(sizeof(char *));
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(ext->tab_name_ptr);
|
2018-07-25 13:33:53 +02:00
|
|
|
if(ext->tab_name_ptr == NULL) return NULL;
|
2017-08-23 14:24:34 +02:00
|
|
|
ext->tab_name_ptr[0] = "";
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_btnmatrix_set_map(ext->btns, ext->tab_name_ptr);
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2020-02-26 19:48:27 +01:00
|
|
|
lv_style_list_copy(lv_obj_get_style_list(tabview, LV_TABVIEW_PART_BG_SCRL), lv_obj_get_style_list(copy,
|
|
|
|
LV_TABVIEW_PART_BG_SCRL));
|
|
|
|
lv_style_list_copy(lv_obj_get_style_list(tabview, LV_TABVIEW_PART_TAB_BG), lv_obj_get_style_list(copy,
|
|
|
|
LV_TABVIEW_PART_TAB_BG));
|
2020-02-29 13:35:53 +01:00
|
|
|
lv_style_list_copy(lv_obj_get_style_list(tabview, LV_TABVIEW_PART_TAB_BTN), lv_obj_get_style_list(copy,
|
2020-03-03 15:37:13 +01:00
|
|
|
LV_TABVIEW_PART_TAB_BTN));
|
2020-01-20 16:11:38 +01:00
|
|
|
|
|
|
|
uint16_t i;
|
|
|
|
for(i = 0; i < copy_ext->tab_cnt; i++) {
|
2020-02-25 15:32:35 +01:00
|
|
|
lv_obj_t * new_tab = lv_tabview_add_tab(tabview, copy_ext->tab_name_ptr[i]);
|
|
|
|
lv_obj_t * copy_tab = lv_tabview_get_tab(copy, i);
|
2020-02-26 19:48:27 +01:00
|
|
|
lv_style_list_copy(lv_obj_get_style_list(new_tab, LV_PAGE_PART_SCRL), lv_obj_get_style_list(copy_tab,
|
|
|
|
LV_PAGE_PART_SCRL));
|
|
|
|
lv_style_list_copy(lv_obj_get_style_list(new_tab, LV_PAGE_PART_SCRLBAR), lv_obj_get_style_list(copy_tab,
|
|
|
|
LV_PAGE_PART_SCRLBAR));
|
2020-01-20 16:11:38 +01:00
|
|
|
lv_obj_refresh_style(new_tab);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Refresh the style with new signal function*/
|
|
|
|
lv_obj_refresh_style(tabview);
|
2017-08-23 14:24:34 +02:00
|
|
|
}
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2020-01-18 23:34:34 +01:00
|
|
|
tabview_realign(tabview);
|
2019-09-19 14:58:07 +02:00
|
|
|
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_INFO("tab view created");
|
2018-07-25 17:57:08 +02:00
|
|
|
|
2020-01-18 23:34:34 +01:00
|
|
|
return tabview;
|
2017-08-23 14:24:34 +02:00
|
|
|
}
|
|
|
|
|
2018-03-16 11:53:27 -04:00
|
|
|
/**
|
|
|
|
* Delete all children of the scrl object, without deleting scrl child.
|
2019-09-26 12:54:40 +02:00
|
|
|
* @param tabview pointer to an object
|
2018-03-16 11:53:27 -04:00
|
|
|
*/
|
2019-09-26 12:54:40 +02:00
|
|
|
void lv_tabview_clean(lv_obj_t * tabview)
|
2018-03-16 11:53:27 -04:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(tabview, LV_OBJX_NAME);
|
|
|
|
|
|
|
|
lv_obj_t * scrl = lv_page_get_scrl(tabview);
|
2018-03-16 11:53:27 -04:00
|
|
|
lv_obj_clean(scrl);
|
|
|
|
}
|
|
|
|
|
2017-08-23 14:24:34 +02:00
|
|
|
/*======================
|
|
|
|
* Add/remove functions
|
|
|
|
*=====================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new tab with the given name
|
|
|
|
* @param tabview pointer to Tab view object where to ass the new tab
|
|
|
|
* @param name the text on the tab button
|
2017-11-15 15:50:33 +01:00
|
|
|
* @return pointer to the created page object (lv_page). You can create your content here
|
2017-08-23 14:24:34 +02:00
|
|
|
*/
|
|
|
|
lv_obj_t * lv_tabview_add_tab(lv_obj_t * tabview, const char * name)
|
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(tabview, LV_OBJX_NAME);
|
|
|
|
LV_ASSERT_STR(name);
|
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
2017-08-23 14:24:34 +02:00
|
|
|
|
|
|
|
/*Create the container page*/
|
|
|
|
lv_obj_t * h = lv_page_create(ext->content, NULL);
|
2017-11-15 15:50:33 +01:00
|
|
|
lv_obj_set_size(h, lv_obj_get_width(tabview), lv_obj_get_height(ext->content));
|
2020-03-06 13:14:25 +01:00
|
|
|
lv_page_set_scrlbar_mode(h, LV_SB_MODE_AUTO);
|
2019-09-18 16:03:29 +02:00
|
|
|
lv_page_set_scroll_propagation(h, true);
|
2020-01-18 23:34:34 +01:00
|
|
|
lv_theme_apply(h, LV_THEME_TABVIEW_PAGE);
|
2017-11-05 00:48:57 +01:00
|
|
|
|
2019-04-10 06:40:49 +02:00
|
|
|
if(page_signal == NULL) page_signal = lv_obj_get_signal_cb(h);
|
2017-08-23 14:24:34 +02:00
|
|
|
|
|
|
|
/*Extend the button matrix map with the new name*/
|
2018-06-19 09:49:58 +02:00
|
|
|
char * name_dm;
|
2019-03-12 06:20:45 +01:00
|
|
|
name_dm = lv_mem_alloc(strlen(name) + 1); /*+1 for the the closing '\0' */
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(name_dm);
|
2019-03-12 06:20:45 +01:00
|
|
|
if(name_dm == NULL) return NULL;
|
|
|
|
strcpy(name_dm, name);
|
2018-07-25 14:43:46 +02:00
|
|
|
|
2017-08-23 14:24:34 +02:00
|
|
|
ext->tab_cnt++;
|
2019-04-18 18:00:11 +03:00
|
|
|
|
|
|
|
switch(ext->btns_pos) {
|
|
|
|
case LV_TABVIEW_BTNS_POS_TOP:
|
|
|
|
case LV_TABVIEW_BTNS_POS_BOTTOM:
|
2020-02-26 19:48:27 +01:00
|
|
|
ext->tab_name_ptr = lv_mem_realloc((void *)ext->tab_name_ptr, sizeof(char *) * (ext->tab_cnt + 1));
|
2019-04-18 18:00:11 +03:00
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_LEFT:
|
|
|
|
case LV_TABVIEW_BTNS_POS_RIGHT:
|
2020-02-26 19:48:27 +01:00
|
|
|
ext->tab_name_ptr = lv_mem_realloc((void *)ext->tab_name_ptr, sizeof(char *) * (ext->tab_cnt * 2));
|
2019-04-18 18:00:11 +03:00
|
|
|
break;
|
|
|
|
}
|
2019-06-06 06:05:40 +02:00
|
|
|
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(ext->tab_name_ptr);
|
2018-07-25 14:43:46 +02:00
|
|
|
if(ext->tab_name_ptr == NULL) return NULL;
|
|
|
|
|
2019-04-19 11:35:02 +03:00
|
|
|
/* FIXME: It is not possible yet to switch tab button position from/to top/bottom from/to left/right at runtime.
|
|
|
|
* Method: clean extra \n when switch from LV_TABVIEW_BTNS_POS_LEFT or LV_TABVIEW_BTNS_POS_RIGHT
|
|
|
|
* to LV_TABVIEW_BTNS_POS_TOP or LV_TABVIEW_BTNS_POS_BOTTOM.
|
|
|
|
*/
|
2019-04-18 18:00:11 +03:00
|
|
|
switch(ext->btns_pos) {
|
2020-02-26 19:48:27 +01:00
|
|
|
default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/
|
|
|
|
case LV_TABVIEW_BTNS_POS_NONE:
|
|
|
|
case LV_TABVIEW_BTNS_POS_TOP:
|
|
|
|
case LV_TABVIEW_BTNS_POS_BOTTOM:
|
|
|
|
ext->tab_name_ptr = lv_mem_realloc(ext->tab_name_ptr, sizeof(char *) * (ext->tab_cnt + 1));
|
2019-09-19 14:58:07 +02:00
|
|
|
|
2020-02-26 19:48:27 +01:00
|
|
|
LV_ASSERT_MEM(ext->tab_name_ptr);
|
|
|
|
if(ext->tab_name_ptr == NULL) return NULL;
|
2019-09-19 14:58:07 +02:00
|
|
|
|
2020-02-26 19:48:27 +01:00
|
|
|
ext->tab_name_ptr[ext->tab_cnt - 1] = name_dm;
|
|
|
|
ext->tab_name_ptr[ext->tab_cnt] = "";
|
2019-09-19 14:58:07 +02:00
|
|
|
|
2020-02-26 19:48:27 +01:00
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_LEFT:
|
|
|
|
case LV_TABVIEW_BTNS_POS_RIGHT:
|
|
|
|
ext->tab_name_ptr = lv_mem_realloc(ext->tab_name_ptr, sizeof(char *) * (ext->tab_cnt * 2));
|
|
|
|
|
|
|
|
LV_ASSERT_MEM(ext->tab_name_ptr);
|
|
|
|
if(ext->tab_name_ptr == NULL) return NULL;
|
|
|
|
|
|
|
|
if(ext->tab_cnt == 1) {
|
|
|
|
ext->tab_name_ptr[0] = name_dm;
|
|
|
|
ext->tab_name_ptr[1] = "";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ext->tab_name_ptr[ext->tab_cnt * 2 - 3] = "\n";
|
|
|
|
ext->tab_name_ptr[ext->tab_cnt * 2 - 2] = name_dm;
|
|
|
|
ext->tab_name_ptr[ext->tab_cnt * 2 - 1] = "";
|
|
|
|
}
|
|
|
|
break;
|
2019-06-06 06:05:40 +02:00
|
|
|
}
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
/* The button matrix's map still points to the old `tab_name_ptr` which might be freed by
|
|
|
|
* `lv_mem_realloc`. So make its current map invalid*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_btnmatrix_ext_t * btnm_ext = lv_obj_get_ext_attr(ext->btns);
|
2019-04-04 07:15:40 +02:00
|
|
|
btnm_ext->map_p = NULL;
|
2019-03-15 22:19:21 +01:00
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_btnmatrix_set_map(ext->btns, ext->tab_name_ptr);
|
|
|
|
lv_btnmatrix_set_btn_ctrl(ext->btns, ext->tab_cur, LV_BTNMATRIX_CTRL_NO_REPEAT);
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2017-11-16 15:32:33 +01:00
|
|
|
/*Set the first btn as active*/
|
2019-09-19 14:58:07 +02:00
|
|
|
if(ext->tab_cnt == 1) ext->tab_cur = 0;
|
2017-10-05 12:55:32 +02:00
|
|
|
|
2019-04-19 06:40:06 +02:00
|
|
|
tabview_realign(tabview); /*Set the size of the pages, tab buttons and indicator*/
|
|
|
|
|
2019-03-12 06:20:45 +01:00
|
|
|
lv_tabview_set_tab_act(tabview, ext->tab_cur, false);
|
|
|
|
|
2017-08-23 14:24:34 +02:00
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*=====================
|
|
|
|
* Setter functions
|
|
|
|
*====================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a new tab
|
|
|
|
* @param tabview pointer to Tab view object
|
|
|
|
* @param id index of a tab to load
|
2019-06-11 13:51:14 +02:00
|
|
|
* @param anim LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately
|
2017-08-23 14:24:34 +02:00
|
|
|
*/
|
2019-06-11 13:51:14 +02:00
|
|
|
void lv_tabview_set_tab_act(lv_obj_t * tabview, uint16_t id, lv_anim_enable_t anim)
|
2017-08-23 14:24:34 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(tabview, LV_OBJX_NAME);
|
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_ANIMATION == 0
|
2019-06-11 13:51:14 +02:00
|
|
|
anim = LV_ANIM_OFF;
|
2018-03-01 12:21:49 +01:00
|
|
|
#endif
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
2018-05-16 23:09:30 +02:00
|
|
|
|
2017-10-31 16:25:52 +01:00
|
|
|
if(id >= ext->tab_cnt) id = ext->tab_cnt - 1;
|
2019-03-12 06:20:45 +01:00
|
|
|
|
2020-02-14 17:03:25 +01:00
|
|
|
lv_btnmatrix_clear_btn_ctrl(ext->btns, ext->tab_cur, LV_BTNMATRIX_CTRL_CHECK_STATE);
|
2017-10-31 16:25:52 +01:00
|
|
|
|
|
|
|
ext->tab_cur = id;
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2019-10-15 11:04:49 +02:00
|
|
|
if(lv_obj_get_base_dir(tabview) == LV_BIDI_DIR_RTL) {
|
|
|
|
id = (ext->tab_cnt - (id + 1));
|
|
|
|
}
|
|
|
|
|
2019-04-18 18:00:11 +03:00
|
|
|
lv_coord_t cont_x;
|
2020-02-02 15:58:08 +01:00
|
|
|
lv_style_int_t scrl_inner = lv_obj_get_style_pad_inner(ext->content, LV_PAGE_PART_SCRL);
|
|
|
|
lv_style_int_t scrl_left = lv_obj_get_style_pad_left(ext->content, LV_PAGE_PART_SCRL);
|
2019-04-18 18:00:11 +03:00
|
|
|
|
|
|
|
switch(ext->btns_pos) {
|
2020-02-26 19:48:27 +01:00
|
|
|
default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/
|
|
|
|
case LV_TABVIEW_BTNS_POS_NONE:
|
|
|
|
case LV_TABVIEW_BTNS_POS_TOP:
|
|
|
|
case LV_TABVIEW_BTNS_POS_BOTTOM:
|
|
|
|
cont_x = -(lv_obj_get_width(tabview) * id + scrl_inner * id + scrl_left);
|
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_LEFT:
|
|
|
|
case LV_TABVIEW_BTNS_POS_RIGHT:
|
|
|
|
cont_x = -((lv_obj_get_width(tabview) - lv_obj_get_width(ext->btns)) * id + scrl_inner * id + scrl_left);
|
|
|
|
break;
|
2019-04-18 18:00:11 +03:00
|
|
|
}
|
|
|
|
|
2019-06-20 06:20:23 +02:00
|
|
|
if(anim == LV_ANIM_OFF || lv_tabview_get_anim_time(tabview) == 0) {
|
2019-09-18 16:03:29 +02:00
|
|
|
lv_obj_set_x(lv_page_get_scrl(ext->content), cont_x);
|
2019-06-27 07:16:15 +02:00
|
|
|
}
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_ANIMATION
|
2019-06-19 09:08:47 -07:00
|
|
|
else {
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_anim_t a;
|
2020-02-19 06:18:24 +01:00
|
|
|
lv_anim_init(&a);
|
|
|
|
lv_anim_set_var(&a, lv_page_get_scrl(ext->content));
|
|
|
|
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_obj_set_x);
|
|
|
|
lv_anim_set_values(&a, lv_obj_get_x(lv_page_get_scrl(ext->content)), cont_x);
|
|
|
|
lv_anim_set_time(&a, ext->anim_time);
|
|
|
|
lv_anim_start(&a);
|
2017-08-23 14:24:34 +02:00
|
|
|
}
|
2019-06-19 09:08:47 -07:00
|
|
|
#endif
|
2017-08-23 14:24:34 +02:00
|
|
|
|
|
|
|
/*Move the indicator*/
|
2019-04-18 18:00:11 +03:00
|
|
|
lv_coord_t indic_size;
|
2019-10-31 20:19:21 -04:00
|
|
|
lv_coord_t indic_pos = 0; /*silence uninitialized variable warning*/;
|
2019-04-18 18:00:11 +03:00
|
|
|
|
2020-02-02 15:58:08 +01:00
|
|
|
lv_style_int_t btns_bg_inner = lv_obj_get_style_pad_inner(tabview, LV_TABVIEW_PART_TAB_BG);
|
|
|
|
lv_style_int_t btns_bg_left = lv_obj_get_style_pad_left(tabview, LV_TABVIEW_PART_TAB_BG);
|
|
|
|
lv_style_int_t btns_bg_top = lv_obj_get_style_pad_top(tabview, LV_TABVIEW_PART_TAB_BG);
|
2020-01-01 18:46:22 +01:00
|
|
|
|
2019-04-18 18:00:11 +03:00
|
|
|
switch(ext->btns_pos) {
|
2020-02-26 19:48:27 +01:00
|
|
|
default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/
|
|
|
|
case LV_TABVIEW_BTNS_POS_NONE:
|
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_TOP:
|
|
|
|
case LV_TABVIEW_BTNS_POS_BOTTOM:
|
|
|
|
indic_size = lv_obj_get_width(ext->indic);
|
|
|
|
indic_pos = indic_size * id + btns_bg_inner * id + btns_bg_left;
|
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_LEFT:
|
|
|
|
case LV_TABVIEW_BTNS_POS_RIGHT:
|
|
|
|
indic_size = lv_obj_get_height(ext->indic);
|
|
|
|
indic_pos = btns_bg_top + id * (indic_size + btns_bg_inner);
|
|
|
|
break;
|
2019-04-18 18:00:11 +03:00
|
|
|
}
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2019-06-19 09:08:47 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2019-06-27 07:16:15 +02:00
|
|
|
if(anim == LV_ANIM_OFF || ext->anim_time == 0)
|
2019-06-19 09:08:47 -07:00
|
|
|
#endif
|
|
|
|
{
|
2019-04-18 18:00:11 +03:00
|
|
|
switch(ext->btns_pos) {
|
2020-02-26 19:48:27 +01:00
|
|
|
default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/
|
|
|
|
case LV_TABVIEW_BTNS_POS_NONE:
|
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_TOP:
|
|
|
|
case LV_TABVIEW_BTNS_POS_BOTTOM:
|
|
|
|
lv_obj_set_x(ext->indic, indic_pos);
|
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_LEFT:
|
|
|
|
case LV_TABVIEW_BTNS_POS_RIGHT:
|
|
|
|
lv_obj_set_y(ext->indic, indic_pos);
|
|
|
|
break;
|
2019-06-06 06:05:40 +02:00
|
|
|
}
|
2019-06-27 07:16:15 +02:00
|
|
|
}
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_ANIMATION
|
2019-06-19 09:08:47 -07:00
|
|
|
else {
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_anim_t a;
|
2020-02-19 06:18:24 +01:00
|
|
|
lv_anim_init(&a);
|
|
|
|
lv_anim_set_var(&a, ext->indic);
|
|
|
|
lv_anim_set_time(&a, ext->anim_time);
|
2019-04-18 18:00:11 +03:00
|
|
|
|
|
|
|
switch(ext->btns_pos) {
|
2020-02-26 19:48:27 +01:00
|
|
|
default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/
|
|
|
|
case LV_TABVIEW_BTNS_POS_NONE:
|
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_TOP:
|
|
|
|
case LV_TABVIEW_BTNS_POS_BOTTOM:
|
|
|
|
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_obj_set_x);
|
|
|
|
lv_anim_set_values(&a, lv_obj_get_x(ext->indic), indic_pos);
|
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_LEFT:
|
|
|
|
case LV_TABVIEW_BTNS_POS_RIGHT:
|
|
|
|
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_obj_set_y);
|
|
|
|
lv_anim_set_values(&a, lv_obj_get_y(ext->indic), indic_pos);
|
|
|
|
break;
|
2019-04-18 18:00:11 +03:00
|
|
|
}
|
|
|
|
|
2020-02-19 06:18:24 +01:00
|
|
|
lv_anim_start(&a);
|
2017-08-23 14:24:34 +02:00
|
|
|
}
|
2019-06-19 09:08:47 -07:00
|
|
|
#endif
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2020-02-14 17:03:25 +01:00
|
|
|
lv_btnmatrix_set_btn_ctrl(ext->btns, ext->tab_cur, LV_BTNMATRIX_CTRL_CHECK_STATE);
|
2017-08-23 14:24:34 +02:00
|
|
|
}
|
|
|
|
|
2017-10-30 17:11:56 +01:00
|
|
|
/**
|
|
|
|
* Set the animation time of tab view when a new tab is loaded
|
|
|
|
* @param tabview pointer to Tab view object
|
|
|
|
* @param anim_time_ms time of animation in milliseconds
|
|
|
|
*/
|
2017-12-19 22:00:32 +01:00
|
|
|
void lv_tabview_set_anim_time(lv_obj_t * tabview, uint16_t anim_time)
|
2017-10-30 17:11:56 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(tabview, LV_OBJX_NAME);
|
|
|
|
|
2019-05-20 09:22:09 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
2019-06-06 06:05:40 +02:00
|
|
|
ext->anim_time = anim_time;
|
2019-05-20 09:22:09 -07:00
|
|
|
#else
|
2019-06-06 06:05:40 +02:00
|
|
|
(void)tabview;
|
|
|
|
(void)anim_time;
|
2019-05-20 09:22:09 -07:00
|
|
|
#endif
|
2017-10-30 17:11:56 +01:00
|
|
|
}
|
|
|
|
|
2018-03-07 15:45:11 -05:00
|
|
|
/**
|
|
|
|
* Set the position of tab select buttons
|
|
|
|
* @param tabview pointer to a tan view object
|
|
|
|
* @param btns_pos which button position
|
|
|
|
*/
|
2018-06-19 09:49:58 +02:00
|
|
|
void lv_tabview_set_btns_pos(lv_obj_t * tabview, lv_tabview_btns_pos_t btns_pos)
|
2018-03-07 15:45:11 -05:00
|
|
|
{
|
2019-10-31 20:19:21 -04:00
|
|
|
if(btns_pos != LV_TABVIEW_BTNS_POS_NONE &&
|
|
|
|
btns_pos != LV_TABVIEW_BTNS_POS_TOP &&
|
|
|
|
btns_pos != LV_TABVIEW_BTNS_POS_BOTTOM &&
|
|
|
|
btns_pos != LV_TABVIEW_BTNS_POS_LEFT &&
|
|
|
|
btns_pos != LV_TABVIEW_BTNS_POS_RIGHT) {
|
|
|
|
LV_LOG_WARN("lv_tabview_set_btns_pos: unexpected button position");
|
|
|
|
return;
|
|
|
|
}
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(tabview, LV_OBJX_NAME);
|
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
2018-03-07 15:45:11 -05:00
|
|
|
|
|
|
|
ext->btns_pos = btns_pos;
|
|
|
|
tabview_realign(tabview);
|
|
|
|
}
|
|
|
|
|
2017-08-23 14:24:34 +02:00
|
|
|
/*=====================
|
|
|
|
* Getter functions
|
|
|
|
*====================*/
|
|
|
|
|
|
|
|
/**
|
2017-12-08 14:34:07 +01:00
|
|
|
* Get the index of the currently active tab
|
2017-08-23 14:24:34 +02:00
|
|
|
* @param tabview pointer to Tab view object
|
2017-11-16 15:32:33 +01:00
|
|
|
* @return the active btn index
|
2017-08-23 14:24:34 +02:00
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
uint16_t lv_tabview_get_tab_act(const lv_obj_t * tabview)
|
2017-08-23 14:24:34 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(tabview, LV_OBJX_NAME);
|
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
2017-10-31 16:25:52 +01:00
|
|
|
return ext->tab_cur;
|
2017-08-23 14:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the number of tabs
|
|
|
|
* @param tabview pointer to Tab view object
|
2017-11-16 15:32:33 +01:00
|
|
|
* @return btn count
|
2017-08-23 14:24:34 +02:00
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
uint16_t lv_tabview_get_tab_count(const lv_obj_t * tabview)
|
2017-08-23 14:24:34 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(tabview, LV_OBJX_NAME);
|
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
2017-08-23 14:24:34 +02:00
|
|
|
return ext->tab_cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the page (content area) of a tab
|
|
|
|
* @param tabview pointer to Tab view object
|
2017-11-16 15:32:33 +01:00
|
|
|
* @param id index of the btn (>= 0)
|
2017-08-23 14:24:34 +02:00
|
|
|
* @return pointer to page (lv_page) object
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
lv_obj_t * lv_tabview_get_tab(const lv_obj_t * tabview, uint16_t id)
|
2017-08-23 14:24:34 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(tabview, LV_OBJX_NAME);
|
|
|
|
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
2019-09-18 16:03:29 +02:00
|
|
|
lv_obj_t * content_scrl = lv_page_get_scrl(ext->content);
|
2019-04-04 07:15:40 +02:00
|
|
|
uint16_t i = 0;
|
2019-09-18 16:03:29 +02:00
|
|
|
lv_obj_t * page = lv_obj_get_child_back(content_scrl, NULL);
|
2017-08-23 14:24:34 +02:00
|
|
|
|
|
|
|
while(page != NULL && i != id) {
|
2019-10-02 16:35:02 +02:00
|
|
|
if(lv_obj_get_signal_cb(page) == page_signal) i++;
|
2019-09-18 16:03:29 +02:00
|
|
|
page = lv_obj_get_child_back(content_scrl, page);
|
2017-08-23 14:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(i == id) return page;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-10-30 17:11:56 +01:00
|
|
|
/**
|
|
|
|
* Get the animation time of tab view when a new tab is loaded
|
|
|
|
* @param tabview pointer to Tab view object
|
|
|
|
* @return time of animation in milliseconds
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
uint16_t lv_tabview_get_anim_time(const lv_obj_t * tabview)
|
2017-10-30 17:11:56 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(tabview, LV_OBJX_NAME);
|
|
|
|
|
2019-05-20 09:22:09 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
2017-10-30 17:11:56 +01:00
|
|
|
return ext->anim_time;
|
2019-05-20 09:22:09 -07:00
|
|
|
#else
|
2019-06-06 06:05:40 +02:00
|
|
|
(void)tabview;
|
2019-05-20 09:22:09 -07:00
|
|
|
return 0;
|
|
|
|
#endif
|
2017-10-30 17:11:56 +01:00
|
|
|
}
|
|
|
|
|
2018-03-07 15:45:11 -05:00
|
|
|
/**
|
|
|
|
* Get position of tab select buttons
|
|
|
|
* @param tabview pointer to a ab view object
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
lv_tabview_btns_pos_t lv_tabview_get_btns_pos(const lv_obj_t * tabview)
|
2018-03-07 15:45:11 -05:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(tabview, LV_OBJX_NAME);
|
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
2018-03-07 15:45:11 -05:00
|
|
|
return ext->btns_pos;
|
|
|
|
}
|
|
|
|
|
2017-08-23 14:24:34 +02:00
|
|
|
/**********************
|
|
|
|
* STATIC FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**
|
2017-11-15 15:50:33 +01:00
|
|
|
* Signal function of the Tab view
|
|
|
|
* @param tabview pointer to a Tab view object
|
|
|
|
* @param sign a signal type from lv_signal_t enum
|
|
|
|
* @param param pointer to a signal specific variable
|
|
|
|
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
|
2017-08-23 14:24:34 +02:00
|
|
|
*/
|
2017-11-15 15:50:33 +01:00
|
|
|
static lv_res_t lv_tabview_signal(lv_obj_t * tabview, lv_signal_t sign, void * param)
|
2017-08-23 14:24:34 +02:00
|
|
|
{
|
2017-11-15 15:50:33 +01:00
|
|
|
lv_res_t res;
|
2020-02-26 19:48:27 +01:00
|
|
|
if(sign == LV_SIGNAL_GET_STYLE) {
|
|
|
|
lv_get_style_info_t * info = param;
|
|
|
|
info->result = lv_tabview_get_style(tabview, info->part);
|
|
|
|
if(info->result != NULL) return LV_RES_OK;
|
|
|
|
else return ancestor_signal(tabview, sign, param);
|
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_GET_STATE_DSC) {
|
2020-01-24 14:55:56 +01:00
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
2020-02-26 19:48:27 +01:00
|
|
|
lv_get_state_info_t * info = param;
|
|
|
|
if(info->part == LV_TABVIEW_PART_TAB_BG) info->result = lv_obj_get_state(ext->btns, LV_BTNMATRIX_PART_BG);
|
2020-02-29 13:35:53 +01:00
|
|
|
else if(info->part == LV_TABVIEW_PART_TAB_BTN) info->result = lv_obj_get_state(ext->btns, LV_BTNMATRIX_PART_BTN);
|
2020-02-26 19:48:27 +01:00
|
|
|
else if(info->part == LV_TABVIEW_PART_INDIC) info->result = lv_obj_get_state(ext->indic, LV_OBJ_PART_MAIN);
|
|
|
|
else if(info->part == LV_TABVIEW_PART_BG_SCRL) info->result = lv_obj_get_state(ext->content, LV_PAGE_PART_SCRL);
|
|
|
|
return LV_RES_OK;
|
2020-01-01 18:46:22 +01:00
|
|
|
}
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
/* Include the ancient signal function */
|
|
|
|
res = ancestor_signal(tabview, sign, param);
|
|
|
|
if(res != LV_RES_OK) return res;
|
2019-09-26 12:54:40 +02:00
|
|
|
if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, LV_OBJX_NAME);
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
|
|
|
if(sign == LV_SIGNAL_CLEANUP) {
|
|
|
|
uint8_t i;
|
2017-11-23 21:28:36 +01:00
|
|
|
for(i = 0; ext->tab_name_ptr[i][0] != '\0'; i++) lv_mem_free(ext->tab_name_ptr[i]);
|
2017-11-15 15:50:33 +01:00
|
|
|
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_mem_free(ext->tab_name_ptr);
|
2017-11-15 15:50:33 +01:00
|
|
|
ext->tab_name_ptr = NULL;
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->btns = NULL; /*These objects were children so they are already invalid*/
|
|
|
|
ext->content = NULL;
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_STYLE_CHG) {
|
2020-01-07 23:43:57 +01:00
|
|
|
/*Be sure the buttons are updated because correct button size is required in `tabview_realign`*/
|
|
|
|
lv_signal_send(ext->btns, LV_SIGNAL_STYLE_CHG, NULL);
|
|
|
|
|
2020-01-01 18:46:22 +01:00
|
|
|
tabview_realign(tabview);
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_COORD_CHG) {
|
2019-04-04 07:15:40 +02:00
|
|
|
if(ext->content != NULL && (lv_obj_get_width(tabview) != lv_area_get_width(param) ||
|
2020-02-26 19:48:27 +01:00
|
|
|
lv_obj_get_height(tabview) != lv_area_get_height(param))) {
|
2017-11-15 15:50:33 +01:00
|
|
|
tabview_realign(tabview);
|
|
|
|
}
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_RELEASED) {
|
2019-06-27 08:33:14 +02:00
|
|
|
#if LV_USE_GROUP
|
2019-03-12 19:20:23 +01:00
|
|
|
/*If released by a KEYPAD or ENCODER then really the tab buttons should be released.
|
|
|
|
* So simulate a CLICK on the tab buttons*/
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_indev_t * indev = lv_indev_get_act();
|
2019-03-29 16:10:18 +01:00
|
|
|
lv_indev_type_t indev_type = lv_indev_get_type(indev);
|
2019-03-12 19:20:23 +01:00
|
|
|
if(indev_type == LV_INDEV_TYPE_KEYPAD ||
|
2020-02-26 19:48:27 +01:00
|
|
|
(indev_type == LV_INDEV_TYPE_ENCODER && lv_group_get_editing(lv_obj_get_group(tabview)))) {
|
2019-03-19 06:30:05 +01:00
|
|
|
lv_event_send(ext->btns, LV_EVENT_CLICKED, lv_event_get_data());
|
2019-03-12 19:20:23 +01:00
|
|
|
}
|
2019-06-27 08:33:14 +02:00
|
|
|
#endif
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_GET_EDITABLE) {
|
2020-02-04 02:09:15 +01:00
|
|
|
bool * editable = (bool *)param;
|
|
|
|
*editable = true;
|
|
|
|
}
|
|
|
|
|
2020-02-26 19:48:27 +01:00
|
|
|
if(sign == LV_SIGNAL_FOCUS || sign == LV_SIGNAL_DEFOCUS || sign == LV_SIGNAL_CONTROL || sign == LV_SIGNAL_PRESSED ||
|
|
|
|
sign == LV_SIGNAL_RELEASED) {
|
2019-04-04 07:15:40 +02:00
|
|
|
/* The button matrix is not in a group (the tab view is in it) but it should handle the
|
|
|
|
* group signals. So propagate the related signals to the button matrix manually*/
|
2017-11-18 00:18:19 +01:00
|
|
|
if(ext->btns) {
|
2019-02-26 09:25:46 +01:00
|
|
|
ext->btns->signal_cb(ext->btns, sign, param);
|
2017-11-18 00:18:19 +01:00
|
|
|
}
|
2018-02-28 15:37:41 +01:00
|
|
|
}
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2019-09-19 14:58:07 +02:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
return res;
|
2017-08-23 14:24:34 +02:00
|
|
|
}
|
2017-11-15 15:50:33 +01:00
|
|
|
|
2017-08-23 14:24:34 +02:00
|
|
|
/**
|
2019-09-19 14:58:07 +02:00
|
|
|
* Signal function of a tab views main scrollable area
|
2017-08-23 14:24:34 +02:00
|
|
|
* @param tab pointer to a tab page object
|
|
|
|
* @param sign a signal type from lv_signal_t enum
|
|
|
|
* @param param pointer to a signal specific variable
|
2017-11-15 15:50:33 +01:00
|
|
|
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
|
2017-08-23 14:24:34 +02:00
|
|
|
*/
|
2019-10-02 16:35:02 +02:00
|
|
|
static lv_res_t tabview_scrl_signal(lv_obj_t * tabview_scrl, lv_signal_t sign, void * param)
|
2017-08-23 14:24:34 +02:00
|
|
|
{
|
2017-11-15 15:50:33 +01:00
|
|
|
lv_res_t res;
|
2017-08-23 14:24:34 +02:00
|
|
|
|
|
|
|
/* Include the ancient signal function */
|
2019-10-02 16:35:02 +02:00
|
|
|
res = ancestor_scrl_signal(tabview_scrl, sign, param);
|
2017-11-15 15:50:33 +01:00
|
|
|
if(res != LV_RES_OK) return res;
|
2019-09-26 12:54:40 +02:00
|
|
|
if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, "");
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2019-10-02 16:35:02 +02:00
|
|
|
lv_obj_t * cont = lv_obj_get_parent(tabview_scrl);
|
2017-11-26 18:57:56 +01:00
|
|
|
lv_obj_t * tabview = lv_obj_get_parent(cont);
|
|
|
|
|
2019-09-19 14:58:07 +02:00
|
|
|
if(sign == LV_SIGNAL_DRAG_THROW_BEGIN) {
|
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
2017-11-26 18:57:56 +01:00
|
|
|
|
2019-09-19 14:58:07 +02:00
|
|
|
lv_indev_t * indev = lv_indev_get_act();
|
|
|
|
lv_point_t point_act;
|
|
|
|
lv_indev_get_point(indev, &point_act);
|
|
|
|
lv_point_t vect;
|
|
|
|
lv_indev_get_vect(indev, &vect);
|
|
|
|
lv_coord_t x_predict = 0;
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2019-09-19 14:58:07 +02:00
|
|
|
while(vect.x != 0) {
|
|
|
|
x_predict += vect.x;
|
|
|
|
vect.x = vect.x * (100 - LV_INDEV_DEF_DRAG_THROW) / 100;
|
|
|
|
}
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2019-11-04 16:56:57 +01:00
|
|
|
res = lv_indev_finish_drag(indev);
|
2019-09-19 14:58:07 +02:00
|
|
|
if(res != LV_RES_OK) return res;
|
2019-10-02 16:35:02 +02:00
|
|
|
lv_obj_t * tab_page = lv_tabview_get_tab(tabview, ext->tab_cur);
|
2020-02-29 13:35:53 +01:00
|
|
|
if(tab_page == NULL) return LV_RES_OK;
|
2019-10-02 16:35:02 +02:00
|
|
|
lv_coord_t page_x1 = tab_page->coords.x1 - tabview->coords.x1 + x_predict;
|
|
|
|
lv_coord_t page_x2 = page_x1 + lv_obj_get_width(tabview);
|
2019-09-19 14:58:07 +02:00
|
|
|
lv_coord_t treshold = lv_obj_get_width(tabview) / 2;
|
2017-11-26 18:57:56 +01:00
|
|
|
|
2019-10-17 06:10:29 +02:00
|
|
|
lv_bidi_dir_t base_dir = lv_obj_get_base_dir(tabview);
|
|
|
|
int16_t tab_cur = ext->tab_cur;
|
2019-09-19 14:58:07 +02:00
|
|
|
if(page_x1 > treshold) {
|
2019-10-17 06:10:29 +02:00
|
|
|
if(base_dir != LV_BIDI_DIR_RTL) tab_cur--;
|
|
|
|
else tab_cur ++;
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(page_x2 < treshold) {
|
2019-10-17 06:10:29 +02:00
|
|
|
if(base_dir != LV_BIDI_DIR_RTL) tab_cur++;
|
|
|
|
else tab_cur --;
|
2019-09-19 14:58:07 +02:00
|
|
|
}
|
2017-11-26 18:57:56 +01:00
|
|
|
|
2019-10-17 06:10:29 +02:00
|
|
|
if(tab_cur > ext->tab_cnt - 1) tab_cur = ext->tab_cnt - 1;
|
|
|
|
if(tab_cur < 0) tab_cur = 0;
|
|
|
|
|
2019-09-19 14:58:07 +02:00
|
|
|
uint32_t id_prev = lv_tabview_get_tab_act(tabview);
|
|
|
|
lv_tabview_set_tab_act(tabview, tab_cur, LV_ANIM_ON);
|
|
|
|
uint32_t id_new = lv_tabview_get_tab_act(tabview);
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2019-09-19 14:58:07 +02:00
|
|
|
if(id_prev != id_new) res = lv_event_send(tabview, LV_EVENT_VALUE_CHANGED, &id_new);
|
|
|
|
if(res != LV_RES_OK) return res;
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2019-09-19 14:58:07 +02:00
|
|
|
}
|
|
|
|
return res;
|
2017-08-23 14:24:34 +02:00
|
|
|
}
|
|
|
|
|
2020-01-01 18:46:22 +01:00
|
|
|
/**
|
|
|
|
* Get the style descriptor of a part of the object
|
|
|
|
* @param page pointer the object
|
|
|
|
* @param part the part from `lv_tabview_part_t`. (LV_TABVIEW_PART_...)
|
|
|
|
* @return pointer to the style descriptor of the specified part
|
|
|
|
*/
|
2020-01-16 14:26:36 +01:00
|
|
|
static lv_style_list_t * lv_tabview_get_style(lv_obj_t * tabview, uint8_t part)
|
2020-01-01 18:46:22 +01:00
|
|
|
{
|
|
|
|
LV_ASSERT_OBJ(tabview, LV_OBJX_NAME);
|
|
|
|
|
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
2020-01-16 14:26:36 +01:00
|
|
|
lv_style_list_t * style_dsc_p;
|
2020-01-01 18:46:22 +01:00
|
|
|
|
|
|
|
switch(part) {
|
2020-02-26 19:48:27 +01:00
|
|
|
case LV_TABVIEW_PART_BG:
|
|
|
|
style_dsc_p = &tabview->style_list;
|
|
|
|
break;
|
|
|
|
case LV_TABVIEW_PART_BG_SCRL:
|
|
|
|
style_dsc_p = lv_obj_get_style_list(ext->content, LV_PAGE_PART_SCRL);
|
|
|
|
break;
|
|
|
|
case LV_TABVIEW_PART_TAB_BG:
|
|
|
|
style_dsc_p = lv_obj_get_style_list(ext->btns, LV_BTNMATRIX_PART_BG);
|
|
|
|
break;
|
2020-02-29 13:35:53 +01:00
|
|
|
case LV_TABVIEW_PART_TAB_BTN:
|
2020-02-26 19:48:27 +01:00
|
|
|
style_dsc_p = lv_obj_get_style_list(ext->btns, LV_BTNMATRIX_PART_BTN);
|
|
|
|
break;
|
|
|
|
case LV_TABVIEW_PART_INDIC:
|
|
|
|
style_dsc_p = lv_obj_get_style_list(ext->indic, LV_OBJ_PART_MAIN);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
style_dsc_p = NULL;
|
2020-01-01 18:46:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return style_dsc_p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-23 14:24:34 +02:00
|
|
|
/**
|
2019-03-12 06:20:45 +01:00
|
|
|
* Called when a tab button is clicked
|
2017-08-23 14:24:34 +02:00
|
|
|
* @param tab_btnm pointer to the tab's button matrix object
|
2019-03-12 06:20:45 +01:00
|
|
|
* @param event type of the event
|
2017-08-23 14:24:34 +02:00
|
|
|
*/
|
2019-03-12 06:20:45 +01:00
|
|
|
static void tab_btnm_event_cb(lv_obj_t * tab_btnm, lv_event_t event)
|
2017-08-23 14:24:34 +02:00
|
|
|
{
|
2019-03-12 06:20:45 +01:00
|
|
|
if(event != LV_EVENT_CLICKED) return;
|
2017-10-30 17:11:56 +01:00
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
uint16_t btn_id = lv_btnmatrix_get_active_btn(tab_btnm);
|
|
|
|
if(btn_id == LV_BTNMATRIX_BTN_NONE) return;
|
2017-10-30 17:11:56 +01:00
|
|
|
|
2020-02-14 17:03:25 +01:00
|
|
|
lv_btnmatrix_clear_btn_ctrl_all(tab_btnm, LV_BTNMATRIX_CTRL_CHECK_STATE);
|
|
|
|
lv_btnmatrix_set_btn_ctrl(tab_btnm, btn_id, LV_BTNMATRIX_CTRL_CHECK_STATE);
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2019-06-21 15:26:28 +02:00
|
|
|
lv_obj_t * tabview = lv_obj_get_parent(tab_btnm);
|
|
|
|
|
|
|
|
uint32_t id_prev = lv_tabview_get_tab_act(tabview);
|
|
|
|
lv_tabview_set_tab_act(tabview, btn_id, LV_ANIM_ON);
|
|
|
|
uint32_t id_new = lv_tabview_get_tab_act(tabview);
|
|
|
|
|
|
|
|
lv_res_t res = LV_RES_OK;
|
2019-06-21 12:37:00 -04:00
|
|
|
if(id_prev != id_new) res = lv_event_send(tabview, LV_EVENT_VALUE_CHANGED, &id_new);
|
2019-06-21 15:26:28 +02:00
|
|
|
|
|
|
|
if(res != LV_RES_OK) return;
|
2017-08-23 14:24:34 +02:00
|
|
|
}
|
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
/**
|
|
|
|
* Realign and resize the elements of Tab view
|
|
|
|
* @param tabview pointer to a Tab view object
|
|
|
|
*/
|
|
|
|
static void tabview_realign(lv_obj_t * tabview)
|
|
|
|
{
|
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
|
|
|
|
2019-09-19 14:58:07 +02:00
|
|
|
refr_btns_size(tabview);
|
|
|
|
refr_content_size(tabview);
|
|
|
|
refr_indic_size(tabview);
|
2017-11-21 10:35:57 +01:00
|
|
|
|
2019-09-19 14:58:07 +02:00
|
|
|
refr_align(tabview);
|
|
|
|
|
|
|
|
lv_tabview_set_tab_act(tabview, ext->tab_cur, LV_ANIM_OFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void refr_indic_size(lv_obj_t * tabview)
|
|
|
|
{
|
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_btnmatrix_ext_t * btnm_ext = lv_obj_get_ext_attr(ext->btns);
|
2019-09-19 14:58:07 +02:00
|
|
|
|
2020-02-02 15:58:08 +01:00
|
|
|
lv_coord_t indic_size = lv_obj_get_style_size(tabview, LV_TABVIEW_PART_INDIC);
|
2019-09-19 14:58:07 +02:00
|
|
|
|
|
|
|
/*Set the indicator width/height*/
|
|
|
|
lv_coord_t indic_w;
|
|
|
|
lv_coord_t indic_h;
|
|
|
|
|
|
|
|
switch(ext->btns_pos) {
|
2020-02-26 19:48:27 +01:00
|
|
|
default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/
|
|
|
|
case LV_TABVIEW_BTNS_POS_NONE:
|
|
|
|
lv_obj_set_hidden(ext->indic, true);
|
2019-09-19 14:58:07 +02:00
|
|
|
indic_w = 0;
|
|
|
|
indic_h = 0;
|
2020-02-26 19:48:27 +01:00
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_TOP:
|
|
|
|
case LV_TABVIEW_BTNS_POS_BOTTOM:
|
|
|
|
lv_obj_set_hidden(ext->indic, false);
|
|
|
|
if(ext->tab_cnt) {
|
|
|
|
indic_h = indic_size;
|
|
|
|
indic_w = lv_area_get_width(&btnm_ext->button_areas[0]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
indic_w = 0;
|
|
|
|
indic_h = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_LEFT:
|
|
|
|
case LV_TABVIEW_BTNS_POS_RIGHT:
|
|
|
|
lv_obj_set_hidden(ext->indic, false);
|
|
|
|
if(ext->tab_cnt) {
|
|
|
|
indic_w = indic_size;
|
|
|
|
indic_h = lv_area_get_height(&btnm_ext->button_areas[0]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
indic_w = 0;
|
|
|
|
indic_h = 0;
|
|
|
|
}
|
|
|
|
break;
|
2019-09-19 14:58:07 +02:00
|
|
|
}
|
2019-04-04 07:15:40 +02:00
|
|
|
|
2019-09-19 14:58:07 +02:00
|
|
|
lv_obj_set_width(ext->indic, indic_w);
|
|
|
|
lv_obj_set_height(ext->indic, indic_h);
|
|
|
|
}
|
2017-11-21 10:35:57 +01:00
|
|
|
|
|
|
|
|
2019-09-19 14:58:07 +02:00
|
|
|
static void refr_btns_size(lv_obj_t * tabview)
|
|
|
|
{
|
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
2019-04-18 18:00:11 +03:00
|
|
|
|
2020-02-02 15:58:08 +01:00
|
|
|
lv_style_int_t tab_bg_left = lv_obj_get_style_pad_left(tabview, LV_TABVIEW_PART_TAB_BG);
|
|
|
|
lv_style_int_t tab_bg_right = lv_obj_get_style_pad_right(tabview, LV_TABVIEW_PART_TAB_BG);
|
|
|
|
lv_style_int_t tab_bg_top = lv_obj_get_style_pad_top(tabview, LV_TABVIEW_PART_TAB_BG);
|
|
|
|
lv_style_int_t tab_bg_bottom = lv_obj_get_style_pad_bottom(tabview, LV_TABVIEW_PART_TAB_BG);
|
2020-01-01 18:46:22 +01:00
|
|
|
|
2020-02-29 13:35:53 +01:00
|
|
|
lv_style_int_t tab_left = lv_obj_get_style_pad_left(tabview, LV_TABVIEW_PART_TAB_BTN);
|
|
|
|
lv_style_int_t tab_right = lv_obj_get_style_pad_right(tabview, LV_TABVIEW_PART_TAB_BTN);
|
|
|
|
lv_style_int_t tab_top = lv_obj_get_style_pad_top(tabview, LV_TABVIEW_PART_TAB_BTN);
|
|
|
|
lv_style_int_t tab_bottom = lv_obj_get_style_pad_bottom(tabview, LV_TABVIEW_PART_TAB_BTN);
|
2020-01-01 18:46:22 +01:00
|
|
|
|
2020-02-29 13:35:53 +01:00
|
|
|
const lv_font_t * font = lv_obj_get_style_text_font(tabview, LV_TABVIEW_PART_TAB_BTN);
|
2019-04-18 18:00:11 +03:00
|
|
|
|
2019-09-19 14:58:07 +02:00
|
|
|
/*Set the tabs height/width*/
|
|
|
|
lv_coord_t btns_w;
|
|
|
|
lv_coord_t btns_h;
|
2017-11-21 10:35:57 +01:00
|
|
|
|
2019-09-19 14:58:07 +02:00
|
|
|
switch(ext->btns_pos) {
|
2020-02-26 19:48:27 +01:00
|
|
|
default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/
|
|
|
|
case LV_TABVIEW_BTNS_POS_NONE:
|
|
|
|
btns_w = 0;
|
|
|
|
btns_h = 0;
|
|
|
|
lv_obj_set_hidden(ext->btns, true);
|
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_TOP:
|
|
|
|
case LV_TABVIEW_BTNS_POS_BOTTOM:
|
|
|
|
lv_obj_set_hidden(ext->btns, false);
|
|
|
|
btns_h = lv_font_get_line_height(font) + tab_top + tab_bottom + tab_bg_top + tab_bg_bottom;
|
|
|
|
btns_w = lv_obj_get_width(tabview);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_LEFT:
|
|
|
|
case LV_TABVIEW_BTNS_POS_RIGHT:
|
|
|
|
lv_obj_set_hidden(ext->btns, false);
|
|
|
|
btns_w = lv_font_get_glyph_width(font, 'A', '\0') +
|
|
|
|
tab_left + tab_right + tab_bg_left + tab_bg_right;
|
|
|
|
btns_h = lv_obj_get_height(tabview);
|
|
|
|
break;
|
2019-09-19 14:58:07 +02:00
|
|
|
}
|
2018-12-20 10:07:28 -05:00
|
|
|
|
2019-09-19 14:58:07 +02:00
|
|
|
lv_obj_set_size(ext->btns, btns_w, btns_h);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void refr_content_size(lv_obj_t * tabview)
|
|
|
|
{
|
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
|
|
|
lv_coord_t cont_w;
|
|
|
|
lv_coord_t cont_h;
|
|
|
|
|
|
|
|
switch(ext->btns_pos) {
|
2020-02-26 19:48:27 +01:00
|
|
|
default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/
|
|
|
|
case LV_TABVIEW_BTNS_POS_NONE:
|
|
|
|
cont_w = lv_obj_get_width(tabview);
|
|
|
|
cont_h = lv_obj_get_height(tabview);
|
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_TOP:
|
|
|
|
case LV_TABVIEW_BTNS_POS_BOTTOM:
|
|
|
|
cont_w = lv_obj_get_width(tabview);
|
|
|
|
cont_h = lv_obj_get_height(tabview) - lv_obj_get_height(ext->btns);
|
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_LEFT:
|
|
|
|
case LV_TABVIEW_BTNS_POS_RIGHT:
|
|
|
|
cont_w = lv_obj_get_width(tabview) - lv_obj_get_width(ext->btns);
|
|
|
|
cont_h = lv_obj_get_height(tabview);
|
|
|
|
break;
|
2018-03-07 15:45:11 -05:00
|
|
|
}
|
|
|
|
|
2019-09-19 14:58:07 +02:00
|
|
|
lv_obj_set_size(ext->content, cont_w, cont_h);
|
|
|
|
|
|
|
|
/*Refresh the size of the tab pages too. `ext->content` has a layout to align the pages*/
|
2020-02-02 15:58:08 +01:00
|
|
|
lv_style_int_t bg_top = lv_obj_get_style_pad_top(tabview, LV_TABVIEW_PART_BG_SCRL);
|
|
|
|
lv_style_int_t bg_bottom = lv_obj_get_style_pad_bottom(tabview, LV_TABVIEW_PART_BG_SCRL);
|
2020-01-01 18:46:22 +01:00
|
|
|
cont_h -= bg_top + bg_bottom;
|
2019-09-18 16:03:29 +02:00
|
|
|
lv_obj_t * content_scrl = lv_page_get_scrl(ext->content);
|
|
|
|
lv_obj_t * pages = lv_obj_get_child(content_scrl, NULL);
|
2017-11-15 15:50:33 +01:00
|
|
|
while(pages != NULL) {
|
2019-09-19 14:58:07 +02:00
|
|
|
/*Be sure adjust only the pages (user can other things)*/
|
|
|
|
if(lv_obj_get_signal_cb(pages) == page_signal) {
|
|
|
|
lv_obj_set_size(pages, cont_w, cont_h);
|
2017-11-21 17:04:06 +01:00
|
|
|
}
|
2019-09-18 16:03:29 +02:00
|
|
|
pages = lv_obj_get_child(content_scrl, pages);
|
2017-11-15 15:50:33 +01:00
|
|
|
}
|
2019-09-19 14:58:07 +02:00
|
|
|
}
|
2017-11-15 15:50:33 +01:00
|
|
|
|
2019-09-19 14:58:07 +02:00
|
|
|
static void refr_align(lv_obj_t * tabview)
|
|
|
|
{
|
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
2017-11-15 15:50:33 +01:00
|
|
|
|
2019-09-19 14:58:07 +02:00
|
|
|
switch(ext->btns_pos) {
|
2020-02-26 19:48:27 +01:00
|
|
|
default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/
|
|
|
|
case LV_TABVIEW_BTNS_POS_NONE:
|
|
|
|
lv_obj_align(ext->content, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_TOP:
|
|
|
|
lv_obj_align(ext->btns, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
|
|
|
lv_obj_align(ext->content, ext->btns, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
|
|
|
|
lv_obj_align(ext->indic, ext->btns, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
|
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_BOTTOM:
|
|
|
|
lv_obj_align(ext->content, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
|
|
|
lv_obj_align(ext->btns, ext->content, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
|
|
|
|
lv_obj_align(ext->indic, ext->btns, LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_LEFT:
|
|
|
|
lv_obj_align(ext->btns, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
|
|
|
lv_obj_align(ext->content, tabview, LV_ALIGN_IN_TOP_LEFT, lv_obj_get_width(ext->btns), 0);
|
|
|
|
lv_obj_align(ext->indic, ext->btns, LV_ALIGN_IN_TOP_RIGHT, 0, 0);
|
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_RIGHT:
|
|
|
|
lv_obj_align(ext->btns, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 0);
|
|
|
|
lv_obj_align(ext->content, tabview, LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
|
|
|
lv_obj_align(ext->indic, ext->btns, LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
|
|
|
break;
|
2019-09-19 14:58:07 +02:00
|
|
|
}
|
2017-11-15 15:50:33 +01:00
|
|
|
}
|
2017-08-23 14:24:34 +02:00
|
|
|
#endif
|