Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/libs/lvgl/lv_objx/lv_page.c
1476 views
1
/*
2
* Copyright (c) 2019 CTCaer
3
*
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms and conditions of the GNU General Public License,
6
* version 2, as published by the Free Software Foundation.
7
*
8
* This program is distributed in the hope it will be useful, but WITHOUT
9
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11
* more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15
*/
16
17
/**
18
* @file lv_page.c
19
*
20
*/
21
22
/*********************
23
* INCLUDES
24
*********************/
25
#include "../lv_objx/lv_page.h"
26
#if USE_LV_PAGE != 0
27
28
#include "../lv_core/lv_group.h"
29
#include "../lv_draw/lv_draw.h"
30
#include "../lv_themes/lv_theme.h"
31
#include "../lv_core/lv_refr.h"
32
#include "../lv_misc/lv_anim.h"
33
#include "../lv_misc/lv_math.h"
34
35
/*********************
36
* DEFINES
37
*********************/
38
#define LV_PAGE_SB_MIN_SIZE (LV_DPI / 8)
39
#define LV_PAGE_SCROLL_ANIM_TIME 200 /*[ms] Scroll anim time on `lv_page_scroll_up/down/left/rigth`*/
40
#define LV_PAGE_END_FLASH_SIZE (LV_DPI / 4)
41
#define LV_PAGE_END_ANIM_TIME 300
42
#define LV_PAGE_END_ANIM_WAIT_TIME 300
43
44
/**********************
45
* TYPEDEFS
46
**********************/
47
48
/**********************
49
* STATIC PROTOTYPES
50
**********************/
51
static void lv_page_sb_refresh(lv_obj_t * page);
52
static bool lv_page_design(lv_obj_t * page, const lv_area_t * mask, lv_design_mode_t mode);
53
static bool lv_scrl_design(lv_obj_t * scrl, const lv_area_t * mask, lv_design_mode_t mode);
54
static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param);
55
static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void * param);
56
#if USE_LV_ANIMATION
57
static void edge_flash_anim(void * page, int32_t v);
58
static void edge_flash_anim_end(void * page);
59
#endif
60
61
/**********************
62
* STATIC VARIABLES
63
**********************/
64
static lv_design_func_t ancestor_design;
65
static lv_signal_func_t ancestor_signal;
66
67
/**********************
68
* MACROS
69
**********************/
70
71
/**********************
72
* GLOBAL FUNCTIONS
73
**********************/
74
75
/**
76
* Create a page objects
77
* @param par pointer to an object, it will be the parent of the new page
78
* @param copy pointer to a page object, if not NULL then the new object will be copied from it
79
* @return pointer to the created page
80
*/
81
lv_obj_t * lv_page_create(lv_obj_t * par, const lv_obj_t * copy)
82
{
83
LV_LOG_TRACE("page create started");
84
85
/*Create the ancestor object*/
86
lv_obj_t * new_page = lv_cont_create(par, copy);
87
lv_mem_assert(new_page);
88
if(new_page == NULL) return NULL;
89
90
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_page);
91
if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_page);
92
93
/*Allocate the object type specific extended data*/
94
lv_page_ext_t * ext = lv_obj_allocate_ext_attr(new_page, sizeof(lv_page_ext_t));
95
lv_mem_assert(ext);
96
if(ext == NULL) return NULL;
97
98
ext->scrl = NULL;
99
ext->pr_action = NULL;
100
ext->rel_action = NULL;
101
ext->sb.hor_draw = 0;
102
ext->sb.ver_draw = 0;
103
ext->bgo = NULL;
104
ext->pr = NULL;
105
ext->sb.style = &lv_style_pretty;
106
ext->sb.mode = LV_SB_MODE_AUTO;
107
ext->edge_flash.enabled = 0;
108
ext->edge_flash.bottom_ip = 0;
109
ext->edge_flash.top_ip = 0;
110
ext->edge_flash.left_ip = 0;
111
ext->edge_flash.right_ip = 0;
112
ext->edge_flash.state = 0;
113
ext->edge_flash.style = &lv_style_plain_color;
114
ext->arrow_scroll = 0;
115
ext->scroll_prop = 0;
116
ext->scroll_prop_ip = 0;
117
118
/*Init the new page object*/
119
if(copy == NULL) {
120
ext->scrl = lv_cont_create(new_page, NULL);
121
lv_obj_set_signal_func(ext->scrl, lv_page_scrollable_signal);
122
lv_obj_set_design_func(ext->scrl, lv_scrl_design);
123
lv_obj_set_drag(ext->scrl, true);
124
lv_obj_set_drag_throw(ext->scrl, true);
125
lv_obj_set_protect(ext->scrl, LV_PROTECT_PARENT | LV_PROTECT_PRESS_LOST);
126
lv_cont_set_fit(ext->scrl, false, true);
127
128
/* Add the signal function only if 'scrolling' is created
129
* because everything has to be ready before any signal is received*/
130
lv_obj_set_signal_func(new_page, lv_page_signal);
131
lv_obj_set_design_func(new_page, lv_page_design);
132
133
lv_page_set_sb_mode(new_page, ext->sb.mode);
134
135
/*Set the default styles*/
136
lv_theme_t * th = lv_theme_get_current();
137
if(th) {
138
if(par == NULL) { /*Different styles if it is screen*/
139
lv_page_set_style(new_page, LV_PAGE_STYLE_BG, th->bg);
140
lv_page_set_style(new_page, LV_PAGE_STYLE_SCRL, &lv_style_transp);
141
} else {
142
lv_page_set_style(new_page, LV_PAGE_STYLE_BG, th->page.bg);
143
lv_page_set_style(new_page, LV_PAGE_STYLE_SCRL, th->page.scrl);
144
145
}
146
lv_page_set_style(new_page, LV_PAGE_STYLE_SB, th->page.sb);
147
} else {
148
lv_page_set_style(new_page, LV_PAGE_STYLE_BG, &lv_style_pretty_color);
149
lv_page_set_style(new_page, LV_PAGE_STYLE_SCRL, &lv_style_pretty);
150
lv_page_set_style(new_page, LV_PAGE_STYLE_SB, &lv_style_pretty_color);
151
}
152
153
} else {
154
lv_page_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
155
ext->scrl = lv_cont_create(new_page, copy_ext->scrl);
156
ext->bgo = lv_page_get_style(copy, LV_PAGE_STYLE_BGO);
157
ext->pr = lv_page_get_style(copy, LV_PAGE_STYLE_PR);
158
lv_obj_set_signal_func(ext->scrl, lv_page_scrollable_signal);
159
160
lv_page_set_pr_action(new_page, copy_ext->pr_action);
161
lv_page_set_rel_action(new_page, copy_ext->rel_action);
162
lv_page_set_sb_mode(new_page, copy_ext->sb.mode);
163
lv_page_set_arrow_scroll(new_page, copy_ext->arrow_scroll);
164
165
166
lv_page_set_style(new_page, LV_PAGE_STYLE_BG, lv_page_get_style(copy, LV_PAGE_STYLE_BG));
167
lv_page_set_style(new_page, LV_PAGE_STYLE_SCRL, lv_page_get_style(copy, LV_PAGE_STYLE_SCRL));
168
lv_page_set_style(new_page, LV_PAGE_STYLE_SB, lv_page_get_style(copy, LV_PAGE_STYLE_SB));
169
170
/* Add the signal function only if 'scrolling' is created
171
* because everything has to be ready before any signal is received*/
172
lv_obj_set_signal_func(new_page, lv_page_signal);
173
lv_obj_set_design_func(new_page, lv_page_design);
174
175
/*Refresh the style with new signal function*/
176
lv_obj_refresh_style(new_page);
177
}
178
179
lv_page_sb_refresh(new_page);
180
181
LV_LOG_INFO("page created");
182
183
return new_page;
184
}
185
186
/**
187
* Delete all children of the scrl object, without deleting scrl child.
188
* @param obj pointer to an object
189
*/
190
void lv_page_clean(lv_obj_t * obj)
191
{
192
lv_obj_t * scrl = lv_page_get_scrl(obj);
193
lv_obj_clean(scrl);
194
}
195
196
/*=====================
197
* Setter functions
198
*====================*/
199
200
/**
201
* Set a release action for the page
202
* @param page pointer to a page object
203
* @param rel_action a function to call when the page is release
204
*/
205
void lv_page_set_rel_action(lv_obj_t * page, lv_action_t rel_action)
206
{
207
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
208
ext->rel_action = rel_action;
209
}
210
211
/**
212
* Set a press action for the page
213
* @param page pointer to a page object
214
* @param pr_action a function to call when the page is pressed
215
*/
216
void lv_page_set_pr_action(lv_obj_t * page, lv_action_t pr_action)
217
{
218
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
219
ext->pr_action = pr_action;
220
}
221
222
/**
223
* Set the scroll bar mode on a page
224
* @param page pointer to a page object
225
* @param sb_mode the new mode from 'lv_page_sb.mode_t' enum
226
*/
227
void lv_page_set_sb_mode(lv_obj_t * page, lv_sb_mode_t sb_mode)
228
{
229
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
230
if(ext->sb.mode == sb_mode) return;
231
232
if(sb_mode == LV_SB_MODE_HIDE) ext->sb.mode |= LV_SB_MODE_HIDE; /*Set the hidden flag*/
233
else if(sb_mode == LV_SB_MODE_UNHIDE) ext->sb.mode &= (~LV_SB_MODE_HIDE); /*Clear the hidden flag*/
234
else {
235
if(ext->sb.mode & LV_SB_MODE_HIDE) sb_mode |= LV_SB_MODE_HIDE;
236
ext->sb.mode = sb_mode;
237
}
238
239
ext->sb.hor_draw = 0;
240
ext->sb.ver_draw = 0;
241
242
lv_page_sb_refresh(page);
243
lv_obj_invalidate(page);
244
}
245
246
/**
247
* Enable/Disable scrolling with arrows if the page is in group (arrows: LV_GROUP_KEY_LEFT/RIGHT/UP/DOWN)
248
* @param page pointer to a page object
249
* @param en true: enable scrolling with arrows
250
*/
251
void lv_page_set_arrow_scroll(lv_obj_t * page, bool en)
252
{
253
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
254
ext->arrow_scroll = en ? 1 : 0;
255
}
256
257
/**
258
* Enable the scroll propagation feature. If enabled then the page will move its parent if there is no more space to scroll.
259
* @param page pointer to a Page
260
* @param en true or false to enable/disable scroll propagation
261
*/
262
void lv_page_set_scroll_propagation(lv_obj_t * page, bool en)
263
{
264
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
265
ext->scroll_prop = en ? 1 : 0;
266
}
267
268
/**
269
* Enable the edge flash effect. (Show an arc when the an edge is reached)
270
* @param page pointer to a Page
271
* @param en true or false to enable/disable end flash
272
*/
273
void lv_page_set_edge_flash(lv_obj_t * page, bool en)
274
{
275
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
276
ext->edge_flash.enabled = en ? 1 : 0;
277
}
278
279
/**
280
* Set a style of a page
281
* @param page pointer to a page object
282
* @param type which style should be set
283
* @param style pointer to a style
284
* */
285
void lv_page_set_style(lv_obj_t * page, lv_page_style_t type, lv_style_t * style)
286
{
287
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
288
289
switch(type) {
290
case LV_PAGE_STYLE_BG:
291
lv_obj_set_style(page, style);
292
break;
293
case LV_PAGE_STYLE_BGO:
294
ext->bgo = style;
295
break;
296
case LV_PAGE_STYLE_PR:
297
ext->pr = style;
298
break;
299
case LV_PAGE_STYLE_SCRL:
300
lv_obj_set_style(ext->scrl, style);
301
break;
302
case LV_PAGE_STYLE_SB:
303
ext->sb.style = style;
304
lv_area_set_height(&ext->sb.hor_area, ext->sb.style->body.padding.inner);
305
lv_area_set_width(&ext->sb.ver_area, ext->sb.style->body.padding.inner);
306
lv_page_sb_refresh(page);
307
lv_obj_refresh_ext_size(page);
308
lv_obj_invalidate(page);
309
break;
310
case LV_PAGE_STYLE_EDGE_FLASH:
311
ext->edge_flash.style = style;
312
break;
313
}
314
}
315
316
/*=====================
317
* Getter functions
318
*====================*/
319
320
/**
321
* Get the scrollable object of a page
322
* @param page pointer to a page object
323
* @return pointer to a container which is the scrollable part of the page
324
*/
325
lv_obj_t * lv_page_get_scrl(const lv_obj_t * page)
326
{
327
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
328
329
return ext->scrl;
330
}
331
332
/**
333
* Get the press action of the page
334
* @param page pointer to a page object
335
* @return a function to call when the page is pressed
336
*/
337
lv_action_t lv_page_get_pr_action(lv_obj_t * page)
338
{
339
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
340
return ext->pr_action;
341
}
342
343
/**
344
* Get the release action of the page
345
* @param page pointer to a page object
346
* @return a function to call when the page is released
347
*/
348
lv_action_t lv_page_get_rel_action(lv_obj_t * page)
349
{
350
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
351
return ext->rel_action;
352
}
353
354
/**
355
* Set the scroll bar mode on a page
356
* @param page pointer to a page object
357
* @return the mode from 'lv_page_sb.mode_t' enum
358
*/
359
lv_sb_mode_t lv_page_get_sb_mode(const lv_obj_t * page)
360
{
361
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
362
return ext->sb.mode;
363
}
364
365
/**
366
* Get the the scrolling with arrows (LV_GROUP_KEY_LEFT/RIGHT/UP/DOWN) is enabled or not
367
* @param page pointer to a page object
368
* @return true: scrolling with arrows is enabled
369
*/
370
bool lv_page_get_arrow_scroll(const lv_obj_t * page)
371
{
372
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
373
return ext->arrow_scroll ? true : false;
374
}
375
376
/**
377
* Get the scroll propagation property
378
* @param page pointer to a Page
379
* @return true or false
380
*/
381
bool lv_page_get_scroll_propagation(lv_obj_t * page)
382
{
383
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
384
return ext->scroll_prop == 0 ? false : true;
385
}
386
387
/**
388
* Get the edge flash effect property.
389
* @param page pointer to a Page
390
* return true or false
391
*/
392
bool lv_page_get_edge_flash(lv_obj_t * page)
393
{
394
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
395
return ext->edge_flash.enabled == 0 ? false : true;
396
}
397
398
/**
399
* Get that width which can be set to the children to still not cause overflow (show scrollbars)
400
* @param page pointer to a page object
401
* @return the width which still fits into the page
402
*/
403
lv_coord_t lv_page_get_fit_width(lv_obj_t * page)
404
{
405
lv_style_t * bg_style = lv_page_get_style(page, LV_PAGE_STYLE_BG);
406
lv_style_t * scrl_style = lv_page_get_style(page, LV_PAGE_STYLE_SCRL);
407
408
return lv_obj_get_width(page) - 2 * (bg_style->body.padding.hor + scrl_style->body.padding.hor);
409
}
410
411
/**
412
* Get that height which can be set to the children to still not cause overflow (show scrollbars)
413
* @param page pointer to a page object
414
* @return the height which still fits into the page
415
*/
416
lv_coord_t lv_page_get_fit_height(lv_obj_t * page)
417
{
418
lv_style_t * bg_style = lv_page_get_style(page, LV_PAGE_STYLE_BG);
419
lv_style_t * scrl_style = lv_page_get_style(page, LV_PAGE_STYLE_SCRL);
420
421
return lv_obj_get_height(page) - 2 * (bg_style->body.padding.ver + scrl_style->body.padding.ver);
422
}
423
424
/**
425
* Get a style of a page
426
* @param page pointer to page object
427
* @param type which style should be get
428
* @return style pointer to a style
429
* */
430
lv_style_t * lv_page_get_style(const lv_obj_t * page, lv_page_style_t type)
431
{
432
lv_style_t * style = NULL;
433
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
434
435
switch(type) {
436
case LV_PAGE_STYLE_BG:
437
style = lv_obj_get_style(page);
438
break;
439
case LV_PAGE_STYLE_BGO:
440
style = ext->bgo;
441
break;
442
case LV_PAGE_STYLE_PR:
443
style = ext->pr;
444
break;
445
case LV_PAGE_STYLE_SCRL:
446
style = lv_obj_get_style(ext->scrl);
447
break;
448
case LV_PAGE_STYLE_SB:
449
style = ext->sb.style;
450
break;
451
case LV_PAGE_STYLE_EDGE_FLASH:
452
style = ext->edge_flash.style;
453
break;
454
default:
455
style = NULL;
456
break;
457
}
458
459
return style;
460
}
461
462
/*=====================
463
* Other functions
464
*====================*/
465
466
/**
467
* Glue the object to the page. After it the page can be moved (dragged) with this object too.
468
* @param obj pointer to an object on a page
469
* @param glue true: enable glue, false: disable glue
470
*/
471
void lv_page_glue_obj(lv_obj_t * obj, bool glue)
472
{
473
lv_obj_set_drag_parent(obj, glue);
474
lv_obj_set_drag(obj, glue);
475
}
476
477
/**
478
* Focus on an object. It ensures that the object will be visible on the page.
479
* @param page pointer to a page object
480
* @param obj pointer to an object to focus (must be on the page)
481
* @param anim_time scroll animation time in milliseconds (0: no animation)
482
*/
483
void lv_page_focus(lv_obj_t * page, const lv_obj_t * obj, uint16_t anim_time)
484
{
485
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
486
487
#if USE_LV_ANIMATION == 0
488
anim_time = 0;
489
#else
490
/* Be sure there is no position changing animation in progress
491
* because it can overide the current changes*/
492
lv_anim_del(page, (lv_anim_fp_t)lv_obj_set_y);
493
lv_anim_del(page, (lv_anim_fp_t)lv_obj_set_pos);
494
lv_anim_del(ext->scrl, (lv_anim_fp_t)lv_obj_set_y);
495
lv_anim_del(ext->scrl, (lv_anim_fp_t)lv_obj_set_pos);
496
#endif
497
498
lv_style_t * style = lv_page_get_style(page, LV_PAGE_STYLE_BG);
499
lv_style_t * style_scrl = lv_page_get_style(page, LV_PAGE_STYLE_SCRL);
500
501
lv_coord_t obj_y = obj->coords.y1 - ext->scrl->coords.y1;
502
lv_coord_t obj_h = lv_obj_get_height(obj);
503
lv_coord_t scrlable_y = lv_obj_get_y(ext->scrl);
504
lv_coord_t page_h = lv_obj_get_height(page);
505
506
lv_coord_t top_err = -(scrlable_y + obj_y);
507
lv_coord_t bot_err = scrlable_y + obj_y + obj_h - page_h;
508
509
/*If obj is higher then the page focus where the "error" is smaller*/
510
511
/*Out of the page on the top*/
512
if((obj_h <= page_h && top_err > 0) ||
513
(obj_h > page_h && top_err < bot_err)) {
514
/*Calculate a new position and let some space above*/
515
scrlable_y = -(obj_y - style_scrl->body.padding.ver - style->body.padding.ver);
516
scrlable_y += style_scrl->body.padding.ver;
517
}
518
/*Out of the page on the bottom*/
519
else if((obj_h <= page_h && bot_err > 0) ||
520
(obj_h > page_h && top_err >= bot_err)) {
521
/*Calculate a new position and let some space below*/
522
scrlable_y = -(obj_y + style_scrl->body.padding.ver + style->body.padding.ver);
523
scrlable_y -= style_scrl->body.padding.ver;
524
scrlable_y += page_h - obj_h;
525
} else {
526
/*Already in focus*/
527
return;
528
}
529
530
if(anim_time == 0) {
531
lv_obj_set_y(ext->scrl, scrlable_y);
532
#if USE_LV_ANIMATION
533
} else {
534
lv_anim_t a;
535
a.act_time = 0;
536
a.start = lv_obj_get_y(ext->scrl);
537
a.end = scrlable_y;
538
a.time = anim_time;
539
a.end_cb = NULL;
540
a.playback = 0;
541
a.repeat = 0;
542
a.var = ext->scrl;
543
a.path = lv_anim_path_linear;
544
a.fp = (lv_anim_fp_t) lv_obj_set_y;
545
lv_anim_create(&a);
546
#endif
547
}
548
}
549
550
/**
551
* Scroll the page horizontally
552
* @param page pointer to a page object
553
* @param dist the distance to scroll (< 0: scroll right; > 0 scroll left)
554
*/
555
void lv_page_scroll_hor(lv_obj_t * page, lv_coord_t dist)
556
{
557
lv_obj_t * scrl = lv_page_get_scrl(page);
558
559
#if USE_LV_ANIMATION
560
lv_anim_t a;
561
a.var = scrl;
562
a.start = lv_obj_get_x(scrl);
563
a.end = a.start + dist;
564
a.fp = (lv_anim_fp_t)lv_obj_set_x;
565
a.path = lv_anim_path_linear;
566
a.end_cb = NULL;
567
a.act_time = 0;
568
a.time = LV_PAGE_SCROLL_ANIM_TIME;
569
a.playback = 0;
570
a.playback_pause = 0;
571
a.repeat = 0;
572
a.repeat_pause = 0;
573
lv_anim_create(&a);
574
#else
575
lv_obj_set_x(scrl, lv_obj_get_x(scrl) + dist);
576
#endif
577
}
578
579
/**
580
* Scroll the page vertically
581
* @param page pointer to a page object
582
* @param dist the distance to scroll (< 0: scroll down; > 0 scroll up)
583
*/
584
void lv_page_scroll_ver(lv_obj_t * page, lv_coord_t dist)
585
{
586
lv_obj_t * scrl = lv_page_get_scrl(page);
587
588
#if USE_LV_ANIMATION
589
lv_anim_t a;
590
a.var = scrl;
591
a.start = lv_obj_get_y(scrl);
592
a.end = a.start + dist;
593
a.fp = (lv_anim_fp_t)lv_obj_set_y;
594
a.path = lv_anim_path_linear;
595
a.end_cb = NULL;
596
a.act_time = 0;
597
a.time = LV_PAGE_SCROLL_ANIM_TIME;
598
a.playback = 0;
599
a.playback_pause = 0;
600
a.repeat = 0;
601
a.repeat_pause = 0;
602
lv_anim_create(&a);
603
#else
604
lv_obj_set_y(scrl, lv_obj_get_y(scrl) + dist);
605
#endif
606
}
607
608
/**
609
* Not intended to use directly by the user but by other object types internally.
610
* Start an edge flash animation. Exactly one `ext->edge_flash.xxx_ip` should be set
611
* @param page
612
*/
613
void lv_page_start_edge_flash(lv_obj_t * page)
614
{
615
#if USE_LV_ANIMATION
616
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
617
if(ext->edge_flash.enabled) {
618
lv_anim_t a;
619
a.var = page;
620
a.start = 0;
621
a.end = LV_PAGE_END_FLASH_SIZE;
622
a.fp = (lv_anim_fp_t)edge_flash_anim;
623
a.path = lv_anim_path_linear;
624
a.end_cb = edge_flash_anim_end;
625
a.act_time = 0;
626
a.time = LV_PAGE_END_ANIM_TIME;
627
a.playback = 1;
628
a.playback_pause = LV_PAGE_END_ANIM_WAIT_TIME;
629
a.repeat = 0;
630
a.repeat_pause = 0;
631
lv_anim_create(&a);
632
}
633
#endif
634
}
635
636
637
/**********************
638
* STATIC FUNCTIONS
639
**********************/
640
641
/**
642
* Handle the drawing related tasks of the pages
643
* @param page pointer to an object
644
* @param mask the object will be drawn only in this area
645
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
646
* (return 'true' if yes)
647
* LV_DESIGN_DRAW: draw the object (always return 'true')
648
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
649
* @param return true/false, depends on 'mode'
650
*/
651
static bool lv_page_design(lv_obj_t * page, const lv_area_t * mask, lv_design_mode_t mode)
652
{
653
if(mode == LV_DESIGN_COVER_CHK) {
654
return ancestor_design(page, mask, mode);
655
} else if(mode == LV_DESIGN_DRAW_MAIN) {
656
/*Draw without border*/
657
lv_style_t * style = lv_page_get_style(page, LV_PAGE_STYLE_BG);
658
lv_coord_t border_width_tmp = style->body.border.width;
659
style->body.border.width = 0;
660
lv_draw_rect(&page->coords, mask, style, lv_obj_get_opa_scale(page));
661
style->body.border.width = border_width_tmp;
662
663
} else if(mode == LV_DESIGN_DRAW_POST) { /*Draw the scroll bars finally*/
664
665
/*Draw only a border*/
666
lv_style_t * style = lv_page_get_style(page, LV_PAGE_STYLE_BG);
667
lv_coord_t shadow_width_tmp = style->body.shadow.width;
668
uint8_t empty_tmp = style->body.empty;
669
style->body.shadow.width = 0;
670
style->body.empty = 1;
671
lv_draw_rect(&page->coords, mask, style, lv_obj_get_opa_scale(page));
672
style->body.shadow.width = shadow_width_tmp;
673
style->body.empty = empty_tmp;
674
675
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
676
677
/*Draw the scrollbars*/
678
lv_area_t sb_area;
679
if(ext->sb.hor_draw && (ext->sb.mode & LV_SB_MODE_HIDE) == 0) {
680
/*Convert the relative coordinates to absolute*/
681
lv_area_copy(&sb_area, &ext->sb.hor_area);
682
sb_area.x1 += page->coords.x1;
683
sb_area.y1 += page->coords.y1;
684
sb_area.x2 += page->coords.x1;
685
sb_area.y2 += page->coords.y1;
686
lv_draw_rect(&sb_area, mask, ext->sb.style, lv_obj_get_opa_scale(page));
687
}
688
689
if(ext->sb.ver_draw && (ext->sb.mode & LV_SB_MODE_HIDE) == 0) {
690
/*Convert the relative coordinates to absolute*/
691
lv_area_copy(&sb_area, &ext->sb.ver_area);
692
sb_area.x1 += page->coords.x1;
693
sb_area.y1 += page->coords.y1;
694
sb_area.x2 += page->coords.x1;
695
sb_area.y2 += page->coords.y1;
696
lv_draw_rect(&sb_area, mask, ext->sb.style, lv_obj_get_opa_scale(page));
697
}
698
699
700
lv_coord_t page_w = lv_obj_get_width(page);
701
lv_coord_t page_h = lv_obj_get_height(page);
702
lv_area_t flash_area;
703
704
if(ext->edge_flash.top_ip) {
705
flash_area.x1 = page->coords.x1 - page_w;
706
flash_area.x2 = page->coords.x2 + page_w;
707
flash_area.y1 = page->coords.y1 - 3 * page_w + ext->edge_flash.state;
708
flash_area.y2 = page->coords.y1 + ext->edge_flash.state;
709
}
710
else if(ext->edge_flash.bottom_ip) {
711
flash_area.x1 = page->coords.x1 - page_w;
712
flash_area.x2 = page->coords.x2 + page_w;
713
flash_area.y1 = page->coords.y2 - ext->edge_flash.state;
714
flash_area.y2 = page->coords.y2 + 3 * page_w - ext->edge_flash.state;
715
}
716
else if(ext->edge_flash.right_ip) {
717
flash_area.x1 = page->coords.x2 - ext->edge_flash.state;
718
flash_area.x2 = page->coords.x2 + 3 * page_h - ext->edge_flash.state;
719
flash_area.y1 = page->coords.y1 - page_h;
720
flash_area.y2 = page->coords.y2 + page_h;
721
}
722
else if(ext->edge_flash.left_ip) {
723
flash_area.x1 = page->coords.x1 - 3 * page_h + ext->edge_flash.state;
724
flash_area.x2 = page->coords.x1 + ext->edge_flash.state;
725
flash_area.y1 = page->coords.y1 - page_h;
726
flash_area.y2 = page->coords.y2 + page_h;
727
}
728
729
if(ext->edge_flash.left_ip || ext->edge_flash.right_ip || ext->edge_flash.top_ip || ext->edge_flash.bottom_ip) {
730
lv_style_t flash_style;
731
lv_style_copy(&flash_style, ext->edge_flash.style);
732
flash_style.body.radius = LV_RADIUS_CIRCLE;
733
uint32_t opa = (flash_style.body.opa * ext->edge_flash.state) / LV_PAGE_END_FLASH_SIZE;
734
flash_style.body.opa = opa;
735
lv_draw_rect(&flash_area, mask, &flash_style, lv_obj_get_opa_scale(page));
736
}
737
738
}
739
740
return true;
741
}
742
743
/**
744
* Handle the drawing related tasks of the scrollable object
745
* @param scrl pointer to an object
746
* @param mask the object will be drawn only in this area
747
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
748
* (return 'true' if yes)
749
* LV_DESIGN_DRAW: draw the object (always return 'true')
750
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
751
* @param return true/false, depends on 'mode'
752
*/
753
static bool lv_scrl_design(lv_obj_t * scrl, const lv_area_t * mask, lv_design_mode_t mode)
754
{
755
if(mode == LV_DESIGN_COVER_CHK) {
756
return ancestor_design(scrl, mask, mode);
757
} else if(mode == LV_DESIGN_DRAW_MAIN) {
758
#if USE_LV_GROUP
759
/* If the page is focused in a group and
760
* the background object is not visible (transparent or empty)
761
* then "activate" the style of the scrollable*/
762
lv_style_t * style_scrl_ori = lv_obj_get_style(scrl);
763
lv_obj_t * page = lv_obj_get_parent(scrl);
764
lv_style_t * style_page = lv_obj_get_style(page);
765
lv_group_t * g = lv_obj_get_group(page);
766
if((style_page->body.empty || style_page->body.opa == LV_OPA_TRANSP) && style_page->body.border.width == 0) { /*Is the background visible?*/
767
if(lv_group_get_focused(g) == page) {
768
lv_style_t * style_mod;
769
style_mod = lv_group_mod_style(g, style_scrl_ori);
770
scrl->style_p = style_mod; /*Temporally change the style to the activated */
771
}
772
}
773
#endif
774
ancestor_design(scrl, mask, mode);
775
776
#if USE_LV_GROUP
777
scrl->style_p = style_scrl_ori; /*Revert the style*/
778
#endif
779
} else if(mode == LV_DESIGN_DRAW_POST) {
780
ancestor_design(scrl, mask, mode);
781
}
782
783
return true;
784
}
785
786
/**
787
* Signal function of the page
788
* @param page pointer to a page object
789
* @param sign a signal type from lv_signal_t enum
790
* @param param pointer to a signal specific variable
791
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
792
*/
793
static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param)
794
{
795
lv_res_t res;
796
797
/* Include the ancient signal function */
798
res = ancestor_signal(page, sign, param);
799
if(res != LV_RES_OK) return res;
800
801
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
802
lv_style_t * style = lv_obj_get_style(page);
803
lv_obj_t * child;
804
if(sign == LV_SIGNAL_CHILD_CHG) { /*Automatically move children to the scrollable object*/
805
child = lv_obj_get_child(page, NULL);
806
while(child != NULL) {
807
if(lv_obj_is_protected(child, LV_PROTECT_PARENT) == false) {
808
lv_obj_t * tmp = child;
809
child = lv_obj_get_child(page, child); /*Get the next child before move this*/
810
lv_obj_set_parent(tmp, ext->scrl);
811
} else {
812
child = lv_obj_get_child(page, child);
813
}
814
}
815
} else if(sign == LV_SIGNAL_STYLE_CHG) {
816
/*If no hor_fit enabled set the scrollable's width to the page's width*/
817
if(lv_cont_get_hor_fit(ext->scrl) == false) {
818
lv_obj_set_width(ext->scrl, lv_obj_get_width(page) - 2 * style->body.padding.hor);
819
} else {
820
ext->scrl->signal_func(ext->scrl, LV_SIGNAL_CORD_CHG, &ext->scrl->coords);
821
}
822
823
/*The scrollbars are important only if they are visible now*/
824
if(ext->sb.hor_draw || ext->sb.ver_draw) lv_page_sb_refresh(page);
825
826
/*Refresh the ext. size because the scrollbars might be positioned out of the page*/
827
lv_obj_refresh_ext_size(page);
828
} else if(sign == LV_SIGNAL_CORD_CHG) {
829
/*Refresh the scrollbar and notify the scrl if the size is changed*/
830
if(ext->scrl != NULL && (lv_obj_get_width(page) != lv_area_get_width(param) ||
831
lv_obj_get_height(page) != lv_area_get_height(param))) {
832
/*If no hor_fit enabled set the scrollable's width to the page's width*/
833
if(lv_cont_get_hor_fit(ext->scrl) == false) {
834
lv_obj_set_width(ext->scrl, lv_obj_get_width(page) - 2 * style->body.padding.hor);
835
}
836
837
ext->scrl->signal_func(ext->scrl, LV_SIGNAL_CORD_CHG, &ext->scrl->coords);
838
839
/*The scrollbars are important only if they are visible now*/
840
if(ext->sb.hor_draw || ext->sb.ver_draw) lv_page_sb_refresh(page);
841
}
842
} else if(sign == LV_SIGNAL_PRESSED) {
843
if(ext->pr_action != NULL) {
844
res = ext->pr_action(page);
845
}
846
} else if(sign == LV_SIGNAL_RELEASED) {
847
if(lv_indev_is_dragging(lv_indev_get_act()) == false) {
848
if(ext->rel_action != NULL) {
849
res = ext->rel_action(page);
850
}
851
}
852
} else if(sign == LV_SIGNAL_REFR_EXT_SIZE) {
853
/*Ensure ext. size for the scrollbars if they are out of the page*/
854
if(page->ext_size < (-ext->sb.style->body.padding.hor)) page->ext_size = -ext->sb.style->body.padding.hor;
855
if(page->ext_size < (-ext->sb.style->body.padding.ver)) page->ext_size = -ext->sb.style->body.padding.ver;
856
} else if(sign == LV_SIGNAL_CONTROLL) {
857
uint32_t c = *((uint32_t *) param);
858
859
if((c == LV_GROUP_KEY_DOWN) && ext->arrow_scroll) {
860
lv_page_scroll_ver(page, - lv_obj_get_height(page) / 4);
861
} else if((c == LV_GROUP_KEY_UP) && ext->arrow_scroll) {
862
lv_page_scroll_ver(page, lv_obj_get_height(page) / 4);
863
} else if((c == LV_GROUP_KEY_RIGHT) && ext->arrow_scroll) {
864
/*If the page can be scrolled horizontally because it's not wide enough then scroll it vertically*/
865
if(lv_page_get_scrl_width(page) < lv_obj_get_width(page)) lv_page_scroll_ver(page, - lv_obj_get_height(page) / 4);
866
else lv_page_scroll_hor(page, - lv_obj_get_width(page) / 4);
867
} else if((c == LV_GROUP_KEY_LEFT) && ext->arrow_scroll) {
868
/*If the page can be scrolled horizontally because it's not wide enough then scroll it vertically*/
869
if(lv_page_get_scrl_width(page) < lv_obj_get_width(page)) lv_page_scroll_ver(page, lv_obj_get_height(page) / 4);
870
else lv_page_scroll_hor(page, lv_obj_get_width(page) / 4);
871
}
872
} else if(sign == LV_SIGNAL_GET_EDITABLE) {
873
bool * editable = (bool *)param;
874
*editable = lv_page_get_arrow_scroll(page);
875
} else if(sign == LV_SIGNAL_GET_TYPE) {
876
lv_obj_type_t * buf = param;
877
uint8_t i;
878
for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/
879
if(buf->type[i] == NULL) break;
880
}
881
buf->type[i] = "lv_page";
882
}
883
884
return res;
885
}
886
887
/**
888
* Signal function of the scrollable part of a page
889
* @param scrl pointer to the scrollable object
890
* @param sign a signal type from lv_signal_t enum
891
* @param param pointer to a signal specific variable
892
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
893
*/
894
static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void * param)
895
{
896
lv_res_t res;
897
898
/* Include the ancient signal function */
899
res = ancestor_signal(scrl, sign, param);
900
if(res != LV_RES_OK) return res;
901
902
lv_obj_t * page = lv_obj_get_parent(scrl);
903
lv_style_t * page_style = lv_obj_get_style(page);
904
lv_page_ext_t * page_ext = lv_obj_get_ext_attr(page);
905
906
if(sign == LV_SIGNAL_CORD_CHG) {
907
/*Limit the position of the scrollable object to be always visible
908
* (Do not let its edge inner then its parent respective edge)*/
909
lv_coord_t new_x = lv_obj_get_x(scrl);
910
lv_coord_t new_y = lv_obj_get_y(scrl);
911
bool refr_x = false;
912
bool refr_y = false;
913
lv_area_t page_coords;
914
lv_area_t scrl_coords;
915
lv_obj_get_coords(scrl, &scrl_coords);
916
lv_obj_get_coords(page, &page_coords);
917
918
lv_area_t * ori_coords = (lv_area_t *) param;
919
lv_coord_t diff_x = scrl->coords.x1 - ori_coords->x1;
920
lv_coord_t diff_y = scrl->coords.y1 - ori_coords->y1;
921
lv_coord_t hpad = page_style->body.padding.hor;
922
lv_coord_t vpad = page_style->body.padding.ver;
923
lv_obj_t * page_parent = lv_obj_get_parent(page);
924
925
lv_indev_t * indev = lv_indev_get_act();
926
lv_point_t drag_vect;
927
lv_indev_get_vect(indev, &drag_vect);
928
929
930
/* Start the scroll propagation if there is drag vector on the indev, but the drag is not started yet
931
* and the scrollable is in a corner. It will enable the scroll propagation only when a new scroll begins and not
932
* when the scrollable is already being scrolled.*/
933
if(page_ext->scroll_prop && page_ext->scroll_prop_ip == 0 && lv_indev_is_dragging(indev) == false) {
934
if(((drag_vect.y > 0 && scrl_coords.y1 == page_coords.y1 + vpad) ||
935
(drag_vect.y < 0 && scrl_coords.y2 == page_coords.y2 - vpad)) &&
936
((drag_vect.x > 0 && scrl_coords.x1 == page_coords.x1 + hpad) ||
937
(drag_vect.x < 0 && scrl_coords.x2 == page_coords.x2 - hpad))) {
938
939
if(lv_obj_get_parent(page_parent) != NULL) { /*Do not propagate the scroll to a screen*/
940
page_ext->scroll_prop_ip = 1;
941
}
942
}
943
}
944
945
/*scrollable width smaller then page width? -> align to left*/
946
if(lv_area_get_width(&scrl_coords) + 2 * hpad <= lv_area_get_width(&page_coords)) {
947
if(scrl_coords.x1 != page_coords.x1 + hpad) {
948
new_x = hpad;
949
refr_x = true;
950
}
951
} else {
952
/*If the scroll propagation is in progress revert the original coordinates (don't let the page scroll)*/
953
if(page_ext->scroll_prop_ip) {
954
if(drag_vect.x == diff_x) { /*`scrl` is bouncing: drag pos. it somewhere and here it is reverted. Handle only the pos. because of drag*/
955
new_x = ori_coords->x1 - page_coords.x1;
956
refr_x = true;
957
}
958
}
959
/*The edges of the scrollable can not be in the page (minus hpad) */
960
else if(scrl_coords.x2 < page_coords.x2 - hpad) {
961
new_x = lv_area_get_width(&page_coords) - lv_area_get_width(&scrl_coords) - hpad; /* Right align */
962
refr_x = true;
963
if(page_ext->edge_flash.enabled &&
964
page_ext->edge_flash.left_ip == 0 && page_ext->edge_flash.right_ip == 0 &&
965
page_ext->edge_flash.top_ip == 0 && page_ext->edge_flash.bottom_ip == 0) {
966
lv_page_start_edge_flash(page);
967
page_ext->edge_flash.right_ip = 1;
968
}
969
}
970
else if(scrl_coords.x1 > page_coords.x1 + hpad) {
971
new_x = hpad; /*Left align*/
972
refr_x = true;
973
if(page_ext->edge_flash.enabled &&
974
page_ext->edge_flash.left_ip == 0 && page_ext->edge_flash.right_ip == 0 &&
975
page_ext->edge_flash.top_ip == 0 && page_ext->edge_flash.bottom_ip == 0) {
976
lv_page_start_edge_flash(page);
977
page_ext->edge_flash.left_ip = 1;
978
}
979
}
980
}
981
982
/*scrollable height smaller then page height? -> align to left*/
983
if(lv_area_get_height(&scrl_coords) + 2 * vpad <= lv_area_get_height(&page_coords)) {
984
if(scrl_coords.y1 != page_coords.y1 + vpad) {
985
new_y = vpad;
986
refr_y = true;
987
}
988
} else {
989
/*If the scroll propagation is in progress revert the original coordinates (don't let the page scroll)*/
990
if(page_ext->scroll_prop_ip) {
991
if(drag_vect.y == diff_y) { /*`scrl` is bouncing: drag pos. it somewhere and here it is reverted. Handle only the pos. because of drag*/
992
new_y = ori_coords->y1 - page_coords.y1;
993
refr_y = true;
994
}
995
}
996
/*The edges of the scrollable can not be in the page (minus vpad) */
997
else if(scrl_coords.y2 < page_coords.y2 - vpad) {
998
new_y = lv_area_get_height(&page_coords) - lv_area_get_height(&scrl_coords) - vpad; /* Bottom align */
999
refr_y = true;
1000
if(page_ext->edge_flash.enabled &&
1001
page_ext->edge_flash.left_ip == 0 && page_ext->edge_flash.right_ip == 0 &&
1002
page_ext->edge_flash.top_ip == 0 && page_ext->edge_flash.bottom_ip == 0) {
1003
lv_page_start_edge_flash(page);
1004
page_ext->edge_flash.bottom_ip = 1;
1005
}
1006
}
1007
else if(scrl_coords.y1 > page_coords.y1 + vpad) {
1008
new_y = vpad; /*Top align*/
1009
refr_y = true;
1010
if(page_ext->edge_flash.enabled &&
1011
page_ext->edge_flash.left_ip == 0 && page_ext->edge_flash.right_ip == 0 &&
1012
page_ext->edge_flash.top_ip == 0 && page_ext->edge_flash.bottom_ip == 0) {
1013
lv_page_start_edge_flash(page);
1014
page_ext->edge_flash.top_ip = 1;
1015
}
1016
}
1017
}
1018
1019
if(refr_x || refr_y) {
1020
lv_obj_set_pos(scrl, new_x, new_y);
1021
1022
if(page_ext->scroll_prop_ip) {
1023
if(refr_y) lv_obj_set_y(page_parent, lv_obj_get_y(page_parent) + diff_y);
1024
if(refr_x) lv_obj_set_x(page_parent, lv_obj_get_x(page_parent) + diff_x);
1025
}
1026
}
1027
1028
lv_page_sb_refresh(page);
1029
}
1030
else if(sign == LV_SIGNAL_DRAG_END) {
1031
1032
/*Scroll propagation is finished on drag end*/
1033
page_ext->scroll_prop_ip = 0;
1034
1035
/*Hide scrollbars if required*/
1036
if(page_ext->sb.mode == LV_SB_MODE_DRAG) {
1037
lv_area_t sb_area_tmp;
1038
if(page_ext->sb.hor_draw) {
1039
lv_area_copy(&sb_area_tmp, &page_ext->sb.hor_area);
1040
sb_area_tmp.x1 += page->coords.x1;
1041
sb_area_tmp.y1 += page->coords.y1;
1042
sb_area_tmp.x2 += page->coords.x1;
1043
sb_area_tmp.y2 += page->coords.y1;
1044
lv_inv_area(&sb_area_tmp);
1045
page_ext->sb.hor_draw = 0;
1046
}
1047
if(page_ext->sb.ver_draw) {
1048
lv_area_copy(&sb_area_tmp, &page_ext->sb.ver_area);
1049
sb_area_tmp.x1 += page->coords.x1;
1050
sb_area_tmp.y1 += page->coords.y1;
1051
sb_area_tmp.x2 += page->coords.x1;
1052
sb_area_tmp.y2 += page->coords.y1;
1053
lv_inv_area(&sb_area_tmp);
1054
page_ext->sb.ver_draw = 0;
1055
}
1056
}
1057
} else if(sign == LV_SIGNAL_PRESSED) {
1058
if(page_ext->pr_action != NULL) {
1059
res = page_ext->pr_action(page);
1060
}
1061
} else if(sign == LV_SIGNAL_RELEASED) {
1062
if(lv_indev_is_dragging(lv_indev_get_act()) == false) {
1063
if(page_ext->rel_action != NULL) {
1064
res = page_ext->rel_action(page);
1065
}
1066
}
1067
}
1068
1069
return res;
1070
}
1071
1072
1073
/**
1074
* Refresh the position and size of the scroll bars.
1075
* @param page pointer to a page object
1076
*/
1077
static void lv_page_sb_refresh(lv_obj_t * page)
1078
{
1079
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
1080
lv_style_t * style = lv_obj_get_style(page);
1081
lv_obj_t * scrl = ext->scrl;
1082
lv_coord_t size_tmp;
1083
lv_coord_t scrl_w = lv_obj_get_width(scrl);
1084
lv_coord_t scrl_h = lv_obj_get_height(scrl);
1085
lv_coord_t hpad = style->body.padding.hor;
1086
lv_coord_t vpad = style->body.padding.ver;
1087
lv_coord_t obj_w = lv_obj_get_width(page);
1088
lv_coord_t obj_h = lv_obj_get_height(page);
1089
1090
/*Always let 'scrollbar width' padding above, under, left and right to the scrollbars
1091
* else:
1092
* - horizontal and vertical scrollbars can overlap on the corners
1093
* - if the page has radius the scrollbar can be out of the radius */
1094
lv_coord_t sb_hor_pad = LV_MATH_MAX(ext->sb.style->body.padding.inner, style->body.padding.hor);
1095
lv_coord_t sb_ver_pad = LV_MATH_MAX(ext->sb.style->body.padding.inner, style->body.padding.ver);
1096
1097
if(ext->sb.mode == LV_SB_MODE_OFF) return;
1098
1099
if(ext->sb.mode == LV_SB_MODE_ON) {
1100
ext->sb.hor_draw = 1;
1101
ext->sb.ver_draw = 1;
1102
}
1103
1104
/*Invalidate the current (old) scrollbar areas*/
1105
lv_area_t sb_area_tmp;
1106
if(ext->sb.hor_draw != 0) {
1107
lv_area_copy(&sb_area_tmp, &ext->sb.hor_area);
1108
sb_area_tmp.x1 += page->coords.x1;
1109
sb_area_tmp.y1 += page->coords.y1;
1110
sb_area_tmp.x2 += page->coords.x1;
1111
sb_area_tmp.y2 += page->coords.y1;
1112
lv_inv_area(&sb_area_tmp);
1113
}
1114
if(ext->sb.ver_draw != 0) {
1115
lv_area_copy(&sb_area_tmp, &ext->sb.ver_area);
1116
sb_area_tmp.x1 += page->coords.x1;
1117
sb_area_tmp.y1 += page->coords.y1;
1118
sb_area_tmp.x2 += page->coords.x1;
1119
sb_area_tmp.y2 += page->coords.y1;
1120
lv_inv_area(&sb_area_tmp);
1121
}
1122
1123
1124
if(ext->sb.mode == LV_SB_MODE_DRAG && lv_indev_is_dragging(lv_indev_get_act()) == false) {
1125
ext->sb.hor_draw = 0;
1126
ext->sb.ver_draw = 0;
1127
return;
1128
1129
}
1130
1131
/*Horizontal scrollbar*/
1132
if(scrl_w <= obj_w - 2 * hpad) { /*Full sized scroll bar*/
1133
lv_area_set_width(&ext->sb.hor_area, obj_w - 2 * sb_hor_pad);
1134
lv_area_set_pos(&ext->sb.hor_area, sb_hor_pad, obj_h - ext->sb.style->body.padding.inner - ext->sb.style->body.padding.ver);
1135
if(ext->sb.mode == LV_SB_MODE_AUTO || ext->sb.mode == LV_SB_MODE_DRAG) ext->sb.hor_draw = 0;
1136
} else {
1137
size_tmp = (obj_w * (obj_w - (2 * sb_hor_pad))) / (scrl_w + 2 * hpad);
1138
if(size_tmp < LV_PAGE_SB_MIN_SIZE) size_tmp = LV_PAGE_SB_MIN_SIZE;
1139
lv_area_set_width(&ext->sb.hor_area, size_tmp);
1140
1141
lv_area_set_pos(&ext->sb.hor_area, sb_hor_pad +
1142
(-(lv_obj_get_x(scrl) - hpad) * (obj_w - size_tmp - 2 * sb_hor_pad)) /
1143
(scrl_w + 2 * hpad - obj_w),
1144
obj_h - ext->sb.style->body.padding.inner - ext->sb.style->body.padding.ver);
1145
1146
if(ext->sb.mode == LV_SB_MODE_AUTO || ext->sb.mode == LV_SB_MODE_DRAG) ext->sb.hor_draw = 1;
1147
}
1148
1149
/*Vertical scrollbar*/
1150
if(scrl_h <= obj_h - 2 * vpad) { /*Full sized scroll bar*/
1151
lv_area_set_height(&ext->sb.ver_area, obj_h - 2 * sb_ver_pad);
1152
lv_area_set_pos(&ext->sb.ver_area, obj_w - ext->sb.style->body.padding.inner - ext->sb.style->body.padding.hor, sb_ver_pad);
1153
if(ext->sb.mode == LV_SB_MODE_AUTO || ext->sb.mode == LV_SB_MODE_DRAG) ext->sb.ver_draw = 0;
1154
} else {
1155
size_tmp = (obj_h * (obj_h - (2 * sb_ver_pad))) / (scrl_h + 2 * vpad);
1156
if(size_tmp < LV_PAGE_SB_MIN_SIZE) size_tmp = LV_PAGE_SB_MIN_SIZE;
1157
lv_area_set_height(&ext->sb.ver_area, size_tmp);
1158
1159
lv_area_set_pos(&ext->sb.ver_area, obj_w - ext->sb.style->body.padding.inner - ext->sb.style->body.padding.hor,
1160
sb_ver_pad +
1161
(-(lv_obj_get_y(scrl) - vpad) * (obj_h - size_tmp - 2 * sb_ver_pad)) /
1162
(scrl_h + 2 * vpad - obj_h));
1163
1164
if(ext->sb.mode == LV_SB_MODE_AUTO || ext->sb.mode == LV_SB_MODE_DRAG) ext->sb.ver_draw = 1;
1165
}
1166
1167
/*Invalidate the new scrollbar areas*/
1168
if(ext->sb.hor_draw != 0) {
1169
lv_area_copy(&sb_area_tmp, &ext->sb.hor_area);
1170
sb_area_tmp.x1 += page->coords.x1;
1171
sb_area_tmp.y1 += page->coords.y1;
1172
sb_area_tmp.x2 += page->coords.x1;
1173
sb_area_tmp.y2 += page->coords.y1;
1174
lv_inv_area(&sb_area_tmp);
1175
}
1176
if(ext->sb.ver_draw != 0) {
1177
lv_area_copy(&sb_area_tmp, &ext->sb.ver_area);
1178
sb_area_tmp.x1 += page->coords.x1;
1179
sb_area_tmp.y1 += page->coords.y1;
1180
sb_area_tmp.x2 += page->coords.x1;
1181
sb_area_tmp.y2 += page->coords.y1;
1182
lv_inv_area(&sb_area_tmp);
1183
}
1184
}
1185
1186
#if USE_LV_ANIMATION
1187
static void edge_flash_anim(void * page, int32_t v)
1188
{
1189
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
1190
ext->edge_flash.state = v;
1191
lv_obj_invalidate(page);
1192
}
1193
1194
static void edge_flash_anim_end(void * page)
1195
{
1196
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
1197
ext->edge_flash.top_ip = 0;
1198
ext->edge_flash.bottom_ip = 0;
1199
ext->edge_flash.left_ip = 0;
1200
ext->edge_flash.right_ip = 0;
1201
lv_obj_invalidate(page);
1202
}
1203
#endif
1204
1205
#endif
1206
1207