refactor(scroll) rename lv_set/get_snap_.. to lv_obj_set/get_scroll_snap_...

This commit is contained in:
Gabor Kiss-Vamosi 2021-02-23 09:45:13 +01:00
parent e9613526f8
commit 54cfc37c5c
10 changed files with 249 additions and 150 deletions

View File

@ -10,6 +10,7 @@ static void column_gap_anim(void * obj, int32_t v)
{
lv_obj_set_style_pad_column(obj, LV_PART_MAIN, LV_STATE_DEFAULT, v);
}
/**
* Demonstrate column and row gap
*/

View File

@ -1,10 +1,10 @@
/**
* @file lv_example_widgets.h
* @file lv_example_style.h
*
*/
#ifndef LV_EX_STYLE_H
#define LV_EX_STYLE_H
#ifndef LV_EXAMPLE_STYLE_H
#define LV_EXAMPLE_STYLE_H
#ifdef __cplusplus
extern "C" {
@ -45,4 +45,4 @@ void lv_example_style_11(void);
} /* extern "C" */
#endif
#endif /*LV_EX_STYLE_H*/
#endif /*LV_EXAMPLE_STYLE_H*/

View File

@ -203,7 +203,7 @@ static void lv_tabview_constructor(lv_obj_t * obj, const lv_obj_t * copy)
}
lv_obj_set_layout(cont, &lv_flex_queue);
lv_obj_set_snap_align_x(cont, LV_SCROLL_SNAP_ALIGN_CENTER);
lv_obj_set_scroll_snap_align_x(cont, LV_SCROLL_SNAP_ALIGN_CENTER);
lv_obj_add_flag(cont, LV_OBJ_FLAG_SCROLL_ONE);
lv_obj_clear_flag(cont, LV_OBJ_FLAG_SCROLL_ON_FOCUS);
}

View File

@ -113,8 +113,8 @@ static void lv_tileview_constructor(lv_obj_t * obj, const lv_obj_t * copy)
lv_obj_set_size(obj, LV_SIZE_PCT(100), LV_SIZE_PCT(100));
lv_obj_add_event_cb(obj, tileview_event_cb, NULL);
lv_obj_add_flag(obj, LV_OBJ_FLAG_SCROLL_ONE);
lv_obj_set_snap_align_x(obj, LV_SCROLL_SNAP_ALIGN_CENTER);
lv_obj_set_snap_align_y(obj, LV_SCROLL_SNAP_ALIGN_CENTER);
lv_obj_set_scroll_snap_align_x(obj, LV_SCROLL_SNAP_ALIGN_CENTER);
lv_obj_set_scroll_snap_align_y(obj, LV_SCROLL_SNAP_ALIGN_CENTER);
}

View File

