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"
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_TABVIEW != 0
|
2017-08-23 14:24:34 +02:00
|
|
|
|
|
|
|
#include "lv_btnm.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-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_ANIMATION
|
2019-05-18 11:44:50 -07:00
|
|
|
#ifndef LV_TABVIEW_DEF_ANIM_TIME
|
2019-06-06 06:05:40 +02:00
|
|
|
#define LV_TABVIEW_DEF_ANIM_TIME 300 /*Animation time of focusing to the a list element [ms] (0: no animation) */
|
2019-04-04 07:15:40 +02:00
|
|
|
#endif
|
2017-11-27 17:48:54 +01:00
|
|
|
#else
|
2019-04-04 07:15:40 +02: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);
|
|
|
|
static lv_res_t tabpage_signal(lv_obj_t * tab_page, lv_signal_t sign, void * param);
|
|
|
|
static lv_res_t tabpage_scrl_signal(lv_obj_t * tab_scrl, lv_signal_t sign, void * param);
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2018-01-25 13:14:10 -08:00
|
|
|
static void tabpage_pressed_handler(lv_obj_t * tabview, lv_obj_t * tabpage);
|
|
|
|
static void tabpage_pressing_handler(lv_obj_t * tabview, lv_obj_t * tabpage);
|
|
|
|
static void tabpage_press_lost_handler(lv_obj_t * tabview, lv_obj_t * tabpage);
|
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);
|
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;
|
|
|
|
static lv_signal_cb_t page_signal;
|
|
|
|
static lv_signal_cb_t page_scrl_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*/
|
|
|
|
lv_obj_t * new_tabview = lv_obj_create(par, copy);
|
2017-11-26 11:38:28 +01:00
|
|
|
lv_mem_assert(new_tabview);
|
2018-07-25 13:33:53 +02:00
|
|
|
if(new_tabview == NULL) return NULL;
|
2019-04-10 06:40:49 +02:00
|
|
|
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(new_tabview);
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2017-08-23 14:24:34 +02:00
|
|
|
/*Allocate the tab type specific extended data*/
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_tabview_ext_t * ext = lv_obj_allocate_ext_attr(new_tabview, sizeof(lv_tabview_ext_t));
|
2017-11-26 11:38:28 +01:00
|
|
|
lv_mem_assert(ext);
|
2018-07-25 13:33:53 +02:00
|
|
|
if(ext == NULL) return NULL;
|
2017-08-23 14:24:34 +02:00
|
|
|
|
|
|
|
/*Initialize the allocated 'ext' */
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->drag_hor = 0;
|
|
|
|
ext->draging = 0;
|
|
|
|
ext->scroll_ver = 0;
|
2017-11-26 18:57:56 +01:00
|
|
|
ext->slide_enable = 1;
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->tab_cur = 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
|
2019-06-06 06:05:40 +02:00
|
|
|
ext->btns_hide = 0;
|
2017-08-23 14:24:34 +02:00
|
|
|
|
|
|
|
/*The signal and design functions are not copied so set them here*/
|
2019-02-26 09:25:46 +01:00
|
|
|
lv_obj_set_signal_cb(new_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 *));
|
|
|
|
lv_mem_assert(ext->tab_name_ptr);
|
|
|
|
if(ext->tab_name_ptr == NULL) return NULL;
|
|
|
|
ext->tab_name_ptr[0] = "";
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->tab_cnt = 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 */
|
|
|
|
lv_obj_set_size(new_tabview, lv_obj_get_width_fit(lv_obj_get_parent(new_tabview)),
|
|
|
|
lv_obj_get_height_fit(lv_obj_get_parent(new_tabview)));
|
2017-11-15 15:50:33 +01:00
|
|
|
|
2019-04-18 18:00:11 +03:00
|
|
|
ext->content = lv_cont_create(new_tabview, NULL);
|
2019-06-06 06:05:40 +02:00
|
|
|
ext->btns = lv_btnm_create(new_tabview, NULL);
|
|
|
|
ext->indic = lv_obj_create(ext->btns, NULL);
|
2019-04-18 18:00:11 +03:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
lv_obj_set_height(ext->btns, 3 * LV_DPI / 4);
|
2019-04-10 08:40:52 +02:00
|
|
|
lv_btnm_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-11-15 15:50:33 +01:00
|
|
|
lv_obj_set_width(ext->indic, LV_DPI);
|
|
|
|
lv_obj_align(ext->indic, ext->btns, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
|
2017-08-23 14:24:34 +02:00
|
|
|
lv_obj_set_click(ext->indic, false);
|
2019-06-06 06:05:40 +02:00
|
|
|
|
2019-02-24 06:24:36 +01:00
|
|
|
lv_cont_set_fit2(ext->content, LV_FIT_TIGHT, LV_FIT_NONE);
|
2017-11-17 15:43:08 +01:00
|
|
|
lv_cont_set_layout(ext->content, LV_LAYOUT_ROW_T);
|
2019-06-11 06:33:33 +02:00
|
|
|
lv_cont_set_style(ext->content, LV_CONT_STYLE_MAIN, &lv_style_transp_tight);
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_obj_set_height(ext->content, lv_obj_get_height(new_tabview) - lv_obj_get_height(ext->btns));
|
2017-11-15 15:50:33 +01:00
|
|
|
lv_obj_align(ext->content, ext->btns, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
|
|
|
|
|
2017-11-16 15:32:33 +01:00
|
|
|
/*Set the default styles*/
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_theme_t * th = lv_theme_get_current();
|
2017-11-16 15:32:33 +01:00
|
|
|
if(th) {
|
2019-02-11 09:35:06 +01:00
|
|
|
lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BG, th->style.tabview.bg);
|
|
|
|
lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_INDIC, th->style.tabview.indic);
|
|
|
|
lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_BG, th->style.tabview.btn.bg);
|
|
|
|
lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_REL, th->style.tabview.btn.rel);
|
|
|
|
lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_PR, th->style.tabview.btn.pr);
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_TGL_REL, th->style.tabview.btn.tgl_rel);
|
|
|
|
lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_TGL_PR, th->style.tabview.btn.tgl_pr);
|
2017-11-16 15:32:33 +01:00
|
|
|
} else {
|
2017-11-19 19:28:45 +01:00
|
|
|
lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BG, &lv_style_plain);
|
2017-11-16 15:32:33 +01:00
|
|
|
lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_BG, &lv_style_transp);
|
|
|
|
lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_INDIC, &lv_style_plain_color);
|
|
|
|
}
|
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;
|
|
|
|
ext->btns = lv_btnm_create(new_tabview, copy_ext->btns);
|
|
|
|
ext->indic = lv_obj_create(ext->btns, copy_ext->indic);
|
|
|
|
ext->content = lv_cont_create(new_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 *));
|
2018-07-25 13:33:53 +02:00
|
|
|
lv_mem_assert(ext->tab_name_ptr);
|
|
|
|
if(ext->tab_name_ptr == NULL) return NULL;
|
2017-08-23 14:24:34 +02:00
|
|
|
ext->tab_name_ptr[0] = "";
|
2019-04-10 08:40:52 +02:00
|
|
|
lv_btnm_set_map(ext->btns, ext->tab_name_ptr);
|
2017-08-23 14:24:34 +02:00
|
|
|
|
|
|
|
uint16_t i;
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_obj_t * new_tab;
|
|
|
|
lv_obj_t * copy_tab;
|
|
|
|
for(i = 0; i < copy_ext->tab_cnt; i++) {
|
2019-04-04 07:15:40 +02:00
|
|
|
new_tab = lv_tabview_add_tab(new_tabview, copy_ext->tab_name_ptr[i]);
|
2017-11-15 15:50:33 +01:00
|
|
|
copy_tab = lv_tabview_get_tab(copy, i);
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_page_set_style(new_tab, LV_PAGE_STYLE_BG, lv_page_get_style(copy_tab, LV_PAGE_STYLE_BG));
|
|
|
|
lv_page_set_style(new_tab, LV_PAGE_STYLE_SCRL, lv_page_get_style(copy_tab, LV_PAGE_STYLE_SCRL));
|
|
|
|
lv_page_set_style(new_tab, LV_PAGE_STYLE_SB, lv_page_get_style(copy_tab, LV_PAGE_STYLE_SB));
|
2017-08-23 14:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*Refresh the style with new signal function*/
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_obj_refresh_style(new_tabview);
|
2017-08-23 14:24:34 +02:00
|
|
|
}
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_INFO("tab view created");
|
2018-07-25 17:57:08 +02:00
|
|
|
|
2017-08-23 14:24:34 +02:00
|
|
|
return new_tabview;
|
|
|
|
}
|
|
|
|
|
2018-03-16 11:53:27 -04:00
|
|
|
/**
|
|
|
|
* Delete all children of the scrl object, without deleting scrl child.
|
|
|
|
* @param obj pointer to an object
|
|
|
|
*/
|
2018-06-19 09:49:58 +02:00
|
|
|
void lv_tabview_clean(lv_obj_t * obj)
|
2018-03-16 11:53:27 -04:00
|
|
|
{
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_obj_t * scrl = lv_page_get_scrl(obj);
|
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-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));
|
2017-11-19 19:28:45 +01:00
|
|
|
lv_page_set_sb_mode(h, LV_SB_MODE_AUTO);
|
2017-11-15 15:50:33 +01:00
|
|
|
lv_page_set_style(h, LV_PAGE_STYLE_BG, &lv_style_transp);
|
2017-12-17 01:54:09 +01:00
|
|
|
lv_page_set_style(h, LV_PAGE_STYLE_SCRL, &lv_style_transp);
|
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);
|
|
|
|
if(page_scrl_signal == NULL) page_scrl_signal = lv_obj_get_signal_cb(lv_page_get_scrl(h));
|
2019-02-26 09:25:46 +01:00
|
|
|
lv_obj_set_signal_cb(h, tabpage_signal);
|
|
|
|
lv_obj_set_signal_cb(lv_page_get_scrl(h), tabpage_scrl_signal);
|
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' */
|
|
|
|
lv_mem_assert(name_dm);
|
|
|
|
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:
|
|
|
|
ext->tab_name_ptr = lv_mem_realloc(ext->tab_name_ptr, sizeof(char *) * (ext->tab_cnt + 1));
|
|
|
|
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));
|
|
|
|
break;
|
|
|
|
}
|
2019-06-06 06:05:40 +02:00
|
|
|
|
2018-07-25 14:43:46 +02:00
|
|
|
lv_mem_assert(ext->tab_name_ptr);
|
|
|
|
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) {
|
|
|
|
case LV_TABVIEW_BTNS_POS_TOP:
|
|
|
|
case LV_TABVIEW_BTNS_POS_BOTTOM:
|
|
|
|
ext->tab_name_ptr[ext->tab_cnt - 1] = name_dm;
|
|
|
|
ext->tab_name_ptr[ext->tab_cnt] = "";
|
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_LEFT:
|
|
|
|
case LV_TABVIEW_BTNS_POS_RIGHT:
|
|
|
|
if(ext->tab_cnt == 1) {
|
2019-06-06 06:05:40 +02:00
|
|
|
ext->tab_name_ptr[0] = name_dm;
|
|
|
|
ext->tab_name_ptr[1] = "";
|
2019-04-18 18:00:11 +03:00
|
|
|
} else {
|
2019-06-06 06:05:40 +02:00
|
|
|
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] = "";
|
2019-04-18 18:00:11 +03:00
|
|
|
}
|
|
|
|
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*/
|
2019-03-15 22:19:21 +01:00
|
|
|
lv_btnm_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
|
|
|
|
2019-04-10 08:40:52 +02:00
|
|
|
lv_btnm_set_map(ext->btns, ext->tab_name_ptr);
|
2019-03-19 06:30:05 +01:00
|
|
|
lv_btnm_set_btn_ctrl(ext->btns, ext->tab_cur, LV_BTNM_CTRL_NO_REPEAT, true);
|
2017-08-23 14:24:34 +02:00
|
|
|
|
|
|
|
/*Modify the indicator size*/
|
2019-04-11 19:59:55 +08:00
|
|
|
const lv_style_t * style_tabs = lv_obj_get_style(ext->btns);
|
2019-04-18 18:00:11 +03:00
|
|
|
lv_coord_t indic_size;
|
|
|
|
lv_coord_t max_h, btn_h, act_y;
|
|
|
|
|
|
|
|
switch(ext->btns_pos) {
|
|
|
|
case LV_TABVIEW_BTNS_POS_TOP:
|
|
|
|
case LV_TABVIEW_BTNS_POS_BOTTOM:
|
2019-06-06 06:05:40 +02:00
|
|
|
indic_size = (lv_obj_get_width(tabview) - style_tabs->body.padding.inner * (ext->tab_cnt - 1) -
|
|
|
|
style_tabs->body.padding.left - style_tabs->body.padding.right) /
|
|
|
|
ext->tab_cnt;
|
2019-04-18 18:00:11 +03:00
|
|
|
lv_obj_set_width(ext->indic, indic_size);
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_obj_set_x(ext->indic, indic_size * ext->tab_cur + style_tabs->body.padding.inner * ext->tab_cur +
|
|
|
|
style_tabs->body.padding.left);
|
2019-04-18 18:00:11 +03:00
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_LEFT:
|
|
|
|
case LV_TABVIEW_BTNS_POS_RIGHT:
|
|
|
|
max_h = lv_obj_get_height(ext->btns) - style_tabs->body.padding.top - style_tabs->body.padding.bottom;
|
|
|
|
btn_h = max_h - ((ext->tab_cnt - 1) * style_tabs->body.padding.inner);
|
|
|
|
btn_h = btn_h / ext->tab_cnt;
|
|
|
|
btn_h--; /*-1 because e.g. height = 100 means 101 pixels (0..100)*/
|
|
|
|
act_y = style_tabs->body.padding.top + ext->tab_cur * (btn_h + style_tabs->body.padding.inner);
|
|
|
|
|
|
|
|
lv_obj_set_height(ext->indic, btn_h);
|
|
|
|
lv_obj_set_y(ext->indic, act_y);
|
|
|
|
break;
|
|
|
|
}
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2017-11-16 15:32:33 +01:00
|
|
|
/*Set the first btn as active*/
|
2017-10-05 12:55:32 +02:00
|
|
|
if(ext->tab_cnt == 1) {
|
2017-10-31 16:25:52 +01:00
|
|
|
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
|
|
|
|
* @param anim_en true: set with sliding animation; false: set immediately
|
|
|
|
*/
|
2017-12-08 14:34:07 +01:00
|
|
|
void lv_tabview_set_tab_act(lv_obj_t * tabview, uint16_t id, bool anim_en)
|
2017-08-23 14:24:34 +02:00
|
|
|
{
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_ANIMATION == 0
|
2018-03-01 12:21:49 +01:00
|
|
|
anim_en = false;
|
|
|
|
#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
|
|
|
|
2019-04-11 19:59:55 +08:00
|
|
|
const lv_style_t * style = lv_obj_get_style(ext->content);
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2018-10-28 10:29:06 +01:00
|
|
|
lv_res_t res = LV_RES_OK;
|
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
|
|
|
|
2019-03-20 06:08:01 +01:00
|
|
|
if(id != ext->tab_cur) res = lv_event_send(tabview, LV_EVENT_SELECTED, &id);
|
2019-03-19 06:30:05 +01:00
|
|
|
if(res != LV_RES_OK) return;
|
|
|
|
|
|
|
|
lv_btnm_set_btn_ctrl(ext->btns, ext->tab_cur, LV_BTNM_CTRL_TGL_STATE, false);
|
2017-10-31 16:25:52 +01:00
|
|
|
|
|
|
|
ext->tab_cur = id;
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2019-04-18 18:00:11 +03:00
|
|
|
lv_coord_t cont_x;
|
|
|
|
|
|
|
|
switch(ext->btns_pos) {
|
|
|
|
case LV_TABVIEW_BTNS_POS_TOP:
|
|
|
|
case LV_TABVIEW_BTNS_POS_BOTTOM:
|
2019-06-06 06:05:40 +02:00
|
|
|
cont_x = -(lv_obj_get_width(tabview) * id + style->body.padding.inner * id + style->body.padding.left);
|
2019-04-18 18:00:11 +03:00
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_LEFT:
|
2019-06-06 06:05:40 +02:00
|
|
|
cont_x = -((lv_obj_get_width(tabview) - lv_obj_get_width(ext->btns)) * id + style->body.padding.inner * id +
|
|
|
|
style->body.padding.left) +
|
|
|
|
lv_obj_get_width(ext->btns);
|
2019-04-18 18:00:11 +03:00
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_RIGHT:
|
2019-06-06 06:05:40 +02:00
|
|
|
cont_x = -((lv_obj_get_width(tabview) - lv_obj_get_width(ext->btns)) * id + style->body.padding.inner * id +
|
|
|
|
style->body.padding.left);
|
2019-04-18 18:00:11 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-06-06 06:05:40 +02:00
|
|
|
if(anim_en == false
|
2019-05-20 09:22:09 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2019-06-06 06:05:40 +02:00
|
|
|
|| ext->anim_time == 0
|
2019-05-20 09:22:09 -07:00
|
|
|
#endif
|
2019-06-06 06:05:40 +02:00
|
|
|
) {
|
2017-08-23 14:24:34 +02:00
|
|
|
lv_obj_set_x(ext->content, cont_x);
|
|
|
|
} else {
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_ANIMATION
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_anim_t a;
|
2019-04-04 07:15:40 +02:00
|
|
|
a.var = ext->content;
|
|
|
|
a.start = lv_obj_get_x(ext->content);
|
|
|
|
a.end = cont_x;
|
2019-05-20 09:22:09 -07:00
|
|
|
a.exec_cb = (lv_anim_exec_cb_t)lv_obj_set_x;
|
|
|
|
a.path_cb = lv_anim_path_linear;
|
|
|
|
a.ready_cb = NULL;
|
2019-04-04 07:15:40 +02:00
|
|
|
a.act_time = 0;
|
|
|
|
a.time = ext->anim_time;
|
|
|
|
a.playback = 0;
|
2017-08-23 14:24:34 +02:00
|
|
|
a.playback_pause = 0;
|
2019-04-04 07:15:40 +02:00
|
|
|
a.repeat = 0;
|
|
|
|
a.repeat_pause = 0;
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_anim_create(&a);
|
2017-11-27 17:48:54 +01:00
|
|
|
#endif
|
2017-08-23 14:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*Move the indicator*/
|
2019-04-11 19:59:55 +08:00
|
|
|
const lv_style_t * tabs_style = lv_obj_get_style(ext->btns);
|
2019-04-18 18:00:11 +03:00
|
|
|
lv_coord_t indic_size;
|
|
|
|
lv_coord_t indic_pos;
|
|
|
|
|
|
|
|
switch(ext->btns_pos) {
|
|
|
|
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 + tabs_style->body.padding.inner * id + tabs_style->body.padding.left;
|
|
|
|
break;
|
2019-06-06 06:05:40 +02:00
|
|
|
case LV_TABVIEW_BTNS_POS_LEFT:
|
|
|
|
case LV_TABVIEW_BTNS_POS_RIGHT:
|
2019-04-18 18:00:11 +03:00
|
|
|
indic_size = lv_obj_get_height(ext->indic);
|
|
|
|
indic_pos = tabs_style->body.padding.top + id * (indic_size + tabs_style->body.padding.inner);
|
|
|
|
break;
|
|
|
|
}
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2019-06-06 06:05:40 +02:00
|
|
|
if(anim_en == false
|
2019-05-20 09:22:09 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2019-06-06 06:05:40 +02:00
|
|
|
|| ext->anim_time == 0
|
2019-05-20 09:22:09 -07:00
|
|
|
#endif
|
2019-06-06 06:05:40 +02:00
|
|
|
) {
|
2019-04-18 18:00:11 +03:00
|
|
|
switch(ext->btns_pos) {
|
|
|
|
case LV_TABVIEW_BTNS_POS_TOP:
|
2019-06-06 06:05:40 +02:00
|
|
|
case LV_TABVIEW_BTNS_POS_BOTTOM: lv_obj_set_x(ext->indic, indic_pos); break;
|
2019-04-18 18:00:11 +03:00
|
|
|
case LV_TABVIEW_BTNS_POS_LEFT:
|
2019-06-06 06:05:40 +02:00
|
|
|
case LV_TABVIEW_BTNS_POS_RIGHT: lv_obj_set_y(ext->indic, indic_pos); break;
|
|
|
|
}
|
2017-08-23 14:24:34 +02:00
|
|
|
} else {
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_ANIMATION
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_anim_t a;
|
2019-06-06 06:05:40 +02:00
|
|
|
a.var = ext->indic;
|
2019-04-18 18:00:11 +03:00
|
|
|
|
|
|
|
switch(ext->btns_pos) {
|
|
|
|
case LV_TABVIEW_BTNS_POS_TOP:
|
|
|
|
case LV_TABVIEW_BTNS_POS_BOTTOM:
|
2019-06-06 06:05:40 +02:00
|
|
|
a.start = lv_obj_get_x(ext->indic);
|
|
|
|
a.end = indic_pos;
|
|
|
|
a.exec_cb = (lv_anim_exec_cb_t)lv_obj_set_x;
|
2019-04-18 18:00:11 +03:00
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_LEFT:
|
|
|
|
case LV_TABVIEW_BTNS_POS_RIGHT:
|
2019-06-06 06:05:40 +02:00
|
|
|
a.start = lv_obj_get_y(ext->indic);
|
|
|
|
a.end = indic_pos;
|
|
|
|
a.exec_cb = (lv_anim_exec_cb_t)lv_obj_set_y;
|
2019-04-18 18:00:11 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-05-20 09:22:09 -07:00
|
|
|
a.path_cb = lv_anim_path_linear;
|
|
|
|
a.ready_cb = NULL;
|
2019-04-04 07:15:40 +02:00
|
|
|
a.act_time = 0;
|
|
|
|
a.time = ext->anim_time;
|
|
|
|
a.playback = 0;
|
2017-08-23 14:24:34 +02:00
|
|
|
a.playback_pause = 0;
|
2019-04-04 07:15:40 +02:00
|
|
|
a.repeat = 0;
|
|
|
|
a.repeat_pause = 0;
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_anim_create(&a);
|
2017-11-27 17:48:54 +01:00
|
|
|
#endif
|
2017-08-23 14:24:34 +02:00
|
|
|
}
|
|
|
|
|
2019-03-19 06:30:05 +01:00
|
|
|
lv_btnm_set_btn_ctrl(ext->btns, ext->tab_cur, LV_BTNM_CTRL_TGL_STATE, true);
|
2017-08-23 14:24:34 +02:00
|
|
|
}
|
|
|
|
|
2017-11-26 18:57:56 +01:00
|
|
|
/**
|
|
|
|
* Enable horizontal sliding with touch pad
|
|
|
|
* @param tabview pointer to Tab view object
|
|
|
|
* @param en true: enable sliding; false: disable sliding
|
|
|
|
*/
|
|
|
|
void lv_tabview_set_sliding(lv_obj_t * tabview, bool en)
|
|
|
|
{
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
|
|
|
ext->slide_enable = en == false ? 0 : 1;
|
2017-11-26 18:57:56 +01:00
|
|
|
}
|
2017-10-31 16:25:52 +01: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-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
|
|
|
}
|
|
|
|
|
2017-11-26 18:57:56 +01:00
|
|
|
/**
|
|
|
|
* Set the style of a tab view
|
|
|
|
* @param tabview pointer to a tan view object
|
|
|
|
* @param type which style should be set
|
|
|
|
* @param style pointer to the new style
|
|
|
|
*/
|
2019-04-11 19:59:55 +08:00
|
|
|
void lv_tabview_set_style(lv_obj_t * tabview, lv_tabview_style_t type, const lv_style_t * style)
|
2017-11-15 15:50:33 +01:00
|
|
|
{
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
2017-11-15 15:50:33 +01:00
|
|
|
|
|
|
|
switch(type) {
|
2019-04-04 07:15:40 +02:00
|
|
|
case LV_TABVIEW_STYLE_BG: lv_obj_set_style(tabview, style); break;
|
2017-11-15 15:50:33 +01:00
|
|
|
case LV_TABVIEW_STYLE_BTN_BG:
|
|
|
|
lv_btnm_set_style(ext->btns, LV_BTNM_STYLE_BG, style);
|
2017-11-21 10:35:57 +01:00
|
|
|
tabview_realign(tabview);
|
2017-11-15 15:50:33 +01:00
|
|
|
break;
|
|
|
|
case LV_TABVIEW_STYLE_BTN_REL:
|
|
|
|
lv_btnm_set_style(ext->btns, LV_BTNM_STYLE_BTN_REL, style);
|
2017-11-21 10:35:57 +01:00
|
|
|
tabview_realign(tabview);
|
2017-11-15 15:50:33 +01:00
|
|
|
break;
|
2019-06-06 06:05:40 +02:00
|
|
|
case LV_TABVIEW_STYLE_BTN_PR: lv_btnm_set_style(ext->btns, LV_BTNM_STYLE_BTN_PR, style); break;
|
|
|
|
case LV_TABVIEW_STYLE_BTN_TGL_REL: lv_btnm_set_style(ext->btns, LV_BTNM_STYLE_BTN_TGL_REL, style); break;
|
|
|
|
case LV_TABVIEW_STYLE_BTN_TGL_PR: lv_btnm_set_style(ext->btns, LV_BTNM_STYLE_BTN_TGL_PR, style); break;
|
2017-11-15 15:50:33 +01:00
|
|
|
case LV_TABVIEW_STYLE_INDIC:
|
|
|
|
lv_obj_set_style(ext->indic, style);
|
2019-04-18 18:00:11 +03:00
|
|
|
|
|
|
|
switch(ext->btns_pos) {
|
|
|
|
case LV_TABVIEW_BTNS_POS_TOP:
|
2019-06-06 06:05:40 +02:00
|
|
|
case LV_TABVIEW_BTNS_POS_BOTTOM: lv_obj_set_height(ext->indic, style->body.padding.inner); break;
|
2019-04-18 18:00:11 +03:00
|
|
|
case LV_TABVIEW_BTNS_POS_LEFT:
|
2019-06-06 06:05:40 +02:00
|
|
|
case LV_TABVIEW_BTNS_POS_RIGHT: lv_obj_set_width(ext->indic, style->body.padding.inner); break;
|
2019-04-18 18:00:11 +03:00
|
|
|
}
|
2019-06-06 06:05:40 +02:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
tabview_realign(tabview);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
|
2018-12-20 10:07:28 -05:00
|
|
|
/**
|
|
|
|
* Set whether tab buttons are hidden
|
|
|
|
* @param tabview pointer to a tab view object
|
2018-12-22 19:45:55 +01:00
|
|
|
* @param en whether tab buttons are hidden
|
2018-12-20 10:07:28 -05:00
|
|
|
*/
|
2019-04-04 07:15:40 +02:00
|
|
|
void lv_tabview_set_btns_hidden(lv_obj_t * tabview, bool en)
|
2018-12-20 10:07:28 -05:00
|
|
|
{
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
2018-12-20 10:07:28 -05:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->btns_hide = en;
|
|
|
|
tabview_realign(tabview);
|
2018-12-20 10:07:28 -05:00
|
|
|
}
|
|
|
|
|
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-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-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
|
|
|
{
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
2019-04-04 07:15:40 +02:00
|
|
|
uint16_t i = 0;
|
|
|
|
lv_obj_t * page = lv_obj_get_child_back(ext->content, NULL);
|
2017-08-23 14:24:34 +02:00
|
|
|
|
|
|
|
while(page != NULL && i != id) {
|
|
|
|
i++;
|
2017-10-31 16:25:52 +01:00
|
|
|
page = lv_obj_get_child_back(ext->content, page);
|
2017-08-23 14:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(i == id) return page;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-11-26 18:57:56 +01:00
|
|
|
/**
|
|
|
|
* Get horizontal sliding is enabled or not
|
|
|
|
* @param tabview pointer to Tab view object
|
|
|
|
* @return true: enable sliding; false: disable sliding
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
bool lv_tabview_get_sliding(const lv_obj_t * tabview)
|
2017-11-26 18:57:56 +01:00
|
|
|
{
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
2017-11-26 18:57:56 +01:00
|
|
|
return ext->slide_enable ? true : false;
|
|
|
|
}
|
|
|
|
|
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-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
|
|
|
}
|
|
|
|
|
2017-08-23 14:24:34 +02:00
|
|
|
/**
|
2017-11-15 15:50:33 +01:00
|
|
|
* Get a style of a tab view
|
|
|
|
* @param tabview pointer to a ab view object
|
|
|
|
* @param type which style should be get
|
|
|
|
* @return style pointer to a style
|
2017-08-23 14:24:34 +02:00
|
|
|
*/
|
2019-04-11 19:59:55 +08:00
|
|
|
const lv_style_t * lv_tabview_get_style(const lv_obj_t * tabview, lv_tabview_style_t type)
|
2017-08-23 14:24:34 +02:00
|
|
|
{
|
2019-04-11 19:59:55 +08:00
|
|
|
const lv_style_t * style = NULL;
|
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
2018-06-19 09:49:58 +02:00
|
|
|
|
|
|
|
switch(type) {
|
2019-04-04 07:15:40 +02:00
|
|
|
case LV_TABVIEW_STYLE_BG: style = lv_obj_get_style(tabview); break;
|
|
|
|
case LV_TABVIEW_STYLE_BTN_BG: style = lv_btnm_get_style(ext->btns, LV_BTNM_STYLE_BG); break;
|
2019-06-06 06:05:40 +02:00
|
|
|
case LV_TABVIEW_STYLE_BTN_REL: style = lv_btnm_get_style(ext->btns, LV_BTNM_STYLE_BTN_REL); break;
|
|
|
|
case LV_TABVIEW_STYLE_BTN_PR: style = lv_btnm_get_style(ext->btns, LV_BTNM_STYLE_BTN_PR); break;
|
|
|
|
case LV_TABVIEW_STYLE_BTN_TGL_REL: style = lv_btnm_get_style(ext->btns, LV_BTNM_STYLE_BTN_TGL_REL); break;
|
|
|
|
case LV_TABVIEW_STYLE_BTN_TGL_PR: style = lv_btnm_get_style(ext->btns, LV_BTNM_STYLE_BTN_TGL_PR); break;
|
2019-04-04 07:15:40 +02:00
|
|
|
default: style = NULL; break;
|
2017-08-23 14:24:34 +02:00
|
|
|
}
|
|
|
|
|
2018-11-05 22:21:20 -06:00
|
|
|
return style;
|
2017-08-23 14:24:34 +02: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
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2018-12-20 10:07:28 -05:00
|
|
|
/**
|
|
|
|
* Get whether tab buttons are hidden
|
|
|
|
* @param tabview pointer to a tab view object
|
|
|
|
* @return whether tab buttons are hidden
|
|
|
|
*/
|
2019-04-04 07:15:40 +02:00
|
|
|
bool lv_tabview_get_btns_hidden(const lv_obj_t * tabview)
|
2018-12-20 10:07:28 -05:00
|
|
|
{
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
2018-12-20 10:07:28 -05:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
return ext->btns_hide;
|
2018-12-20 10:07:28 -05:00
|
|
|
}
|
|
|
|
|
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;
|
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;
|
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;
|
|
|
|
} else if(sign == LV_SIGNAL_CORD_CHG) {
|
|
|
|
if(ext->content != NULL && (lv_obj_get_width(tabview) != lv_area_get_width(param) ||
|
|
|
|
lv_obj_get_height(tabview) != lv_area_get_height(param))) {
|
2017-11-15 15:50:33 +01:00
|
|
|
tabview_realign(tabview);
|
|
|
|
}
|
2019-04-04 07:15:40 +02:00
|
|
|
} else if(sign == LV_SIGNAL_RELEASED) {
|
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 ||
|
2019-06-06 06:05:40 +02: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-04-04 07:15:40 +02:00
|
|
|
} else if(sign == LV_SIGNAL_FOCUS || sign == LV_SIGNAL_DEFOCUS || sign == LV_SIGNAL_CONTROL) {
|
|
|
|
/* 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
|
|
|
}
|
2019-03-12 14:29:37 +01:00
|
|
|
|
2019-03-12 19:20:23 +01:00
|
|
|
if(sign == LV_SIGNAL_FOCUS) {
|
2019-03-29 16:10:18 +01:00
|
|
|
lv_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act());
|
2018-10-15 20:12:12 +02:00
|
|
|
/*With ENCODER select the first button only in edit mode*/
|
|
|
|
if(indev_type == LV_INDEV_TYPE_ENCODER) {
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_GROUP
|
2018-10-15 20:12:12 +02:00
|
|
|
lv_group_t * g = lv_obj_get_group(tabview);
|
|
|
|
if(lv_group_get_editing(g)) {
|
|
|
|
lv_btnm_ext_t * btnm_ext = lv_obj_get_ext_attr(ext->btns);
|
2019-04-04 07:15:40 +02:00
|
|
|
btnm_ext->btn_id_pr = 0;
|
2018-10-15 20:12:12 +02:00
|
|
|
lv_obj_invalidate(ext->btns);
|
|
|
|
}
|
2019-02-18 12:17:56 -05:00
|
|
|
#endif
|
2018-10-15 20:12:12 +02:00
|
|
|
} else {
|
|
|
|
lv_btnm_ext_t * btnm_ext = lv_obj_get_ext_attr(ext->btns);
|
2019-04-04 07:15:40 +02:00
|
|
|
btnm_ext->btn_id_pr = 0;
|
2018-10-15 20:12:12 +02:00
|
|
|
lv_obj_invalidate(ext->btns);
|
|
|
|
}
|
|
|
|
}
|
2018-07-25 21:52:50 +02:00
|
|
|
} else if(sign == LV_SIGNAL_GET_EDITABLE) {
|
2018-10-05 17:22:49 +02:00
|
|
|
bool * editable = (bool *)param;
|
2019-04-04 07:15:40 +02:00
|
|
|
*editable = true;
|
2018-06-19 09:49:58 +02:00
|
|
|
} else if(sign == LV_SIGNAL_GET_TYPE) {
|
2018-02-28 15:37:41 +01:00
|
|
|
lv_obj_type_t * buf = param;
|
|
|
|
uint8_t i;
|
2019-04-04 07:15:40 +02:00
|
|
|
for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/
|
2018-02-28 15:37:41 +01:00
|
|
|
if(buf->type[i] == NULL) break;
|
|
|
|
}
|
|
|
|
buf->type[i] = "lv_tabview";
|
|
|
|
}
|
2017-08-23 14:24:34 +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
|
|
|
/**
|
|
|
|
* Signal function of a tab's page
|
|
|
|
* @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
|
|
|
*/
|
2017-11-15 15:50:33 +01:00
|
|
|
static lv_res_t tabpage_signal(lv_obj_t * tab_page, 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 */
|
2017-11-15 15:50:33 +01:00
|
|
|
res = page_signal(tab_page, sign, param);
|
|
|
|
if(res != LV_RES_OK) return res;
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_obj_t * cont = lv_obj_get_parent(tab_page);
|
2017-11-26 18:57:56 +01:00
|
|
|
lv_obj_t * tabview = lv_obj_get_parent(cont);
|
|
|
|
|
|
|
|
if(lv_tabview_get_sliding(tabview) == false) return res;
|
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
if(sign == LV_SIGNAL_PRESSED) {
|
2018-01-25 13:14:10 -08:00
|
|
|
tabpage_pressed_handler(tabview, tab_page);
|
2018-06-19 09:49:58 +02:00
|
|
|
} else if(sign == LV_SIGNAL_PRESSING) {
|
2018-01-25 13:14:10 -08:00
|
|
|
tabpage_pressing_handler(tabview, tab_page);
|
2018-06-19 09:49:58 +02:00
|
|
|
} else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) {
|
2018-01-25 13:14:10 -08:00
|
|
|
tabpage_press_lost_handler(tabview, tab_page);
|
2017-08-23 14:24:34 +02:00
|
|
|
}
|
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
return res;
|
2017-08-23 14:24:34 +02:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Signal function of the tab page's scrollable object
|
|
|
|
* @param tab_scrl pointer to a tab page's scrollable 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
|
|
|
*/
|
2017-11-15 15:50:33 +01:00
|
|
|
static lv_res_t tabpage_scrl_signal(lv_obj_t * tab_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 */
|
2017-11-15 15:50:33 +01:00
|
|
|
res = page_scrl_signal(tab_scrl, sign, param);
|
|
|
|
if(res != LV_RES_OK) return res;
|
|
|
|
|
|
|
|
lv_obj_t * tab_page = lv_obj_get_parent(tab_scrl);
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_obj_t * cont = lv_obj_get_parent(tab_page);
|
|
|
|
lv_obj_t * tabview = lv_obj_get_parent(cont);
|
2017-11-26 18:57:56 +01:00
|
|
|
|
|
|
|
if(lv_tabview_get_sliding(tabview) == false) return res;
|
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
if(sign == LV_SIGNAL_PRESSED) {
|
2018-01-25 13:14:10 -08:00
|
|
|
tabpage_pressed_handler(tabview, tab_page);
|
2018-06-19 09:49:58 +02:00
|
|
|
} else if(sign == LV_SIGNAL_PRESSING) {
|
2018-01-25 13:14:10 -08:00
|
|
|
tabpage_pressing_handler(tabview, tab_page);
|
2018-06-19 09:49:58 +02:00
|
|
|
} else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) {
|
2018-01-25 13:14:10 -08:00
|
|
|
tabpage_press_lost_handler(tabview, tab_page);
|
2017-08-23 14:24:34 +02:00
|
|
|
}
|
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
return res;
|
2017-08-23 14:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when a tab's page or scrollable object is pressed
|
2017-11-16 15:32:33 +01:00
|
|
|
* @param tabview pointer to the btn view object
|
|
|
|
* @param tabpage pointer to the page of a btn
|
2017-08-23 14:24:34 +02:00
|
|
|
*/
|
2018-01-25 13:14:10 -08:00
|
|
|
static void tabpage_pressed_handler(lv_obj_t * tabview, lv_obj_t * tabpage)
|
2017-08-23 14:24:34 +02:00
|
|
|
{
|
2017-12-02 20:43:50 +01:00
|
|
|
(void)tabpage;
|
|
|
|
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_indev_t * indev = lv_indev_get_act();
|
2017-10-09 15:21:26 +02:00
|
|
|
lv_indev_get_point(indev, &ext->point_last);
|
2017-08-23 14:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when a tab's page or scrollable object is being pressed
|
2017-11-16 15:32:33 +01:00
|
|
|
* @param tabview pointer to the btn view object
|
|
|
|
* @param tabpage pointer to the page of a btn
|
2017-08-23 14:24:34 +02:00
|
|
|
*/
|
2018-01-25 13:14:10 -08:00
|
|
|
static void tabpage_pressing_handler(lv_obj_t * tabview, lv_obj_t * tabpage)
|
2017-08-23 14:24:34 +02:00
|
|
|
{
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_indev_t * indev = lv_indev_get_act();
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_point_t point_act;
|
2017-10-09 15:21:26 +02:00
|
|
|
lv_indev_get_point(indev, &point_act);
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_coord_t x_diff = point_act.x - ext->point_last.x;
|
|
|
|
lv_coord_t y_diff = point_act.y - ext->point_last.y;
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2019-06-06 06:05:40 +02:00
|
|
|
if(!ext->scroll_ver && (x_diff >= LV_INDEV_DEF_DRAG_LIMIT || x_diff <= -LV_INDEV_DEF_DRAG_LIMIT)) {
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->draging = 1;
|
|
|
|
/*Check if the page is on the edge */
|
|
|
|
if((lv_page_on_edge(tabpage, LV_PAGE_EDGE_LEFT) && x_diff > 0) ||
|
|
|
|
(lv_page_on_edge(tabpage, LV_PAGE_EDGE_RIGHT) && x_diff < 0)) {
|
|
|
|
if(ext->drag_hor == 0) {
|
|
|
|
ext->point_last.x = point_act.x;
|
|
|
|
ext->point_last.y = point_act.y;
|
|
|
|
}
|
|
|
|
ext->drag_hor = 1;
|
|
|
|
lv_obj_set_drag(lv_page_get_scrl(tabpage), false);
|
2019-03-22 19:08:21 -04:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
} else if(ext->drag_hor == 0) {
|
|
|
|
ext->drag_hor = 0;
|
|
|
|
}
|
|
|
|
} else if(y_diff >= LV_INDEV_DEF_DRAG_LIMIT || y_diff <= -LV_INDEV_DEF_DRAG_LIMIT) {
|
|
|
|
ext->drag_hor = 0;
|
|
|
|
ext->draging = 1;
|
|
|
|
ext->scroll_ver = 1;
|
|
|
|
} else
|
|
|
|
ext->draging = 0;
|
2019-03-22 19:08:21 -04:00
|
|
|
|
2017-11-22 10:34:08 +01:00
|
|
|
if(ext->drag_hor) {
|
2017-08-23 14:24:34 +02:00
|
|
|
lv_obj_set_x(ext->content, lv_obj_get_x(ext->content) + point_act.x - ext->point_last.x);
|
|
|
|
ext->point_last.x = point_act.x;
|
|
|
|
ext->point_last.y = point_act.y;
|
|
|
|
|
|
|
|
/*Move the indicator*/
|
2019-06-06 06:05:40 +02:00
|
|
|
const lv_style_t * tabs_style = lv_obj_get_style(ext->btns);
|
2019-04-18 18:00:11 +03:00
|
|
|
lv_coord_t indic_size;
|
|
|
|
lv_coord_t p;
|
|
|
|
lv_coord_t indic_y;
|
|
|
|
const lv_style_t * indic_style;
|
|
|
|
|
|
|
|
switch(ext->btns_pos) {
|
|
|
|
case LV_TABVIEW_BTNS_POS_TOP:
|
|
|
|
case LV_TABVIEW_BTNS_POS_BOTTOM:
|
|
|
|
indic_size = lv_obj_get_width(ext->indic);
|
|
|
|
indic_style = lv_obj_get_style(ext->indic);
|
2019-06-06 06:05:40 +02:00
|
|
|
p = ((tabpage->coords.x1 - tabview->coords.x1) * (indic_size + tabs_style->body.padding.inner)) /
|
|
|
|
lv_obj_get_width(tabview);
|
2019-04-18 18:00:11 +03:00
|
|
|
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_obj_set_x(ext->indic, indic_size * ext->tab_cur + tabs_style->body.padding.inner * ext->tab_cur +
|
|
|
|
indic_style->body.padding.left - p);
|
2019-04-18 18:00:11 +03:00
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_LEFT:
|
|
|
|
case LV_TABVIEW_BTNS_POS_RIGHT:
|
|
|
|
indic_size = lv_obj_get_height(ext->indic);
|
2019-06-06 06:05:40 +02:00
|
|
|
indic_y = tabs_style->body.padding.top + ext->tab_cur * (indic_size + tabs_style->body.padding.inner);
|
2019-04-18 18:00:11 +03:00
|
|
|
lv_obj_set_y(ext->indic, indic_y);
|
|
|
|
break;
|
|
|
|
}
|
2017-08-23 14:24:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when a tab's page or scrollable object is released or the press id lost
|
2017-11-16 15:32:33 +01:00
|
|
|
* @param tabview pointer to the btn view object
|
|
|
|
* @param tabpage pointer to the page of a btn
|
2017-08-23 14:24:34 +02:00
|
|
|
*/
|
2018-01-25 13:14:10 -08:00
|
|
|
static void tabpage_press_lost_handler(lv_obj_t * tabview, lv_obj_t * tabpage)
|
2017-08-23 14:24:34 +02:00
|
|
|
{
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->drag_hor = 0;
|
|
|
|
ext->draging = 0;
|
|
|
|
ext->scroll_ver = 0;
|
2017-08-23 14:24:34 +02:00
|
|
|
|
|
|
|
lv_obj_set_drag(lv_page_get_scrl(tabpage), true);
|
|
|
|
|
2017-10-09 15:21:26 +02:00
|
|
|
lv_indev_t * indev = lv_indev_get_act();
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_point_t point_act;
|
2017-10-09 15:21:26 +02:00
|
|
|
lv_indev_get_point(indev, &point_act);
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_point_t vect;
|
2017-11-22 10:34:08 +01:00
|
|
|
lv_indev_get_vect(indev, &vect);
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_coord_t x_predict = 0;
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
while(vect.x != 0) {
|
2017-11-22 10:34:08 +01:00
|
|
|
x_predict += vect.x;
|
2019-04-02 12:15:35 +02:00
|
|
|
vect.x = vect.x * (100 - LV_INDEV_DEF_DRAG_THROW) / 100;
|
2017-08-23 14:24:34 +02:00
|
|
|
}
|
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_coord_t page_x1 = tabpage->coords.x1 - tabview->coords.x1 + x_predict;
|
|
|
|
lv_coord_t page_x2 = page_x1 + lv_obj_get_width(tabpage);
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_coord_t treshold = lv_obj_get_width(tabview) / 2;
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2017-10-31 16:25:52 +01:00
|
|
|
uint16_t tab_cur = ext->tab_cur;
|
2017-11-15 15:50:33 +01:00
|
|
|
if(page_x1 > treshold) {
|
2017-10-31 16:25:52 +01:00
|
|
|
if(tab_cur != 0) tab_cur--;
|
2017-11-15 15:50:33 +01:00
|
|
|
} else if(page_x2 < treshold) {
|
2017-10-31 16:25:52 +01:00
|
|
|
if(tab_cur < ext->tab_cnt - 1) tab_cur++;
|
2017-08-23 14:24:34 +02:00
|
|
|
}
|
|
|
|
|
2018-07-07 22:24:31 +02:00
|
|
|
lv_tabview_set_tab_act(tabview, tab_cur, true);
|
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
|
|
|
|
2019-03-12 06:20:45 +01:00
|
|
|
uint16_t btn_id = lv_btnm_get_active_btn(tab_btnm);
|
|
|
|
if(btn_id == LV_BTNM_BTN_NONE) return;
|
2017-10-30 17:11:56 +01:00
|
|
|
|
2019-03-19 06:30:05 +01:00
|
|
|
lv_btnm_set_btn_ctrl_all(tab_btnm, LV_BTNM_CTRL_TGL_STATE, false);
|
|
|
|
lv_btnm_set_btn_ctrl(tab_btnm, btn_id, LV_BTNM_CTRL_TGL_STATE, true);
|
2017-08-23 14:24:34 +02:00
|
|
|
|
2019-03-12 06:20:45 +01:00
|
|
|
lv_obj_t * tab = lv_obj_get_parent(tab_btnm);
|
|
|
|
lv_tabview_set_tab_act(tab, btn_id, true);
|
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);
|
|
|
|
|
|
|
|
lv_obj_set_width(ext->btns, lv_obj_get_width(tabview));
|
2017-11-21 10:35:57 +01:00
|
|
|
|
2018-12-20 10:07:28 -05:00
|
|
|
if(ext->btns_hide) {
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_obj_set_hidden(ext->btns, true);
|
|
|
|
lv_obj_set_hidden(ext->indic, true);
|
|
|
|
lv_obj_set_height(ext->content, lv_obj_get_height(tabview));
|
|
|
|
lv_obj_align(ext->content, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
|
|
|
} else if(ext->tab_cnt != 0) {
|
|
|
|
lv_obj_set_hidden(ext->btns, false);
|
|
|
|
lv_obj_set_hidden(ext->indic, false);
|
|
|
|
|
2019-04-11 19:59:55 +08:00
|
|
|
const lv_style_t * style_btn_bg = lv_tabview_get_style(tabview, LV_TABVIEW_STYLE_BTN_BG);
|
|
|
|
const lv_style_t * style_btn_rel = lv_tabview_get_style(tabview, LV_TABVIEW_STYLE_BTN_REL);
|
2017-11-21 10:35:57 +01:00
|
|
|
|
2019-04-18 18:00:11 +03:00
|
|
|
/*Set the indicator width/height*/
|
|
|
|
lv_coord_t indic_size;
|
|
|
|
lv_coord_t max_h;
|
2017-11-21 10:35:57 +01:00
|
|
|
|
2019-04-18 18:00:11 +03:00
|
|
|
switch(ext->btns_pos) {
|
|
|
|
case LV_TABVIEW_BTNS_POS_TOP:
|
|
|
|
case LV_TABVIEW_BTNS_POS_BOTTOM:
|
2019-06-06 06:05:40 +02:00
|
|
|
indic_size = (lv_obj_get_width(tabview) - style_btn_bg->body.padding.inner * (ext->tab_cnt - 1) -
|
|
|
|
style_btn_bg->body.padding.left - style_btn_bg->body.padding.right) /
|
|
|
|
ext->tab_cnt;
|
2019-04-18 18:00:11 +03:00
|
|
|
lv_obj_set_width(ext->indic, indic_size);
|
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_LEFT:
|
|
|
|
case LV_TABVIEW_BTNS_POS_RIGHT:
|
|
|
|
lv_obj_set_height(ext->btns, lv_obj_get_height(tabview));
|
|
|
|
|
2019-06-06 06:05:40 +02:00
|
|
|
max_h =
|
|
|
|
lv_obj_get_height(ext->btns) - style_btn_bg->body.padding.top - style_btn_bg->body.padding.bottom;
|
2019-04-18 18:00:11 +03:00
|
|
|
indic_size = max_h - ((ext->tab_cnt - 1) * style_btn_bg->body.padding.inner);
|
|
|
|
indic_size = indic_size / ext->tab_cnt;
|
|
|
|
indic_size--; /*-1 because e.g. height = 100 means 101 pixels (0..100)*/
|
|
|
|
lv_obj_set_height(ext->indic, indic_size);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Set the tabs height/width*/
|
|
|
|
lv_coord_t btns_size;
|
|
|
|
|
|
|
|
switch(ext->btns_pos) {
|
|
|
|
case LV_TABVIEW_BTNS_POS_TOP:
|
|
|
|
case LV_TABVIEW_BTNS_POS_BOTTOM:
|
2019-06-06 06:05:40 +02:00
|
|
|
btns_size = lv_font_get_line_height(style_btn_rel->text.font) + style_btn_rel->body.padding.top +
|
|
|
|
style_btn_rel->body.padding.bottom + style_btn_bg->body.padding.top +
|
|
|
|
style_btn_bg->body.padding.bottom;
|
2019-04-18 18:00:11 +03:00
|
|
|
lv_obj_set_height(ext->btns, btns_size);
|
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_LEFT:
|
|
|
|
case LV_TABVIEW_BTNS_POS_RIGHT:
|
2019-05-01 16:43:32 +02:00
|
|
|
btns_size = lv_font_get_glyph_width(style_btn_rel->text.font, 'A', '\0') +
|
2019-06-06 06:05:40 +02:00
|
|
|
style_btn_rel->body.padding.left + style_btn_rel->body.padding.right +
|
2019-04-18 18:00:11 +03:00
|
|
|
style_btn_bg->body.padding.left + style_btn_bg->body.padding.right;
|
|
|
|
lv_obj_set_width(ext->btns, btns_size);
|
|
|
|
break;
|
|
|
|
}
|
2017-11-21 10:35:57 +01:00
|
|
|
|
2019-04-18 18:00:11 +03:00
|
|
|
switch(ext->btns_pos) {
|
|
|
|
case LV_TABVIEW_BTNS_POS_TOP:
|
|
|
|
case LV_TABVIEW_BTNS_POS_BOTTOM:
|
|
|
|
lv_obj_set_height(ext->content, lv_obj_get_height(tabview) - lv_obj_get_height(ext->btns));
|
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_LEFT:
|
2019-06-06 06:05:40 +02:00
|
|
|
case LV_TABVIEW_BTNS_POS_RIGHT: lv_obj_set_height(ext->content, lv_obj_get_height(tabview)); break;
|
2019-04-18 18:00:11 +03:00
|
|
|
}
|
2018-12-20 10:07:28 -05:00
|
|
|
|
|
|
|
switch(ext->btns_pos) {
|
2019-04-04 07:15:40 +02:00
|
|
|
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);
|
2019-04-18 18:00:11 +03:00
|
|
|
lv_obj_align(ext->indic, ext->btns, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
|
|
|
|
|
|
|
|
lv_cont_set_fit2(ext->content, LV_FIT_TIGHT, LV_FIT_NONE);
|
|
|
|
lv_cont_set_layout(ext->content, LV_LAYOUT_ROW_T);
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_obj_set_height(ext->content, lv_obj_get_height(tabview) - lv_obj_get_height(ext->btns));
|
2019-04-18 18:00:11 +03:00
|
|
|
|
|
|
|
// lv_obj_set_height(ext->btns, 3 * LV_DPI / 4);
|
|
|
|
|
|
|
|
// lv_obj_set_width(ext->indic, LV_DPI);
|
2019-04-04 07:15:40 +02:00
|
|
|
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);
|
2019-04-18 18:28:15 +03:00
|
|
|
lv_obj_align(ext->indic, ext->btns, LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
2019-04-18 18:00:11 +03:00
|
|
|
|
|
|
|
lv_cont_set_fit2(ext->content, LV_FIT_TIGHT, LV_FIT_NONE);
|
|
|
|
lv_cont_set_layout(ext->content, LV_LAYOUT_ROW_T);
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_obj_set_height(ext->content, lv_obj_get_height(tabview) - lv_obj_get_height(ext->btns));
|
2019-04-18 18:00:11 +03:00
|
|
|
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);
|
|
|
|
|
|
|
|
lv_cont_set_fit2(ext->content, LV_FIT_TIGHT, LV_FIT_NONE);
|
|
|
|
lv_cont_set_layout(ext->content, LV_LAYOUT_ROW_T);
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_obj_set_width(ext->content, lv_obj_get_width(tabview) - lv_obj_get_width(ext->btns));
|
2019-04-18 18:00:11 +03:00
|
|
|
|
|
|
|
lv_obj_set_height(ext->btns, lv_obj_get_height(tabview));
|
|
|
|
lv_obj_set_width(ext->indic, style_btn_bg->body.padding.inner);
|
|
|
|
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);
|
2019-04-18 18:28:15 +03:00
|
|
|
lv_obj_align(ext->indic, ext->btns, LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
2019-04-18 18:00:11 +03:00
|
|
|
|
|
|
|
lv_cont_set_fit2(ext->content, LV_FIT_TIGHT, LV_FIT_NONE);
|
|
|
|
lv_cont_set_layout(ext->content, LV_LAYOUT_ROW_T);
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_obj_set_width(ext->content, lv_obj_get_width(tabview) - lv_obj_get_width(ext->btns));
|
2019-04-18 18:00:11 +03:00
|
|
|
|
|
|
|
lv_obj_set_height(ext->btns, lv_obj_get_height(tabview));
|
|
|
|
lv_obj_set_width(ext->indic, style_btn_bg->body.padding.inner);
|
2019-04-04 07:15:40 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-03-07 15:45:11 -05:00
|
|
|
}
|
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
lv_obj_t * pages = lv_obj_get_child(ext->content, NULL);
|
|
|
|
while(pages != NULL) {
|
2019-06-06 06:05:40 +02:00
|
|
|
if(lv_obj_get_signal_cb(pages) == tabpage_signal) { /*Be sure adjust only the pages (user can other things)*/
|
2019-04-18 18:00:11 +03:00
|
|
|
switch(ext->btns_pos) {
|
|
|
|
case LV_TABVIEW_BTNS_POS_TOP:
|
|
|
|
case LV_TABVIEW_BTNS_POS_BOTTOM:
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_obj_set_size(pages, lv_obj_get_width(tabview), lv_obj_get_height(ext->content));
|
2019-04-18 18:00:11 +03:00
|
|
|
break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_LEFT:
|
|
|
|
case LV_TABVIEW_BTNS_POS_RIGHT:
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_obj_set_size(pages, lv_obj_get_width(tabview) - lv_obj_get_width(ext->btns),
|
|
|
|
lv_obj_get_height(ext->content));
|
2019-04-18 18:00:11 +03:00
|
|
|
break;
|
2019-06-06 06:05:40 +02:00
|
|
|
}
|
2017-11-21 17:04:06 +01:00
|
|
|
}
|
2017-11-15 15:50:33 +01:00
|
|
|
pages = lv_obj_get_child(ext->content, pages);
|
|
|
|
}
|
|
|
|
|
2018-12-20 10:07:28 -05:00
|
|
|
if(!ext->btns_hide) {
|
2019-04-18 18:00:11 +03:00
|
|
|
switch(ext->btns_pos) {
|
2019-06-06 06:05:40 +02:00
|
|
|
case LV_TABVIEW_BTNS_POS_TOP: 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->indic, ext->btns, LV_ALIGN_IN_TOP_LEFT, 0, 0); break;
|
|
|
|
case LV_TABVIEW_BTNS_POS_LEFT: 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->indic, ext->btns, LV_ALIGN_IN_TOP_LEFT, 0, 0); break;
|
|
|
|
}
|
2018-12-20 10:07:28 -05:00
|
|
|
}
|
2017-11-15 15:50:33 +01:00
|
|
|
|
2017-12-08 14:34:07 +01:00
|
|
|
lv_tabview_set_tab_act(tabview, ext->tab_cur, false);
|
2017-11-15 15:50:33 +01:00
|
|
|
}
|
2017-08-23 14:24:34 +02:00
|
|
|
#endif
|