def fix_scrolling(self):
        """Eliminate excessive scrolling.

        Closes gap between first child/first arrow or
        last child/last_arrow if it exists. Such gap is
        sometimes formed when scrolling the first or last
        child inwards the scroll area, since their width
        isn't a multiple of the scrolling speed.
        """
        ### retrieve rects of first and last children

        first_rect = self.children[0].rect
        last_rect = self.children[-1].rect

        ### before starting to check if there's an gap we
        ### must check if at least one of the children
        ### is completely inside the scroll area, because
        ### since there can't be any gap if the neither
        ### children is inside such area there would be no
        ### point in checking anyway

        ## check whether each child is completely inside the
        ## scroll area

        first_inside = self.scroll_area.contains(first_rect)
        last_inside = self.scroll_area.contains(last_rect)

        ## if neither the first nor the last rect are
        ## completely inside the scroll area, cancel the
        ## execution of the rest of the method by returning
        ## earlier
        if not first_inside and not last_inside:
            return

        ### now check the need for correction based on
        ### whether the menu manager is a menuar and
        ### on which of the children is the one inside the
        ### scroll area (they can't be both completely
        ### inside, otherwise there would be no need to make
        ### the menu scrollable in the first place)

        if self.is_menubar:

            ## if the first_rect is inside the scroll area
            ## and its left isn't aligned with the left
            ## arrow right it means there's a gap, so align
            ## them by moving the children by the difference
            ## between them

            if first_inside and first_rect.left != self.left_arrow.rect.right:

                # calculate the difference
                x_offset = self.left_arrow.rect.right - first_rect.left

                # move children
                self.children.rect.move_ip(x_offset, 0)

            ## if the last_rect is inside the scroll area
            ## and its right isn't aligned with the down
            ## arrow left it means there's a gap, so align
            ## them by moving the children by the difference
            ## between them

            elif last_inside and last_rect.right != self.right_arrow.rect.left:

                # calculate the difference
                x_offset = self.right_arrow.rect.left - last_rect.right

                # move children
                self.children.rect.move_ip(x_offset, 0)

        else:

            ## if the first_rect is inside the scroll area
            ## and its top isn't aligned with the up arrow
            ## top it means there's a gap, so align them by
            ## moving the children by the difference between
            ## them

            if first_inside and first_rect.top != self.up_arrow.rect.bottom:

                # calculate the difference
                y_offset = self.up_arrow.rect.bottom - first_rect.top

                # move children
                self.children.rect.move_ip(0, y_offset)

            ## if the last_rect is inside the scroll area
            ## and its bottom isn't aligned with the down
            ## arrow top it means there's a gap, so align
            ## them by moving the children by the difference
            ## between them

            elif last_inside and last_rect.bottom != self.down_arrow.rect.top:

                # calculate the difference
                y_offset = self.down_arrow.rect.top - last_rect.bottom

                # move children
                self.children.rect.move_ip(0, y_offset)
Eliminate excessive scrolling.

        Closes gap between first child/first arrow or
        last child/last_arrow if it exists. Such gap is
        sometimes formed when scrolling the first or last
        child inwards the scroll area, since their width
        isn't a multiple of the scrolling speed.
        
nodezator/menu/scroll.py