Skip to content

Commit ef9a4b8

Browse files
committed
Clamp edge pins to positive values in wrapping parents.
1 parent 0b38bde commit ef9a4b8

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

lib/src/api/models/pins_model.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ class EdgePinsModel with EquatableMixin, SerializableMixin {
125125
/// pins model is one which has no pin on a given axis.
126126
bool get isInvalidVertically => top == null && bottom == null;
127127

128+
/// Whether this [EdgePinsModel] has any negative pins.
129+
bool get anyNegativePins =>
130+
(left != null && left! < 0) ||
131+
(top != null && top! < 0) ||
132+
(right != null && right! < 0) ||
133+
(bottom != null && bottom! < 0);
134+
128135
/// Whether this [EdgePinsModel] is invalid on at least one axis.
129136
/// An invalid pins model is one which has no pin on a given axis.
130137
bool get isOneAxisInvalid => isInvalidHorizontally || isInvalidVertically;
@@ -208,6 +215,34 @@ class EdgePinsModel with EquatableMixin, SerializableMixin {
208215
EdgePin.bottom => copyWithBottom(value)
209216
};
210217

218+
/// Returns a new [EdgePinsModel] with all negative pins clamped to zero.
219+
EdgePinsModel copyWithNoNegativePins() {
220+
double? newLeft = left;
221+
double? newTop = top;
222+
double? newRight = right;
223+
double? newBottom = bottom;
224+
225+
if (newLeft != null && newLeft < 0) {
226+
newLeft = 0;
227+
}
228+
if (newTop != null && newTop < 0) {
229+
newTop = 0;
230+
}
231+
if (newRight != null && newRight < 0) {
232+
newRight = 0;
233+
}
234+
if (newBottom != null && newBottom < 0) {
235+
newBottom = 0;
236+
}
237+
238+
return EdgePinsModel(
239+
left: newLeft,
240+
top: newTop,
241+
right: newRight,
242+
bottom: newBottom,
243+
);
244+
}
245+
211246
/// Get a pin from this instance of [EdgePinsModel], given a [pin] enum.
212247
///
213248
/// This is useful for abstraction and polymorphic behavior.

0 commit comments

Comments
 (0)