@@ -512,6 +512,35 @@ impl ItemRc {
512512 result
513513 }
514514
515+ /// Returns an absolute position of `p` in the `ancestor`'s coordinate system
516+ /// (does not add this item's x and y)
517+ /// Don't rely on any specific behavior if `self` isn't a descendant of `ancestor`.
518+ fn map_to_ancestor ( & self , p : LogicalPoint , ancestor : & Self ) -> LogicalPoint {
519+ let mut current = self . clone ( ) ;
520+ let mut result = p;
521+ if & current == ancestor {
522+ return result;
523+ }
524+ let supports_transformations = self
525+ . window_adapter ( )
526+ . map ( |adapter| adapter. renderer ( ) . supports_transformations ( ) )
527+ . unwrap_or ( true ) ;
528+ while let Some ( parent) = current. parent_item ( ParentItemTraversalMode :: StopAtPopups ) {
529+ if & parent == ancestor {
530+ break ;
531+ }
532+ let geometry = parent. geometry ( ) ;
533+ if supports_transformations {
534+ if let Some ( transform) = parent. children_transform ( ) {
535+ result = transform. transform_point ( result. cast ( ) ) . cast ( ) ;
536+ }
537+ }
538+ result += geometry. origin . to_vector ( ) ;
539+ current = parent;
540+ }
541+ result
542+ }
543+
515544 /// Return the index of the item within the ItemTree
516545 pub fn index ( & self ) -> u32 {
517546 self . index
@@ -847,6 +876,40 @@ impl ItemRc {
847876 // Should practically always be possible.
848877 . and_then ( |child_transform| child_transform. inverse ( ) )
849878 }
879+
880+ pub ( crate ) fn try_scroll_into_visible ( & self ) {
881+ let mut parent = self . parent_item ( ParentItemTraversalMode :: StopAtPopups ) ;
882+ while let Some ( item_rc) = parent. as_ref ( ) {
883+ let item_ref = item_rc. borrow ( ) ;
884+ if let Some ( flickable) = vtable:: VRef :: downcast_pin :: < crate :: items:: Flickable > ( item_ref)
885+ {
886+ let geo = self . geometry ( ) ;
887+
888+ flickable. reveal_points (
889+ item_rc,
890+ & [
891+ self . map_to_ancestor (
892+ LogicalPoint :: new (
893+ geo. origin . x - flickable. viewport_x ( ) . 0 ,
894+ geo. origin . y - flickable. viewport_y ( ) . 0 ,
895+ ) ,
896+ & item_rc,
897+ ) ,
898+ self . map_to_ancestor (
899+ LogicalPoint :: new (
900+ geo. max_x ( ) - flickable. viewport_x ( ) . 0 ,
901+ geo. max_y ( ) - flickable. viewport_y ( ) . 0 ,
902+ ) ,
903+ & item_rc,
904+ ) ,
905+ ] ,
906+ ) ;
907+ break ;
908+ }
909+
910+ parent = item_rc. parent_item ( ParentItemTraversalMode :: StopAtPopups ) ;
911+ }
912+ }
850913}
851914
852915impl PartialEq for ItemRc {
0 commit comments