@@ -39,6 +39,9 @@ pub struct State {
3939 /// and remains that way until the user moves the scroll_handle. Once unstuck (false)
4040 /// it remains false until the scroll touches the end position, which reenables stickiness.
4141 scroll_stuck_to_end : Vec2b ,
42+
43+ /// Area that can be dragged. This is the size of the content from the last frame.
44+ interact_rect : Option < Rect > ,
4245}
4346
4447impl Default for State {
@@ -52,6 +55,7 @@ impl Default for State {
5255 vel : Vec2 :: ZERO ,
5356 scroll_start_offset_from_top_left : [ None ; 2 ] ,
5457 scroll_stuck_to_end : Vec2b :: TRUE ,
58+ interact_rect : None ,
5559 }
5660 }
5761}
@@ -473,9 +477,6 @@ struct Prepared {
473477 scrolling_enabled : bool ,
474478 stick_to_end : Vec2b ,
475479 animated : bool ,
476-
477- /// Id of the drag area. We store this until we know the size of the content to interact with.
478- drag_area_id : Id ,
479480}
480481
481482impl ScrollArea {
@@ -588,16 +589,15 @@ impl ScrollArea {
588589 let viewport = Rect :: from_min_size ( Pos2 :: ZERO + state. offset , inner_size) ;
589590 let dt = ui. input ( |i| i. stable_dt ) . at_most ( 0.1 ) ;
590591
591- let drag_area_id = id. with ( "area" ) ;
592-
593592 if ( scrolling_enabled && drag_to_scroll)
594593 && ( state. content_is_too_large [ 0 ] || state. content_is_too_large [ 1 ] )
595594 {
596595 // Drag contents to scroll (for touch screens mostly).
597596 // We must do this BEFORE adding content to the `ScrollArea`,
598597 // or we will steal input from the widgets we contain.
599- // This response is not available on the first frame.
600- let content_response_option = ui. ctx ( ) . read_response ( drag_area_id) ;
598+ let content_response_option = state
599+ . interact_rect
600+ . map ( |rect| ui. interact ( rect, id. with ( "area" ) , Sense :: drag ( ) ) ) ;
601601
602602 if content_response_option. map ( |response| response. dragged ( ) ) == Some ( true ) {
603603 for d in 0 ..2 {
@@ -677,7 +677,6 @@ impl ScrollArea {
677677 scrolling_enabled,
678678 stick_to_end,
679679 animated,
680- drag_area_id,
681680 }
682681 }
683682
@@ -790,7 +789,6 @@ impl Prepared {
790789 scrolling_enabled,
791790 stick_to_end,
792791 animated,
793- drag_area_id,
794792 } = self ;
795793
796794 let content_size = content_ui. min_size ( ) ;
@@ -882,10 +880,6 @@ impl Prepared {
882880 Rect :: from_min_size ( inner_rect. min , inner_size)
883881 } ;
884882
885- // At this point we know the actual size of the area we can interact with, so we do the interaction
886- // here. The result is ignored and read at the start of the frame.
887- let _ = ui. interact ( inner_rect, drag_area_id, Sense :: drag ( ) ) ;
888-
889883 let outer_rect = Rect :: from_min_size ( inner_rect. min , inner_rect. size ( ) + current_bar_use) ;
890884
891885 let content_is_too_large = Vec2b :: new (
@@ -1211,6 +1205,7 @@ impl Prepared {
12111205
12121206 state. show_scroll = show_scroll_this_frame;
12131207 state. content_is_too_large = content_is_too_large;
1208+ state. interact_rect = Some ( inner_rect) ;
12141209
12151210 state. store ( ui. ctx ( ) , id) ;
12161211
0 commit comments