From e5ef35e6ffd4789fe0f9c1b5a7bcb93ddf9f99d3 Mon Sep 17 00:00:00 2001 From: Krzysztof Magiera Date: Tue, 2 Dec 2014 18:52:57 +0000 Subject: [PATCH] Minor fixes in improvements in Java code. --- .../src/com/facebook/csslayout/CSSNode.java | 48 +++++++++++-------- .../com/facebook/csslayout/LayoutEngine.java | 4 ++ 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/java/src/com/facebook/csslayout/CSSNode.java b/src/java/src/com/facebook/csslayout/CSSNode.java index 02357e38..41db5ce4 100644 --- a/src/java/src/com/facebook/csslayout/CSSNode.java +++ b/src/java/src/com/facebook/csslayout/CSSNode.java @@ -98,6 +98,15 @@ public class CSSNode { private CSSNode mParent; private MeasureFunction mMeasureFunction = null; private LayoutState mLayoutState = LayoutState.DIRTY; + private int mTag; + + public int getTag() { + return mTag; + } + + public void setTag(int tag) { + mTag = tag; + } public int getChildCount() { return mChildren.size(); @@ -151,7 +160,7 @@ public class CSSNode { * Performs the actual layout and saves the results in {@link #layout} */ public void calculateLayout() { - resetLayoutResultRecursive(); + layout.resetResult(); LayoutEngine.layoutNode(this, CSSConstants.UNDEFINED); } @@ -200,32 +209,33 @@ public class CSSNode { mLayoutState = LayoutState.UP_TO_DATE; } - @Override - public String toString() { - String layoutString = layout.toString(); + private void toStringWithIndentation(StringBuilder result, int level) { + // Spaces and tabs are dropped by IntelliJ logcat integration, so rely on __ instead. + StringBuilder indentation = new StringBuilder(); + for (int i = 0; i < level; ++i) { + indentation.append("__"); + } + + result.append(indentation.toString()); + result.append(layout.toString()); if (getChildCount() == 0) { - return layoutString; + return; } - layoutString += ", children: [\n"; - + result.append(", children: [\n"); for (int i = 0; i < getChildCount(); i++) { - String childString = getChildAt(i).toString(); - childString = childString.replaceAll("\n", "\n\t"); - layoutString += "\t" + childString + "\n"; + getChildAt(i).toStringWithIndentation(result, level + 1); + result.append("\n"); } - - layoutString += "]"; - - return layoutString; + result.append(indentation + "]"); } - private void resetLayoutResultRecursive() { - layout.resetResult(); - for (int i = 0; i < getChildCount(); i++) { - getChildAt(i).resetLayoutResultRecursive(); - } + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + this.toStringWithIndentation(sb, 0); + return sb.toString(); } protected boolean valuesEqual(float f1, float f2) { diff --git a/src/java/src/com/facebook/csslayout/LayoutEngine.java b/src/java/src/com/facebook/csslayout/LayoutEngine.java index 349b1cef..6459ae55 100644 --- a/src/java/src/com/facebook/csslayout/LayoutEngine.java +++ b/src/java/src/com/facebook/csslayout/LayoutEngine.java @@ -273,6 +273,10 @@ public class LayoutEngine { private static void layoutNodeImpl(CSSNode node, float parentMaxWidth) { + for (int i = 0; i < node.getChildCount(); i++) { + node.getChildAt(i).layout.resetResult(); + } + /** START_GENERATED **/ CSSFlexDirection mainAxis = getFlexDirection(node);