2016-06-08 07:25:08 +02:00
|
|
|
/**
|
|
|
|
* @file lv_page.c
|
2018-06-19 09:49:58 +02:00
|
|
|
*
|
2016-06-08 07:25:08 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
2018-07-07 11:53:22 +02:00
|
|
|
#include "../lv_objx/lv_page.h"
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_PAGE != 0
|
2016-06-08 07:25:08 +02:00
|
|
|
|
2019-09-24 16:30:38 +02:00
|
|
|
#include "../lv_core/lv_debug.h"
|
2017-11-30 11:35:33 +01:00
|
|
|
#include "../lv_core/lv_group.h"
|
2016-10-04 09:45:39 +02:00
|
|
|
#include "../lv_draw/lv_draw.h"
|
2017-11-16 15:32:33 +01:00
|
|
|
#include "../lv_themes/lv_theme.h"
|
2017-11-30 11:35:33 +01:00
|
|
|
#include "../lv_core/lv_refr.h"
|
2017-11-23 20:42:14 +01:00
|
|
|
#include "../lv_misc/lv_anim.h"
|
|
|
|
#include "../lv_misc/lv_math.h"
|
2016-06-08 07:25:08 +02:00
|
|
|
|
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
2019-09-26 10:51:54 +02:00
|
|
|
#define LV_OBJX_NAME "lv_page"
|
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
#define LV_PAGE_SB_MIN_SIZE (LV_DPI / 8)
|
2019-04-04 16:44:16 +02:00
|
|
|
|
|
|
|
/*[ms] Scroll anim time on `lv_page_scroll_up/down/left/rigth`*/
|
|
|
|
#define LV_PAGE_SCROLL_ANIM_TIME 200
|
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
#define LV_PAGE_END_FLASH_SIZE (LV_DPI / 4)
|
|
|
|
#define LV_PAGE_END_ANIM_TIME 300
|
|
|
|
#define LV_PAGE_END_ANIM_WAIT_TIME 300
|
2016-06-08 07:25:08 +02:00
|
|
|
|
2019-06-19 13:43:02 +02:00
|
|
|
#if LV_USE_ANIMATION == 0
|
|
|
|
#undef LV_PAGE_DEF_ANIM_TIME
|
|
|
|
#define LV_PAGE_DEF_ANIM_TIME 0 /*No animation*/
|
|
|
|
#endif
|
|
|
|
|
2016-06-08 07:25:08 +02:00
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC PROTOTYPES
|
|
|
|
**********************/
|
2019-01-01 01:32:16 +01:00
|
|
|
static void lv_page_sb_refresh(lv_obj_t * page);
|
2019-09-06 19:53:39 +02:00
|
|
|
static lv_design_res_t lv_page_design(lv_obj_t * page, const lv_area_t * clip_area, lv_design_mode_t mode);
|
2017-11-05 00:48:57 +01:00
|
|
|
static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param);
|
2020-01-01 15:25:16 +01:00
|
|
|
static lv_style_dsc_t * lv_page_get_style(lv_obj_t * page, uint8_t part);
|
2017-11-05 00:48:57 +01:00
|
|
|
static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void * param);
|
2019-02-26 09:25:46 +01:00
|
|
|
static void scrl_def_event_cb(lv_obj_t * scrl, lv_event_t event);
|
2019-05-20 09:22:09 -07:00
|
|
|
#if LV_USE_ANIMATION
|
|
|
|
static void edge_flash_anim(void * page, lv_anim_value_t v);
|
|
|
|
static void edge_flash_anim_end(lv_anim_t * a);
|
|
|
|
#endif
|
2016-06-08 07:25:08 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC VARIABLES
|
|
|
|
**********************/
|
2019-02-26 09:25:46 +01:00
|
|
|
static lv_design_cb_t ancestor_design;
|
|
|
|
static lv_signal_cb_t ancestor_signal;
|
2016-10-04 15:19:07 +02:00
|
|
|
|
2016-06-08 07:25:08 +02:00
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* GLOBAL FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a page objects
|
2016-10-07 11:15:46 +02:00
|
|
|
* @param par pointer to an object, it will be the parent of the new page
|
|
|
|
* @param copy pointer to a page object, if not NULL then the new object will be copied from it
|
2016-06-08 07:25:08 +02:00
|
|
|
* @return pointer to the created page
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
lv_obj_t * lv_page_create(lv_obj_t * par, const lv_obj_t * copy)
|
2016-06-08 07:25:08 +02:00
|
|
|
{
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_TRACE("page create started");
|
2018-07-25 17:57:08 +02:00
|
|
|
|
2016-10-04 09:45:39 +02:00
|
|
|
/*Create the ancestor object*/
|
2017-04-13 16:12:03 +02:00
|
|
|
lv_obj_t * new_page = lv_cont_create(par, copy);
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(new_page);
|
2018-07-25 13:33:53 +02:00
|
|
|
if(new_page == NULL) return NULL;
|
|
|
|
|
2019-04-10 06:40:49 +02:00
|
|
|
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(new_page);
|
|
|
|
if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_cb(new_page);
|
2016-06-08 07:25:08 +02:00
|
|
|
|
2016-10-04 09:45:39 +02:00
|
|
|
/*Allocate the object type specific extended data*/
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_page_ext_t * ext = lv_obj_allocate_ext_attr(new_page, sizeof(lv_page_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) {
|
|
|
|
lv_obj_del(new_page);
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-07-25 13:33:53 +02:00
|
|
|
|
2019-06-06 06:05:40 +02:00
|
|
|
ext->scrl = NULL;
|
2019-12-31 07:03:34 +01:00
|
|
|
lv_style_dsc_init(&ext->sb.style);
|
2019-06-06 06:05:40 +02:00
|
|
|
ext->sb.hor_draw = 0;
|
|
|
|
ext->sb.ver_draw = 0;
|
|
|
|
ext->sb.mode = LV_SB_MODE_AUTO;
|
2019-05-20 18:31:47 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2019-12-31 07:03:34 +01:00
|
|
|
lv_style_dsc_init(&ext->edge_flash.style);
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->edge_flash.enabled = 0;
|
2018-11-24 20:31:06 +01:00
|
|
|
ext->edge_flash.bottom_ip = 0;
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->edge_flash.top_ip = 0;
|
|
|
|
ext->edge_flash.left_ip = 0;
|
|
|
|
ext->edge_flash.right_ip = 0;
|
|
|
|
ext->edge_flash.state = 0;
|
2019-06-27 07:16:15 +02:00
|
|
|
ext->anim_time = LV_PAGE_DEF_ANIM_TIME;
|
2019-05-20 18:31:47 -07:00
|
|
|
#endif
|
2019-09-17 16:07:30 +02:00
|
|
|
ext->scroll_prop = 0;
|
2019-09-17 14:38:55 +02:00
|
|
|
ext->scroll_prop_obj = NULL;
|
2016-06-08 07:25:08 +02:00
|
|
|
|
2019-12-31 07:03:34 +01:00
|
|
|
|
|
|
|
|
2016-10-04 09:45:39 +02:00
|
|
|
/*Init the new page object*/
|
2016-10-07 11:15:46 +02:00
|
|
|
if(copy == NULL) {
|
2018-06-19 09:49:58 +02:00
|
|
|
ext->scrl = lv_cont_create(new_page, NULL);
|
|
|
|
lv_obj_set_drag(ext->scrl, true);
|
|
|
|
lv_obj_set_drag_throw(ext->scrl, true);
|
|
|
|
lv_obj_set_protect(ext->scrl, LV_PROTECT_PARENT | LV_PROTECT_PRESS_LOST);
|
2019-02-24 06:41:00 +01:00
|
|
|
lv_cont_set_fit4(ext->scrl, LV_FIT_FILL, LV_FIT_FILL, LV_FIT_FILL, LV_FIT_FILL);
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_obj_set_event_cb(ext->scrl, scrl_def_event_cb); /*Propagate some event to the background
|
|
|
|
object by default for convenience */
|
2019-12-31 06:10:50 +01:00
|
|
|
lv_obj_set_signal_cb(ext->scrl, lv_page_scrollable_signal);
|
2017-04-21 09:15:39 +02:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
/* Add the signal function only if 'scrolling' is created
|
2019-12-26 01:30:20 +01:00
|
|
|
+ * because everything has to be ready before any signal is received*/
|
2019-02-26 09:25:46 +01:00
|
|
|
lv_obj_set_signal_cb(new_page, lv_page_signal);
|
|
|
|
lv_obj_set_design_cb(new_page, lv_page_design);
|
2017-11-15 15:50:33 +01:00
|
|
|
|
2017-11-05 00:48:57 +01:00
|
|
|
lv_page_set_sb_mode(new_page, ext->sb.mode);
|
2017-11-16 15:32:33 +01:00
|
|
|
|
2020-01-07 23:43:57 +01:00
|
|
|
lv_obj_refresh_style(new_page);
|
2019-12-31 06:10:50 +01:00
|
|
|
|
2016-06-08 07:25:08 +02:00
|
|
|
} else {
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_page_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->scrl = lv_cont_create(new_page, copy_ext->scrl);
|
2019-02-26 09:25:46 +01:00
|
|
|
lv_obj_set_signal_cb(ext->scrl, lv_page_scrollable_signal);
|
2016-10-04 09:45:39 +02:00
|
|
|
|
2019-12-16 06:14:34 +01:00
|
|
|
/* Add the signal function only if 'scrolling' is created
|
|
|
|
* because everything has to be ready before any signal is received*/
|
|
|
|
lv_obj_set_signal_cb(new_page, lv_page_signal);
|
|
|
|
lv_obj_set_design_cb(new_page, lv_page_design);
|
2018-07-12 23:38:27 +02:00
|
|
|
|
2019-12-31 06:10:50 +01:00
|
|
|
// lv_page_set_style(new_page, LV_PAGE_STYLE_BG, lv_page_get_style(copy, LV_PAGE_STYLE_BG));
|
|
|
|
// lv_page_set_style(new_page, LV_PAGE_STYLE_SCRL, lv_page_get_style(copy, LV_PAGE_STYLE_SCRL));
|
2020-01-01 18:46:22 +01:00
|
|
|
// lv_page_set_style(new_page, LV_PAGE_STYLE_SCRLBAR, lv_page_get_style(copy, LV_PAGE_STYLE_SCRLBAR));
|
2017-01-08 13:06:41 +01:00
|
|
|
|
2019-12-16 06:14:34 +01:00
|
|
|
lv_page_set_sb_mode(new_page, copy_ext->sb.mode);
|
2016-06-08 07:25:08 +02:00
|
|
|
}
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2019-12-31 06:10:50 +01:00
|
|
|
|
2016-10-07 11:15:46 +02:00
|
|
|
lv_page_sb_refresh(new_page);
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_INFO("page created");
|
2018-07-25 17:57:08 +02:00
|
|
|
|
2016-10-07 11:15:46 +02:00
|
|
|
return new_page;
|
2016-06-08 07:25:08 +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 page pointer to an object
|
2018-03-16 11:53:27 -04:00
|
|
|
*/
|
2019-09-26 12:54:40 +02:00
|
|
|
void lv_page_clean(lv_obj_t * page)
|
2018-03-16 11:53:27 -04:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(page, LV_OBJX_NAME);
|
|
|
|
|
|
|
|
lv_obj_t * scrl = lv_page_get_scrl(page);
|
2018-03-16 11:53:27 -04:00
|
|
|
lv_obj_clean(scrl);
|
|
|
|
}
|
|
|
|
|
2016-10-04 15:29:52 +02:00
|
|
|
/*=====================
|
|
|
|
* Setter functions
|
|
|
|
*====================*/
|
|
|
|
|
2017-04-13 10:20:35 +02:00
|
|
|
/**
|
|
|
|
* Set the scroll bar mode on a page
|
|
|
|
* @param page pointer to a page object
|
2018-07-12 23:38:27 +02:00
|
|
|
* @param sb_mode the new mode from 'lv_page_sb.mode_t' enum
|
2017-04-13 10:20:35 +02:00
|
|
|
*/
|
2017-11-18 00:18:19 +01:00
|
|
|
void lv_page_set_sb_mode(lv_obj_t * page, lv_sb_mode_t sb_mode)
|
2017-04-13 10:20:35 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(page, LV_OBJX_NAME);
|
|
|
|
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
|
2018-05-16 23:09:30 +02:00
|
|
|
if(ext->sb.mode == sb_mode) return;
|
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
if(sb_mode == LV_SB_MODE_HIDE)
|
|
|
|
ext->sb.mode |= LV_SB_MODE_HIDE; /*Set the hidden flag*/
|
|
|
|
else if(sb_mode == LV_SB_MODE_UNHIDE)
|
|
|
|
ext->sb.mode &= (~LV_SB_MODE_HIDE); /*Clear the hidden flag*/
|
2018-08-10 01:11:20 +02:00
|
|
|
else {
|
2018-10-05 17:22:49 +02:00
|
|
|
if(ext->sb.mode & LV_SB_MODE_HIDE) sb_mode |= LV_SB_MODE_HIDE;
|
|
|
|
ext->sb.mode = sb_mode;
|
2018-08-10 01:11:20 +02:00
|
|
|
}
|
2018-08-10 01:04:20 +02:00
|
|
|
|
2017-11-05 00:48:57 +01:00
|
|
|
ext->sb.hor_draw = 0;
|
|
|
|
ext->sb.ver_draw = 0;
|
2018-08-10 01:04:20 +02:00
|
|
|
|
2017-11-05 00:48:57 +01:00
|
|
|
lv_page_sb_refresh(page);
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_obj_invalidate(page);
|
2017-04-13 10:20:35 +02:00
|
|
|
}
|
|
|
|
|
2019-06-19 00:35:35 +02:00
|
|
|
/**
|
|
|
|
* Set the animation time for the page
|
|
|
|
* @param page pointer to a page object
|
|
|
|
* @param anim_time animation time in milliseconds
|
|
|
|
*/
|
|
|
|
void lv_page_set_anim_time(lv_obj_t * page, uint16_t anim_time)
|
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(page, LV_OBJX_NAME);
|
|
|
|
|
2019-06-19 00:35:35 +02:00
|
|
|
#if LV_USE_ANIMATION
|
2019-06-19 09:08:47 -07:00
|
|
|
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
|
2019-06-27 07:16:15 +02:00
|
|
|
ext->anim_time = anim_time;
|
2019-06-20 06:26:24 +02:00
|
|
|
#else
|
2019-06-27 07:16:15 +02:00
|
|
|
(void)page; /*Unused*/
|
|
|
|
(void)anim_time; /*Unused*/
|
2019-06-19 00:35:35 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-11-07 20:41:52 +01:00
|
|
|
/**
|
2019-04-04 07:15:40 +02:00
|
|
|
* Enable the scroll propagation feature. If enabled then the page will move its parent if there is
|
|
|
|
* no more space to scroll.
|
2019-09-19 14:58:07 +02:00
|
|
|
* The page needs to have a page-like parent (e.g. `lv_page`, `lv_tabview` tab, `lv_win` content area etc)
|
|
|
|
* If enabled drag direction will be changed `LV_DRAG_DIR_ONE` automatically to allow scrolling only in one direction at one time.
|
2018-11-07 20:41:52 +01:00
|
|
|
* @param page pointer to a Page
|
|
|
|
* @param en true or false to enable/disable scroll propagation
|
|
|
|
*/
|
2019-09-17 16:07:30 +02:00
|
|
|
void lv_page_set_scroll_propagation(lv_obj_t * page, bool en)
|
2018-11-07 20:41:52 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(page, LV_OBJX_NAME);
|
|
|
|
|
2018-11-07 20:41:52 +01:00
|
|
|
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
|
2019-09-19 14:58:07 +02:00
|
|
|
if(en) lv_obj_set_drag_dir(ext->scrl, LV_DRAG_DIR_ONE);
|
|
|
|
else lv_obj_set_drag_dir(ext->scrl, LV_DRAG_DIR_BOTH);
|
|
|
|
|
2019-09-17 16:07:30 +02:00
|
|
|
ext->scroll_prop = en ? 1 : 0;
|
2018-11-07 20:41:52 +01:00
|
|
|
}
|
|
|
|
|
2018-11-24 20:31:06 +01:00
|
|
|
/**
|
|
|
|
* Enable the edge flash effect. (Show an arc when the an edge is reached)
|
|
|
|
* @param page pointer to a Page
|
|
|
|
* @param en true or false to enable/disable end flash
|
|
|
|
*/
|
|
|
|
void lv_page_set_edge_flash(lv_obj_t * page, bool en)
|
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(page, LV_OBJX_NAME);
|
|
|
|
|
2019-05-20 18:31:47 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
|
2018-11-24 20:31:06 +01:00
|
|
|
ext->edge_flash.enabled = en ? 1 : 0;
|
2019-05-20 18:31:47 -07:00
|
|
|
#else
|
2019-06-06 06:05:40 +02:00
|
|
|
(void)page;
|
|
|
|
(void)en;
|
2019-05-20 18:31:47 -07:00
|
|
|
#endif
|
2018-11-24 20:31:06 +01:00
|
|
|
}
|
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
/*=====================
|
|
|
|
* Getter functions
|
|
|
|
*====================*/
|
2017-11-05 00:48:57 +01:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
/**
|
|
|
|
* Get the scrollable object of a page
|
|
|
|
* @param page pointer to a page object
|
|
|
|
* @return pointer to a container which is the scrollable part of the page
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
lv_obj_t * lv_page_get_scrl(const lv_obj_t * page)
|
2017-11-15 15:50:33 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(page, LV_OBJX_NAME);
|
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
|
2017-11-15 15:50:33 +01:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
return ext->scrl;
|
2017-04-13 10:20:35 +02:00
|
|
|
}
|
2016-12-18 22:07:03 +01:00
|
|
|
|
2019-06-19 00:35:35 +02:00
|
|
|
/**
|
|
|
|
* Get the animation time
|
|
|
|
* @param page pointer to a page object
|
|
|
|
* @return the animation time in milliseconds
|
|
|
|
*/
|
|
|
|
uint16_t lv_page_get_anim_time(const lv_obj_t * page)
|
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(page, LV_OBJX_NAME);
|
|
|
|
|
2019-06-19 00:35:35 +02:00
|
|
|
#if LV_USE_ANIMATION
|
|
|
|
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
|
|
|
|
return ext->anim_time;
|
|
|
|
#else
|
2019-06-27 07:16:15 +02:00
|
|
|
(void)page; /*Unused*/
|
2019-06-19 00:35:35 +02:00
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
/**
|
|
|
|
* Set the scroll bar mode on a page
|
|
|
|
* @param page pointer to a page object
|
|
|
|
* @return the mode from 'lv_page_sb.mode_t' enum
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
lv_sb_mode_t lv_page_get_sb_mode(const lv_obj_t * page)
|
2017-11-15 15:50:33 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(page, LV_OBJX_NAME);
|
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
|
|
|
|
return ext->sb.mode;
|
|
|
|
}
|
|
|
|
|
2018-11-07 20:41:52 +01:00
|
|
|
/**
|
|
|
|
* Get the scroll propagation property
|
|
|
|
* @param page pointer to a Page
|
|
|
|
* @return true or false
|
|
|
|
*/
|
2019-09-17 16:07:30 +02:00
|
|
|
bool lv_page_get_scroll_propagation(lv_obj_t * page)
|
2018-11-07 20:41:52 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(page, LV_OBJX_NAME);
|
|
|
|
|
2018-11-07 20:41:52 +01:00
|
|
|
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
|
2019-09-17 16:07:30 +02:00
|
|
|
return ext->scroll_prop ? true : false;
|
2018-11-07 20:41:52 +01:00
|
|
|
}
|
|
|
|
|
2018-11-24 20:31:06 +01:00
|
|
|
/**
|
|
|
|
* Get the edge flash effect property.
|
|
|
|
* @param page pointer to a Page
|
|
|
|
* return true or false
|
|
|
|
*/
|
|
|
|
bool lv_page_get_edge_flash(lv_obj_t * page)
|
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(page, LV_OBJX_NAME);
|
|
|
|
|
2019-05-20 18:31:47 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2018-11-24 20:31:06 +01:00
|
|
|
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
|
|
|
|
return ext->edge_flash.enabled == 0 ? false : true;
|
2019-05-20 18:31:47 -07:00
|
|
|
#else
|
2019-06-06 06:05:40 +02:00
|
|
|
(void)page;
|
2019-05-20 18:31:47 -07:00
|
|
|
return false;
|
|
|
|
#endif
|
2018-11-24 20:31:06 +01:00
|
|
|
}
|
|
|
|
|
2018-10-17 05:42:27 +02:00
|
|
|
/**
|
|
|
|
* Get that width which can be set to the children to still not cause overflow (show scrollbars)
|
|
|
|
* @param page pointer to a page object
|
|
|
|
* @return the width which still fits into the page
|
|
|
|
*/
|
|
|
|
lv_coord_t lv_page_get_fit_width(lv_obj_t * page)
|
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(page, LV_OBJX_NAME);
|
|
|
|
|
2020-01-06 22:14:04 +01:00
|
|
|
lv_style_int_t bg_left = lv_obj_get_style_int(page, LV_PAGE_PART_BG, LV_STYLE_PAD_LEFT);
|
|
|
|
lv_style_int_t bg_right = lv_obj_get_style_int(page, LV_PAGE_PART_BG, LV_STYLE_PAD_RIGHT);
|
|
|
|
lv_style_int_t scrl_left = lv_obj_get_style_int(page, LV_PAGE_PART_SCRL, LV_STYLE_PAD_LEFT);
|
|
|
|
lv_style_int_t scrl_right = lv_obj_get_style_int(page, LV_PAGE_PART_SCRL, LV_STYLE_PAD_RIGHT);
|
2018-10-17 05:42:27 +02:00
|
|
|
|
2019-12-31 06:10:50 +01:00
|
|
|
return lv_obj_get_width(page) - bg_left - bg_right - scrl_left - scrl_right;
|
2018-10-17 05:42:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get that height which can be set to the children to still not cause overflow (show scrollbars)
|
|
|
|
* @param page pointer to a page object
|
|
|
|
* @return the height which still fits into the page
|
|
|
|
*/
|
|
|
|
lv_coord_t lv_page_get_fit_height(lv_obj_t * page)
|
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(page, LV_OBJX_NAME);
|
|
|
|
|
2020-01-06 22:14:04 +01:00
|
|
|
lv_style_int_t bg_top = lv_obj_get_style_int(page, LV_PAGE_PART_BG, LV_STYLE_PAD_TOP);
|
|
|
|
lv_style_int_t bg_bottom = lv_obj_get_style_int(page, LV_PAGE_PART_BG, LV_STYLE_PAD_BOTTOM);
|
|
|
|
lv_style_int_t scrl_top = lv_obj_get_style_int(page, LV_PAGE_PART_SCRL, LV_STYLE_PAD_TOP);
|
|
|
|
lv_style_int_t scrl_bottom = lv_obj_get_style_int(page, LV_PAGE_PART_SCRL, LV_STYLE_PAD_BOTTOM);
|
2018-10-17 05:42:27 +02:00
|
|
|
|
2019-12-31 06:10:50 +01:00
|
|
|
return lv_obj_get_height(page) - bg_top - bg_bottom - scrl_top - scrl_bottom;
|
2018-10-17 05:42:27 +02:00
|
|
|
}
|
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
/*=====================
|
|
|
|
* Other functions
|
|
|
|
*====================*/
|
|
|
|
|
2019-03-22 19:08:21 -04:00
|
|
|
/**
|
|
|
|
* Find whether the page has been scrolled to a certain edge.
|
|
|
|
* @param page Page object
|
|
|
|
* @param edge Edge to check
|
|
|
|
* @return true if the page is on the specified edge
|
|
|
|
*/
|
2019-04-04 07:15:40 +02:00
|
|
|
bool lv_page_on_edge(lv_obj_t * page, lv_page_edge_t edge)
|
|
|
|
{
|
2019-04-11 19:59:55 +08:00
|
|
|
lv_obj_t * scrl = lv_page_get_scrl(page);
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_area_t page_coords;
|
|
|
|
lv_area_t scrl_coords;
|
|
|
|
|
|
|
|
lv_obj_get_coords(scrl, &scrl_coords);
|
|
|
|
lv_obj_get_coords(page, &page_coords);
|
|
|
|
|
2020-01-06 22:14:04 +01:00
|
|
|
lv_style_int_t left = lv_obj_get_style_int(page, LV_PAGE_PART_BG, LV_STYLE_PAD_LEFT);
|
|
|
|
lv_style_int_t right = lv_obj_get_style_int(page, LV_PAGE_PART_BG, LV_STYLE_PAD_RIGHT);
|
|
|
|
lv_style_int_t top = lv_obj_get_style_int(page, LV_PAGE_PART_BG, LV_STYLE_PAD_TOP);
|
|
|
|
lv_style_int_t bottom = lv_obj_get_style_int(page, LV_PAGE_PART_BG, LV_STYLE_PAD_BOTTOM);
|
2019-12-31 06:10:50 +01:00
|
|
|
|
|
|
|
if((edge & LV_PAGE_EDGE_TOP) && scrl_coords.y1 == page_coords.y1 + top) return true;
|
|
|
|
if((edge & LV_PAGE_EDGE_BOTTOM) && scrl_coords.y2 == page_coords.y2 - bottom) return true;
|
|
|
|
if((edge & LV_PAGE_EDGE_LEFT) && scrl_coords.x1 == page_coords.x1 + left) return true;
|
|
|
|
if((edge & LV_PAGE_EDGE_RIGHT) && scrl_coords.x2 == page_coords.x2 - right) return true;
|
2019-04-04 07:15:40 +02:00
|
|
|
|
|
|
|
return false;
|
2019-03-22 19:08:21 -04:00
|
|
|
}
|
|
|
|
|
2016-06-08 07:25:08 +02:00
|
|
|
/**
|
|
|
|
* Glue the object to the page. After it the page can be moved (dragged) with this object too.
|
2016-12-17 10:50:28 +01:00
|
|
|
* @param obj pointer to an object on a page
|
2016-10-07 11:15:46 +02:00
|
|
|
* @param glue true: enable glue, false: disable glue
|
2016-06-08 07:25:08 +02:00
|
|
|
*/
|
2016-12-17 10:50:28 +01:00
|
|
|
void lv_page_glue_obj(lv_obj_t * obj, bool glue)
|
2016-06-08 07:25:08 +02:00
|
|
|
{
|
2016-12-17 10:50:28 +01:00
|
|
|
lv_obj_set_drag_parent(obj, glue);
|
|
|
|
lv_obj_set_drag(obj, glue);
|
2016-06-08 07:25:08 +02:00
|
|
|
}
|
|
|
|
|
2016-12-17 21:22:16 +01:00
|
|
|
/**
|
|
|
|
* Focus on an object. It ensures that the object will be visible on the page.
|
|
|
|
* @param page pointer to a page object
|
|
|
|
* @param obj pointer to an object to focus (must be on the page)
|
2019-06-19 00:35:35 +02:00
|
|
|
* @param anim_en LV_ANIM_ON to focus with animation; LV_ANIM_OFF to focus without animation
|
2016-12-17 21:22:16 +01:00
|
|
|
*/
|
2019-06-19 00:35:35 +02:00
|
|
|
void lv_page_focus(lv_obj_t * page, const lv_obj_t * obj, lv_anim_enable_t anim_en)
|
2016-12-17 21:22:16 +01:00
|
|
|
{
|
2018-10-15 19:00:03 +02:00
|
|
|
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
|
|
|
|
|
2019-05-20 09:22:09 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2018-07-06 17:12:06 +03:00
|
|
|
/* Be sure there is no position changing animation in progress
|
|
|
|
* because it can overide the current changes*/
|
2019-06-12 23:10:54 +02:00
|
|
|
lv_anim_del(page, (lv_anim_exec_xcb_t)lv_obj_set_x);
|
|
|
|
lv_anim_del(page, (lv_anim_exec_xcb_t)lv_obj_set_y);
|
|
|
|
lv_anim_del(ext->scrl, (lv_anim_exec_xcb_t)lv_obj_set_x);
|
|
|
|
lv_anim_del(ext->scrl, (lv_anim_exec_xcb_t)lv_obj_set_y);
|
2018-07-03 14:27:53 +02:00
|
|
|
#endif
|
|
|
|
|
2016-12-17 21:22:16 +01:00
|
|
|
|
2019-03-01 23:50:30 +01:00
|
|
|
/*If obj is higher then the page focus where the "error" is smaller*/
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_coord_t obj_y = obj->coords.y1 - ext->scrl->coords.y1;
|
|
|
|
lv_coord_t obj_h = lv_obj_get_height(obj);
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_coord_t scrlable_y = lv_obj_get_y(ext->scrl);
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_coord_t page_h = lv_obj_get_height(page);
|
2016-12-17 21:22:16 +01:00
|
|
|
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_coord_t top_err = -(scrlable_y + obj_y);
|
|
|
|
lv_coord_t bot_err = scrlable_y + obj_y + obj_h - page_h;
|
2016-12-19 11:58:11 +01:00
|
|
|
|
2020-01-06 22:14:04 +01:00
|
|
|
lv_style_int_t bg_top = lv_obj_get_style_int(page, LV_PAGE_PART_BG, LV_STYLE_PAD_TOP);
|
|
|
|
lv_style_int_t bg_bottom = lv_obj_get_style_int(page, LV_PAGE_PART_BG, LV_STYLE_PAD_BOTTOM);
|
|
|
|
lv_style_int_t scrl_top = lv_obj_get_style_int(page, LV_PAGE_PART_SCRL, LV_STYLE_PAD_TOP);
|
|
|
|
lv_style_int_t scrl_bottom = lv_obj_get_style_int(page, LV_PAGE_PART_SCRL, LV_STYLE_PAD_BOTTOM);
|
2019-12-31 06:10:50 +01:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
/*Out of the page on the top*/
|
2019-04-04 07:15:40 +02:00
|
|
|
if((obj_h <= page_h && top_err > 0) || (obj_h > page_h && top_err < bot_err)) {
|
2017-11-15 15:50:33 +01:00
|
|
|
/*Calculate a new position and let some space above*/
|
2019-12-31 06:10:50 +01:00
|
|
|
scrlable_y = -(obj_y - scrl_top - bg_top);
|
|
|
|
scrlable_y += scrl_top;
|
2017-11-15 15:50:33 +01:00
|
|
|
}
|
|
|
|
/*Out of the page on the bottom*/
|
2019-04-04 07:15:40 +02:00
|
|
|
else if((obj_h <= page_h && bot_err > 0) || (obj_h > page_h && top_err >= bot_err)) {
|
2017-11-05 00:48:57 +01:00
|
|
|
/*Calculate a new position and let some space below*/
|
2019-12-31 06:10:50 +01:00
|
|
|
scrlable_y = -(obj_y + scrl_bottom + bg_bottom);
|
|
|
|
scrlable_y -= scrl_bottom;
|
2018-06-11 16:00:30 -07:00
|
|
|
scrlable_y += page_h - obj_h;
|
2019-03-01 23:50:30 +01:00
|
|
|
}
|
|
|
|
|
2019-12-31 06:10:50 +01:00
|
|
|
|
2019-03-01 23:50:30 +01:00
|
|
|
/*If obj is wider then the page focus where the "error" is smaller*/
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_coord_t obj_x = obj->coords.x1 - ext->scrl->coords.x1;
|
|
|
|
lv_coord_t obj_w = lv_obj_get_width(obj);
|
2019-03-01 23:50:30 +01:00
|
|
|
lv_coord_t scrlable_x = lv_obj_get_x(ext->scrl);
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_coord_t page_w = lv_obj_get_width(page);
|
2019-03-01 23:50:30 +01:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_coord_t left_err = -(scrlable_x + obj_x);
|
2019-03-01 23:50:30 +01:00
|
|
|
lv_coord_t right_err = scrlable_x + obj_x + obj_w - page_w;
|
|
|
|
|
2020-01-06 22:14:04 +01:00
|
|
|
lv_style_int_t bg_left = lv_obj_get_style_int(page, LV_PAGE_PART_BG, LV_STYLE_PAD_LEFT);
|
|
|
|
lv_style_int_t bg_right = lv_obj_get_style_int(page, LV_PAGE_PART_BG, LV_STYLE_PAD_RIGHT);
|
|
|
|
lv_style_int_t scrl_left = lv_obj_get_style_int(page, LV_PAGE_PART_SCRL, LV_STYLE_PAD_LEFT);
|
|
|
|
lv_style_int_t scrl_right = lv_obj_get_style_int(page, LV_PAGE_PART_SCRL, LV_STYLE_PAD_RIGHT);
|
2019-12-31 06:10:50 +01:00
|
|
|
|
2019-03-13 23:58:33 +01:00
|
|
|
/*Out of the page on the left*/
|
2019-04-04 07:15:40 +02:00
|
|
|
if((obj_w <= page_w && left_err > 0) || (obj_w > page_w && left_err < right_err)) {
|
2019-12-31 06:10:50 +01:00
|
|
|
/*Calculate a new position and let some space on the side*/
|
|
|
|
scrlable_x = -(obj_x - scrl_left - bg_left);
|
|
|
|
scrlable_x += scrl_left;
|
2019-03-01 23:50:30 +01:00
|
|
|
}
|
2019-03-13 23:58:33 +01:00
|
|
|
/*Out of the page on the rigth*/
|
2019-04-04 07:15:40 +02:00
|
|
|
else if((obj_w <= page_w && right_err > 0) || (obj_w > page_w && left_err >= right_err)) {
|
2019-12-31 06:10:50 +01:00
|
|
|
/*Calculate a new position and let some space on teh side*/
|
|
|
|
scrlable_x = -(obj_x + scrl_right + bg_right);
|
|
|
|
scrlable_x -= scrl_right;
|
2019-03-01 23:50:30 +01:00
|
|
|
scrlable_x += page_w - obj_w;
|
2017-11-15 15:50:33 +01:00
|
|
|
}
|
2016-12-17 21:22:16 +01:00
|
|
|
|
2019-06-21 15:26:28 +02:00
|
|
|
if(anim_en == LV_ANIM_OFF || lv_page_get_anim_time(page) == 0) {
|
2017-11-15 15:50:33 +01:00
|
|
|
lv_obj_set_y(ext->scrl, scrlable_y);
|
2019-03-01 23:50:30 +01:00
|
|
|
lv_obj_set_x(ext->scrl, scrlable_x);
|
2018-07-06 16:29:45 +03:00
|
|
|
} else {
|
2019-06-19 00:35:35 +02:00
|
|
|
#if LV_USE_ANIMATION
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_anim_t a;
|
2017-05-02 00:16:48 +02:00
|
|
|
a.act_time = 0;
|
2019-04-04 07:15:40 +02:00
|
|
|
a.start = lv_obj_get_y(ext->scrl);
|
|
|
|
a.end = scrlable_y;
|
2019-06-19 00:40:20 +02:00
|
|
|
a.time = lv_page_get_anim_time(page);
|
2019-06-06 06:05:40 +02:00
|
|
|
a.ready_cb = NULL;
|
2017-05-02 00:16:48 +02:00
|
|
|
a.playback = 0;
|
2019-04-04 07:15:40 +02:00
|
|
|
a.repeat = 0;
|
|
|
|
a.var = ext->scrl;
|
2019-06-06 06:05:40 +02:00
|
|
|
a.path_cb = lv_anim_path_linear;
|
2019-06-12 23:10:54 +02:00
|
|
|
a.exec_cb = (lv_anim_exec_xcb_t)lv_obj_set_y;
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_anim_create(&a);
|
2019-03-01 23:50:30 +01:00
|
|
|
|
2019-06-06 06:05:40 +02:00
|
|
|
a.start = lv_obj_get_x(ext->scrl);
|
|
|
|
a.end = scrlable_x;
|
2019-06-12 23:10:54 +02:00
|
|
|
a.exec_cb = (lv_anim_exec_xcb_t)lv_obj_set_x;
|
2019-03-01 23:50:30 +01:00
|
|
|
lv_anim_create(&a);
|
2017-11-27 17:48:54 +01:00
|
|
|
#endif
|
2017-05-02 00:16:48 +02:00
|
|
|
}
|
2016-12-17 21:22:16 +01:00
|
|
|
}
|
2016-10-04 15:29:52 +02:00
|
|
|
|
2018-08-04 21:48:40 +02:00
|
|
|
/**
|
2018-08-10 01:04:20 +02:00
|
|
|
* Scroll the page horizontally
|
2018-08-04 21:48:40 +02:00
|
|
|
* @param page pointer to a page object
|
2018-08-10 01:04:20 +02:00
|
|
|
* @param dist the distance to scroll (< 0: scroll right; > 0 scroll left)
|
2018-08-04 21:48:40 +02:00
|
|
|
*/
|
2018-08-10 01:04:20 +02:00
|
|
|
void lv_page_scroll_hor(lv_obj_t * page, lv_coord_t dist)
|
2018-08-04 21:48:40 +02:00
|
|
|
{
|
2018-10-05 17:22:49 +02:00
|
|
|
lv_obj_t * scrl = lv_page_get_scrl(page);
|
2018-08-04 21:48:40 +02:00
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_ANIMATION
|
2018-10-05 17:22:49 +02:00
|
|
|
lv_anim_t a;
|
2019-04-04 07:15:40 +02:00
|
|
|
a.var = scrl;
|
|
|
|
a.start = lv_obj_get_x(scrl);
|
|
|
|
a.end = a.start + dist;
|
2019-06-12 23:10:54 +02:00
|
|
|
a.exec_cb = (lv_anim_exec_xcb_t)lv_obj_set_x;
|
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 = LV_PAGE_SCROLL_ANIM_TIME;
|
|
|
|
a.playback = 0;
|
2018-10-05 17:22:49 +02:00
|
|
|
a.playback_pause = 0;
|
2019-04-04 07:15:40 +02:00
|
|
|
a.repeat = 0;
|
|
|
|
a.repeat_pause = 0;
|
2018-10-05 17:22:49 +02:00
|
|
|
lv_anim_create(&a);
|
2018-08-04 21:48:40 +02:00
|
|
|
#else
|
2018-10-05 17:22:49 +02:00
|
|
|
lv_obj_set_x(scrl, lv_obj_get_x(scrl) + dist);
|
2018-08-04 21:48:40 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-10 01:04:20 +02:00
|
|
|
* Scroll the page vertically
|
2018-08-04 21:48:40 +02:00
|
|
|
* @param page pointer to a page object
|
2018-08-10 01:04:20 +02:00
|
|
|
* @param dist the distance to scroll (< 0: scroll down; > 0 scroll up)
|
2018-08-04 21:48:40 +02:00
|
|
|
*/
|
2018-08-10 01:04:20 +02:00
|
|
|
void lv_page_scroll_ver(lv_obj_t * page, lv_coord_t dist)
|
2018-08-04 21:48:40 +02:00
|
|
|
{
|
2018-10-05 17:22:49 +02:00
|
|
|
lv_obj_t * scrl = lv_page_get_scrl(page);
|
2018-08-10 01:04:20 +02:00
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_ANIMATION
|
2018-10-05 17:22:49 +02:00
|
|
|
lv_anim_t a;
|
2019-04-04 07:15:40 +02:00
|
|
|
a.var = scrl;
|
|
|
|
a.start = lv_obj_get_y(scrl);
|
|
|
|
a.end = a.start + dist;
|
2019-06-12 23:10:54 +02:00
|
|
|
a.exec_cb = (lv_anim_exec_xcb_t)lv_obj_set_y;
|
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 = LV_PAGE_SCROLL_ANIM_TIME;
|
|
|
|
a.playback = 0;
|
2018-10-05 17:22:49 +02:00
|
|
|
a.playback_pause = 0;
|
2019-04-04 07:15:40 +02:00
|
|
|
a.repeat = 0;
|
|
|
|
a.repeat_pause = 0;
|
2018-10-05 17:22:49 +02:00
|
|
|
lv_anim_create(&a);
|
2018-08-04 21:48:40 +02:00
|
|
|
#else
|
2019-02-08 10:20:05 -05:00
|
|
|
lv_obj_set_y(scrl, lv_obj_get_y(scrl) + dist);
|
2018-08-04 21:48:40 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-11-25 09:54:13 +01:00
|
|
|
/**
|
|
|
|
* Not intended to use directly by the user but by other object types internally.
|
2019-09-17 16:07:30 +02:00
|
|
|
* Start an edge flash animation.
|
2018-11-25 09:54:13 +01:00
|
|
|
* @param page
|
2019-09-17 16:07:30 +02:00
|
|
|
* @param edge the edge to flash. Can be `LV_PAGE_EDGE_LEFT/RIGHT/TOP/BOTTOM`
|
2018-11-25 09:54:13 +01:00
|
|
|
*/
|
2019-09-17 16:07:30 +02:00
|
|
|
void lv_page_start_edge_flash(lv_obj_t * page, lv_page_edge_t edge)
|
2018-11-25 09:54:13 +01:00
|
|
|
{
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_ANIMATION
|
2018-11-25 09:54:13 +01:00
|
|
|
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
|
2019-09-17 16:07:30 +02:00
|
|
|
if(ext->edge_flash.enabled == 0) return;
|
|
|
|
|
|
|
|
if(ext->edge_flash.left_ip ||
|
|
|
|
ext->edge_flash.right_ip ||
|
|
|
|
ext->edge_flash.top_ip ||
|
|
|
|
ext->edge_flash.bottom_ip) {
|
|
|
|
return;
|
2018-11-25 09:54:13 +01:00
|
|
|
}
|
2019-09-17 16:07:30 +02:00
|
|
|
|
|
|
|
lv_anim_t a;
|
|
|
|
a.var = page;
|
|
|
|
a.start = 0;
|
|
|
|
a.end = LV_PAGE_END_FLASH_SIZE;
|
|
|
|
a.exec_cb = (lv_anim_exec_xcb_t)edge_flash_anim;
|
|
|
|
a.path_cb = lv_anim_path_linear;
|
|
|
|
a.ready_cb = edge_flash_anim_end;
|
|
|
|
a.act_time = 0;
|
|
|
|
a.time = LV_PAGE_END_ANIM_TIME;
|
|
|
|
a.playback = 1;
|
|
|
|
a.playback_pause = LV_PAGE_END_ANIM_WAIT_TIME;
|
|
|
|
a.repeat = 0;
|
|
|
|
a.repeat_pause = 0;
|
|
|
|
lv_anim_create(&a);
|
|
|
|
|
|
|
|
switch(edge) {
|
|
|
|
case LV_PAGE_EDGE_BOTTOM: ext->edge_flash.bottom_ip = 1; break;
|
|
|
|
case LV_PAGE_EDGE_TOP: ext->edge_flash.top_ip = 1; break;
|
|
|
|
case LV_PAGE_EDGE_LEFT: ext->edge_flash.left_ip = 1; break;
|
|
|
|
case LV_PAGE_EDGE_RIGHT: ext->edge_flash.right_ip = 1; break;
|
|
|
|
}
|
|
|
|
|
2019-06-20 06:20:23 +02:00
|
|
|
#else
|
2019-06-27 07:16:15 +02:00
|
|
|
(void)page; /*Unused*/
|
2018-12-10 15:35:57 -05:00
|
|
|
#endif
|
2018-11-25 09:54:13 +01:00
|
|
|
}
|
|
|
|
|
2016-06-08 07:25:08 +02:00
|
|
|
/**********************
|
|
|
|
* STATIC FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
2016-10-04 09:45:39 +02:00
|
|
|
/**
|
|
|
|
* Handle the drawing related tasks of the pages
|
2016-10-07 11:15:46 +02:00
|
|
|
* @param page pointer to an object
|
2019-09-06 19:53:39 +02:00
|
|
|
* @param clip_area the object will be drawn only in this area
|
2016-10-04 09:45:39 +02:00
|
|
|
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
|
|
|
* (return 'true' if yes)
|
|
|
|
* LV_DESIGN_DRAW: draw the object (always return 'true')
|
|
|
|
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
|
2019-09-06 19:53:39 +02:00
|
|
|
* @param return an element of `lv_design_res_t`
|
2016-10-04 09:45:39 +02:00
|
|
|
*/
|
2019-09-06 19:53:39 +02:00
|
|
|
static lv_design_res_t lv_page_design(lv_obj_t * page, const lv_area_t * clip_area, lv_design_mode_t mode)
|
2016-10-04 09:45:39 +02:00
|
|
|
{
|
|
|
|
if(mode == LV_DESIGN_COVER_CHK) {
|
2019-09-06 19:53:39 +02:00
|
|
|
return ancestor_design(page, clip_area, mode);
|
2019-04-11 19:59:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if(mode == LV_DESIGN_DRAW_MAIN) {
|
2019-12-31 06:10:50 +01:00
|
|
|
lv_draw_rect_dsc_t draw_dsc;
|
|
|
|
lv_draw_rect_dsc_init(&draw_dsc);
|
|
|
|
lv_obj_init_draw_rect_dsc(page, LV_PAGE_PART_BG, &draw_dsc);
|
2017-12-02 20:50:05 +01:00
|
|
|
|
2019-12-31 06:10:50 +01:00
|
|
|
/*Draw without border first*/
|
|
|
|
draw_dsc.border_width = 0;
|
|
|
|
|
|
|
|
lv_draw_rect(&page->coords, clip_area, &draw_dsc);
|
|
|
|
|
2020-01-06 22:14:04 +01:00
|
|
|
if(lv_obj_get_style_int(page, LV_PAGE_PART_BG, LV_STYLE_CLIP_CORNER)) {
|
2019-12-31 06:10:50 +01:00
|
|
|
lv_draw_mask_radius_param_t * mp = lv_mem_buf_get(sizeof(lv_draw_mask_radius_param_t));
|
|
|
|
|
2020-01-06 22:14:04 +01:00
|
|
|
lv_coord_t r = lv_obj_get_style_int(page, LV_PAGE_PART_BG, LV_STYLE_RADIUS);
|
2019-12-31 06:10:50 +01:00
|
|
|
|
|
|
|
lv_draw_mask_radius_init(mp, &page->coords, r, false);
|
2019-11-14 07:16:24 +01:00
|
|
|
/*Add the mask and use `page+8` as custom id. Don't use `page` directly because it might be sued by the user*/
|
|
|
|
lv_draw_mask_add(mp, page + 8);
|
2019-09-06 19:53:39 +02:00
|
|
|
}
|
2019-05-09 15:55:01 +02:00
|
|
|
} else if(mode == LV_DESIGN_DRAW_POST) {
|
2019-12-31 06:10:50 +01:00
|
|
|
lv_draw_rect_dsc_t draw_dsc;
|
|
|
|
lv_draw_rect_dsc_init(&draw_dsc);
|
|
|
|
lv_obj_init_draw_rect_dsc(page, LV_PAGE_PART_BG, &draw_dsc);
|
2017-12-02 20:50:05 +01:00
|
|
|
|
2019-12-31 06:10:50 +01:00
|
|
|
/*Draw only a border. It ensures that the page looks "closed" even with overflowing scrollable*/
|
2020-01-01 16:01:31 +01:00
|
|
|
draw_dsc.shadow_width = 0;
|
2019-12-31 06:10:50 +01:00
|
|
|
draw_dsc.bg_opa = LV_OPA_TRANSP;
|
|
|
|
lv_draw_rect(&page->coords, clip_area, &draw_dsc);
|
2016-10-04 09:45:39 +02:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
/*Draw the scrollbars*/
|
2019-12-31 06:10:50 +01:00
|
|
|
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
|
|
|
|
lv_draw_rect_dsc_init(&draw_dsc);
|
2020-01-01 18:46:22 +01:00
|
|
|
lv_obj_init_draw_rect_dsc(page, LV_PAGE_PART_SCRLBAR, &draw_dsc);
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_area_t sb_area;
|
2018-08-10 01:04:20 +02:00
|
|
|
if(ext->sb.hor_draw && (ext->sb.mode & LV_SB_MODE_HIDE) == 0) {
|
2018-06-19 09:49:58 +02:00
|
|
|
/*Convert the relative coordinates to absolute*/
|
2017-11-28 16:15:13 +01:00
|
|
|
lv_area_copy(&sb_area, &ext->sb.hor_area);
|
2018-06-19 09:49:58 +02:00
|
|
|
sb_area.x1 += page->coords.x1;
|
2017-12-02 20:50:05 +01:00
|
|
|
sb_area.y1 += page->coords.y1;
|
|
|
|
sb_area.x2 += page->coords.x1;
|
|
|
|
sb_area.y2 += page->coords.y1;
|
2019-12-31 06:10:50 +01:00
|
|
|
lv_draw_rect(&sb_area, clip_area, &draw_dsc);
|
2018-06-19 09:49:58 +02:00
|
|
|
}
|
2016-10-04 09:45:39 +02:00
|
|
|
|
2018-08-10 01:04:20 +02:00
|
|
|
if(ext->sb.ver_draw && (ext->sb.mode & LV_SB_MODE_HIDE) == 0) {
|
2017-01-04 11:54:39 +01:00
|
|
|
/*Convert the relative coordinates to absolute*/
|
2017-11-28 16:15:13 +01:00
|
|
|
lv_area_copy(&sb_area, &ext->sb.ver_area);
|
2017-12-02 20:50:05 +01:00
|
|
|
sb_area.x1 += page->coords.x1;
|
|
|
|
sb_area.y1 += page->coords.y1;
|
|
|
|
sb_area.x2 += page->coords.x1;
|
|
|
|
sb_area.y2 += page->coords.y1;
|
2019-12-31 06:10:50 +01:00
|
|
|
lv_draw_rect(&sb_area, clip_area, &draw_dsc);
|
2018-06-19 09:49:58 +02:00
|
|
|
}
|
2018-11-24 20:31:06 +01:00
|
|
|
|
2019-05-20 18:31:47 -07:00
|
|
|
#if LV_USE_ANIMATION
|
|
|
|
{
|
|
|
|
lv_coord_t page_w = lv_obj_get_width(page);
|
|
|
|
lv_coord_t page_h = lv_obj_get_height(page);
|
|
|
|
|
|
|
|
lv_area_t flash_area;
|
|
|
|
|
|
|
|
if(ext->edge_flash.top_ip) {
|
|
|
|
flash_area.x1 = page->coords.x1 - page_w;
|
|
|
|
flash_area.x2 = page->coords.x2 + page_w;
|
|
|
|
flash_area.y1 = page->coords.y1 - 3 * page_w + ext->edge_flash.state;
|
|
|
|
flash_area.y2 = page->coords.y1 + ext->edge_flash.state;
|
|
|
|
} else if(ext->edge_flash.bottom_ip) {
|
|
|
|
flash_area.x1 = page->coords.x1 - page_w;
|
|
|
|
flash_area.x2 = page->coords.x2 + page_w;
|
|
|
|
flash_area.y1 = page->coords.y2 - ext->edge_flash.state;
|
|
|
|
flash_area.y2 = page->coords.y2 + 3 * page_w - ext->edge_flash.state;
|
|
|
|
} else if(ext->edge_flash.right_ip) {
|
|
|
|
flash_area.x1 = page->coords.x2 - ext->edge_flash.state;
|
|
|
|
flash_area.x2 = page->coords.x2 + 3 * page_h - ext->edge_flash.state;
|
|
|
|
flash_area.y1 = page->coords.y1 - page_h;
|
|
|
|
flash_area.y2 = page->coords.y2 + page_h;
|
|
|
|
} else if(ext->edge_flash.left_ip) {
|
|
|
|
flash_area.x1 = page->coords.x1 - 3 * page_h + ext->edge_flash.state;
|
|
|
|
flash_area.x2 = page->coords.x1 + ext->edge_flash.state;
|
|
|
|
flash_area.y1 = page->coords.y1 - page_h;
|
|
|
|
flash_area.y2 = page->coords.y2 + page_h;
|
|
|
|
}
|
2018-11-24 20:31:06 +01:00
|
|
|
|
2019-05-20 18:31:47 -07:00
|
|
|
if(ext->edge_flash.left_ip || ext->edge_flash.right_ip || ext->edge_flash.top_ip ||
|
|
|
|
ext->edge_flash.bottom_ip) {
|
2019-12-31 22:13:32 +01:00
|
|
|
lv_draw_rect_dsc_t edge_draw_dsc;
|
|
|
|
lv_draw_rect_dsc_init(&edge_draw_dsc);
|
|
|
|
lv_obj_init_draw_rect_dsc(page, LV_PAGE_PART_EDGE_FLASH, &edge_draw_dsc);
|
|
|
|
edge_draw_dsc.radius = LV_RADIUS_CIRCLE;
|
|
|
|
uint32_t opa = (edge_draw_dsc.bg_opa * ext->edge_flash.state) / LV_PAGE_END_FLASH_SIZE;
|
|
|
|
edge_draw_dsc.bg_opa = opa;
|
|
|
|
lv_draw_rect(&flash_area, clip_area, &edge_draw_dsc);
|
2019-05-20 18:31:47 -07:00
|
|
|
}
|
2018-11-24 20:31:06 +01:00
|
|
|
}
|
2019-09-06 19:53:39 +02:00
|
|
|
|
2019-12-31 22:13:32 +01:00
|
|
|
#endif
|
2020-01-06 22:14:04 +01:00
|
|
|
if(lv_obj_get_style_int(page, LV_PAGE_PART_BG, LV_STYLE_CLIP_CORNER)) {
|
2019-11-14 07:16:24 +01:00
|
|
|
void * param = lv_draw_mask_remove_custom(page + 8);
|
2019-11-19 06:25:14 +01:00
|
|
|
lv_mem_buf_release(param);
|
2019-09-06 19:53:39 +02:00
|
|
|
}
|
2018-06-19 09:49:58 +02:00
|
|
|
}
|
2016-10-04 09:45:39 +02:00
|
|
|
|
2019-09-06 19:53:39 +02:00
|
|
|
return LV_DESIGN_RES_OK;
|
2016-10-04 09:45:39 +02:00
|
|
|
}
|
2017-11-05 00:48:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Signal function of the page
|
|
|
|
* @param page pointer to a page 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
|
|
|
|
*/
|
|
|
|
static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param)
|
|
|
|
{
|
|
|
|
lv_res_t res;
|
2020-01-01 21:44:16 +01:00
|
|
|
if(sign == LV_SIGNAL_GET_STYLE) {
|
2020-01-07 23:43:57 +01:00
|
|
|
lv_get_style_info_t * info = param;
|
|
|
|
info->result = lv_page_get_style(page, info->part);
|
|
|
|
if(info->result != NULL) return LV_RES_OK;
|
|
|
|
else return ancestor_signal(page, sign, param);
|
2020-01-05 20:05:11 +01:00
|
|
|
} else if(sign == LV_SIGNAL_GET_STATE) {
|
|
|
|
lv_get_state_info_t * info = param;
|
|
|
|
if(info->part == LV_PAGE_PART_SCRL) info->result = lv_obj_get_state(lv_page_get_scrl(page), LV_CONT_PART_MAIN);
|
|
|
|
else info->result = lv_obj_get_state(page, info->part);
|
2019-12-31 06:10:50 +01:00
|
|
|
return LV_RES_OK;
|
|
|
|
}
|
2017-11-05 00:48:57 +01:00
|
|
|
|
|
|
|
/* Include the ancient signal function */
|
|
|
|
res = ancestor_signal(page, sign, param);
|
2017-11-07 17:00:55 +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, LV_OBJX_NAME);
|
2017-11-05 00:48:57 +01:00
|
|
|
|
2017-11-07 17:00:55 +01:00
|
|
|
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
|
2019-09-17 16:07:30 +02:00
|
|
|
if(sign == LV_SIGNAL_CLEANUP) {
|
|
|
|
/*Check whether the object being deleted is propagating scroll to the parent */
|
|
|
|
if(ext->scroll_prop) {
|
|
|
|
lv_obj_t * parent_page = lv_obj_get_parent(lv_obj_get_parent(page));
|
|
|
|
lv_page_ext_t * parent_ext = lv_obj_get_ext_attr(parent_page);
|
|
|
|
if(parent_ext->scroll_prop_obj == page) {
|
|
|
|
parent_ext->scroll_prop_obj = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*Automatically move children to the scrollable object*/
|
|
|
|
else if(sign == LV_SIGNAL_CHILD_CHG) {
|
|
|
|
lv_obj_t * child;
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_fit_t fit_left = lv_page_get_scrl_fit_left(page);
|
2019-10-11 14:15:38 +02:00
|
|
|
lv_fit_t fit_right = lv_page_get_scrl_fit_right(page);
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_fit_t fit_top = lv_page_get_scrl_fit_top(page);
|
2019-10-17 06:10:29 +02:00
|
|
|
lv_bidi_dir_t base_dir = lv_obj_get_base_dir(page);
|
|
|
|
|
2020-01-06 22:14:04 +01:00
|
|
|
lv_style_int_t scrl_left = lv_obj_get_style_int(page, LV_PAGE_PART_SCRL, LV_STYLE_PAD_LEFT);
|
|
|
|
lv_style_int_t scrl_right = lv_obj_get_style_int(page, LV_PAGE_PART_SCRL, LV_STYLE_PAD_RIGHT);
|
|
|
|
lv_style_int_t scrl_top = lv_obj_get_style_int(page, LV_PAGE_PART_SCRL, LV_STYLE_PAD_TOP);
|
2019-12-31 06:10:50 +01:00
|
|
|
|
2019-10-17 06:10:29 +02:00
|
|
|
child = lv_obj_get_child(page, NULL);
|
2017-11-07 17:00:55 +01:00
|
|
|
while(child != NULL) {
|
|
|
|
if(lv_obj_is_protected(child, LV_PROTECT_PARENT) == false) {
|
|
|
|
lv_obj_t * tmp = child;
|
2019-06-06 06:05:40 +02:00
|
|
|
child = lv_obj_get_child(page, child); /*Get the next child before move this*/
|
2019-02-24 06:41:00 +01:00
|
|
|
|
2019-10-11 14:15:38 +02:00
|
|
|
/* Reposition the child to take padding into account (Only if it's on (0;0) or (widht;height) coordinates now)
|
2019-04-19 06:10:01 +02:00
|
|
|
* It's required to keep new the object on the same coordinate if FIT is enabled.*/
|
2019-10-17 06:10:29 +02:00
|
|
|
if((tmp->coords.x1 == page->coords.x1) &&
|
2019-10-31 20:19:07 -04:00
|
|
|
(fit_left == LV_FIT_TIGHT || fit_left == LV_FIT_FILL) &&
|
2019-10-17 06:10:29 +02:00
|
|
|
base_dir != LV_BIDI_DIR_RTL) {
|
2019-12-31 06:10:50 +01:00
|
|
|
tmp->coords.x1 += scrl_left;
|
|
|
|
tmp->coords.x2 += scrl_left;
|
2019-10-11 14:15:38 +02:00
|
|
|
}
|
2019-10-17 06:10:29 +02:00
|
|
|
else if((tmp->coords.x2 == page->coords.x2) &&
|
|
|
|
(fit_right == LV_FIT_TIGHT || fit_right == LV_FIT_FILL)
|
|
|
|
&& base_dir == LV_BIDI_DIR_RTL) {
|
2019-12-31 06:10:50 +01:00
|
|
|
tmp->coords.x1 -= scrl_right;
|
|
|
|
tmp->coords.x2 -= scrl_right;
|
2019-04-19 06:10:01 +02:00
|
|
|
}
|
|
|
|
if((tmp->coords.y1 == page->coords.y1) && (fit_top == LV_FIT_TIGHT || fit_top == LV_FIT_FILL)) {
|
2019-12-31 06:10:50 +01:00
|
|
|
tmp->coords.y1 += scrl_top;
|
|
|
|
tmp->coords.y2 += scrl_top;
|
2019-04-19 06:10:01 +02:00
|
|
|
}
|
2017-11-07 17:00:55 +01:00
|
|
|
lv_obj_set_parent(tmp, ext->scrl);
|
|
|
|
} else {
|
|
|
|
child = lv_obj_get_child(page, child);
|
2017-11-05 00:48:57 +01:00
|
|
|
}
|
|
|
|
}
|
2018-06-19 09:49:58 +02:00
|
|
|
} else if(sign == LV_SIGNAL_STYLE_CHG) {
|
2020-01-05 01:16:13 +01:00
|
|
|
ext->scrl->signal_cb(ext->scrl, LV_SIGNAL_COORD_CHG, &ext->scrl->coords);
|
2017-11-07 17:00:55 +01:00
|
|
|
|
2020-01-06 22:14:04 +01:00
|
|
|
lv_style_int_t sb_width = lv_obj_get_style_int(page, LV_PAGE_PART_SCRLBAR, LV_STYLE_SIZE);
|
2019-12-31 06:10:50 +01:00
|
|
|
lv_area_set_height(&ext->sb.hor_area, sb_width);
|
|
|
|
lv_area_set_width(&ext->sb.ver_area, sb_width);
|
|
|
|
|
2017-11-07 17:00:55 +01:00
|
|
|
/*The scrollbars are important only if they are visible now*/
|
|
|
|
if(ext->sb.hor_draw || ext->sb.ver_draw) lv_page_sb_refresh(page);
|
|
|
|
|
|
|
|
/*Refresh the ext. size because the scrollbars might be positioned out of the page*/
|
2019-04-11 06:26:41 +02:00
|
|
|
lv_obj_refresh_ext_draw_pad(page);
|
2020-01-05 01:16:13 +01:00
|
|
|
} else if(sign == LV_SIGNAL_COORD_CHG) {
|
2017-11-07 17:00:55 +01:00
|
|
|
/*Refresh the scrollbar and notify the scrl if the size is changed*/
|
2017-11-28 16:15:13 +01:00
|
|
|
if(ext->scrl != NULL && (lv_obj_get_width(page) != lv_area_get_width(param) ||
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_obj_get_height(page) != lv_area_get_height(param))) {
|
2017-11-05 00:48:57 +01:00
|
|
|
/*If no hor_fit enabled set the scrollable's width to the page's width*/
|
2020-01-05 01:16:13 +01:00
|
|
|
ext->scrl->signal_cb(ext->scrl, LV_SIGNAL_COORD_CHG, &ext->scrl->coords);
|
2017-11-07 17:00:55 +01:00
|
|
|
|
2017-11-05 00:48:57 +01:00
|
|
|
/*The scrollbars are important only if they are visible now*/
|
|
|
|
if(ext->sb.hor_draw || ext->sb.ver_draw) lv_page_sb_refresh(page);
|
|
|
|
}
|
2019-04-11 06:26:41 +02:00
|
|
|
} else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) {
|
2019-12-31 06:10:50 +01:00
|
|
|
|
2020-01-06 22:14:04 +01:00
|
|
|
lv_style_int_t sb_bottom = lv_obj_get_style_int(page, LV_PAGE_PART_SCRLBAR, LV_STYLE_PAD_BOTTOM);
|
|
|
|
lv_style_int_t sb_right = lv_obj_get_style_int(page, LV_PAGE_PART_SCRLBAR, LV_STYLE_PAD_RIGHT);
|
2019-12-31 06:10:50 +01:00
|
|
|
|
2017-11-07 17:00:55 +01:00
|
|
|
/*Ensure ext. size for the scrollbars if they are out of the page*/
|
2019-12-31 06:10:50 +01:00
|
|
|
if(page->ext_draw_pad < (-sb_right)) page->ext_draw_pad = -sb_right;
|
|
|
|
if(page->ext_draw_pad < (-sb_bottom)) page->ext_draw_pad = -sb_bottom;
|
2019-03-19 07:15:00 +01:00
|
|
|
} else if(sign == LV_SIGNAL_CONTROL) {
|
2019-04-04 07:15:40 +02:00
|
|
|
uint32_t c = *((uint32_t *)param);
|
2018-07-12 23:38:27 +02:00
|
|
|
|
2019-06-21 15:26:28 +02:00
|
|
|
if(c == LV_KEY_DOWN) {
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_page_scroll_ver(page, -lv_obj_get_height(page) / 4);
|
2019-06-21 15:26:28 +02:00
|
|
|
} else if(c == LV_KEY_UP) {
|
2018-10-05 17:22:49 +02:00
|
|
|
lv_page_scroll_ver(page, lv_obj_get_height(page) / 4);
|
2019-06-21 15:26:28 +02:00
|
|
|
} else if(c == LV_KEY_RIGHT) {
|
2019-04-04 07:15:40 +02:00
|
|
|
/*If the page can't be scrolled horizontally because it's not wide enough then scroll it
|
|
|
|
* vertically*/
|
|
|
|
if(lv_page_get_scrl_width(page) <= lv_obj_get_width(page))
|
|
|
|
lv_page_scroll_ver(page, -lv_obj_get_height(page) / 4);
|
|
|
|
else
|
|
|
|
lv_page_scroll_hor(page, -lv_obj_get_width(page) / 4);
|
2019-06-21 15:26:28 +02:00
|
|
|
} else if(c == LV_KEY_LEFT) {
|
2019-04-04 07:15:40 +02:00
|
|
|
/*If the page can't be scrolled horizontally because it's not wide enough then scroll it
|
|
|
|
* vertically*/
|
|
|
|
if(lv_page_get_scrl_width(page) <= lv_obj_get_width(page))
|
|
|
|
lv_page_scroll_ver(page, lv_obj_get_height(page) / 4);
|
|
|
|
else
|
|
|
|
lv_page_scroll_hor(page, lv_obj_get_width(page) / 4);
|
2018-07-06 17:12:06 +03:00
|
|
|
}
|
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-06-21 15:26:28 +02:00
|
|
|
*editable = true;
|
2018-02-28 15:37:41 +01:00
|
|
|
}
|
2017-11-05 00:48:57 +01:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
return res;
|
2017-11-05 00:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Signal function of the scrollable part of a page
|
|
|
|
* @param scrl pointer to the scrollable 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
|
|
|
|
*/
|
|
|
|
static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void * param)
|
|
|
|
{
|
2019-12-31 06:10:50 +01:00
|
|
|
|
|
|
|
if(sign == LV_SIGNAL_GET_STYLE) {
|
|
|
|
return ancestor_signal(scrl, sign, param);
|
|
|
|
}
|
|
|
|
|
2017-11-05 00:48:57 +01:00
|
|
|
lv_res_t res;
|
|
|
|
|
|
|
|
/* Include the ancient signal function */
|
|
|
|
res = ancestor_signal(scrl, sign, param);
|
2020-01-10 18:16:20 +01:00
|
|
|
|
2017-11-07 17:00:55 +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-11-05 00:48:57 +01:00
|
|
|
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_obj_t * page = lv_obj_get_parent(scrl);
|
|
|
|
lv_page_ext_t * page_ext = lv_obj_get_ext_attr(page);
|
2017-11-05 00:48:57 +01:00
|
|
|
|
2020-01-05 01:16:13 +01:00
|
|
|
if(sign == LV_SIGNAL_COORD_CHG) {
|
2017-11-07 17:00:55 +01:00
|
|
|
/*Limit the position of the scrollable object to be always visible
|
|
|
|
* (Do not let its edge inner then its parent respective edge)*/
|
2018-11-07 20:41:52 +01:00
|
|
|
lv_coord_t new_x = lv_obj_get_x(scrl);
|
|
|
|
lv_coord_t new_y = lv_obj_get_y(scrl);
|
2019-04-04 07:15:40 +02:00
|
|
|
bool refr_x = false;
|
|
|
|
bool refr_y = false;
|
2018-11-07 20:41:52 +01:00
|
|
|
lv_area_t page_coords;
|
|
|
|
lv_area_t scrl_coords;
|
2018-11-07 20:58:36 +01:00
|
|
|
lv_obj_get_coords(scrl, &scrl_coords);
|
|
|
|
lv_obj_get_coords(page, &page_coords);
|
|
|
|
|
2018-11-07 20:41:52 +01:00
|
|
|
lv_obj_t * page_parent = lv_obj_get_parent(page);
|
|
|
|
|
2019-09-17 14:38:55 +02:00
|
|
|
/*Handle scroll propagation*/
|
2018-11-07 20:41:52 +01:00
|
|
|
lv_indev_t * indev = lv_indev_get_act();
|
2019-09-17 16:07:30 +02:00
|
|
|
if(page_ext->scroll_prop && indev) {
|
2019-09-17 14:38:55 +02:00
|
|
|
lv_point_t * drag_sum = &indev->proc.types.pointer.drag_sum;
|
|
|
|
lv_page_ext_t * parent_ext = lv_obj_get_ext_attr(lv_obj_get_parent(page_parent));
|
|
|
|
if(parent_ext->scroll_prop_obj == NULL) {
|
2019-09-18 16:03:29 +02:00
|
|
|
/*If the dragging just started or scroll is already propagated to this object
|
|
|
|
* enable the scroll propagation if the conditions are met*/
|
|
|
|
if((lv_indev_is_dragging(indev) == false || page_ext->scroll_prop_obj) && (drag_sum->y || drag_sum->x)) {
|
2019-09-17 14:38:55 +02:00
|
|
|
/*Propagate vertically?*/
|
2019-09-17 16:07:30 +02:00
|
|
|
if((drag_sum->y > 0 && lv_page_on_edge(page, LV_PAGE_EDGE_TOP)) ||
|
|
|
|
(drag_sum->y < 0 && lv_page_on_edge(page, LV_PAGE_EDGE_BOTTOM))) {
|
|
|
|
lv_obj_set_drag_parent(page, true);
|
|
|
|
lv_obj_set_drag_parent(scrl, true);
|
|
|
|
parent_ext->scroll_prop_obj = page;
|
2019-09-17 14:38:55 +02:00
|
|
|
}
|
|
|
|
/*Propagate horizontally?*/
|
2019-09-17 16:07:30 +02:00
|
|
|
if((drag_sum->x > 0 && lv_page_on_edge(page, LV_PAGE_EDGE_LEFT)) ||
|
|
|
|
(drag_sum->x < 0 && lv_page_on_edge(page, LV_PAGE_EDGE_RIGHT))) {
|
|
|
|
lv_obj_set_drag_parent(page, true);
|
|
|
|
lv_obj_set_drag_parent(scrl, true);
|
|
|
|
parent_ext->scroll_prop_obj = page;
|
2019-09-17 14:38:55 +02:00
|
|
|
}
|
2018-11-07 20:41:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-07 17:00:55 +01:00
|
|
|
|
2020-01-06 22:14:04 +01:00
|
|
|
lv_style_int_t left = lv_obj_get_style_int(page, LV_PAGE_PART_BG, LV_STYLE_PAD_LEFT);
|
|
|
|
lv_style_int_t right = lv_obj_get_style_int(page, LV_PAGE_PART_BG, LV_STYLE_PAD_RIGHT);
|
|
|
|
lv_style_int_t top = lv_obj_get_style_int(page, LV_PAGE_PART_BG, LV_STYLE_PAD_TOP);
|
|
|
|
lv_style_int_t bottom = lv_obj_get_style_int(page, LV_PAGE_PART_BG, LV_STYLE_PAD_BOTTOM);
|
2019-12-31 06:10:50 +01:00
|
|
|
|
2017-11-07 17:00:55 +01:00
|
|
|
/*scrollable width smaller then page width? -> align to left*/
|
2019-12-31 06:10:50 +01:00
|
|
|
if(lv_area_get_width(&scrl_coords) + left +right <= lv_area_get_width(&page_coords)) {
|
|
|
|
if(scrl_coords.x1 != page_coords.x1 + left) {
|
|
|
|
new_x = left;
|
2017-11-07 17:00:55 +01:00
|
|
|
refr_x = true;
|
2017-11-05 00:48:57 +01:00
|
|
|
}
|
2017-11-07 17:00:55 +01:00
|
|
|
} else {
|
|
|
|
/*The edges of the scrollable can not be in the page (minus hpad) */
|
2019-12-31 06:10:50 +01:00
|
|
|
if(scrl_coords.x2 < page_coords.x2 - right) {
|
|
|
|
new_x = lv_area_get_width(&page_coords) - lv_area_get_width(&scrl_coords) - right; /* Right align */
|
2018-06-19 09:49:58 +02:00
|
|
|
refr_x = true;
|
2019-09-17 16:07:30 +02:00
|
|
|
lv_page_start_edge_flash(page, LV_PAGE_EDGE_RIGHT);
|
2019-12-31 06:10:50 +01:00
|
|
|
} else if(scrl_coords.x1 > page_coords.x1 + left) {
|
|
|
|
new_x = left; /*Left align*/
|
2017-11-07 17:00:55 +01:00
|
|
|
refr_x = true;
|
2019-09-17 16:07:30 +02:00
|
|
|
lv_page_start_edge_flash(page, LV_PAGE_EDGE_LEFT);
|
2017-11-07 17:00:55 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-05 00:48:57 +01:00
|
|
|
|
2019-03-23 01:05:41 +01:00
|
|
|
/*scrollable height smaller then page height? -> align to top*/
|
2019-12-31 06:10:50 +01:00
|
|
|
if(lv_area_get_height(&scrl_coords) + top + bottom <= lv_area_get_height(&page_coords)) {
|
|
|
|
if(scrl_coords.y1 != page_coords.y1 + top) {
|
|
|
|
new_y = top;
|
2017-11-07 17:00:55 +01:00
|
|
|
refr_y = true;
|
2017-11-05 00:48:57 +01:00
|
|
|
}
|
2017-11-07 17:00:55 +01:00
|
|
|
} else {
|
|
|
|
/*The edges of the scrollable can not be in the page (minus vpad) */
|
2019-12-31 06:10:50 +01:00
|
|
|
if(scrl_coords.y2 < page_coords.y2 - bottom) {
|
|
|
|
new_y = lv_area_get_height(&page_coords) - lv_area_get_height(&scrl_coords) - bottom; /* Bottom align */
|
2018-06-19 09:49:58 +02:00
|
|
|
refr_y = true;
|
2019-09-17 16:07:30 +02:00
|
|
|
lv_page_start_edge_flash(page, LV_PAGE_EDGE_BOTTOM);
|
2019-12-31 06:10:50 +01:00
|
|
|
} else if(scrl_coords.y1 > page_coords.y1 + top) {
|
|
|
|
new_y = top; /*Top align*/
|
2017-11-07 17:00:55 +01:00
|
|
|
refr_y = true;
|
2019-09-17 16:07:30 +02:00
|
|
|
lv_page_start_edge_flash(page, LV_PAGE_EDGE_TOP);
|
2017-11-05 00:48:57 +01:00
|
|
|
}
|
|
|
|
}
|
2018-11-07 20:41:52 +01:00
|
|
|
|
2018-11-07 20:58:36 +01:00
|
|
|
if(refr_x || refr_y) {
|
2017-11-07 17:00:55 +01:00
|
|
|
lv_obj_set_pos(scrl, new_x, new_y);
|
|
|
|
}
|
|
|
|
|
|
|
|
lv_page_sb_refresh(page);
|
2019-04-04 07:15:40 +02:00
|
|
|
} else if(sign == LV_SIGNAL_DRAG_END) {
|
2018-11-07 20:41:52 +01:00
|
|
|
|
|
|
|
/*Scroll propagation is finished on drag end*/
|
2019-09-17 14:38:55 +02:00
|
|
|
if(page_ext->scroll_prop_obj) {
|
2019-09-17 16:07:30 +02:00
|
|
|
lv_obj_t * scroller_page = page_ext->scroll_prop_obj;
|
2019-09-17 14:38:55 +02:00
|
|
|
page_ext->scroll_prop_obj = NULL;
|
2019-09-17 16:07:30 +02:00
|
|
|
lv_obj_set_drag_parent(scroller_page, false);
|
|
|
|
lv_obj_set_drag_parent(lv_page_get_scrl(scroller_page), false);
|
|
|
|
|
|
|
|
/*The scrolling can be chained so stop all of them*/
|
|
|
|
lv_page_ext_t * scroller_ext = lv_obj_get_ext_attr(scroller_page);
|
|
|
|
while(scroller_ext->scroll_prop_obj) {
|
|
|
|
scroller_page = scroller_ext->scroll_prop_obj;
|
|
|
|
scroller_ext->scroll_prop_obj = NULL;
|
|
|
|
lv_obj_set_drag_parent(scroller_page, false);
|
|
|
|
lv_obj_set_drag_parent(lv_page_get_scrl(scroller_page), false);
|
|
|
|
|
|
|
|
scroller_ext = lv_obj_get_ext_attr(scroller_page);
|
|
|
|
}
|
2019-09-17 14:38:55 +02:00
|
|
|
}
|
2018-11-07 20:41:52 +01:00
|
|
|
|
2017-11-07 17:00:55 +01:00
|
|
|
/*Hide scrollbars if required*/
|
2017-11-18 00:18:19 +01:00
|
|
|
if(page_ext->sb.mode == LV_SB_MODE_DRAG) {
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_disp_t * disp = lv_obj_get_disp(page);
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_area_t sb_area_tmp;
|
2017-11-07 17:00:55 +01:00
|
|
|
if(page_ext->sb.hor_draw) {
|
2017-11-28 16:15:13 +01:00
|
|
|
lv_area_copy(&sb_area_tmp, &page_ext->sb.hor_area);
|
2017-11-07 17:00:55 +01:00
|
|
|
sb_area_tmp.x1 += page->coords.x1;
|
|
|
|
sb_area_tmp.y1 += page->coords.y1;
|
2018-07-12 17:16:14 +02:00
|
|
|
sb_area_tmp.x2 += page->coords.x1;
|
|
|
|
sb_area_tmp.y2 += page->coords.y1;
|
2019-02-12 15:38:13 +01:00
|
|
|
lv_inv_area(disp, &sb_area_tmp);
|
2017-11-07 17:00:55 +01:00
|
|
|
page_ext->sb.hor_draw = 0;
|
2017-11-05 00:48:57 +01:00
|
|
|
}
|
2019-04-04 07:15:40 +02:00
|
|
|
if(page_ext->sb.ver_draw) {
|
2017-11-28 16:15:13 +01:00
|
|
|
lv_area_copy(&sb_area_tmp, &page_ext->sb.ver_area);
|
2017-11-07 17:00:55 +01:00
|
|
|
sb_area_tmp.x1 += page->coords.x1;
|
|
|
|
sb_area_tmp.y1 += page->coords.y1;
|
2018-07-12 17:16:14 +02:00
|
|
|
sb_area_tmp.x2 += page->coords.x1;
|
|
|
|
sb_area_tmp.y2 += page->coords.y1;
|
2019-02-12 15:38:13 +01:00
|
|
|
lv_inv_area(disp, &sb_area_tmp);
|
2017-11-07 17:00:55 +01:00
|
|
|
page_ext->sb.ver_draw = 0;
|
|
|
|
}
|
|
|
|
}
|
2017-11-05 00:48:57 +01:00
|
|
|
}
|
2017-11-15 15:50:33 +01:00
|
|
|
return res;
|
2017-11-05 00:48:57 +01:00
|
|
|
}
|
2017-07-20 01:09:20 +02:00
|
|
|
|
2019-02-26 09:25:46 +01:00
|
|
|
/**
|
|
|
|
* Propagate the input device related event of the scrollable to the parent page background
|
|
|
|
* It is used by default if the scrollable's event is not specified
|
|
|
|
* @param scrl pointer to the page's scrollable object
|
|
|
|
* @param event type of the event
|
2019-03-19 06:30:05 +01:00
|
|
|
* @param data data of the event
|
2019-02-26 09:25:46 +01:00
|
|
|
*/
|
|
|
|
static void scrl_def_event_cb(lv_obj_t * scrl, lv_event_t event)
|
|
|
|
{
|
|
|
|
lv_obj_t * page = lv_obj_get_parent(scrl);
|
|
|
|
|
2019-04-18 06:45:45 +02:00
|
|
|
/*clang-format off*/
|
2019-06-06 06:05:40 +02:00
|
|
|
if(event == LV_EVENT_PRESSED || event == LV_EVENT_PRESSING || event == LV_EVENT_PRESS_LOST ||
|
|
|
|
event == LV_EVENT_RELEASED || event == LV_EVENT_SHORT_CLICKED || event == LV_EVENT_CLICKED ||
|
2019-07-17 12:43:50 +02:00
|
|
|
event == LV_EVENT_LONG_PRESSED || event == LV_EVENT_LONG_PRESSED_REPEAT ||
|
|
|
|
event == LV_EVENT_DRAG_BEGIN || event == LV_EVENT_DRAG_END || event == LV_EVENT_DRAG_THROW_BEGIN) {
|
2019-03-19 06:30:05 +01:00
|
|
|
lv_event_send(page, event, lv_event_get_data());
|
2019-02-26 09:25:46 +01:00
|
|
|
}
|
2019-04-18 06:45:45 +02:00
|
|
|
/*clang-format on*/
|
2019-02-26 09:25:46 +01:00
|
|
|
}
|
|
|
|
|
2020-01-01 15:25:16 +01:00
|
|
|
/**
|
|
|
|
* Get the style descriptor of a part of the object
|
|
|
|
* @param page pointer the object
|
|
|
|
* @param part the part from `lv_page_part_t`. (LV_PAGE_PART_...)
|
|
|
|
* @return pointer to the style descriptor of the specified part
|
|
|
|
*/
|
|
|
|
static lv_style_dsc_t * lv_page_get_style(lv_obj_t * page, uint8_t part)
|
2019-12-31 22:13:32 +01:00
|
|
|
{
|
|
|
|
LV_ASSERT_OBJ(page, LV_OBJX_NAME);
|
|
|
|
|
|
|
|
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
|
|
|
|
lv_style_dsc_t * style_dsc_p;
|
|
|
|
|
2020-01-01 15:25:16 +01:00
|
|
|
switch(part) {
|
2019-12-31 22:13:32 +01:00
|
|
|
case LV_PAGE_PART_BG:
|
|
|
|
style_dsc_p = &page->style_dsc;
|
|
|
|
break;
|
|
|
|
case LV_PAGE_PART_SCRL:
|
|
|
|
style_dsc_p = lv_obj_get_style(ext->scrl, LV_CONT_PART_MAIN);
|
|
|
|
break;
|
2020-01-01 18:46:22 +01:00
|
|
|
case LV_PAGE_PART_SCRLBAR:
|
2019-12-31 22:13:32 +01:00
|
|
|
style_dsc_p = &ext->sb.style;
|
|
|
|
break;
|
|
|
|
#if LV_USE_ANIMATION
|
|
|
|
case LV_PAGE_PART_EDGE_FLASH:
|
|
|
|
style_dsc_p = &ext->edge_flash.style;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
style_dsc_p = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return style_dsc_p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-08 07:25:08 +02:00
|
|
|
/**
|
2016-10-07 11:15:46 +02:00
|
|
|
* Refresh the position and size of the scroll bars.
|
|
|
|
* @param page pointer to a page object
|
2016-06-08 07:25:08 +02:00
|
|
|
*/
|
2016-10-07 11:15:46 +02:00
|
|
|
static void lv_page_sb_refresh(lv_obj_t * page)
|
2016-06-08 07:25:08 +02:00
|
|
|
{
|
2019-04-11 19:59:55 +08:00
|
|
|
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
|
|
|
|
lv_obj_t * scrl = ext->scrl;
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_coord_t size_tmp;
|
|
|
|
lv_coord_t scrl_w = lv_obj_get_width(scrl);
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_coord_t scrl_h = lv_obj_get_height(scrl);
|
|
|
|
lv_coord_t obj_w = lv_obj_get_width(page);
|
|
|
|
lv_coord_t obj_h = lv_obj_get_height(page);
|
2016-10-07 11:15:46 +02:00
|
|
|
|
2020-01-06 22:14:04 +01:00
|
|
|
lv_style_int_t sb_width = lv_obj_get_style_int(page, LV_PAGE_PART_SCRLBAR, LV_STYLE_SIZE);
|
|
|
|
lv_style_int_t sb_right = lv_obj_get_style_int(page, LV_PAGE_PART_SCRLBAR, LV_STYLE_PAD_RIGHT);
|
|
|
|
lv_style_int_t sb_bottom = lv_obj_get_style_int(page, LV_PAGE_PART_SCRLBAR, LV_STYLE_PAD_BOTTOM);
|
2019-12-31 06:10:50 +01:00
|
|
|
|
2020-01-06 22:14:04 +01:00
|
|
|
lv_style_int_t bg_left = lv_obj_get_style_int(page, LV_PAGE_PART_BG, LV_STYLE_PAD_LEFT);
|
|
|
|
lv_style_int_t bg_right = lv_obj_get_style_int(page, LV_PAGE_PART_BG, LV_STYLE_PAD_RIGHT);
|
|
|
|
lv_style_int_t bg_top = lv_obj_get_style_int(page, LV_PAGE_PART_BG, LV_STYLE_PAD_TOP);
|
|
|
|
lv_style_int_t bg_bottom = lv_obj_get_style_int(page, LV_PAGE_PART_BG, LV_STYLE_PAD_BOTTOM);
|
2019-12-31 06:10:50 +01:00
|
|
|
|
2017-11-05 00:48:57 +01:00
|
|
|
/*Always let 'scrollbar width' padding above, under, left and right to the scrollbars
|
|
|
|
* else:
|
|
|
|
* - horizontal and vertical scrollbars can overlap on the corners
|
|
|
|
* - if the page has radius the scrollbar can be out of the radius */
|
2019-12-31 06:10:50 +01:00
|
|
|
lv_coord_t sb_hor_pad = LV_MATH_MAX(sb_width, sb_right);
|
|
|
|
lv_coord_t sb_ver_pad = LV_MATH_MAX(sb_width, sb_bottom);
|
2016-12-21 14:49:23 +01:00
|
|
|
|
2017-11-18 00:18:19 +01:00
|
|
|
if(ext->sb.mode == LV_SB_MODE_OFF) return;
|
2017-11-05 00:48:57 +01:00
|
|
|
|
2017-11-18 00:18:19 +01:00
|
|
|
if(ext->sb.mode == LV_SB_MODE_ON) {
|
2017-11-05 00:48:57 +01:00
|
|
|
ext->sb.hor_draw = 1;
|
|
|
|
ext->sb.ver_draw = 1;
|
2017-01-04 11:54:39 +01:00
|
|
|
}
|
|
|
|
|
2016-12-21 14:49:23 +01:00
|
|
|
/*Invalidate the current (old) scrollbar areas*/
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_disp_t * disp = lv_obj_get_disp(page);
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_area_t sb_area_tmp;
|
2017-11-05 00:48:57 +01:00
|
|
|
if(ext->sb.hor_draw != 0) {
|
2017-11-28 16:15:13 +01:00
|
|
|
lv_area_copy(&sb_area_tmp, &ext->sb.hor_area);
|
2017-10-20 10:17:02 +02:00
|
|
|
sb_area_tmp.x1 += page->coords.x1;
|
|
|
|
sb_area_tmp.y1 += page->coords.y1;
|
2018-07-12 17:16:14 +02:00
|
|
|
sb_area_tmp.x2 += page->coords.x1;
|
|
|
|
sb_area_tmp.y2 += page->coords.y1;
|
2019-02-12 15:38:13 +01:00
|
|
|
lv_inv_area(disp, &sb_area_tmp);
|
2017-01-04 11:54:39 +01:00
|
|
|
}
|
2019-04-04 07:15:40 +02:00
|
|
|
if(ext->sb.ver_draw != 0) {
|
2017-11-28 16:15:13 +01:00
|
|
|
lv_area_copy(&sb_area_tmp, &ext->sb.ver_area);
|
2017-10-20 10:17:02 +02:00
|
|
|
sb_area_tmp.x1 += page->coords.x1;
|
|
|
|
sb_area_tmp.y1 += page->coords.y1;
|
2018-07-12 17:16:14 +02:00
|
|
|
sb_area_tmp.x2 += page->coords.x1;
|
|
|
|
sb_area_tmp.y2 += page->coords.y1;
|
2019-02-12 15:38:13 +01:00
|
|
|
lv_inv_area(disp, &sb_area_tmp);
|
2017-01-04 11:54:39 +01:00
|
|
|
}
|
2016-10-04 09:45:39 +02:00
|
|
|
|
2017-11-18 00:18:19 +01:00
|
|
|
if(ext->sb.mode == LV_SB_MODE_DRAG && lv_indev_is_dragging(lv_indev_get_act()) == false) {
|
2017-11-05 00:48:57 +01:00
|
|
|
ext->sb.hor_draw = 0;
|
|
|
|
ext->sb.ver_draw = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-15 18:58:01 +02:00
|
|
|
/*Full sized horizontal scrollbar*/
|
2019-12-31 06:10:50 +01:00
|
|
|
if(scrl_w <= obj_w - bg_left - bg_right) {
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_area_set_width(&ext->sb.hor_area, obj_w - 2 * sb_hor_pad);
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_area_set_pos(&ext->sb.hor_area, sb_hor_pad,
|
2019-12-31 06:10:50 +01:00
|
|
|
obj_h - sb_width - sb_bottom);
|
2019-04-04 07:15:40 +02:00
|
|
|
if(ext->sb.mode == LV_SB_MODE_AUTO || ext->sb.mode == LV_SB_MODE_DRAG) ext->sb.hor_draw = 0;
|
2019-05-15 18:58:01 +02:00
|
|
|
}
|
|
|
|
/*Smaller horizontal scrollbar*/
|
|
|
|
else {
|
2019-06-06 06:05:40 +02:00
|
|
|
size_tmp =
|
2019-12-31 06:10:50 +01:00
|
|
|
(obj_w * (obj_w - (2 * sb_hor_pad))) / (scrl_w + bg_left + bg_right);
|
2017-11-05 00:48:57 +01:00
|
|
|
if(size_tmp < LV_PAGE_SB_MIN_SIZE) size_tmp = LV_PAGE_SB_MIN_SIZE;
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_area_set_width(&ext->sb.hor_area, size_tmp);
|
2016-06-08 07:25:08 +02:00
|
|
|
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_area_set_pos(&ext->sb.hor_area,
|
|
|
|
sb_hor_pad +
|
2019-12-31 06:10:50 +01:00
|
|
|
(-(lv_obj_get_x(scrl) -bg_left) * (obj_w - size_tmp - 2 * sb_hor_pad)) /
|
2020-01-01 15:25:16 +01:00
|
|
|
(scrl_w + bg_left + bg_right - obj_w),
|
2019-12-31 06:10:50 +01:00
|
|
|
obj_h - sb_width - sb_bottom);
|
2017-01-04 12:07:55 +01:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
if(ext->sb.mode == LV_SB_MODE_AUTO || ext->sb.mode == LV_SB_MODE_DRAG) ext->sb.hor_draw = 1;
|
2016-06-08 07:25:08 +02:00
|
|
|
}
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2019-05-15 18:58:01 +02:00
|
|
|
/*Full sized vertical scroll bar*/
|
2019-12-31 06:10:50 +01:00
|
|
|
if(scrl_h <= obj_h - bg_top - bg_bottom) {
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_area_set_height(&ext->sb.ver_area, obj_h - 2 * sb_ver_pad);
|
|
|
|
lv_area_set_pos(&ext->sb.ver_area,
|
2019-12-31 06:10:50 +01:00
|
|
|
obj_w - sb_width - sb_right, sb_ver_pad);
|
2019-04-04 07:15:40 +02:00
|
|
|
if(ext->sb.mode == LV_SB_MODE_AUTO || ext->sb.mode == LV_SB_MODE_DRAG) ext->sb.ver_draw = 0;
|
2019-05-15 18:58:01 +02:00
|
|
|
}
|
|
|
|
/*Smaller vertical scroll bar*/
|
|
|
|
else {
|
2019-06-06 06:05:40 +02:00
|
|
|
size_tmp =
|
2019-12-31 06:10:50 +01:00
|
|
|
(obj_h * (obj_h - (2 * sb_ver_pad))) / (scrl_h + bg_top + bg_bottom);
|
2017-11-05 00:48:57 +01:00
|
|
|
if(size_tmp < LV_PAGE_SB_MIN_SIZE) size_tmp = LV_PAGE_SB_MIN_SIZE;
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_area_set_height(&ext->sb.ver_area, size_tmp);
|
2016-06-08 07:25:08 +02:00
|
|
|
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_area_set_pos(&ext->sb.ver_area,
|
2019-12-31 06:10:50 +01:00
|
|
|
obj_w - sb_width - sb_right,
|
|
|
|
sb_ver_pad + (-(lv_obj_get_y(scrl) - sb_bottom) *
|
2019-06-06 06:05:40 +02:00
|
|
|
(obj_h - size_tmp - 2 * sb_ver_pad)) /
|
2019-12-31 06:10:50 +01:00
|
|
|
(scrl_h + bg_top + bg_bottom - obj_h));
|
2017-01-04 12:07:55 +01:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
if(ext->sb.mode == LV_SB_MODE_AUTO || ext->sb.mode == LV_SB_MODE_DRAG) ext->sb.ver_draw = 1;
|
2016-06-08 07:25:08 +02:00
|
|
|
}
|
2016-12-21 14:49:23 +01:00
|
|
|
|
|
|
|
/*Invalidate the new scrollbar areas*/
|
2017-11-05 00:48:57 +01:00
|
|
|
if(ext->sb.hor_draw != 0) {
|
2017-11-28 16:15:13 +01:00
|
|
|
lv_area_copy(&sb_area_tmp, &ext->sb.hor_area);
|
2017-10-20 10:17:02 +02:00
|
|
|
sb_area_tmp.x1 += page->coords.x1;
|
|
|
|
sb_area_tmp.y1 += page->coords.y1;
|
2018-07-12 17:16:14 +02:00
|
|
|
sb_area_tmp.x2 += page->coords.x1;
|
|
|
|
sb_area_tmp.y2 += page->coords.y1;
|
2019-02-12 15:38:13 +01:00
|
|
|
lv_inv_area(disp, &sb_area_tmp);
|
2017-01-04 11:54:39 +01:00
|
|
|
}
|
2019-04-04 07:15:40 +02:00
|
|
|
if(ext->sb.ver_draw != 0) {
|
2017-11-28 16:15:13 +01:00
|
|
|
lv_area_copy(&sb_area_tmp, &ext->sb.ver_area);
|
2017-10-20 10:17:02 +02:00
|
|
|
sb_area_tmp.x1 += page->coords.x1;
|
|
|
|
sb_area_tmp.y1 += page->coords.y1;
|
2018-07-12 17:16:14 +02:00
|
|
|
sb_area_tmp.x2 += page->coords.x1;
|
|
|
|
sb_area_tmp.y2 += page->coords.y1;
|
2019-02-12 15:38:13 +01:00
|
|
|
lv_inv_area(disp, &sb_area_tmp);
|
2017-01-04 11:54:39 +01:00
|
|
|
}
|
2016-10-04 15:19:07 +02:00
|
|
|
}
|
2016-10-04 09:45:39 +02:00
|
|
|
|
2019-05-20 09:22:09 -07:00
|
|
|
#if LV_USE_ANIMATION
|
|
|
|
static void edge_flash_anim(void * page, lv_anim_value_t v)
|
2018-11-24 20:31:06 +01:00
|
|
|
{
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
|
2018-11-24 20:31:06 +01:00
|
|
|
ext->edge_flash.state = v;
|
|
|
|
lv_obj_invalidate(page);
|
|
|
|
}
|
|
|
|
|
2019-04-22 08:45:07 +02:00
|
|
|
static void edge_flash_anim_end(lv_anim_t * a)
|
2018-11-24 20:31:06 +01:00
|
|
|
{
|
2019-04-22 08:45:07 +02:00
|
|
|
lv_page_ext_t * ext = lv_obj_get_ext_attr(a->var);
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->edge_flash.top_ip = 0;
|
2018-11-24 20:31:06 +01:00
|
|
|
ext->edge_flash.bottom_ip = 0;
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->edge_flash.left_ip = 0;
|
|
|
|
ext->edge_flash.right_ip = 0;
|
2019-04-22 08:45:07 +02:00
|
|
|
lv_obj_invalidate(a->var);
|
2018-11-24 20:31:06 +01:00
|
|
|
}
|
2019-05-20 09:22:09 -07:00
|
|
|
#endif
|
2018-11-24 20:31:06 +01:00
|
|
|
|
2016-06-08 07:25:08 +02:00
|
|
|
#endif
|