Skip to content

Commit

Permalink
enhance margin and goneMargin
Browse files Browse the repository at this point in the history
  • Loading branch information
hackw committed Apr 30, 2022
1 parent 8ce0645 commit 86c2225
Showing 1 changed file with 87 additions and 2 deletions.
89 changes: 87 additions & 2 deletions lib/src/constraint_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -785,9 +785,29 @@ ConstraintId sId(int siblingIndexOffset) {
class _Align {
ConstraintId? id;
_AlignType type;
double? _margin;
double? _goneMargin;

_Align(this.id, this.type);

_Align margin(double margin) {
if (_margin != null || _goneMargin != null) {
_margin = margin;
return this;
} else {
return _Align(id, type).._margin = margin;
}
}

_Align goneMargin(double goneMargin) {
if (_margin != null || _goneMargin != null) {
_goneMargin = goneMargin;
return this;
} else {
return _Align(id, type).._goneMargin = goneMargin;
}
}

@override
bool operator ==(Object other) =>
identical(this, other) ||
Expand Down Expand Up @@ -836,8 +856,8 @@ class Constraint extends ConstraintDefine {

/// Both margin and goneMargin can be negative
final bool percentageMargin;
final EdgeInsets margin;
final EdgeInsets goneMargin;
EdgeInsets margin;
EdgeInsets goneMargin;

/// These are the base constraints constraint on sibling id or parent
/// The essence of constraints is alignment
Expand Down Expand Up @@ -1387,6 +1407,71 @@ class Constraint extends ConstraintDefine {
bottom = centerBottomRightTo!.bottom;
}

if (left != null) {
if (left._margin != null) {
margin = margin.add(EdgeInsets.only(
left: left._margin!,
)) as EdgeInsets;
}
if (left._goneMargin != null) {
goneMargin = goneMargin.add(EdgeInsets.only(
left: left._goneMargin!,
)) as EdgeInsets;
}
}

if (top != null) {
if (top._margin != null) {
margin = margin.add(EdgeInsets.only(
top: top._margin!,
)) as EdgeInsets;
}
if (top._goneMargin != null) {
goneMargin = goneMargin.add(EdgeInsets.only(
top: top._goneMargin!,
)) as EdgeInsets;
}
}

if (right != null) {
if (right._margin != null) {
margin = margin.add(EdgeInsets.only(
right: right._margin!,
)) as EdgeInsets;
}
if (right._goneMargin != null) {
goneMargin = goneMargin.add(EdgeInsets.only(
right: right._goneMargin!,
)) as EdgeInsets;
}
}

if (bottom != null) {
if (bottom._margin != null) {
margin = margin.add(EdgeInsets.only(
bottom: bottom._margin!,
)) as EdgeInsets;
}
if (bottom._goneMargin != null) {
goneMargin = goneMargin.add(EdgeInsets.only(
bottom: bottom._goneMargin!,
)) as EdgeInsets;
}
}

if (baseline != null) {
if (baseline._margin != null) {
margin = margin.add(EdgeInsets.only(
bottom: baseline._margin!,
)) as EdgeInsets;
}
if (baseline._goneMargin != null) {
goneMargin = goneMargin.add(EdgeInsets.only(
bottom: baseline._goneMargin!,
)) as EdgeInsets;
}
}

/// Convert wrapper constraints finish
/// Constraint priority: matchParent > wrapper constraints > base constraints
Expand Down

0 comments on commit 86c2225

Please sign in to comment.