original_docstring: Construct menu based on defaults.
  
          :param items: collection of menu items
          :param layout: layout information of the menu
          :return: newly created instance of Menu
          
docstring: Construct menu based on defaults.
docstring_tokens: Construct menu based on defaults .
code: def with_defaults(cls, items: Tuple[MenuItem, ...],
                        layout: MenuLayout = MenuLayout()) -> "Menu":
          """Construct menu based on defaults.
  
          :param items: collection of menu items
          :param layout: layout information of the menu
          :return: newly created instance of Menu
          """
          item_size = reduce(max_size, [item.size for item in items])
          total_rows = -(-len(items) // layout.columns)
          calculated_rows = min(layout.rows, total_rows) if layout.rows else total_rows
          calculated_size = Size(
              layout.columns * item_size.width + (layout.columns - 1) * layout.item_space.width,
              calculated_rows * item_size.height + (calculated_rows - 1) * layout.item_space.height)
          centered_position = center_in_rect(calculated_size).position
  
          if layout.position:
              x = layout.position.x if layout.position.x >= 0 else centered_position.x
              y = layout.position.y if layout.position.y >= 0 else centered_position.y
              menu_position = Point(x, y)
          else:
              menu_position = centered_position
  
          return Menu(
              items=items,
              item_size=item_size,
              item_space=layout.item_space,
              columns=layout.columns,
              rows=calculated_rows,
              position=menu_position)
code_tokens: def with_defaults ( cls , items : Tuple [ MenuItem , ... ] , layout : MenuLayout = MenuLayout ( ) ) -> "Menu" : item_size = reduce ( max_size , [ item . size for item in items ] ) total_rows = - ( - len ( items ) // layout . columns ) calculated_rows = min ( layout . rows , total_rows ) if layout . rows else total_rows calculated_size = Size ( layout . columns * item_size . width + ( layout . columns - 1 ) * layout . item_space . width , calculated_rows * item_size . height + ( calculated_rows - 1 ) * layout . item_space . height ) centered_position = center_in_rect ( calculated_size ) . position if layout . position : x = layout . position . x if layout . position . x >= 0 else centered_position . x y = layout . position . y if layout . position . y >= 0 else centered_position . y menu_position = Point ( x , y ) else : menu_position = centered_position return Menu ( items = items , item_size = item_size , item_space = layout . item_space , columns = layout . columns , rows = calculated_rows , position = menu_position )
short_docstring: Construct menu based on defaults.
short_docstring_tokens: Construct menu based on defaults .
comment: """Construct menu based on defaults.
  
          :param items: collection of menu items
          :param layout: layout information of the menu
          :return: newly created instance of Menu
          """