RelativeRect.fromRect constructor

RelativeRect.fromRect(Rect rect, 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.

Implementation

factory RelativeRect.fromRect(Rect rect, Rect container) {
  return RelativeRect.fromLTRB(
    rect.left - container.left,
    rect.top - container.top,
    container.right - rect.right,
    container.bottom - rect.bottom,
  );
}