/*1* Copyright (c) 2019 CTCaer2*3* This program is free software; you can redistribute it and/or modify it4* under the terms and conditions of the GNU General Public License,5* version 2, as published by the Free Software Foundation.6*7* This program is distributed in the hope it will be useful, but WITHOUT8* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or9* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for10* more details.11*12* You should have received a copy of the GNU General Public License13* along with this program. If not, see <http://www.gnu.org/licenses/>.14*/1516/**17* @file lv_page.h18*19*/2021#ifndef LV_PAGE_H22#define LV_PAGE_H2324#ifdef __cplusplus25extern "C" {26#endif2728/*********************29* INCLUDES30*********************/31#ifdef LV_CONF_INCLUDE_SIMPLE32#include "lv_conf.h"33#else34#include "../../lv_conf.h"35#endif3637#if USE_LV_PAGE != 03839/*Testing of dependencies*/40#if USE_LV_CONT == 041#error "lv_page: lv_cont is required. Enable it in lv_conf.h (USE_LV_CONT 1) "42#endif4344#include "lv_cont.h"45#include "../lv_core/lv_indev.h"4647/*********************48* DEFINES49*********************/5051/**********************52* TYPEDEFS53**********************/5455/*Scrollbar modes: shows when should the scrollbars be visible*/56enum57{58LV_SB_MODE_OFF = 0x0, /*Never show scrollbars*/59LV_SB_MODE_ON = 0x1, /*Always show scrollbars*/60LV_SB_MODE_DRAG = 0x2, /*Show scrollbars when page is being dragged*/61LV_SB_MODE_AUTO = 0x3, /*Show scrollbars when the scrollable container is large enough to be scrolled*/62LV_SB_MODE_HIDE = 0x4, /*Hide the scroll bar temporally*/63LV_SB_MODE_UNHIDE = 0x5, /*Unhide the previously hidden scrollbar. Recover it's type too*/64};65typedef uint8_t lv_sb_mode_t;6667/*Data of page*/68typedef struct69{70lv_cont_ext_t bg; /*Ext. of ancestor*/71/*New data for this type */72lv_obj_t * scrl; /*The scrollable object on the background*/73lv_style_t *bgo; /*The scrollable object on the background*/74lv_style_t *pr; /*The scrollable object on the background*/75lv_action_t rel_action; /*Function to call when the page is released*/76lv_action_t pr_action; /*Function to call when the page is pressed*/77struct {78lv_style_t *style; /*Style of scrollbars*/79lv_area_t hor_area; /*Horizontal scrollbar area relative to the page. (Handled by the library) */80lv_area_t ver_area; /*Vertical scrollbar area relative to the page (Handled by the library)*/81uint8_t hor_draw :1; /*1: horizontal scrollbar is visible now (Handled by the library)*/82uint8_t ver_draw :1; /*1: vertical scrollbar is visible now (Handled by the library)*/83lv_sb_mode_t mode:3; /*Scrollbar visibility from 'lv_page_sb_mode_t'*/84} sb;85struct {86uint16_t state; /*Store the current size of the edge flash effect*/87lv_style_t *style; /*Style of edge flash effect (usually homogeneous circle)*/88uint8_t enabled :1; /*1: Show a flash animation on the edge*/89uint8_t top_ip :1; /*Used internally to show that top most position is reached (flash is In Progress)*/90uint8_t bottom_ip :1; /*Used internally to show that bottom most position is reached (flash is In Progress)*/91uint8_t right_ip :1; /*Used internally to show that right most position is reached (flash is In Progress)*/92uint8_t left_ip :1; /*Used internally to show that left most position is reached (flash is In Progress)*/93}edge_flash;9495uint8_t arrow_scroll :1; /*1: Enable scrolling with LV_GROUP_KEY_LEFT/RIGHT/UP/DOWN*/96uint8_t scroll_prop :1; /*1: Propagate the scrolling the the parent if the edge is reached*/97uint8_t scroll_prop_ip :1; /*1: Scroll propagation is in progress (used by the library)*/98} lv_page_ext_t;99100enum {101LV_PAGE_STYLE_BG,102LV_PAGE_STYLE_BGO,103LV_PAGE_STYLE_PR,104LV_PAGE_STYLE_SCRL,105LV_PAGE_STYLE_SB,106LV_PAGE_STYLE_EDGE_FLASH,107};108typedef uint8_t lv_page_style_t;109110/**********************111* GLOBAL PROTOTYPES112**********************/113114/**115* Create a page objects116* @param par pointer to an object, it will be the parent of the new page117* @param copy pointer to a page object, if not NULL then the new object will be copied from it118* @return pointer to the created page119*/120lv_obj_t * lv_page_create(lv_obj_t * par, const lv_obj_t * copy);121122/**123* Delete all children of the scrl object, without deleting scrl child.124* @param obj pointer to an object125*/126void lv_page_clean(lv_obj_t *obj);127128/**129* Get the press action of the page130* @param page pointer to a page object131* @return a function to call when the page is pressed132*/133lv_action_t lv_page_get_pr_action(lv_obj_t * page);134135/**136* Get the release action of the page137* @param page pointer to a page object138* @return a function to call when the page is released139*/140lv_action_t lv_page_get_rel_action(lv_obj_t * page);141142/**143* Get the scrollable object of a page144* @param page pointer to a page object145* @return pointer to a container which is the scrollable part of the page146*/147lv_obj_t * lv_page_get_scrl(const lv_obj_t * page);148149/*=====================150* Setter functions151*====================*/152153/**154* Set a release action for the page155* @param page pointer to a page object156* @param rel_action a function to call when the page is released157*/158void lv_page_set_rel_action(lv_obj_t * page, lv_action_t rel_action);159160/**161* Set a press action for the page162* @param page pointer to a page object163* @param pr_action a function to call when the page is pressed164*/165void lv_page_set_pr_action(lv_obj_t * page, lv_action_t pr_action);166167/**168* Set the scroll bar mode on a page169* @param page pointer to a page object170* @param sb_mode the new mode from 'lv_page_sb.mode_t' enum171*/172void lv_page_set_sb_mode(lv_obj_t * page, lv_sb_mode_t sb_mode);173174/**175* Enable/Disable scrolling with arrows if the page is in group (arrows: LV_GROUP_KEY_LEFT/RIGHT/UP/DOWN)176* @param page pointer to a page object177* @param en true: enable scrolling with arrows178*/179void lv_page_set_arrow_scroll(lv_obj_t * page, bool en);180181/**182* Enable the scroll propagation feature. If enabled then the page will move its parent if there is no more space to scroll.183* @param page pointer to a Page184* @param en true or false to enable/disable scroll propagation185*/186void lv_page_set_scroll_propagation(lv_obj_t * page, bool en);187188/**189* Enable the edge flash effect. (Show an arc when the an edge is reached)190* @param page pointer to a Page191* @param en true or false to enable/disable end flash192*/193void lv_page_set_edge_flash(lv_obj_t * page, bool en);194195/**196* Set the fit attribute of the scrollable part of a page.197* It means it can set its size automatically to involve all children.198* (Can be set separately horizontally and vertically)199* @param page pointer to a page object200* @param hor_en true: enable horizontal fit201* @param ver_en true: enable vertical fit202*/203static inline void lv_page_set_scrl_fit(lv_obj_t *page, bool hor_en, bool ver_en)204{205lv_cont_set_fit(lv_page_get_scrl(page), hor_en, ver_en);206}207208/**209* Set width of the scrollable part of a page210* @param page pointer to a page object211* @param w the new width of the scrollable (it ha no effect is horizontal fit is enabled)212*/213static inline void lv_page_set_scrl_width(lv_obj_t *page, lv_coord_t w)214{215lv_obj_set_width(lv_page_get_scrl(page), w);216}217218/**219* Set height of the scrollable part of a page220* @param page pointer to a page object221* @param h the new height of the scrollable (it ha no effect is vertical fit is enabled)222*/223static inline void lv_page_set_scrl_height(lv_obj_t *page, lv_coord_t h)224{225lv_obj_set_height(lv_page_get_scrl(page), h);226227}228229/**230* Set the layout of the scrollable part of the page231* @param page pointer to a page object232* @param layout a layout from 'lv_cont_layout_t'233*/234static inline void lv_page_set_scrl_layout(lv_obj_t * page, lv_layout_t layout)235{236lv_cont_set_layout(lv_page_get_scrl(page), layout);237}238239/**240* Set a style of a page241* @param page pointer to a page object242* @param type which style should be set243* @param style pointer to a style244*/245void lv_page_set_style(lv_obj_t *page, lv_page_style_t type, lv_style_t *style);246247/*=====================248* Getter functions249*====================*/250251/**252* Set the scroll bar mode on a page253* @param page pointer to a page object254* @return the mode from 'lv_page_sb.mode_t' enum255*/256lv_sb_mode_t lv_page_get_sb_mode(const lv_obj_t * page);257258259/**260* Get the the scrolling with arrows (LV_GROUP_KEY_LEFT/RIGHT/UP/DOWN) is enabled or not261* @param page pointer to a page object262* @return true: scrolling with arrows is enabled263*/264bool lv_page_get_arrow_scroll(const lv_obj_t * page);265266/**267* Get the scroll propagation property268* @param page pointer to a Page269* @return true or false270*/271bool lv_page_get_scroll_propagation(lv_obj_t * page);272273/**274* Get the edge flash effect property.275* @param page pointer to a Page276* return true or false277*/278bool lv_page_get_edge_flash(lv_obj_t * page);279280/**281* Get that width which can be set to the children to still not cause overflow (show scrollbars)282* @param page pointer to a page object283* @return the width which still fits into the page284*/285lv_coord_t lv_page_get_fit_width(lv_obj_t * page);286287/**288* Get that height which can be set to the children to still not cause overflow (show scrollbars)289* @param page pointer to a page object290* @return the height which still fits into the page291*/292lv_coord_t lv_page_get_fit_height(lv_obj_t * page);293294/**295* Get width of the scrollable part of a page296* @param page pointer to a page object297* @return the width of the scrollable298*/299static inline lv_coord_t lv_page_get_scrl_width(const lv_obj_t *page)300{301return lv_obj_get_width(lv_page_get_scrl(page));302}303304/**305* Get height of the scrollable part of a page306* @param page pointer to a page object307* @return the height of the scrollable308*/309static inline lv_coord_t lv_page_get_scrl_height(const lv_obj_t *page)310{311return lv_obj_get_height(lv_page_get_scrl(page));312}313314/**315* Get the layout of the scrollable part of a page316* @param page pointer to page object317* @return the layout from 'lv_cont_layout_t'318*/319static inline lv_layout_t lv_page_get_scrl_layout(const lv_obj_t * page)320{321return lv_cont_get_layout(lv_page_get_scrl(page));322}323324/**325* Get horizontal fit attribute of the scrollable part of a page326* @param page pointer to a page object327* @return true: horizontal fit is enabled; false: disabled328*/329static inline bool lv_page_get_scrl_hor_fit(const lv_obj_t * page)330{331return lv_cont_get_hor_fit(lv_page_get_scrl(page));332}333334/**335* Get vertical fit attribute of the scrollable part of a page336* @param page pointer to a page object337* @return true: vertical fit is enabled; false: disabled338*/339static inline bool lv_page_get_scrl_fit_ver(const lv_obj_t * page)340{341return lv_cont_get_ver_fit(lv_page_get_scrl(page));342}343344/**345* Get a style of a page346* @param page pointer to page object347* @param type which style should be get348* @return style pointer to a style349*/350lv_style_t * lv_page_get_style(const lv_obj_t *page, lv_page_style_t type);351352/*=====================353* Other functions354*====================*/355356/**357* Glue the object to the page. After it the page can be moved (dragged) with this object too.358* @param obj pointer to an object on a page359* @param glue true: enable glue, false: disable glue360*/361void lv_page_glue_obj(lv_obj_t * obj, bool glue);362363/**364* Focus on an object. It ensures that the object will be visible on the page.365* @param page pointer to a page object366* @param obj pointer to an object to focus (must be on the page)367* @param anim_time scroll animation time in milliseconds (0: no animation)368*/369void lv_page_focus(lv_obj_t * page, const lv_obj_t * obj, uint16_t anim_time);370371/**372* Scroll the page horizontally373* @param page pointer to a page object374* @param dist the distance to scroll (< 0: scroll left; > 0 scroll right)375*/376void lv_page_scroll_hor(lv_obj_t * page, lv_coord_t dist);377378/**379* Scroll the page vertically380* @param page pointer to a page object381* @param dist the distance to scroll (< 0: scroll down; > 0 scroll up)382*/383void lv_page_scroll_ver(lv_obj_t * page, lv_coord_t dist);384385/**386* Not intended to use directly by the user but by other object types internally.387* Start an edge flash animation. Exactly one `ext->edge_flash.xxx_ip` should be set388* @param page389*/390void lv_page_start_edge_flash(lv_obj_t * page);391/**********************392* MACROS393**********************/394395#endif /*USE_LV_PAGE*/396397#ifdef __cplusplus398} /* extern "C" */399#endif400401#endif /*LV_PAGE_H*/402403404