@@ -420,6 +420,32 @@ class Box {
420420 math.max (a.y, b.y),
421421 );
422422
423+ /// Construct a rectangle from given handle and its origin.
424+ factory Box .fromHandle (
425+ Vector2 origin, HandlePosition handle, double width, double height) {
426+ switch (handle) {
427+ case HandlePosition .none:
428+ case HandlePosition .topLeft:
429+ return Box .fromLTWH (origin.x - width, origin.y - height, width, height);
430+ case HandlePosition .topRight:
431+ return Box .fromLTWH (origin.x, origin.y - height, width, height);
432+ case HandlePosition .bottomLeft:
433+ return Box .fromLTWH (origin.x - width, origin.y, width, height);
434+ case HandlePosition .bottomRight:
435+ return Box .fromLTWH (origin.x, origin.y, width, height);
436+ case HandlePosition .left:
437+ return Box .fromLTWH (
438+ origin.x - width, origin.y - height / 2 , width, height);
439+ case HandlePosition .top:
440+ return Box .fromLTWH (
441+ origin.x - width / 2 , origin.y - height, width, height);
442+ case HandlePosition .right:
443+ return Box .fromLTWH (origin.x, origin.y - height / 2 , width, height);
444+ case HandlePosition .bottom:
445+ return Box .fromLTWH (origin.x - width / 2 , origin.y, width, height);
446+ }
447+ }
448+
423449 /// The Vector2 of the left edge of this rectangle from the x axis.
424450 final double left;
425451
@@ -490,8 +516,12 @@ class Box {
490516 /// To translate a rectangle by an [Vector2] rather than by separate x and y
491517 /// components, consider [shift] .
492518 Box translate (double translateX, double translateY) {
493- return Box .fromLTRB (left + translateX, top + translateY, right + translateX,
494- bottom + translateY);
519+ return Box .fromLTRB (
520+ left + translateX,
521+ top + translateY,
522+ right + translateX,
523+ bottom + translateY,
524+ );
495525 }
496526
497527 /// Returns a new rectangle with edges moved outwards by the given delta.
@@ -624,20 +654,55 @@ class Box {
624654 );
625655 }
626656
657+ /// Whether this box is overflowing the given [child] box. Returns true if
658+ /// any of the child's edges are outside of this box.
659+ bool isOverflowing (Box child) {
660+ return child.left < left ||
661+ child.top < top ||
662+ child.right > right ||
663+ child.bottom > bottom ||
664+ child.width > width ||
665+ child.height > height;
666+ }
667+
627668 /// Constrains the given [child] box instance within the bounds of this box.
628669 /// This function will preserve the sign of the child's width and height.
629670 /// It will also maintain the aspect ratio of the child if the [aspectRatio]
630671 /// is specified.
631672 ///
632673 /// [child] the child box to clamp inside this box.
674+ ///
633675 /// [resizeMode] defines how to contain the child, whether it should keep its
634676 /// aspect ratio or not, or if it should be resized to fit.
635677 ///
678+ /// [allowResizeOverflow] decides whether to allow the box to overflow the
679+ /// resize operation to its opposite side to continue the resize operation
680+ /// until its constrained on both sides.
681+ ///
682+ /// If this is set to false, the box will cease the resize operation the
683+ /// instant it hits an edge of the [clampingRect] .
684+ ///
685+ /// If this is set to true, the box will continue the resize operation until
686+ /// it is constrained to both sides of the [clampingRect] .
687+ ///
688+ /// [handle] defines the handle that is being dragged to resize the box if
689+ /// available. This only matters if [allowResizeOverflow] is set to false.
690+ ///
691+ /// [currentFlip] defines the current flip of the box if available.
692+ ///
693+ /// [aspectRatio] will allow the box to maintain its aspect ratio if
694+ /// it overflows outside its clamping box and needs to be re-adjusted to
695+ /// fit back inside. This will ensure that the correction operation will
696+ /// maintain the aspect ratio of the box.
697+ ///
636698 /// [returns] a new box instance.
637699 Box containOther (
638700 Box child, {
639701 ResizeMode resizeMode = ResizeMode .freeform,
702+ HandlePosition handle = HandlePosition .none,
703+ Flip currentFlip = Flip .none,
640704 double ? aspectRatio,
705+ bool allowResizeOverflow = true ,
641706 }) {
642707 final double xSign = child.width.sign;
643708 final double ySign = child.height.sign;
0 commit comments