Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Expanded sorting for auto layouts #736

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,23 @@ class AutoLayoutAlignStrategy extends AlignStrategy<PBLayoutIntermediateNode> {
// New children list
var spacedChildren = <PBIntermediateNode>[];
var children = context.tree.childrenOf(node);
sortChildren(children);

var isVertical = true;
num space;

// Add boxes if necessary for Column
if (node is PBIntermediateColumnLayout) {
node.sortChildren(children);
isVertical = true;
space = node.layoutProperties.spacing;
}
// Add boxes if necessary for Row
else if (node is PBIntermediateRowLayout) {
node.sortChildren(children);
isVertical = false;
space = node.layoutProperties.spacing;
} else {
sortChildren(children);
}

for (var i = 0; i < children.length; i++) {
Expand Down
6 changes: 6 additions & 0 deletions lib/interpret_and_optimize/entities/layouts/column.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,10 @@ class PBIntermediateColumnLayout extends PBLayoutIntermediateNode
..mapRawChildren(json, tree);
return tempCol;
}

@override
void sortChildren(List<PBIntermediateNode> children) {
children.sort((child0, child1) =>
child0.frame.topLeft.y.compareTo(child1.frame.topLeft.y));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,18 @@ abstract class PBIntermediateNode
extension PBPointLegacyMethod on Point {
Point clone() => Point(x, y);

int compareTo(Point anotherPoint) =>
y == anotherPoint.y || (y.abs() - anotherPoint.y.abs()).abs() < 3
? x.compareTo(anotherPoint.x)
: y.compareTo(anotherPoint.y);
int compareTo(Point anotherPoint) {
// Get both comparation points
var yCompare = y.compareTo(anotherPoint.y);
var xCompare = x.compareTo(anotherPoint.x);

// Check who has a bigger difference and return it
if (yCompare.abs() > xCompare.abs()) {
return yCompare;
} else {
return xCompare;
}
}

bool operator <(Object point) {
if (point is Point) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ abstract class PBLayoutIntermediateNode extends PBIntermediateNode
if (context != null) {
resize(context, children);
}
sortChildren(children);
}
}

Expand Down