@@ -179,8 +179,10 @@ static void StartInertialScrolling(LCUI_Widget w)
179
179
{
180
180
int distance ;
181
181
int64_t time_delta ;
182
+
182
183
LCUI_ScrollBar scrollbar ;
183
184
InertialScrolling effect ;
185
+
184
186
scrollbar = Widget_GetData (w , self .prototype );
185
187
effect = & scrollbar -> effect ;
186
188
effect -> end_pos = scrollbar -> pos ;
@@ -386,12 +388,13 @@ static void ScrollBar_UpdateSize(LCUI_Widget w)
386
388
}
387
389
}
388
390
389
- static void ScrollLayer_OnWheel (LCUI_Widget target , LCUI_WidgetEvent e ,
390
- void * arg )
391
+ static void ScrollBox_OnWheel (LCUI_Widget box , LCUI_WidgetEvent e , void * arg )
391
392
{
392
393
int pos , new_pos ;
394
+
393
395
LCUI_Widget w = e -> data ;
394
396
LCUI_ScrollBar scrollbar = Widget_GetData (w , self .prototype );
397
+
395
398
pos = ScrollBar_GetPosition (w );
396
399
if (e -> wheel .delta > 0 ) {
397
400
new_pos = pos - scrollbar -> scroll_step ;
@@ -405,15 +408,16 @@ static void ScrollLayer_OnWheel(LCUI_Widget target, LCUI_WidgetEvent e,
405
408
}
406
409
}
407
410
408
- /** 滚动层的触屏事件响应 */
409
- static void ScrollLayer_OnTouch (LCUI_Widget target , LCUI_WidgetEvent e ,
410
- void * arg )
411
+ /** 容器的触屏事件响应 */
412
+ static void ScrollBox_OnTouch (LCUI_Widget box , LCUI_WidgetEvent e , void * arg )
411
413
{
412
414
uint_t time_delta ;
413
415
int i , pos , distance ;
414
- LCUI_TouchPoint point ;
416
+
415
417
LCUI_Widget w = e -> data ;
416
418
LCUI_ScrollBar scrollbar ;
419
+ LCUI_TouchPoint point ;
420
+
417
421
if (e -> touch .n_points < 1 ) {
418
422
return ;
419
423
}
@@ -451,14 +455,14 @@ static void ScrollLayer_OnTouch(LCUI_Widget target, LCUI_WidgetEvent e,
451
455
scrollbar -> is_draggable = TRUE;
452
456
break ;
453
457
case LCUI_WEVENT_TOUCHUP :
454
- Widget_ReleaseTouchCapture (target , -1 );
458
+ Widget_ReleaseTouchCapture (box , -1 );
455
459
time_delta = (uint_t )LCUI_GetTimeDelta (scrollbar -> timestamp );
456
460
if (scrollbar -> is_dragged && time_delta < 50 ) {
457
461
StartInertialScrolling (w );
458
462
}
459
463
scrollbar -> touch_point_id = -1 ;
460
464
scrollbar -> is_dragged = FALSE;
461
- Widget_BlockEvent (target , FALSE);
465
+ Widget_BlockEvent (box , FALSE);
462
466
break ;
463
467
case LCUI_WEVENT_TOUCHMOVE :
464
468
if (!scrollbar -> is_draggable ) {
@@ -495,11 +499,11 @@ static void ScrollLayer_OnTouch(LCUI_Widget target, LCUI_WidgetEvent e,
495
499
e -> cancel_bubble = FALSE;
496
500
break ;
497
501
}
498
- /* start drag action and block all events of target */
502
+ /* start drag action and block all events of box */
499
503
scrollbar -> is_dragged = TRUE;
500
504
LCUIWidget_ClearEventTarget (NULL );
501
- Widget_BlockEvent (target , TRUE);
502
- Widget_SetTouchCapture (target , point -> id );
505
+ Widget_BlockEvent (box , TRUE);
506
+ Widget_SetTouchCapture (box , point -> id );
503
507
default :
504
508
break ;
505
509
}
@@ -525,13 +529,18 @@ void ScrollBar_BindBox(LCUI_Widget w, LCUI_Widget box)
525
529
if (scrollbar -> box ) {
526
530
Widget_UnbindEvent (scrollbar -> box , "resize" ,
527
531
ScrollBar_OnUpdateSize );
532
+ Widget_UnbindEvent (box , "setscroll" , ScrollBar_OnSetPosition );
533
+ Widget_UnbindEvent (box , "mousewheel" , ScrollBox_OnWheel );
534
+ Widget_UnbindEvent (box , "touch" , ScrollBox_OnTouch );
528
535
}
529
536
scrollbar -> box = box ;
530
537
if (box ) {
531
538
Widget_BindEvent (box , "resize" , ScrollBar_OnUpdateSize , w ,
532
539
NULL );
533
540
Widget_BindEvent (box , "setscroll" , ScrollBar_OnSetPosition , w ,
534
541
NULL );
542
+ Widget_BindEvent (box , "mousewheel" , ScrollBox_OnWheel , w , NULL );
543
+ Widget_BindEvent (box , "touch" , ScrollBox_OnTouch , w , NULL );
535
544
}
536
545
ScrollBar_UpdateSize (w );
537
546
}
@@ -547,8 +556,6 @@ void ScrollBar_BindTarget(LCUI_Widget w, LCUI_Widget target)
547
556
scrollbar -> target = target ;
548
557
Widget_AddClass (target , "scrollbar-target" );
549
558
Widget_BindEvent (target , "resize" , ScrollBar_OnUpdateSize , w , NULL );
550
- Widget_BindEvent (target , "mousewheel" , ScrollLayer_OnWheel , w , NULL );
551
- Widget_BindEvent (target , "touch" , ScrollLayer_OnTouch , w , NULL );
552
559
ScrollBar_UpdateSize (w );
553
560
}
554
561
0 commit comments