Skip to content

Commit 196f47c

Browse files
committed
fix(widget): Scrollbar_BindBox() not working after scrollbar initialize
1 parent 8c1d105 commit 196f47c

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/gui/widget/scrollbar.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,14 @@ static void Slider_OnMouseDown( LCUI_Widget slider,
309309
Widget_BindEvent( slider, "mouseup", Slider_OnMouseUp, w, NULL );
310310
}
311311

312+
static void ScrollBar_OnLink( LCUI_Widget w, LCUI_WidgetEvent e, void *arg )
313+
{
314+
LCUI_ScrollBar scrollbar = Widget_GetData( w, self.prototype );
315+
if( !scrollbar->box ) {
316+
ScrollBar_BindBox( w, w->parent );
317+
}
318+
}
319+
312320
static void ScrollBar_OnInit( LCUI_Widget w )
313321
{
314322
LCUI_Widget slider;
@@ -329,9 +337,9 @@ static void ScrollBar_OnInit( LCUI_Widget w )
329337
InitInertialScrolling( &scrollbar->effect );
330338
Widget_BindEvent( slider, "mousedown",
331339
Slider_OnMouseDown, w, NULL );
340+
Widget_BindEvent( w, "link", ScrollBar_OnLink, NULL, NULL );
332341
Widget_AddClass( slider, "scrollbar-slider" );
333342
Widget_Append( w, slider );
334-
ScrollBar_BindBox( w, w->parent );
335343
}
336344

337345
static void ScrollBar_UpdateSize( LCUI_Widget w )
@@ -493,8 +501,10 @@ void ScrollBar_BindBox( LCUI_Widget w, LCUI_Widget box )
493501
ScrollBar_OnUpdateSize );
494502
}
495503
scrollbar->box = box;
496-
Widget_BindEvent( box, "resize", ScrollBar_OnUpdateSize, w, NULL );
497-
Widget_BindEvent( box, "setscroll", ScrollBar_OnSetPosition, w, NULL );
504+
if( box ) {
505+
Widget_BindEvent( box, "resize", ScrollBar_OnUpdateSize, w, NULL );
506+
Widget_BindEvent( box, "setscroll", ScrollBar_OnSetPosition, w, NULL );
507+
}
498508
ScrollBar_UpdateSize( w );
499509
}
500510

0 commit comments

Comments
 (0)