Expose the resolved direction in the node's layout

This commit is contained in:
Lucas Rocha
2015-05-20 11:12:24 +01:00
parent ee1cbacc30
commit 524b44200a
7 changed files with 33 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ public class CSSLayout {
public float bottom;
public float width = CSSConstants.UNDEFINED;
public float height = CSSConstants.UNDEFINED;
public CSSDirection direction = CSSDirection.LTR;
/**
* This should always get called before calling {@link LayoutEngine#layoutNode(CSSNode, float)}
@@ -30,6 +31,7 @@ public class CSSLayout {
bottom = 0;
width = CSSConstants.UNDEFINED;
height = CSSConstants.UNDEFINED;
direction = CSSDirection.LTR;
}
public void copy(CSSLayout layout) {
@@ -39,6 +41,7 @@ public class CSSLayout {
bottom = layout.bottom;
width = layout.width;
height = layout.height;
direction = layout.direction;
}
@Override
@@ -48,6 +51,7 @@ public class CSSLayout {
"top: " + top + ", " +
"width: " + width + ", " +
"height: " + height +
"direction: " + direction +
"}";
}
}

View File

@@ -211,6 +211,13 @@ public class CSSNode {
return o1.equals(o2);
}
public void setDirection(CSSDirection direction) {
if (!valuesEqual(style.direction, direction)) {
style.direction = direction;
dirty();
}
}
public void setFlexDirection(CSSFlexDirection flexDirection) {
if (!valuesEqual(style.flexDirection, flexDirection)) {
style.flexDirection = flexDirection;
@@ -336,6 +343,10 @@ public class CSSNode {
return layout.height;
}
public CSSDirection getLayoutDirection() {
return layout.direction;
}
/**
* Get this node's padding, as defined by style + default padding.
*/

View File

@@ -85,6 +85,10 @@ public class LayoutEngine {
}
}
private static void setLayoutDirection(CSSNode node, CSSDirection direction) {
node.layout.direction = direction;
}
private static float getStylePosition(CSSNode node, PositionIndex position) {
switch (position) {
case TOP:
@@ -521,6 +525,9 @@ public class LayoutEngine {
setDimensionFromStyle(node, mainAxis);
setDimensionFromStyle(node, crossAxis);
// Set the resolved resolution in the node's layout
setLayoutDirection(node, direction);
// The position is set by the parent, but we need to complete it with a
// delta composed of the margin and left/top/right/bottom
setLayoutPosition(node, getLeading(mainAxis), getLayoutPosition(node, getLeading(mainAxis)) + getLeadingMargin(node, mainAxis) +