@ -108,8 +108,8 @@ void _lv_indev_scroll_throw_handler(lv_indev_proc_t * proc)
proc->types.pointer.scroll_throw_vect.x = 0;
}
lv_snap_align_t align_x = lv_obj_get_snap_align_x(scroll_obj);
lv_snap_align_t align_y = lv_obj_get_snap_align_y(scroll_obj);
lv_snap_align_t align_x = lv_obj_get_scroll_snap_align_x(scroll_obj);
lv_snap_align_t align_y = lv_obj_get_scroll_snap_align_y(scroll_obj);
if(proc->types.pointer.scroll_dir == LV_INDEV_SCROLL_DIR_VER) {
proc->types.pointer.scroll_throw_vect.x = 0;
@ -348,7 +348,7 @@ static void init_scroll_limits(lv_indev_proc_t * proc)
}
/*With STOP limit the scrolling to the perv and next snap point*/
else {
switch(lv_obj_get_snap_align_y(obj)) {
switch(lv_obj_get_scroll_snap_align_y(obj)) {
case LV_SCROLL_SNAP_ALIGN_START:
proc->types.pointer.scroll_area.y1 = find_snap_point_y(obj, obj->coords.y1 + 1, LV_COORD_MAX, 0);
proc->types.pointer.scroll_area.y2 = find_snap_point_y(obj, LV_COORD_MIN, obj->coords.y1 - 1, 0);
@ -369,7 +369,7 @@ static void init_scroll_limits(lv_indev_proc_t * proc)
break;
}
switch(lv_obj_get_snap_align_x(obj)) {
switch(lv_obj_get_scroll_snap_align_x(obj)) {
case LV_SCROLL_SNAP_ALIGN_START:
proc->types.pointer.scroll_area.x1 = find_snap_point_x(obj, obj->coords.x1, LV_COORD_MAX, 0);
proc->types.pointer.scroll_area.x2 = find_snap_point_x(obj, LV_COORD_MIN, obj->coords.x1, 0);
@ -400,7 +400,7 @@ static void init_scroll_limits(lv_indev_proc_t * proc)
static lv_coord_t find_snap_point_x(const lv_obj_t * obj, lv_coord_t min, lv_coord_t max, lv_coord_t ofs)
{
lv_snap_align_t align = lv_obj_get_snap_align_x(obj);
lv_snap_align_t align = lv_obj_get_scroll_snap_align_x(obj);
if(align == LV_SCROLL_SNAP_ALIGN_NONE) return 0;
lv_coord_t dist = LV_COORD_MAX;
@ -447,7 +447,7 @@ static lv_coord_t find_snap_point_x(const lv_obj_t * obj, lv_coord_t min, lv_coo
*/
static lv_coord_t find_snap_point_y(const lv_obj_t * obj, lv_coord_t min, lv_coord_t max, lv_coord_t ofs)
{
lv_snap_align_t align = lv_obj_get_snap_align_y(obj);
lv_snap_align_t align = lv_obj_get_scroll_snap_align_y(obj);
if(align == LV_SCROLL_SNAP_ALIGN_NONE) return 0;
lv_coord_t dist = LV_COORD_MAX;

View File

@ -39,7 +39,6 @@
#define LV_OBJ_DEF_HEIGHT (LV_DPX(50))
#define GRID_DEBUG 0 /*Draw rectangles on grid cells*/
#define STYLE_TRANSITION_MAX 32
#define SCROLLBAR_MIN_SIZE (LV_DPX(10))
/**********************
* TYPEDEFS
@ -819,135 +818,19 @@ static lv_draw_res_t lv_obj_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv
static void draw_scrollbar(lv_obj_t * obj, const lv_area_t * clip_area)
{
if(lv_obj_has_flag(obj, LV_OBJ_FLAG_SCROLLABLE) == false) return;
lv_indev_scroll_dir_t sm = lv_obj_get_scrollbar_mode(obj);
if(sm == LV_SCROLLBAR_MODE_OFF) return;
lv_area_t hor_area;
lv_area_t ver_area;
lv_obj_get_scrollbar_area(obj, &hor_area, &ver_area);
/*If there is no indev scrolling this object but `mode==active` return*/
lv_indev_t * indev = lv_indev_get_next(NULL);
if(sm == LV_SCROLLBAR_MODE_ACTIVE) {
while(indev) {
if(lv_indev_get_scroll_obj(indev) == obj) break;
indev = lv_indev_get_next(indev);
}
if(indev == NULL) return;
}
lv_coord_t st = lv_obj_get_scroll_top(obj);
lv_coord_t sb = lv_obj_get_scroll_bottom(obj);
lv_coord_t sl = lv_obj_get_scroll_left(obj);
lv_coord_t sr = lv_obj_get_scroll_right(obj);
lv_indev_scroll_dir_t dir = lv_obj_get_scroll_dir(obj);
bool ver_draw = false;
if((dir & LV_DIR_VER) &&
((sm == LV_SCROLLBAR_MODE_ON) ||
(sm == LV_SCROLLBAR_MODE_AUTO && (st > 0 || sb > 0)) ||
(sm == LV_SCROLLBAR_MODE_ACTIVE && lv_indev_get_scroll_dir(indev) == LV_INDEV_SCROLL_DIR_VER))) {
ver_draw = true;
}
bool hor_draw = false;
if((dir & LV_DIR_HOR) &&
((sm == LV_SCROLLBAR_MODE_ON) ||
(sm == LV_SCROLLBAR_MODE_AUTO && (sl > 0 || sr > 0)) ||
(sm == LV_SCROLLBAR_MODE_ACTIVE && lv_indev_get_scroll_dir(indev) == LV_INDEV_SCROLL_DIR_HOR))) {
hor_draw = true;
}
if(!hor_draw && !ver_draw) return;
lv_coord_t end_space = lv_obj_get_style_pad_top(obj, LV_PART_SCROLLBAR);
lv_coord_t side_space = lv_obj_get_style_pad_right(obj, LV_PART_SCROLLBAR);
lv_coord_t tickness = lv_obj_get_style_size(obj, LV_PART_SCROLLBAR);
lv_coord_t obj_h = lv_obj_get_height(obj);
lv_coord_t obj_w = lv_obj_get_width(obj);
lv_coord_t ver_reg_space = ver_draw ? tickness + side_space : 0;
lv_coord_t hor_req_space = hor_draw ? tickness + side_space : 0;
lv_coord_t rem;
if(lv_area_get_size(&hor_area) <= 0 && lv_area_get_size(&ver_area) <= 0) return;
lv_draw_rect_dsc_t draw_dsc;
lv_res_t sb_res = scrollbar_init_draw_dsc(obj, &draw_dsc);
if(sb_res != LV_RES_OK) return;
lv_area_t area;
area.y1 = obj->coords.y1;
area.y2 = obj->coords.y2;
area.x2 = obj->coords.x2 - side_space;
area.x1 = area.x2 - tickness;
/*Draw horizontal scrollbar if the mode is ON or can be scrolled in this direction*/
lv_coord_t content_h = obj_h + st + sb;
if(ver_draw && content_h && _lv_area_is_on(&area, clip_area)) {
lv_coord_t sb_h = ((obj_h - end_space * 2 - hor_req_space) * obj_h) / content_h;
sb_h = LV_MAX(sb_h, SCROLLBAR_MIN_SIZE);
rem = (obj_h - end_space * 2 - hor_req_space) - sb_h; /*Remaining size from the scrollbar track that is not the scrollbar itself*/
lv_coord_t scroll_h = content_h - obj_h; /*The size of the content which can be really scrolled*/
if(scroll_h <= 0) {
area.y1 = obj->coords.y1 + end_space;
area.y2 = obj->coords.y2 - end_space - hor_req_space - 1;
area.x2 = obj->coords.x2 - side_space;
area.x1 = area.x2 - tickness + 1;
} else {
lv_coord_t sb_y = (rem * sb) / scroll_h;
sb_y = rem - sb_y;
area.y1 = obj->coords.y1 + sb_y + end_space;
area.y2 = area.y1 + sb_h - 1;
area.x2 = obj->coords.x2 - side_space;
area.x1 = area.x2 - tickness;
if(area.y1 < obj->coords.y1 + end_space) {
area.y1 = obj->coords.y1 + end_space;
if(area.y1 + SCROLLBAR_MIN_SIZE > area.y2) area.y2 = area.y1 + SCROLLBAR_MIN_SIZE;
}
if(area.y2 > obj->coords.y2 - hor_req_space - end_space) {
area.y2 = obj->coords.y2 - hor_req_space - end_space;
if(area.y2 - SCROLLBAR_MIN_SIZE < area.y1) area.y1 = area.y2 - SCROLLBAR_MIN_SIZE;
}
}
lv_draw_rect(&area, clip_area, &draw_dsc);
}
area.y2 = obj->coords.y2 - side_space;
area.y1 = area.y2 - tickness;
area.x1 = obj->coords.x1;
area.x2 = obj->coords.x2;
/*Draw horizontal scrollbar if the mode is ON or can be scrolled in this direction*/
lv_coord_t content_w = obj_w + sl + sr;
if(hor_draw && content_w && _lv_area_is_on(&area, clip_area)) {
lv_coord_t sb_w = ((obj_w - end_space * 2 - ver_reg_space) * obj_w) / content_w;
sb_w = LV_MAX(sb_w, SCROLLBAR_MIN_SIZE);
rem = (obj_w - end_space * 2 - ver_reg_space) - sb_w; /*Remaining size from the scrollbar track that is not the scrollbar itself*/
lv_coord_t scroll_w = content_w - obj_w; /*The size of the content which can be really scrolled*/
if(scroll_w <= 0) {
area.y2 = obj->coords.y2 - side_space;
area.y1 = area.y2 - tickness + 1;
area.x1 = obj->coords.x1 + end_space;
area.x2 = obj->coords.x2 - end_space - ver_reg_space - 1;
} else {
lv_coord_t sb_x = (rem * sr) / scroll_w;
sb_x = rem - sb_x;
area.x1 = obj->coords.x1 + sb_x + end_space;
area.x2 = area.x1 + sb_w - 1;
area.y2 = obj->coords.y2 - side_space;
area.y1 = area.y2 - tickness;
if(area.x1 < obj->coords.x1 + end_space) {
area.x1 = obj->coords.x1 + end_space;
if(area.x1 + SCROLLBAR_MIN_SIZE > area.x2) area.x2 = area.x1 + SCROLLBAR_MIN_SIZE;
}
if(area.x2 > obj->coords.x2 - ver_reg_space - end_space) {
area.x2 = obj->coords.x2 - ver_reg_space - end_space;
if(area.x2 - SCROLLBAR_MIN_SIZE < area.x1) area.x1 = area.x2 - SCROLLBAR_MIN_SIZE;
}
}
lv_draw_rect(&area, clip_area, &draw_dsc);
}
if(lv_area_get_size(&hor_area) > 0) lv_draw_rect(&hor_area, clip_area, &draw_dsc);
if(lv_area_get_size(&ver_area) > 0) lv_draw_rect(&ver_area, clip_area, &draw_dsc);
}
/**

View File

@ -371,6 +371,18 @@ lv_coord_t lv_obj_get_height_fit(const lv_obj_t * obj)
return lv_obj_get_height(obj) - top - bottom;
}
void lv_obj_get_coords_fit(const lv_obj_t * obj, lv_area_t * area)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_obj_get_coords(obj, area);
area->x1 += lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
area->x2 -= lv_obj_get_style_pad_right(obj, LV_PART_MAIN);
area->y1 += lv_obj_get_style_pad_top(obj, LV_PART_MAIN);
area->y2 -= lv_obj_get_style_pad_bottom(obj, LV_PART_MAIN);
}
lv_coord_t lv_obj_get_self_width(struct _lv_obj_t * obj)
{
lv_point_t p = {0, LV_COORD_MIN};
@ -423,6 +435,15 @@ void lv_obj_move_to(lv_obj_t * obj, lv_coord_t x, lv_coord_t y, bool notify)
lv_area_t ori;
lv_obj_get_coords(obj, &ori);
/*Check if the object inside the parent or not*/
lv_area_t parent_fit_area;
lv_obj_get_coords_fit(parent, &parent_fit_area);
/* If the object is already out of the parent and its position is changes
* surely the scrollbars also changes so invalidate them*/
bool on1 = _lv_area_is_in(&ori, &parent_fit_area, 0);
if(!on1) lv_obj_scrollbar_invalidate(parent);
obj->coords.x1 += diff.x;
obj->coords.y1 += diff.y;
obj->coords.x2 += diff.x;
@ -438,6 +459,11 @@ void lv_obj_move_to(lv_obj_t * obj, lv_coord_t x, lv_coord_t y, bool notify)
/*Invalidate the new area*/
lv_obj_invalidate(obj);
/* If the object was out of the parent invalidate the new scrollbar area too.
* If it wasn't out of the parent but out now, also invalidate the srollbars*/
bool on2 = _lv_area_is_in(&obj->coords, &parent_fit_area, 0);
if(on1 || (!on1 && on2)) lv_obj_scrollbar_invalidate(parent);
}
void lv_obj_move_children_by(lv_obj_t * obj, lv_coord_t x_diff, lv_coord_t y_diff)
@ -610,6 +636,17 @@ static bool refr_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h)
lv_area_t ori;
lv_obj_get_coords(obj, &ori);
lv_obj_t * parent = lv_obj_get_parent(obj);
/*Check if the object inside the parent or not*/
lv_area_t parent_fit_area;
lv_obj_get_coords_fit(parent, &parent_fit_area);
/* If the object is already out of the parent and its position is changes
* surely the scrollbars also changes so invalidate them*/
bool on1 = _lv_area_is_in(&ori, &parent_fit_area, 0);
if(!on1) lv_obj_scrollbar_invalidate(parent);
/* Set the length and height
* Be sure the content is not scrolled in an invalid position on the new size*/
obj->coords.y2 = obj->coords.y1 + h - 1;
@ -624,11 +661,15 @@ static bool refr_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h)
lv_signal_send(obj, LV_SIGNAL_COORD_CHG, &ori);
/*Send a signal to the parent too*/
lv_obj_t * par = lv_obj_get_parent(obj);
if(par != NULL) lv_signal_send(par, LV_SIGNAL_CHILD_CHG, obj);
if(parent != NULL) lv_signal_send(parent, LV_SIGNAL_CHILD_CHG, obj);
/*Invalidate the new area*/
lv_obj_invalidate(obj);
/* If the object was out of the parent invalidate the new scrollbar area too.
* If it wasn't out of the parent but out now, also invalidate the srollbars*/
bool on2 = _lv_area_is_in(&obj->coords, &parent_fit_area, 0);
if(on1 || (!on1 && on2)) lv_obj_scrollbar_invalidate(parent);
return true;
}

View File

@ -200,19 +200,26 @@ lv_coord_t lv_obj_get_width(const struct _lv_obj_t * obj);
lv_coord_t lv_obj_get_height(const struct _lv_obj_t * obj);
/**
* Get that width reduced by the left and right padding.
* Get the width reduced by the left and right padding.
* @param obj pointer to an object
* @return the width which still fits into the container without causing overflow (making the object scrollable)
* @return the width which still fits into its parent without causing overflow (making the parent scrollable)
*/
lv_coord_t lv_obj_get_width_fit(const struct _lv_obj_t * obj);
/**
* Get that height reduced by the top an bottom padding.
* Get the height reduced by the top an bottom padding.
* @param obj pointer to an object
* @return the height which still fits into the container without causing overflow (making the object scrollable)
* @return the height which still fits into the parent without causing overflow (making the parent scrollable)
*/
lv_coord_t lv_obj_get_height_fit(const struct _lv_obj_t * obj);
/**
* Get the area reduced by the paddings.
* @param obj pointer to an object
* @param area the area which still fits into the parent without causing overflow (making the parent scrollable)
*/
void lv_obj_get_coords_fit(const struct _lv_obj_t * obj, lv_area_t * area);
/**
* Get the width occupied by the "parts" of the widget. E.g. the width of all columns of a table.
* @param obj pointer to an objects

View File

@ -8,6 +8,8 @@
*********************/
#include "lv_obj_scroll.h"
#include "lv_obj.h"
#include "lv_indev.h"
#include "lv_disp.h"
/*********************
* DEFINES
@ -15,6 +17,7 @@
#define MY_CLASS &lv_obj_class
#define SCROLL_ANIM_TIME_MIN 200 /*ms*/
#define SCROLL_ANIM_TIME_MAX 400 /*ms*/
#define SCROLLBAR_MIN_SIZE (LV_DPX(10))
/**********************
* TYPEDEFS
@ -68,13 +71,13 @@ void lv_obj_set_scroll_dir(struct _lv_obj_t * obj, lv_dir_t dir)
}
}
void lv_obj_set_snap_align_x(struct _lv_obj_t * obj, lv_snap_align_t align)
void lv_obj_set_scroll_snap_align_x(struct _lv_obj_t * obj, lv_snap_align_t align)
{
lv_obj_allocate_spec_attr(obj);
obj->spec_attr->snap_align_x = align;
}
void lv_obj_set_snap_align_y(struct _lv_obj_t * obj, lv_snap_align_t align)
void lv_obj_set_scroll_snap_align_y(struct _lv_obj_t * obj, lv_snap_align_t align)
{
lv_obj_allocate_spec_attr(obj);
obj->spec_attr->snap_align_y = align;
@ -96,13 +99,13 @@ lv_dir_t lv_obj_get_scroll_dir(const struct _lv_obj_t * obj)
else return LV_DIR_ALL;
}
lv_snap_align_t lv_obj_get_snap_align_x(const struct _lv_obj_t * obj)
lv_snap_align_t lv_obj_get_scroll_snap_align_x(const struct _lv_obj_t * obj)
{
if(obj->spec_attr) return obj->spec_attr->snap_align_x;
else return LV_SCROLL_SNAP_ALIGN_NONE;
}
lv_snap_align_t lv_obj_get_snap_align_y(const struct _lv_obj_t * obj)
lv_snap_align_t lv_obj_get_scroll_snap_align_y(const struct _lv_obj_t * obj)
{
if(obj->spec_attr) return obj->spec_attr->snap_align_y;
else return LV_SCROLL_SNAP_ALIGN_NONE;
@ -386,6 +389,155 @@ void lv_obj_scroll_to_view_recursive(lv_obj_t * obj, lv_anim_enable_t anim_en)
}
}
void lv_obj_get_scrollbar_area(lv_obj_t * obj, lv_area_t * hor_area, lv_area_t * ver_area)
{
lv_area_set(hor_area, 0, 0, 0, 0);
lv_area_set(ver_area, 0, 0, 0, 0);
if(lv_obj_has_flag(obj, LV_OBJ_FLAG_SCROLLABLE) == false) return;
lv_indev_scroll_dir_t sm = lv_obj_get_scrollbar_mode(obj);
if(sm == LV_SCROLLBAR_MODE_OFF) return;
/*If there is no indev scrolling this object but `mode==active` return*/
lv_indev_t * indev = lv_indev_get_next(NULL);
if(sm == LV_SCROLLBAR_MODE_ACTIVE) {
while(indev) {
if(lv_indev_get_scroll_obj(indev) == obj) break;
indev = lv_indev_get_next(indev);
}
if(indev == NULL) return;
}
lv_coord_t st = lv_obj_get_scroll_top(obj);
lv_coord_t sb = lv_obj_get_scroll_bottom(obj);
lv_coord_t sl = lv_obj_get_scroll_left(obj);
lv_coord_t sr = lv_obj_get_scroll_right(obj);
lv_indev_scroll_dir_t dir = lv_obj_get_scroll_dir(obj);
bool ver_draw = false;
if((dir & LV_DIR_VER) &&
((sm == LV_SCROLLBAR_MODE_ON) ||
(sm == LV_SCROLLBAR_MODE_AUTO && (st > 0 || sb > 0)) ||
(sm == LV_SCROLLBAR_MODE_ACTIVE && lv_indev_get_scroll_dir(indev) == LV_INDEV_SCROLL_DIR_VER))) {
ver_draw = true;
}
bool hor_draw = false;
if((dir & LV_DIR_HOR) &&
((sm == LV_SCROLLBAR_MODE_ON) ||
(sm == LV_SCROLLBAR_MODE_AUTO && (sl > 0 || sr > 0)) ||
(sm == LV_SCROLLBAR_MODE_ACTIVE && lv_indev_get_scroll_dir(indev) == LV_INDEV_SCROLL_DIR_HOR))) {
hor_draw = true;
}
if(!hor_draw && !ver_draw) return;
lv_coord_t end_space = lv_obj_get_style_pad_top(obj, LV_PART_SCROLLBAR);
lv_coord_t side_space = lv_obj_get_style_pad_right(obj, LV_PART_SCROLLBAR);
lv_coord_t tickness = lv_obj_get_style_size(obj, LV_PART_SCROLLBAR);
lv_coord_t obj_h = lv_obj_get_height(obj);
lv_coord_t obj_w = lv_obj_get_width(obj);
lv_coord_t ver_reg_space = ver_draw ? tickness + side_space : 0;
lv_coord_t hor_req_space = hor_draw ? tickness + side_space : 0;
lv_coord_t rem;
if(lv_obj_get_style_bg_opa(obj, LV_PART_SCROLLBAR) < LV_OPA_MIN &&
lv_obj_get_style_border_opa(obj, LV_PART_SCROLLBAR) < LV_OPA_MIN) {
return;
}
/*Draw horizontal scrollbar if the mode is ON or can be scrolled in this direction*/
lv_coord_t content_h = obj_h + st + sb;
if(ver_draw && content_h) {
hor_area->y1 = obj->coords.y1;
hor_area->y2 = obj->coords.y2;
hor_area->x2 = obj->coords.x2 - side_space;
hor_area->x1 = hor_area->x2 - tickness;
lv_coord_t sb_h = ((obj_h - end_space * 2 - hor_req_space) * obj_h) / content_h;
sb_h = LV_MAX(sb_h, SCROLLBAR_MIN_SIZE);
rem = (obj_h - end_space * 2 - hor_req_space) - sb_h; /*Remaining size from the scrollbar track that is not the scrollbar itself*/
lv_coord_t scroll_h = content_h - obj_h; /*The size of the content which can be really scrolled*/
if(scroll_h <= 0) {
hor_area->y1 = obj->coords.y1 + end_space;
hor_area->y2 = obj->coords.y2 - end_space - hor_req_space - 1;
hor_area->x2 = obj->coords.x2 - side_space;
hor_area->x1 = hor_area->x2 - tickness + 1;
} else {
lv_coord_t sb_y = (rem * sb) / scroll_h;
sb_y = rem - sb_y;
hor_area->y1 = obj->coords.y1 + sb_y + end_space;
hor_area->y2 = hor_area->y1 + sb_h - 1;
hor_area->x2 = obj->coords.x2 - side_space;
hor_area->x1 = hor_area->x2 - tickness;
if(hor_area->y1 < obj->coords.y1 + end_space) {
hor_area->y1 = obj->coords.y1 + end_space;
if(hor_area->y1 + SCROLLBAR_MIN_SIZE > hor_area->y2) hor_area->y2 = hor_area->y1 + SCROLLBAR_MIN_SIZE;
}
if(hor_area->y2 > obj->coords.y2 - hor_req_space - end_space) {
hor_area->y2 = obj->coords.y2 - hor_req_space - end_space;
if(hor_area->y2 - SCROLLBAR_MIN_SIZE < hor_area->y1) hor_area->y1 = hor_area->y2 - SCROLLBAR_MIN_SIZE;
}
}
}
/*Draw horizontal scrollbar if the mode is ON or can be scrolled in this direction*/
lv_coord_t content_w = obj_w + sl + sr;
if(hor_draw && content_w) {
ver_area->y2 = obj->coords.y2 - side_space;
ver_area->y1 = ver_area->y2 - tickness;
ver_area->x1 = obj->coords.x1;
ver_area->x2 = obj->coords.x2;
lv_coord_t sb_w = ((obj_w - end_space * 2 - ver_reg_space) * obj_w) / content_w;
sb_w = LV_MAX(sb_w, SCROLLBAR_MIN_SIZE);
rem = (obj_w - end_space * 2 - ver_reg_space) - sb_w; /*Remaining size from the scrollbar track that is not the scrollbar itself*/
lv_coord_t scroll_w = content_w - obj_w; /*The size of the content which can be really scrolled*/
if(scroll_w <= 0) {
ver_area->y2 = obj->coords.y2 - side_space;
ver_area->y1 = ver_area->y2 - tickness + 1;
ver_area->x1 = obj->coords.x1 + end_space;
ver_area->x2 = obj->coords.x2 - end_space - ver_reg_space - 1;
} else {
lv_coord_t sb_x = (rem * sr) / scroll_w;
sb_x = rem - sb_x;
ver_area->x1 = obj->coords.x1 + sb_x + end_space;
ver_area->x2 = ver_area->x1 + sb_w - 1;
ver_area->y2 = obj->coords.y2 - side_space;
ver_area->y1 = ver_area->y2 - tickness;
if(ver_area->x1 < obj->coords.x1 + end_space) {
ver_area->x1 = obj->coords.x1 + end_space;
if(ver_area->x1 + SCROLLBAR_MIN_SIZE > ver_area->x2) ver_area->x2 = ver_area->x1 + SCROLLBAR_MIN_SIZE;
}
if(ver_area->x2 > obj->coords.x2 - ver_reg_space - end_space) {
ver_area->x2 = obj->coords.x2 - ver_reg_space - end_space;
if(ver_area->x2 - SCROLLBAR_MIN_SIZE < ver_area->x1) ver_area->x1 = ver_area->x2 - SCROLLBAR_MIN_SIZE;
}
}
}
}
void lv_obj_scrollbar_invalidate(lv_obj_t * obj)
{
lv_area_t hor_area;
lv_area_t ver_area;
lv_obj_get_scrollbar_area(obj, &hor_area, &ver_area);
if(lv_area_get_size(&hor_area) <= 0 && lv_area_get_size(&ver_area) <= 0) return;
if(lv_area_get_size(&hor_area) > 0) lv_obj_invalidate_area(obj, &hor_area);
if(lv_area_get_size(&ver_area) > 0) lv_obj_invalidate_area(obj, &ver_area);
}
/**********************
* STATIC FUNCTIONS
**********************/

View File

@ -73,14 +73,14 @@ void lv_obj_set_scroll_dir(struct _lv_obj_t * obj, lv_dir_t dir);
* @param obj pointer to an object
* @param align the snap align to set from `lv_snap_align_t`
*/
void lv_obj_set_snap_align_x(struct _lv_obj_t * obj, lv_snap_align_t align);
void lv_obj_set_scroll_snap_align_x(struct _lv_obj_t * obj, lv_snap_align_t align);
/**
* Set where to snap the children when scrolling ends vertically
* @param obj pointer to an object
* @param align the snap align to set from `lv_snap_align_t`
*/
void lv_obj_set_snap_align_y(struct _lv_obj_t * obj, lv_snap_align_t align);
void lv_obj_set_scroll_snap_align_y(struct _lv_obj_t * obj, lv_snap_align_t align);
/*=====================
* Getter functions
@ -105,14 +105,14 @@ lv_dir_t lv_obj_get_scroll_dir(const struct _lv_obj_t * obj);
* @param obj pointer to an object
* @return the current snap align from `lv_snap_align_t`
*/
lv_snap_align_t lv_obj_get_snap_align_x(const struct _lv_obj_t * obj);
lv_snap_align_t lv_obj_get_scroll_snap_align_x(const struct _lv_obj_t * obj);
/**
* Get where to snap the children when scrolling ends vertically
* @param obj pointer to an object
* @return the current snap align from `lv_snap_align_t`
*/
lv_snap_align_t lv_obj_get_snap_align_y(const struct _lv_obj_t * obj);
lv_snap_align_t lv_obj_get_scroll_snap_align_y(const struct _lv_obj_t * obj);
/**
* Get current X scroll position.
@ -248,6 +248,21 @@ void lv_obj_scroll_to_view(struct _lv_obj_t * obj, lv_anim_enable_t anim_en);
*/
void lv_obj_scroll_to_view_recursive(struct _lv_obj_t * obj, lv_anim_enable_t anim_en);
/**
* Get the area of the scrollbars
* @param obj pointer to an object
* @param hor_area pointer to store the area of the horizontal scrollbar
* @param ver_area pointer to store the area of the vertical scrollbar
*/
void lv_obj_get_scrollbar_area(struct _lv_obj_t * obj, lv_area_t * hor, lv_area_t * ver);
/**
* Invalidate the area of the scrollbars
* @param obj pointer to an object
*/
void lv_obj_scrollbar_invalidate(struct _lv_obj_t * obj);
/**********************
* MACROS
**********************/