@@ -339,56 +339,17 @@ impl<T, W: Widget<T>> ClipBox<T, W> {
339339 }
340340 }
341341
342- /// Changes the viewport offset by `delta`.
343- ///
344- /// Returns true if the offset actually changed. Even if `delta` is non-zero, the offset might
345- /// not change. For example, if you try to move the viewport down but it is already at the
346- /// bottom of the child widget, then the offset will not change and this function will return
347- /// false.
348- pub fn pan_by ( & mut self , ctx : & mut EventCtx , delta : Vec2 ) -> bool {
349- self . pan_to ( ctx: & mut EventCtx , self . viewport_origin ( ) + delta)
350- }
351-
352- /// Changes the viewport offset on the specified axis to 'position'.
353- ///
354- /// The other axis will remain unchanged.
355- pub fn pan_to_on_axis ( & mut self , ctx : & mut EventCtx , axis : Axis , position : f64 ) -> bool {
356- let new_origin = axis. pack ( position, axis. minor_pos ( self . viewport_origin ( ) ) ) ;
357- self . with_port ( ctx, |ctx, port| { port. pan_to ( new_origin. into ( ) ) ; } )
358- }
359-
360- /// Sets the viewport origin to `pos`.
361- ///
362- /// Returns true if the position changed. Note that the valid values for the viewport origin
363- /// are constrained by the size of the child, and so the origin might not get set to exactly
364- /// `pos`.
365- pub fn pan_to ( & mut self , ctx : & mut EventCtx , origin : Point ) -> bool {
366- self . with_port ( ctx, |ctx, port|{ port. pan_to ( origin) ; } )
367- }
368-
369- /// Adjust the viewport to display as much of the target region as is possible.
370- ///
371- /// Returns `true` if the viewport changes.
372- ///
373- /// This will move the viewport the smallest distance that fully shows
374- /// the target region. If the target region is larger than the viewport,
375- /// we will display the portion that fits, prioritizing the portion closest
376- /// to the origin.
377- pub fn pan_to_visible ( & mut self , ctx : & mut EventCtx , region : Rect ) -> bool {
378- self . with_port ( ctx, |ctx, port|{ port. pan_to_visible ( region) ; } )
379- }
380-
381342 /// Modify the `ClipBox`'s viewport rectangle with a closure.
382343 ///
383344 /// The provided callback function can modify its argument, and when it is
384345 /// done then this `ClipBox` will be modified to have the new viewport rectangle.
385- pub fn with_port < F : FnOnce ( & mut EventCtx , & mut Viewport ) > ( & mut self , ctx : & mut EventCtx , f : F ) -> bool {
346+ pub fn with_port < F : FnOnce ( & mut EventCtx , & mut Viewport ) > ( & mut self , ctx : & mut EventCtx , data : T , env : & Env , f : F ) -> bool {
386347 f ( ctx, & mut self . port ) ;
387348 let new_content_origin = -self . port . view_origin ;
388349
389350 if new_content_origin != self . child . layout_rect ( ) . origin ( ) {
390351 self . child
391- . set_origin_dyn ( ctx, new_content_origin) ;
352+ . set_origin_dyn ( ctx, data , env , new_content_origin) ;
392353 true
393354 } else {
394355 false
@@ -406,7 +367,7 @@ impl<T: Data, W: Widget<T>> Widget<T> for ClipBox<T, W> {
406367 // prevent unexpected behaviour, by clipping SCROLL_TO_VIEW notifications
407368 // to this ClipBox's viewport.
408369 ctx. set_handled ( ) ;
409- self . with_port ( ctx, |ctx, port| {
370+ self . with_port ( ctx, data , env , |ctx, port| {
410371 port. fixed_scroll_to_view_handling (
411372 ctx,
412373 * global_highlight_rect,
@@ -416,7 +377,7 @@ impl<T: Data, W: Widget<T>> Widget<T> for ClipBox<T, W> {
416377 }
417378 }
418379 } else {
419- self . child . event ( ctx, & child_event , data, env) ;
380+ self . child . event ( ctx, event , data, env) ;
420381 }
421382 }
422383
@@ -462,11 +423,11 @@ impl<T: Data, W: Widget<T>> Widget<T> for ClipBox<T, W> {
462423 } ;
463424
464425 self . port . content_size = content_size;
465- self . child . set_origin ( ctx, data, env, Point :: ORIGIN ) ;
466-
467426 self . port . view_size = bc. constrain ( content_size) ;
468- let new_offset = self . port . clamp_view_origin ( self . viewport_origin ( ) ) ;
469- self . pan_to ( new_offset) ;
427+
428+ let new_offset = -self . port . clamp_view_origin ( -self . child . layout_rect ( ) . origin ( ) ) ;
429+ self . child . set_origin ( ctx, data, env, new_offset) ;
430+
470431 trace ! ( "Computed sized: {}" , self . viewport_size( ) ) ;
471432 self . viewport_size ( )
472433 }
0 commit comments