code: def _merge_dimensions(dimension, preferred=None, dont_extend=False):
          
          dimension = dimension or LayoutDimension()
  
          # When a preferred dimension was explicitly given to the Window,
          # ignore the UIControl.
          if dimension.preferred_specified:
              preferred = dimension.preferred
  
          # When a 'preferred' dimension is given by the UIControl, make sure
          # that it stays within the bounds of the Window.
          if preferred is not None:
              if dimension.max:
                  preferred = min(preferred, dimension.max)
  
              if dimension.min:
                  preferred = max(preferred, dimension.min)
  
          # When a `dont_extend` flag has been given, use the preferred dimension
          # also as the max dimension.
          if dont_extend and preferred is not None:
              max_ = min(dimension.max, preferred)
          else:
              max_ = dimension.max
  
          return LayoutDimension(
              min=dimension.min, max=max_,
              preferred=preferred, weight=dimension.weight)
docs: Take the LayoutDimension from this `Window` class and the received
          preferred size from the `UIControl` and return a `LayoutDimension` to
          report to the parent container.