MCPcopy Create free account
hub / github.com/microsoft/SandDance / _adjustFitWithinBounds

Function _adjustFitWithinBounds

docs/app/js/sanddance-app.js:31892–31913  ·  view source on GitHub ↗

* Adjusts a element rectangle to fit within the bounds given. If directionalHintFixed or covertarget is passed in * then the element will not flip sides on the target. They will, however, be nudged to fit within the bounds given.

(element, target, bounding, positionData, gap, directionalHintFixed, coverTarget)

Source from the content-addressed store, hash-verified

31890 * Adjusts a element rectangle to fit within the bounds given. If directionalHintFixed or covertarget is passed in
31891 * then the element will not flip sides on the target. They will, however, be nudged to fit within the bounds given.
31892 */ function _adjustFitWithinBounds(element, target, bounding, positionData, gap, directionalHintFixed, coverTarget) {
31893 if (gap === void 0) gap = 0;
31894 var alignmentEdge = positionData.alignmentEdge, alignTargetEdge = positionData.alignTargetEdge;
31895 var elementEstimate = {
31896 elementRectangle: element,
31897 targetEdge: positionData.targetEdge,
31898 alignmentEdge: alignmentEdge
31899 };
31900 if (!directionalHintFixed && !coverTarget) elementEstimate = _flipToFit(element, target, bounding, positionData, gap);
31901 var outOfBounds = _getOutOfBoundsEdges(element, bounding);
31902 if (alignTargetEdge) // The edge opposite to the alignment edge might be out of bounds.
31903 // Flip alignment to see if we can get it within bounds.
31904 {
31905 if (elementEstimate.alignmentEdge && outOfBounds.indexOf(elementEstimate.alignmentEdge * -1) > -1) {
31906 var flippedElementEstimate = _flipAlignmentEdge(elementEstimate, target, gap, coverTarget);
31907 if (_isRectangleWithinBounds(flippedElementEstimate.elementRectangle, bounding)) return flippedElementEstimate;
31908 else // If the flipped elements edges are still out of bounds, try nudging it.
31909 elementEstimate = _alignOutOfBoundsEdges(_getOutOfBoundsEdges(flippedElementEstimate.elementRectangle, bounding), elementEstimate, bounding);
31910 }
31911 } else elementEstimate = _alignOutOfBoundsEdges(outOfBounds, elementEstimate, bounding);
31912 return elementEstimate;
31913}
31914/**
31915 * Iterates through a list of out of bounds edges and tries to nudge and align them.
31916 * @param outOfBoundsEdges - Array of edges that are out of bounds

Callers 1

Calls 5

_flipToFitFunction · 0.85
_getOutOfBoundsEdgesFunction · 0.85
_flipAlignmentEdgeFunction · 0.85
_isRectangleWithinBoundsFunction · 0.85
_alignOutOfBoundsEdgesFunction · 0.85

Tested by

no test coverage detected