1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00
lvgl/lv_objx/lv_page.c

695 lines
23 KiB
C
Raw Normal View History

2016-06-08 07:25:08 +02:00
/**
* @file lv_page.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_conf.h"
2016-06-08 07:25:08 +02:00
#if USE_LV_PAGE != 0
#include "misc/math/math_base.h"
2016-06-08 07:25:08 +02:00
#include "../lv_objx/lv_page.h"
#include "../lv_objx/lv_rect.h"
#include "../lv_draw/lv_draw.h"
#include "../lv_obj/lv_refr.h"
#include "../lv_misc/anim.h"
2016-06-08 07:25:08 +02:00
/*********************
* DEFINES
*********************/
/*Test configurations*/
#ifndef LV_PAGE_ANIM_FOCUS_TIME
#define LV_PAGE_ANIM_FOCUS_TIME 300 /*List focus animation time [ms] (0: turn off the animation)*/
#endif
2016-06-08 07:25:08 +02:00
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
2016-10-07 11:15:46 +02:00
static void lv_page_sb_refresh(lv_obj_t * main);
static bool lv_page_design(lv_obj_t * page, const area_t * mask, lv_design_mode_t mode);
static bool lv_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void* param);
2016-10-07 11:15:46 +02:00
static void lv_pages_init(void);
2016-06-08 07:25:08 +02:00
/**********************
* STATIC VARIABLES
**********************/
static lv_pages_t lv_pages_def;
static lv_pages_t lv_pages_simple;
static lv_pages_t lv_pages_transp;
2016-10-04 15:29:52 +02:00
static lv_design_f_t ancestor_design_f;
2016-06-08 07:25:08 +02:00
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/*-----------------
* Create function
*-----------------*/
/**
* 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
*/
2016-10-07 11:15:46 +02:00
lv_obj_t * lv_page_create(lv_obj_t * par, lv_obj_t * copy)
2016-06-08 07:25:08 +02:00
{
/*Create the ancestor object*/
2016-10-07 11:15:46 +02:00
lv_obj_t * new_page = lv_rect_create(par, copy);
dm_assert(new_page);
2016-06-08 07:25:08 +02:00
/*Allocate the object type specific extended data*/
2016-10-07 11:15:46 +02:00
lv_page_ext_t * ext = lv_obj_alloc_ext(new_page, sizeof(lv_page_ext_t));
dm_assert(ext);
ext->scrl = NULL;
ext->pr_action = NULL;
ext->rel_action = NULL;
ext->sbh_draw = 0;
ext->sbv_draw = 0;
if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_f(new_page);
2016-06-08 07:25:08 +02:00
/*Init the new page object*/
2016-10-07 11:15:46 +02:00
if(copy == NULL) {
lv_pages_t * pages = lv_pages_get(LV_PAGES_DEF, NULL);
ext->scrl = lv_rect_create(new_page, NULL);
lv_obj_set_signal_f(ext->scrl, lv_scrl_signal);
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_rect_set_fit(ext->scrl, true, true);
lv_obj_set_style(ext->scrl, &pages->scrl_rects);
2016-10-07 11:15:46 +02:00
/* Add the signal function only if 'scrolling' is created
* because everything has to be ready before any signal is received*/
2016-10-07 11:15:46 +02:00
lv_obj_set_signal_f(new_page, lv_page_signal);
lv_obj_set_design_f(new_page, lv_page_design);
lv_obj_set_style(new_page, pages);
2016-06-08 07:25:08 +02:00
} else {
2016-10-07 11:15:46 +02:00
lv_page_ext_t * copy_ext = lv_obj_get_ext(copy);
ext->scrl = lv_rect_create(new_page, copy_ext->scrl);
lv_obj_set_signal_f(ext->scrl, lv_scrl_signal);
lv_page_set_pr_action(new_page, copy_ext->pr_action);
lv_page_set_rel_action(new_page, copy_ext->rel_action);
2016-10-07 11:15:46 +02:00
/* Add the signal function only if 'scrolling' is created
* because everything has to be ready before any signal is received*/
2016-10-07 11:15:46 +02:00
lv_obj_set_signal_f(new_page, lv_page_signal);
lv_obj_set_design_f(new_page, lv_page_design);
/*Refresh the style with new signal function*/
lv_obj_refr_style(new_page);
2016-06-08 07:25:08 +02:00
}
2016-10-07 11:15:46 +02:00
lv_page_sb_refresh(new_page);
2016-06-08 07:25:08 +02:00
2016-10-07 11:15:46 +02:00
return new_page;
2016-06-08 07:25:08 +02:00
}
/**
* Signal function of the page
2016-10-07 11:15:46 +02:00
* @param page pointer to a page object
2016-06-08 07:25:08 +02:00
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
*/
2016-10-07 11:15:46 +02:00
bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param)
2016-06-08 07:25:08 +02:00
{
bool obj_valid = true;
/* Include the ancient signal function */
2016-10-07 11:15:46 +02:00
obj_valid = lv_rect_signal(page, sign, param);
2016-06-08 07:25:08 +02:00
/* The object can be deleted so check its validity and then
* make the object specific signal handling */
if(obj_valid != false) {
2016-10-07 11:15:46 +02:00
lv_page_ext_t * ext = lv_obj_get_ext(page);
lv_pages_t * pages = lv_obj_get_style(page);
lv_obj_t * child;
switch(sign) {
case LV_SIGNAL_CHILD_CHG: /*Move children to the scrollable object*/
2016-10-07 11:15:46 +02:00
child = lv_obj_get_child(page, NULL);
while(child != NULL) {
if(lv_obj_is_protected(child, LV_PROTECT_PARENT) == false) {
lv_obj_t * tmp = child;
2016-10-07 11:15:46 +02:00
child = lv_obj_get_child(page, child); /*Get the next child before move this*/
lv_obj_set_parent(tmp, ext->scrl);
} else {
2016-10-07 11:15:46 +02:00
child = lv_obj_get_child(page, child);
}
}
break;
case LV_SIGNAL_STYLE_CHG:
2016-10-07 11:15:46 +02:00
area_set_height(&ext->sbh, pages->sb_width);
area_set_width(&ext->sbv, pages->sb_width);
lv_obj_set_style(ext->scrl, &pages->scrl_rects);
2016-10-07 11:15:46 +02:00
if(pages->sb_mode == LV_PAGE_SB_MODE_ON) {
ext->sbh_draw = 1;
ext->sbv_draw = 1;
} else {
2016-10-07 11:15:46 +02:00
ext->sbh_draw = 0;
ext->sbv_draw = 0;
}
2016-10-07 11:15:46 +02:00
lv_page_sb_refresh(page);
break;
case LV_SIGNAL_CORD_CHG:
/*Refresh the scrollbar and notify the scrl if the size is changed*/
if(ext->scrl != NULL &&
(lv_obj_get_width(page) != area_get_width(param) ||
lv_obj_get_height(page) != area_get_height(param))) {
ext->scrl->signal_f(ext->scrl, LV_SIGNAL_CORD_CHG, &ext->scrl->cords);
/*The scrolbars are important olny if they are visible now*/
if(ext->sbh_draw != 0 || ext->sbv_draw != 0)
2016-12-20 15:02:23 +01:00
lv_page_sb_refresh(page);
2016-12-20 15:02:23 +01:00
}
break;
2016-12-22 15:00:22 +01:00
case LV_SIGNAL_PRESSED:
if(ext->pr_action != NULL) {
ext->pr_action(page, param);
}
break;
case LV_SIGNAL_RELEASED:
if(lv_dispi_is_dragging(param) == false) {
if(ext->rel_action != NULL) {
ext->rel_action(page, param);
}
}
break;
default:
break;
}
}
return obj_valid;
}
/**
* 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
*/
static bool lv_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void* param)
{
bool obj_valid = true;
/* Include the ancient signal function */
obj_valid = lv_rect_signal(scrl, sign, param);
/* The object can be deleted so check its validity and then
* make the object specific signal handling */
if(obj_valid != false) {
2016-06-08 07:25:08 +02:00
cord_t new_x;
cord_t new_y;
bool refr_x = false;
bool refr_y = false;
area_t page_cords;
area_t obj_cords;
lv_obj_t * page = lv_obj_get_parent(scrl);
lv_pages_t * style = lv_obj_get_style(page);
2016-10-07 11:15:46 +02:00
lv_page_ext_t * page_ext = lv_obj_get_ext(page);
cord_t hpad = style->bg_rects.hpad;
cord_t vpad = style->bg_rects.vpad;
2016-06-08 07:25:08 +02:00
switch(sign) {
case LV_SIGNAL_CORD_CHG:
new_x = lv_obj_get_x(scrl);
new_y = lv_obj_get_y(scrl);
lv_obj_get_cords(scrl, &obj_cords);
2016-10-07 11:15:46 +02:00
lv_obj_get_cords(page, &page_cords);
2016-06-08 07:25:08 +02:00
/*scrollable width smaller then page width? -> align to left*/
if(area_get_width(&obj_cords) + 2 * hpad < area_get_width(&page_cords)) {
if(obj_cords.x1 != page_cords.x1 + hpad) {
new_x = hpad;
2016-06-08 07:25:08 +02:00
refr_x = true;
}
} else {
/*The edges of the scrollable can not be in the page (minus hpad) */
if(obj_cords.x2 < page_cords.x2 - hpad) {
new_x = area_get_width(&page_cords) - area_get_width(&obj_cords) - hpad; /* Right align */
2016-06-08 07:25:08 +02:00
refr_x = true;
}
if (obj_cords.x1 > page_cords.x1 + hpad) {
new_x = hpad; /*Left align*/
2016-06-08 07:25:08 +02:00
refr_x = true;
}
}
/*scrollable height smaller then page height? -> align to left*/
if(area_get_height(&obj_cords) + 2 * vpad < area_get_height(&page_cords)) {
if(obj_cords.y1 != page_cords.y1 + vpad) {
new_y = vpad;
2016-06-08 07:25:08 +02:00
refr_y = true;
}
} else {
/*The edges of the scrollable can not be in the page (minus vpad) */
if(obj_cords.y2 < page_cords.y2 - vpad) {
new_y = area_get_height(&page_cords) - area_get_height(&obj_cords) - vpad; /* Bottom align */
2016-06-08 07:25:08 +02:00
refr_y = true;
}
if (obj_cords.y1 > page_cords.y1 + vpad) {
new_y = vpad; /*Top align*/
2016-06-08 07:25:08 +02:00
refr_y = true;
}
}
2016-06-08 07:25:08 +02:00
if(refr_x != false || refr_y != false) {
lv_obj_set_pos(scrl, new_x, new_y);
2016-06-08 07:25:08 +02:00
}
2016-10-07 11:15:46 +02:00
lv_page_sb_refresh(page);
2016-06-08 07:25:08 +02:00
break;
2016-06-08 07:25:08 +02:00
case LV_SIGNAL_DRAG_BEGIN:
if(style->sb_mode == LV_PAGE_SB_MODE_DRAG ) {
cord_t sbh_pad = MATH_MAX(style->sb_width, style->bg_rects.hpad);
cord_t sbv_pad = MATH_MAX(style->sb_width, style->bg_rects.vpad);
if(area_get_height(&page_ext->sbv) < lv_obj_get_height(scrl) - 2 * sbv_pad) {
2016-10-07 11:15:46 +02:00
page_ext->sbv_draw = 1;
2016-06-08 07:25:08 +02:00
}
if(area_get_width(&page_ext->sbh) < lv_obj_get_width(scrl) - 2 * sbh_pad) {
2016-10-07 11:15:46 +02:00
page_ext->sbh_draw = 1;
2016-06-08 07:25:08 +02:00
}
}
break;
2016-06-08 07:25:08 +02:00
case LV_SIGNAL_DRAG_END:
if(style->sb_mode == LV_PAGE_SB_MODE_DRAG) {
area_t sb_area_tmp;
if(page_ext->sbh_draw != 0) {
area_cpy(&sb_area_tmp, &page_ext->sbh);
sb_area_tmp.x1 += page->cords.x1;
sb_area_tmp.y1 += page->cords.y1;
sb_area_tmp.x2 += page->cords.x2;
sb_area_tmp.y2 += page->cords.y2;
lv_inv_area(&sb_area_tmp);
page_ext->sbh_draw = 0;
}
if(page_ext->sbv_draw != 0) {
area_cpy(&sb_area_tmp, &page_ext->sbv);
sb_area_tmp.x1 += page->cords.x1;
sb_area_tmp.y1 += page->cords.y1;
sb_area_tmp.x2 += page->cords.x2;
sb_area_tmp.y2 += page->cords.y2;
lv_inv_area(&sb_area_tmp);
page_ext->sbv_draw = 0;
}
2016-06-08 07:25:08 +02:00
}
break;
case LV_SIGNAL_PRESSED:
2016-12-22 15:00:22 +01:00
if(page_ext->pr_action != NULL) {
page_ext->pr_action(page, param);
}
break;
case LV_SIGNAL_RELEASED:
2016-12-22 15:00:22 +01:00
if(lv_dispi_is_dragging(param) == false) {
if(page_ext->rel_action != NULL) {
page_ext->rel_action(page, param);
}
}
break;
2016-06-08 07:25:08 +02:00
default:
break;
2016-06-08 07:25:08 +02:00
}
}
2016-06-08 07:25:08 +02:00
return obj_valid;
}
2016-10-04 15:29:52 +02:00
/*=====================
* Setter functions
*====================*/
/**
* Set a release action for the page
* @param page pointer to a page object
* @param rel_action a function to call when the page is released
*/
void lv_page_set_rel_action(lv_obj_t * page, lv_action_t rel_action)
{
lv_page_ext_t * ext = lv_obj_get_ext(page);
ext->rel_action = rel_action;
}
/**
* Set a press action for the page
* @param page pointer to a page object
* @param pr_action a function to call when the page is pressed
*/
void lv_page_set_pr_action(lv_obj_t * page, lv_action_t pr_action)
{
lv_page_ext_t * ext = lv_obj_get_ext(page);
ext->pr_action = pr_action;
}
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
}
/**
* 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)
* @param anim_en true: scroll with animation
*/
void lv_page_focus(lv_obj_t * page, lv_obj_t * obj, bool anim_en)
{
lv_page_ext_t * ext = lv_obj_get_ext(page);
lv_pages_t * style = lv_obj_get_style(page);
cord_t obj_y = obj->cords.y1 - ext->scrl->cords.y1;
cord_t obj_h = lv_obj_get_height(obj);
cord_t scrlable_y = lv_obj_get_y(ext->scrl);
cord_t page_h = lv_obj_get_height(page);
bool refr = false;
cord_t top_err = -(scrlable_y + obj_y);
cord_t bot_err = scrlable_y + obj_y + obj_h - page_h;
/*If obj is higher then the page focus where the "error" is smaller*/
/*Out of the page on the top*/
if((obj_h <= page_h && top_err > 0) ||
2016-12-30 21:46:55 +01:00
(obj_h > page_h && top_err < bot_err)) {
/*Calculate a new position and to let scrable_rects.vpad space above*/
scrlable_y = -(obj_y - style->scrl_rects.vpad - style->bg_rects.vpad);
scrlable_y += style->scrl_rects.vpad;
refr = true;
}
/*Out of the page on the bottom*/
else if((obj_h <= page_h && bot_err > 0) ||
2016-12-30 21:46:55 +01:00
(obj_h > page_h && top_err >= bot_err)) {
/*Calculate a new position and to let scrable_rects.vpad space below*/
scrlable_y = -obj_y;
scrlable_y += page_h - obj_h;
scrlable_y -= style->scrl_rects.vpad;
refr = true;
}
if(refr != false) {
#if LV_PAGE_ANIM_FOCUS_TIME == 0
lv_obj_set_y(ext->scrl, scrlable_y);
#else
if(anim_en == false) {
lv_obj_set_y(ext->scrl, scrlable_y);
} else {
anim_t a;
a.act_time = 0;
a.start = lv_obj_get_y(ext->scrl);
a.end = scrlable_y;
a.time = LV_PAGE_ANIM_FOCUS_TIME;//anim_speed_to_time(LV_PAGE_ANIM_SPEED, a.start, a.end);
a.end_cb = NULL;
a.playback = 0;
a.repeat = 0;
a.var = ext->scrl;
a.path = anim_get_path(ANIM_PATH_LIN);
a.fp = (anim_fp_t) lv_obj_set_y;
anim_create(&a);
}
#endif
}
}
2016-10-04 15:29:52 +02:00
/*=====================
* Getter functions
*====================*/
2016-12-17 10:50:28 +01:00
/**
* Get the scrollable object of a page-
* @param page pointer to page object
* @return pointer to rectangle which is the scrollable part of the page
*/
lv_obj_t * lv_page_get_scrl(lv_obj_t * page)
2016-12-17 10:50:28 +01:00
{
lv_page_ext_t * ext = lv_obj_get_ext(page);
return ext->scrl;
2016-12-17 10:50:28 +01:00
}
2016-06-08 07:25:08 +02:00
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_pages_builtin_t enum
2016-10-07 11:15:46 +02:00
* @param copy copy the style to this variable. (NULL if unused)
2016-06-08 07:25:08 +02:00
* @return pointer to an lv_pages_t style
*/
2016-10-07 11:15:46 +02:00
lv_pages_t * lv_pages_get(lv_pages_builtin_t style, lv_pages_t * copy)
2016-06-08 07:25:08 +02:00
{
static bool style_inited = false;
/*Make the style initialization if it is not done yet*/
if(style_inited == false) {
lv_pages_init();
style_inited = true;
}
2016-06-08 07:25:08 +02:00
lv_pages_t * style_p;
switch(style) {
case LV_PAGES_DEF:
style_p = &lv_pages_def;
break;
case LV_PAGES_SIMPLE:
style_p = &lv_pages_simple;
break;
2016-06-08 07:25:08 +02:00
case LV_PAGES_TRANSP:
style_p = &lv_pages_transp;
break;
default:
style_p = &lv_pages_def;
2016-06-08 07:25:08 +02:00
}
2016-10-07 11:15:46 +02:00
if(copy != NULL) {
if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_pages_t));
else memcpy(copy, &lv_pages_def, sizeof(lv_pages_t));
2016-06-08 07:25:08 +02:00
}
return style_p;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Handle the drawing related tasks of the pages
2016-10-07 11:15:46 +02:00
* @param page pointer to an object
* @param mask the object will be drawn only in this area
* @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
* @param return true/false, depends on 'mode'
*/
2016-10-07 11:15:46 +02:00
static bool lv_page_design(lv_obj_t * page, const area_t * mask, lv_design_mode_t mode)
{
if(mode == LV_DESIGN_COVER_CHK) {
2016-10-07 11:15:46 +02:00
return ancestor_design_f(page, mask, mode);
} else if(mode == LV_DESIGN_DRAW_MAIN) {
2016-10-07 11:15:46 +02:00
ancestor_design_f(page, mask, mode);
} else if(mode == LV_DESIGN_DRAW_POST) { /*Draw the scroll bars finally*/
ancestor_design_f(page, mask, mode);
2016-10-07 11:15:46 +02:00
lv_page_ext_t * ext = lv_obj_get_ext(page);
lv_pages_t * style = lv_obj_get_style(page);
opa_t sb_opa = lv_obj_get_opa(page) * style->sb_opa /100;
/*Draw the scrollbars*/
area_t sb_area;
2016-10-07 11:15:46 +02:00
if(ext->sbh_draw != 0) {
/*Convert the relative coordinates to absolute*/
area_cpy(&sb_area, &ext->sbh);
sb_area.x1 += page->cords.x1;
sb_area.y1 += page->cords.y1;
sb_area.x2 += page->cords.x1;
sb_area.y2 += page->cords.y1;
lv_draw_rect(&sb_area, mask, &style->sb_rects, sb_opa);
}
2016-10-07 11:15:46 +02:00
if(ext->sbv_draw != 0) {
/*Convert the relative coordinates to absolute*/
area_cpy(&sb_area, &ext->sbv);
sb_area.x1 += page->cords.x1;
sb_area.y1 += page->cords.y1;
sb_area.x2 += page->cords.x1;
sb_area.y2 += page->cords.y1;
lv_draw_rect(&sb_area, mask, &style->sb_rects, sb_opa);
}
}
return true;
}
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
{
/*Always let sb_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 */
2016-10-07 11:15:46 +02:00
lv_page_ext_t * page_ext = lv_obj_get_ext(page);
lv_pages_t * style = lv_obj_get_style(page);
lv_obj_t * scrl = page_ext->scrl;
2016-06-08 07:25:08 +02:00
cord_t size_tmp;
cord_t scrl_w = lv_obj_get_width(scrl);
cord_t scrl_h = lv_obj_get_height(scrl);
cord_t hpad = style->bg_rects.hpad;
cord_t vpad = style->bg_rects.vpad;
2016-10-07 11:15:46 +02:00
cord_t obj_w = lv_obj_get_width(page);
cord_t obj_h = lv_obj_get_height(page);
cord_t sbh_pad = MATH_MAX(style->sb_width, style->bg_rects.hpad);
cord_t sbv_pad = MATH_MAX(style->sb_width, style->bg_rects.vpad);
2016-10-07 11:15:46 +02:00
if(style->sb_mode == LV_PAGE_SB_MODE_OFF) return;
if(style->sb_mode == LV_PAGE_SB_MODE_ON) {
page_ext->sbh_draw = 1;
page_ext->sbv_draw = 1;
}
/*Invalidate the current (old) scrollbar areas*/
area_t sb_area_tmp;
if(page_ext->sbh_draw != 0) {
area_cpy(&sb_area_tmp, &page_ext->sbh);
sb_area_tmp.x1 += page->cords.x1;
sb_area_tmp.y1 += page->cords.y1;
sb_area_tmp.x2 += page->cords.x2;
sb_area_tmp.y2 += page->cords.y2;
lv_inv_area(&sb_area_tmp);
}
if(page_ext->sbv_draw != 0) {
area_cpy(&sb_area_tmp, &page_ext->sbv);
sb_area_tmp.x1 += page->cords.x1;
sb_area_tmp.y1 += page->cords.y1;
sb_area_tmp.x2 += page->cords.x2;
sb_area_tmp.y2 += page->cords.y2;
lv_inv_area(&sb_area_tmp);
}
2016-06-08 07:25:08 +02:00
/*Horizontal scrollbar*/
if(scrl_w <= obj_w - 2 * hpad) { /*Full sized scroll bar*/
area_set_width(&page_ext->sbh, obj_w - 2 * sbh_pad);
area_set_pos(&page_ext->sbh, sbh_pad, obj_h - style->sb_width);
if(style->sb_mode == LV_PAGE_SB_MODE_AUTO) page_ext->sbh_draw = 0;
} else {
size_tmp = (obj_w * (obj_w - (2 * sbh_pad))) / (scrl_w + 2 * hpad);
2016-10-07 11:15:46 +02:00
area_set_width(&page_ext->sbh, size_tmp);
2016-06-08 07:25:08 +02:00
area_set_pos(&page_ext->sbh, sbh_pad +
(-(lv_obj_get_x(scrl) - hpad) * (obj_w - size_tmp - 2 * sbh_pad)) /
(scrl_w + 2 * hpad - obj_w ), obj_h - style->sb_width);
if(style->sb_mode == LV_PAGE_SB_MODE_AUTO) page_ext->sbh_draw = 1;
2016-06-08 07:25:08 +02:00
}
/*Vertical scrollbar*/
if(scrl_h <= obj_h - 2 * vpad) { /*Full sized scroll bar*/
area_set_height(&page_ext->sbv, obj_h - 2 * sbv_pad);
area_set_pos(&page_ext->sbv, obj_w - style->sb_width, sbv_pad);
if(style->sb_mode == LV_PAGE_SB_MODE_AUTO) page_ext->sbv_draw = 0;
2016-06-08 07:25:08 +02:00
} else {
size_tmp = (obj_h * (obj_h - (2 * sbv_pad))) / (scrl_h + 2 * vpad);
2016-10-07 11:15:46 +02:00
area_set_height(&page_ext->sbv, size_tmp);
2016-06-08 07:25:08 +02:00
area_set_pos(&page_ext->sbv, obj_w - style->sb_width,
sbv_pad +
(-(lv_obj_get_y(scrl) - vpad) * (obj_h - size_tmp - 2 * sbv_pad)) /
(scrl_h + 2 * vpad - obj_h ));
if(style->sb_mode == LV_PAGE_SB_MODE_AUTO) page_ext->sbv_draw = 1;
2016-06-08 07:25:08 +02:00
}
/*Invalidate the new scrollbar areas*/
if(page_ext->sbh_draw != 0) {
area_cpy(&sb_area_tmp, &page_ext->sbh);
sb_area_tmp.x1 += page->cords.x1;
sb_area_tmp.y1 += page->cords.y1;
sb_area_tmp.x2 += page->cords.x2;
sb_area_tmp.y2 += page->cords.y2;
lv_inv_area(&sb_area_tmp);
}
if(page_ext->sbv_draw != 0) {
area_cpy(&sb_area_tmp, &page_ext->sbv);
sb_area_tmp.x1 += page->cords.x1;
sb_area_tmp.y1 += page->cords.y1;
sb_area_tmp.x2 += page->cords.x2;
sb_area_tmp.y2 += page->cords.y2;
lv_inv_area(&sb_area_tmp);
}
}
/**
* Initialize the page styles
*/
static void lv_pages_init(void)
{
/*Default style*/
lv_rects_get(LV_RECTS_DEF, &lv_pages_def.bg_rects);
lv_rects_get(LV_RECTS_DEF, &lv_pages_def.scrl_rects);
lv_pages_def.scrl_rects.objs.color = COLOR_WHITE;
lv_pages_def.scrl_rects.gcolor = COLOR_SILVER;
lv_pages_def.scrl_rects.bcolor = COLOR_GRAY;
lv_rects_get(LV_RECTS_DEF, &lv_pages_def.sb_rects);
lv_pages_def.sb_rects.objs.color = COLOR_BLACK;
lv_pages_def.sb_rects.gcolor = COLOR_BLACK;
lv_pages_def.sb_rects.bcolor = COLOR_WHITE;
lv_pages_def.sb_rects.bwidth = 1 * LV_DOWNSCALE;
lv_pages_def.sb_rects.round = 5 * LV_DOWNSCALE;
lv_pages_def.sb_width= 8 * LV_DOWNSCALE;
lv_pages_def.sb_opa=50;
lv_pages_def.sb_mode = LV_PAGE_SB_MODE_AUTO;
/*No (transparent) scrollable style*/
memcpy(&lv_pages_simple, &lv_pages_def, sizeof(lv_pages_t));
lv_rects_get(LV_RECTS_TRANSP, &lv_pages_simple.scrl_rects);
lv_pages_simple.scrl_rects.vpad = 0 * LV_DOWNSCALE;
lv_pages_simple.scrl_rects.hpad = 0 * LV_DOWNSCALE;
/*Transparent style*/
memcpy(&lv_pages_transp, &lv_pages_simple, sizeof(lv_pages_t));
lv_rects_get(LV_RECTS_TRANSP, &lv_pages_transp.bg_rects);
lv_pages_transp.bg_rects.vpad = 10 * LV_DOWNSCALE;
lv_pages_transp.bg_rects.hpad = 10 * LV_DOWNSCALE;
lv_pages_transp.bg_rects.opad = 10 * LV_DOWNSCALE;
/* Make transparent bg. only witth bwidth = 0 nad empty = 1
* because with transp = 1 the design function will not be called
* to draw the scrollbars*/
lv_pages_transp.bg_rects.objs.transp = 0;
2016-06-08 07:25:08 +02:00
}
#endif