def warp(self, mouse_pos):
        """Warp menu to given position.

        Used for popup menu behaviour, in order for the menu
        manager to appear in the given mouse position.

        mouse_pos (2-tuple of integers)
            represent position of the mouse cursor. It is the
            position to which to warp the menu manager.
        """
        ### retrieve the attribute name of the boundaries
        ### rect's point nearest to the mouse position

        attr_name = get_nearest_attr_name(
            mouse_pos,
            self.boundaries_rect,
        )

        ### now calculate the deltas for the x and y axes
        ### so that the menu manager is warped to the mouse
        ### position with the point in the attribute name
        ### calculated above ending up in the mouse position

        end_x, end_y = mouse_pos
        start_x, start_y = getattr(self.rect, attr_name)

        dx, dy = end_x - start_x, end_y - start_y

        ### admin task: increment dx and dy if the attribute
        ### name used is respectively to the right and/or
        ### to the bottom of the rect
        ### (this is needed because of how rects handle
        ### collision: points in the right or bottom of the
        ### rect are not considered colliding points)

        if "right" in attr_name:
            dx += 1
        if "bottom" in attr_name:
            dy += 1

        ### handle clamping before moving

        ## before moving the menu manager in fact, simulate
        ## the movement by creating a moved copy of its
        ## rect and also simulate the clamping by creating
        ## a copy of the moved rect clamped to the boundaries
        ## rect

        moved_copy = self.rect.move(dx, dy)
        clamped_copy = moved_copy.clamp(self.boundaries_rect)

        ## if the clamped copy ends up positioned differently
        ## from the moved copy, it means our original deltas
        ## need to be adjusted so that when we move the menu
        ## in fact we already land in a clamped position

        if moved_copy != clamped_copy:

            end_x, end_y = clamped_copy.topleft
            start_x, start_y = self.rect.topleft

            dx, dy = end_x - start_x, end_y - start_y

        ### now that the deltas were properly calculate and,
        ### if it was needed, we also adjusted the clamping,
        ### we can finally translate the menu manager
        self.translate(dx, dy)

        ### we also reposition the contents of the menu
        ### manager inside the pygame.Rect stored in its
        ### 'rect' attribute
        self.reposition_menu_manager_contents()
Warp menu to given position.

        Used for popup menu behaviour, in order for the menu
        manager to appear in the given mouse position.

        mouse_pos (2-tuple of integers)
            represent position of the mouse cursor. It is the
            position to which to warp the menu manager.
        
nodezator/menu/behaviour.py