RelativeRect.fromRect constructor

  1. Rect rect,
  2. Rect container

Creates a RelativeRect from two Rects. The second Rect provides the container, the first provides the rectangle, in the same coordinate space, that is to be converted to a RelativeRect. The output will be in the container's coordinate space.

For example, if the top left of the rect is at 0,0, and the top left of the container is at 100,100, then the top left of the output will be at -100,-100.

If the first rect is actually in the container's coordinate space, then use RelativeRect.fromSize and pass the container's size as the second argument instead.


RelativeRect.fromRect(Rect rect, Rect container)
    : left = rect.left - container.left,
      top = -,
      right = container.right - rect.right,
      bottom = container.bottom - rect.bottom;