@@ -470,7 +470,7 @@ impl ItemRc {
470470 /// Returns an absolute position of `p` in the parent item coordinate system
471471 /// (does not add this item's x and y)
472472 pub fn map_to_window ( & self , p : LogicalPoint ) -> LogicalPoint {
473- self . map_to_item_tree_impl ( p, None )
473+ self . map_to_item_tree_impl ( p, |_| None )
474474 }
475475
476476 /// Returns an absolute position of `p` in the `ItemTree`'s coordinate system
@@ -480,53 +480,31 @@ impl ItemRc {
480480 p : LogicalPoint ,
481481 item_tree : & vtable:: VRc < ItemTreeVTable > ,
482482 ) -> LogicalPoint {
483- self . map_to_item_tree_impl ( p, Some ( item_tree) )
483+ self . map_to_item_tree_impl ( p, |current| current. is_root_item_of ( item_tree) )
484+ }
485+
486+ /// Returns an absolute position of `p` in the `ancestor`'s coordinate system
487+ /// (does not add this item's x and y)
488+ /// Don't rely on any specific behavior if `self` isn't a descendant of `ancestor`.
489+ fn map_to_ancestor ( & self , p : LogicalPoint , ancestor : & Self ) -> LogicalPoint {
490+ self . map_to_item_tree_impl ( p, |parent, _| parent == ancestor)
484491 }
485492
486493 fn map_to_item_tree_impl (
487494 & self ,
488495 p : LogicalPoint ,
489- item_tree : Option < & vtable :: VRc < ItemTreeVTable > > ,
496+ stop_condition : impl Fn ( & ItemRc ) -> bool ,
490497 ) -> LogicalPoint {
491498 let mut current = self . clone ( ) ;
492499 let mut result = p;
493- if item_tree . is_some_and ( |item_tree| current. is_root_item_of ( item_tree ) ) {
500+ if stop_condition ( & current) {
494501 return result;
495502 }
496503 let supports_transformations = self
497504 . window_adapter ( )
498505 . is_none_or ( |adapter| adapter. renderer ( ) . supports_transformations ( ) ) ;
499506 while let Some ( parent) = current. parent_item ( ParentItemTraversalMode :: StopAtPopups ) {
500- if item_tree. is_some_and ( |item_tree| current. is_root_item_of ( item_tree) ) {
501- break ;
502- }
503- let geometry = parent. geometry ( ) ;
504- if supports_transformations {
505- if let Some ( transform) = parent. children_transform ( ) {
506- result = transform. transform_point ( result. cast ( ) ) . cast ( ) ;
507- }
508- }
509- result += geometry. origin . to_vector ( ) ;
510- current = parent;
511- }
512- result
513- }
514-
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 {
507+ if stop_condition ( & parent) {
530508 break ;
531509 }
532510 let geometry = parent. geometry ( ) ;
0 commit comments