private static float boundAxis(CSSNode node, int axis, float value) { float min = CSSConstants.Undefined; float max = CSSConstants.Undefined; if (axis == CSS_FLEX_DIRECTION_COLUMN || axis == CSS_FLEX_DIRECTION_COLUMN_REVERSE) { min = node.style.minHeight; max = node.style.maxHeight; } else if (axis == CSS_FLEX_DIRECTION_ROW || axis == CSS_FLEX_DIRECTION_ROW_REVERSE) { min = node.style.minWidth; max = node.style.maxWidth; } float boundValue = value; if (!float.IsNaN(max) && max >= 0.0 && boundValue > max) { boundValue = max; } if (!float.IsNaN(min) && min >= 0.0 && boundValue < min) { boundValue = min; } return boundValue; }
public void TestChildren() { CSSNode parent = new CSSNode(); foreach (CSSNode node in parent) { Assert.Fail(node.ToString()); } CSSNode child0 = new CSSNode(); Assert.AreEqual(-1, parent.IndexOf(child0)); parent.Insert(0, child0); foreach (CSSNode node in parent) { Assert.AreEqual(0, parent.IndexOf(node)); } CSSNode child1 = new CSSNode(); parent.Insert(1, child1); int index = 0; foreach (CSSNode node in parent) { Assert.AreEqual(index++, parent.IndexOf(node)); } parent.RemoveAt(0); Assert.AreEqual(-1, parent.IndexOf(child0)); Assert.AreEqual(0, parent.IndexOf(child1)); parent.Clear(); Assert.AreEqual(0, parent.Count); parent.Clear(); Assert.AreEqual(0, parent.Count); }
public void testInvalidatesCacheWhenChildAdded() { CSSNode root = new CSSNode(); CSSNode c0 = new CSSNode(); CSSNode c1 = new CSSNode(); CSSNode c0c0 = new CSSNode(); CSSNode c0c1 = new CSSNode(); CSSNode c1c0 = new CSSNode(); c0c1.Width = 200; c0c1.Height = 200; root.addChildAt(c0, 0); root.addChildAt(c1, 1); c0.addChildAt(c0c0, 0); c0c0.addChildAt(c1c0, 0); root.calculateLayout(); markLayoutAppliedForTree(root); c0.addChildAt(c0c1, 1); root.calculateLayout(); Assert.IsTrue(root.HasNewLayout); Assert.IsTrue(c0.HasNewLayout); Assert.IsTrue(c0c1.HasNewLayout); Assert.IsTrue(c0c0.HasNewLayout); Assert.IsTrue(c1.HasNewLayout); Assert.IsFalse(c1c0.HasNewLayout); }
private void markLayoutAppliedForTree(CSSNode root) { root.MarkLayoutSeen(); for (int i = 0; i < root.getChildCount(); i++) { markLayoutAppliedForTree(root.getChildAt(i)); } }
public void TestCannotAddChildToMultipleParents() { CSSNode parent1 = new CSSNode(); CSSNode parent2 = new CSSNode(); CSSNode child = new CSSNode(); parent1.Insert(0, child); parent2.Insert(0, child); }
public void testCannotAddChildToMultipleParents() { CSSNode parent1 = new CSSNode(); CSSNode parent2 = new CSSNode(); CSSNode child = new CSSNode(); parent1.addChildAt(child, 0); parent2.addChildAt(child, 0); }
private void assertTreeHasNewLayout(bool expectedHasNewLayout, CSSNode root) { Assert.AreEqual(expectedHasNewLayout, root.HasNewLayout); for (int i = 0; i < root.getChildCount(); i++) { assertTreeHasNewLayout(expectedHasNewLayout, root.getChildAt(i)); } }
public void Test_flex_basis_flex_grow_column() { CSSNode root = new CSSNode(); root.StyleWidth = 100; root.StyleHeight = 100; CSSNode root_child0 = new CSSNode(); root_child0.FlexGrow = 1; root_child0.FlexBasis = 50; root.Insert(0, root_child0); CSSNode root_child1 = new CSSNode(); root_child1.FlexGrow = 1; root.Insert(1, root_child1); root.StyleDirection = CSSDirection.LeftToRight; root.CalculateLayout(); Assert.AreEqual(0, root.LayoutX); Assert.AreEqual(0, root.LayoutY); Assert.AreEqual(100, root.LayoutWidth); Assert.AreEqual(100, root.LayoutHeight); Assert.AreEqual(0, root_child0.LayoutX); Assert.AreEqual(0, root_child0.LayoutY); Assert.AreEqual(100, root_child0.LayoutWidth); Assert.AreEqual(75, root_child0.LayoutHeight); Assert.AreEqual(0, root_child1.LayoutX); Assert.AreEqual(75, root_child1.LayoutY); Assert.AreEqual(100, root_child1.LayoutWidth); Assert.AreEqual(25, root_child1.LayoutHeight); root.StyleDirection = CSSDirection.RightToLeft; root.CalculateLayout(); Assert.AreEqual(0, root.LayoutX); Assert.AreEqual(0, root.LayoutY); Assert.AreEqual(100, root.LayoutWidth); Assert.AreEqual(100, root.LayoutHeight); Assert.AreEqual(0, root_child0.LayoutX); Assert.AreEqual(0, root_child0.LayoutY); Assert.AreEqual(100, root_child0.LayoutWidth); Assert.AreEqual(75, root_child0.LayoutHeight); Assert.AreEqual(0, root_child1.LayoutX); Assert.AreEqual(75, root_child1.LayoutY); Assert.AreEqual(100, root_child1.LayoutWidth); Assert.AreEqual(25, root_child1.LayoutHeight); }
private static bool areLayoutsEqual(CSSNode a, CSSNode b) { bool doNodesHaveSameLayout = areFloatsEqual(a.layout.position[POSITION_LEFT], b.layout.position[POSITION_LEFT]) && areFloatsEqual(a.layout.position[POSITION_TOP], b.layout.position[POSITION_TOP]) && areFloatsEqual(a.layout.dimensions[DIMENSION_WIDTH], b.layout.dimensions[DIMENSION_WIDTH]) && areFloatsEqual(a.layout.dimensions[DIMENSION_HEIGHT], b.layout.dimensions[DIMENSION_HEIGHT]); if (!doNodesHaveSameLayout) { return false; } for (int i = 0; i < a.getChildCount(); i++) { if (!areLayoutsEqual(a.getChildAt(i), b.getChildAt(i))) { return false; } } return true; }
internal static void layoutNode(CSSLayoutContext layoutContext, CSSNode node, float parentMaxWidth, CSSDirection? parentDirection) { if (needsRelayout(node, parentMaxWidth)) { node.lastLayout.requestedWidth = node.layout.dimensions[DIMENSION_WIDTH]; node.lastLayout.requestedHeight = node.layout.dimensions[DIMENSION_HEIGHT]; node.lastLayout.parentMaxWidth = parentMaxWidth; layoutNodeImpl(layoutContext, node, parentMaxWidth, parentDirection); node.lastLayout.copy(node.layout); } else { node.layout.copy(node.lastLayout); } node.markHasNewLayout(); }
public void TestAddChildGetParent() { CSSNode parent = new CSSNode(); CSSNode child = new CSSNode(); Assert.IsNull(child.Parent); Assert.AreEqual(0, parent.Count); parent.Insert(0, child); Assert.AreEqual(1, parent.Count); Assert.AreEqual(child, parent[0]); Assert.AreEqual(parent, child.Parent); parent.RemoveAt(0); Assert.IsNull(child.Parent); Assert.AreEqual(0, parent.Count); }
public void testAddChildGetParent() { CSSNode parent = new CSSNode(); CSSNode child = new CSSNode(); Assert.IsNull(child.getParent()); Assert.AreEqual(0, parent.getChildCount()); parent.addChildAt(child, 0); Assert.AreEqual(1, parent.getChildCount()); Assert.AreEqual(child, parent.getChildAt(0)); Assert.AreEqual(parent, child.getParent()); parent.removeChildAt(0); Assert.IsNull(child.getParent()); Assert.AreEqual(0, parent.getChildCount()); }
public void testCachesFullTree() { CSSNode root = new CSSNode(); CSSNode c0 = new CSSNode(); CSSNode c1 = new CSSNode(); CSSNode c0c0 = new CSSNode(); root.addChildAt(c0, 0); root.addChildAt(c1, 1); c0.addChildAt(c0c0, 0); root.calculateLayout(); assertTreeHasNewLayout(true, root); markLayoutAppliedForTree(root); root.calculateLayout(); Assert.IsTrue(root.HasNewLayout); assertTreeHasNewLayout(false, c0); assertTreeHasNewLayout(false, c1); }
public void Test_border_center_child() { CSSNode root = new CSSNode(); root.JustifyContent = CSSJustify.Center; root.AlignItems = CSSAlign.Center; root.SetBorder(CSSEdge.Start, 10); root.SetBorder(CSSEdge.End, 20); root.SetBorder(CSSEdge.Bottom, 20); root.StyleWidth = 100; root.StyleHeight = 100; CSSNode root_child0 = new CSSNode(); root_child0.StyleWidth = 10; root_child0.StyleHeight = 10; root.Insert(0, root_child0); root.StyleDirection = CSSDirection.LeftToRight; root.CalculateLayout(); Assert.AreEqual(0, root.LayoutX); Assert.AreEqual(0, root.LayoutY); Assert.AreEqual(100, root.LayoutWidth); Assert.AreEqual(100, root.LayoutHeight); Assert.AreEqual(40, root_child0.LayoutX); Assert.AreEqual(35, root_child0.LayoutY); Assert.AreEqual(10, root_child0.LayoutWidth); Assert.AreEqual(10, root_child0.LayoutHeight); root.StyleDirection = CSSDirection.RightToLeft; root.CalculateLayout(); Assert.AreEqual(0, root.LayoutX); Assert.AreEqual(0, root.LayoutY); Assert.AreEqual(100, root.LayoutWidth); Assert.AreEqual(100, root.LayoutHeight); Assert.AreEqual(50, root_child0.LayoutX); Assert.AreEqual(35, root_child0.LayoutY); Assert.AreEqual(10, root_child0.LayoutWidth); Assert.AreEqual(10, root_child0.LayoutHeight); }
public void testInvalidateCacheWhenHeightChangesPosition() { CSSNode root = new CSSNode(); CSSNode c0 = new CSSNode(); CSSNode c1 = new CSSNode(); CSSNode c1c0 = new CSSNode(); root.addChildAt(c0, 0); root.addChildAt(c1, 1); c1.addChildAt(c1c0, 0); root.calculateLayout(); markLayoutAppliedForTree(root); c0.Height = 100; root.calculateLayout(); Assert.IsTrue(root.HasNewLayout); Assert.IsTrue(c0.HasNewLayout); Assert.IsTrue(c1.HasNewLayout); Assert.IsFalse(c1c0.HasNewLayout); }
public void testDoesNotInvalidateCacheWhenPropertyIsTheSame() { CSSNode root = new CSSNode(); CSSNode c0 = new CSSNode(); CSSNode c1 = new CSSNode(); CSSNode c0c0 = new CSSNode(); root.addChildAt(c0, 0); root.addChildAt(c1, 1); c0.addChildAt(c0c0, 0); root.Width = 200; root.calculateLayout(); markLayoutAppliedForTree(root); root.Width = 200; root.calculateLayout(); Assert.IsTrue(root.HasNewLayout); assertTreeHasNewLayout(false, c0); assertTreeHasNewLayout(false, c1); }
public void Test_absolute_layout_start_top_end_bottom() { CSSNode root = new CSSNode(); root.StyleWidth = 100; root.StyleHeight = 100; CSSNode root_child0 = new CSSNode(); root_child0.PositionType = CSSPositionType.Absolute; root_child0.SetPosition(CSSEdge.Start, 10); root_child0.SetPosition(CSSEdge.Top, 10); root_child0.SetPosition(CSSEdge.End, 10); root_child0.SetPosition(CSSEdge.Bottom, 10); root.Insert(0, root_child0); root.StyleDirection = CSSDirection.LeftToRight; root.CalculateLayout(); Assert.AreEqual(0, root.LayoutX); Assert.AreEqual(0, root.LayoutY); Assert.AreEqual(100, root.LayoutWidth); Assert.AreEqual(100, root.LayoutHeight); Assert.AreEqual(10, root_child0.LayoutX); Assert.AreEqual(10, root_child0.LayoutY); Assert.AreEqual(80, root_child0.LayoutWidth); Assert.AreEqual(80, root_child0.LayoutHeight); root.StyleDirection = CSSDirection.RightToLeft; root.CalculateLayout(); Assert.AreEqual(0, root.LayoutX); Assert.AreEqual(0, root.LayoutY); Assert.AreEqual(100, root.LayoutWidth); Assert.AreEqual(100, root.LayoutHeight); Assert.AreEqual(10, root_child0.LayoutX); Assert.AreEqual(10, root_child0.LayoutY); Assert.AreEqual(80, root_child0.LayoutWidth); Assert.AreEqual(80, root_child0.LayoutHeight); }
public void Test_align_items_min_max() { CSSNode root = new CSSNode(); root.AlignItems = CSSAlign.Center; root.StyleMinWidth = 100; root.StyleMaxWidth = 200; root.StyleHeight = 100; CSSNode root_child0 = new CSSNode(); root_child0.StyleWidth = 60; root_child0.StyleHeight = 60; root.Insert(0, root_child0); root.StyleDirection = CSSDirection.LeftToRight; root.CalculateLayout(); Assert.AreEqual(0, root.LayoutX); Assert.AreEqual(0, root.LayoutY); Assert.AreEqual(100, root.LayoutWidth); Assert.AreEqual(100, root.LayoutHeight); Assert.AreEqual(20, root_child0.LayoutX); Assert.AreEqual(0, root_child0.LayoutY); Assert.AreEqual(60, root_child0.LayoutWidth); Assert.AreEqual(60, root_child0.LayoutHeight); root.StyleDirection = CSSDirection.RightToLeft; root.CalculateLayout(); Assert.AreEqual(0, root.LayoutX); Assert.AreEqual(0, root.LayoutY); Assert.AreEqual(100, root.LayoutWidth); Assert.AreEqual(100, root.LayoutHeight); Assert.AreEqual(20, root_child0.LayoutX); Assert.AreEqual(0, root_child0.LayoutY); Assert.AreEqual(60, root_child0.LayoutWidth); Assert.AreEqual(60, root_child0.LayoutHeight); }
public void Test_align_self_center() { CSSNode root = new CSSNode(); root.StyleWidth = 100; root.StyleHeight = 100; CSSNode root_child0 = new CSSNode(); root_child0.AlignSelf = CSSAlign.Center; root_child0.StyleWidth = 10; root_child0.StyleHeight = 10; root.Insert(0, root_child0); root.StyleDirection = CSSDirection.LeftToRight; root.CalculateLayout(); Assert.AreEqual(0, root.LayoutX); Assert.AreEqual(0, root.LayoutY); Assert.AreEqual(100, root.LayoutWidth); Assert.AreEqual(100, root.LayoutHeight); Assert.AreEqual(45, root_child0.LayoutX); Assert.AreEqual(0, root_child0.LayoutY); Assert.AreEqual(10, root_child0.LayoutWidth); Assert.AreEqual(10, root_child0.LayoutHeight); root.StyleDirection = CSSDirection.RightToLeft; root.CalculateLayout(); Assert.AreEqual(0, root.LayoutX); Assert.AreEqual(0, root.LayoutY); Assert.AreEqual(100, root.LayoutWidth); Assert.AreEqual(100, root.LayoutHeight); Assert.AreEqual(45, root_child0.LayoutX); Assert.AreEqual(0, root_child0.LayoutY); Assert.AreEqual(10, root_child0.LayoutWidth); Assert.AreEqual(10, root_child0.LayoutHeight); }
public void Test_margin_and_flex_column() { CSSNode root = new CSSNode(); root.StyleWidth = 100; root.StyleHeight = 100; CSSNode root_child0 = new CSSNode(); root_child0.FlexGrow = 1; root_child0.SetMargin(CSSEdge.Top, 10); root.Insert(0, root_child0); root.StyleDirection = CSSDirection.LeftToRight; root.CalculateLayout(); Assert.AreEqual(0, root.LayoutX); Assert.AreEqual(0, root.LayoutY); Assert.AreEqual(100, root.LayoutWidth); Assert.AreEqual(100, root.LayoutHeight); Assert.AreEqual(0, root_child0.LayoutX); Assert.AreEqual(10, root_child0.LayoutY); Assert.AreEqual(100, root_child0.LayoutWidth); Assert.AreEqual(90, root_child0.LayoutHeight); root.StyleDirection = CSSDirection.RightToLeft; root.CalculateLayout(); Assert.AreEqual(0, root.LayoutX); Assert.AreEqual(0, root.LayoutY); Assert.AreEqual(100, root.LayoutWidth); Assert.AreEqual(100, root.LayoutHeight); Assert.AreEqual(0, root_child0.LayoutX); Assert.AreEqual(10, root_child0.LayoutY); Assert.AreEqual(100, root_child0.LayoutWidth); Assert.AreEqual(90, root_child0.LayoutHeight); }
public void Test_justify_content_column_space_around() { CSSNode root = new CSSNode(); root.JustifyContent = CSSJustify.SpaceAround; root.Width = 102f; root.Height = 102f; CSSNode root_child0 = new CSSNode(); root_child0.Height = 10f; root.Insert(0, root_child0); CSSNode root_child1 = new CSSNode(); root_child1.Height = 10f; root.Insert(1, root_child1); CSSNode root_child2 = new CSSNode(); root_child2.Height = 10f; root.Insert(2, root_child2); root.StyleDirection = CSSDirection.LTR; root.CalculateLayout(); Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); Assert.AreEqual(102f, root.LayoutWidth); Assert.AreEqual(102f, root.LayoutHeight); Assert.AreEqual(0f, root_child0.LayoutX); Assert.AreEqual(12f, root_child0.LayoutY); Assert.AreEqual(102f, root_child0.LayoutWidth); Assert.AreEqual(10f, root_child0.LayoutHeight); Assert.AreEqual(0f, root_child1.LayoutX); Assert.AreEqual(46f, root_child1.LayoutY); Assert.AreEqual(102f, root_child1.LayoutWidth); Assert.AreEqual(10f, root_child1.LayoutHeight); Assert.AreEqual(0f, root_child2.LayoutX); Assert.AreEqual(80f, root_child2.LayoutY); Assert.AreEqual(102f, root_child2.LayoutWidth); Assert.AreEqual(10f, root_child2.LayoutHeight); root.StyleDirection = CSSDirection.RTL; root.CalculateLayout(); Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); Assert.AreEqual(102f, root.LayoutWidth); Assert.AreEqual(102f, root.LayoutHeight); Assert.AreEqual(0f, root_child0.LayoutX); Assert.AreEqual(12f, root_child0.LayoutY); Assert.AreEqual(102f, root_child0.LayoutWidth); Assert.AreEqual(10f, root_child0.LayoutHeight); Assert.AreEqual(0f, root_child1.LayoutX); Assert.AreEqual(46f, root_child1.LayoutY); Assert.AreEqual(102f, root_child1.LayoutWidth); Assert.AreEqual(10f, root_child1.LayoutHeight); Assert.AreEqual(0f, root_child2.LayoutX); Assert.AreEqual(80f, root_child2.LayoutY); Assert.AreEqual(102f, root_child2.LayoutWidth); Assert.AreEqual(10f, root_child2.LayoutHeight); }
public void Test_rounding_flex_basis_flex_grow_row_prime_number_width() { CSSNode.SetExperimentalFeatureEnabled(CSSExperimentalFeature.Rounding, true); CSSNode root = new CSSNode(); root.FlexDirection = CSSFlexDirection.Row; root.Width = 113f; root.Height = 100f; CSSNode root_child0 = new CSSNode(); root_child0.FlexGrow = 1f; root.Insert(0, root_child0); CSSNode root_child1 = new CSSNode(); root_child1.FlexGrow = 1f; root.Insert(1, root_child1); CSSNode root_child2 = new CSSNode(); root_child2.FlexGrow = 1f; root.Insert(2, root_child2); CSSNode root_child3 = new CSSNode(); root_child3.FlexGrow = 1f; root.Insert(3, root_child3); CSSNode root_child4 = new CSSNode(); root_child4.FlexGrow = 1f; root.Insert(4, root_child4); root.StyleDirection = CSSDirection.LTR; root.CalculateLayout(); Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); Assert.AreEqual(113f, root.LayoutWidth); Assert.AreEqual(100f, root.LayoutHeight); Assert.AreEqual(0f, root_child0.LayoutX); Assert.AreEqual(0f, root_child0.LayoutY); Assert.AreEqual(23f, root_child0.LayoutWidth); Assert.AreEqual(100f, root_child0.LayoutHeight); Assert.AreEqual(23f, root_child1.LayoutX); Assert.AreEqual(0f, root_child1.LayoutY); Assert.AreEqual(22f, root_child1.LayoutWidth); Assert.AreEqual(100f, root_child1.LayoutHeight); Assert.AreEqual(45f, root_child2.LayoutX); Assert.AreEqual(0f, root_child2.LayoutY); Assert.AreEqual(23f, root_child2.LayoutWidth); Assert.AreEqual(100f, root_child2.LayoutHeight); Assert.AreEqual(68f, root_child3.LayoutX); Assert.AreEqual(0f, root_child3.LayoutY); Assert.AreEqual(22f, root_child3.LayoutWidth); Assert.AreEqual(100f, root_child3.LayoutHeight); Assert.AreEqual(90f, root_child4.LayoutX); Assert.AreEqual(0f, root_child4.LayoutY); Assert.AreEqual(23f, root_child4.LayoutWidth); Assert.AreEqual(100f, root_child4.LayoutHeight); root.StyleDirection = CSSDirection.RTL; root.CalculateLayout(); Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); Assert.AreEqual(113f, root.LayoutWidth); Assert.AreEqual(100f, root.LayoutHeight); Assert.AreEqual(90f, root_child0.LayoutX); Assert.AreEqual(0f, root_child0.LayoutY); Assert.AreEqual(23f, root_child0.LayoutWidth); Assert.AreEqual(100f, root_child0.LayoutHeight); Assert.AreEqual(68f, root_child1.LayoutX); Assert.AreEqual(0f, root_child1.LayoutY); Assert.AreEqual(22f, root_child1.LayoutWidth); Assert.AreEqual(100f, root_child1.LayoutHeight); Assert.AreEqual(45f, root_child2.LayoutX); Assert.AreEqual(0f, root_child2.LayoutY); Assert.AreEqual(23f, root_child2.LayoutWidth); Assert.AreEqual(100f, root_child2.LayoutHeight); Assert.AreEqual(23f, root_child3.LayoutX); Assert.AreEqual(0f, root_child3.LayoutY); Assert.AreEqual(22f, root_child3.LayoutWidth); Assert.AreEqual(100f, root_child3.LayoutHeight); Assert.AreEqual(0f, root_child4.LayoutX); Assert.AreEqual(0f, root_child4.LayoutY); Assert.AreEqual(23f, root_child4.LayoutWidth); Assert.AreEqual(100f, root_child4.LayoutHeight); CSSNode.SetExperimentalFeatureEnabled(CSSExperimentalFeature.Rounding, false); }
private static void assertLayoutsEqual(String message, CSSNode actual, CSSNode expected) { Assert.IsTrue( areLayoutsEqual(actual, expected), message + "\nActual:\n" + actual.ToString() + "\nExpected:\n" + expected.ToString() ); }
private static MeasureOutput MeasurePicker(CSSNode node, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode) { return new MeasureOutput(width, 40); }
public void Test_align_content_stretch() { CSSNode root = new CSSNode(); root.AlignContent = CSSAlign.Stretch; root.Wrap = CSSWrap.Wrap; root.Width = 100f; root.Height = 100f; CSSNode root_child0 = new CSSNode(); root_child0.Width = 50f; root.Insert(0, root_child0); CSSNode root_child1 = new CSSNode(); root_child1.Width = 50f; root.Insert(1, root_child1); CSSNode root_child2 = new CSSNode(); root_child2.Width = 50f; root.Insert(2, root_child2); CSSNode root_child3 = new CSSNode(); root_child3.Width = 50f; root.Insert(3, root_child3); CSSNode root_child4 = new CSSNode(); root_child4.Width = 50f; root.Insert(4, root_child4); root.StyleDirection = CSSDirection.LTR; root.CalculateLayout(); Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); Assert.AreEqual(100f, root.LayoutWidth); Assert.AreEqual(100f, root.LayoutHeight); Assert.AreEqual(0f, root_child0.LayoutX); Assert.AreEqual(0f, root_child0.LayoutY); Assert.AreEqual(50f, root_child0.LayoutWidth); Assert.AreEqual(0f, root_child0.LayoutHeight); Assert.AreEqual(0f, root_child1.LayoutX); Assert.AreEqual(0f, root_child1.LayoutY); Assert.AreEqual(50f, root_child1.LayoutWidth); Assert.AreEqual(0f, root_child1.LayoutHeight); Assert.AreEqual(0f, root_child2.LayoutX); Assert.AreEqual(0f, root_child2.LayoutY); Assert.AreEqual(50f, root_child2.LayoutWidth); Assert.AreEqual(0f, root_child2.LayoutHeight); Assert.AreEqual(0f, root_child3.LayoutX); Assert.AreEqual(0f, root_child3.LayoutY); Assert.AreEqual(50f, root_child3.LayoutWidth); Assert.AreEqual(0f, root_child3.LayoutHeight); Assert.AreEqual(0f, root_child4.LayoutX); Assert.AreEqual(0f, root_child4.LayoutY); Assert.AreEqual(50f, root_child4.LayoutWidth); Assert.AreEqual(0f, root_child4.LayoutHeight); root.StyleDirection = CSSDirection.RTL; root.CalculateLayout(); Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); Assert.AreEqual(100f, root.LayoutWidth); Assert.AreEqual(100f, root.LayoutHeight); Assert.AreEqual(50f, root_child0.LayoutX); Assert.AreEqual(0f, root_child0.LayoutY); Assert.AreEqual(50f, root_child0.LayoutWidth); Assert.AreEqual(0f, root_child0.LayoutHeight); Assert.AreEqual(50f, root_child1.LayoutX); Assert.AreEqual(0f, root_child1.LayoutY); Assert.AreEqual(50f, root_child1.LayoutWidth); Assert.AreEqual(0f, root_child1.LayoutHeight); Assert.AreEqual(50f, root_child2.LayoutX); Assert.AreEqual(0f, root_child2.LayoutY); Assert.AreEqual(50f, root_child2.LayoutWidth); Assert.AreEqual(0f, root_child2.LayoutHeight); Assert.AreEqual(50f, root_child3.LayoutX); Assert.AreEqual(0f, root_child3.LayoutY); Assert.AreEqual(50f, root_child3.LayoutWidth); Assert.AreEqual(0f, root_child3.LayoutHeight); Assert.AreEqual(50f, root_child4.LayoutX); Assert.AreEqual(0f, root_child4.LayoutY); Assert.AreEqual(50f, root_child4.LayoutWidth); Assert.AreEqual(0f, root_child4.LayoutHeight); }
public void Test_justify_content_overflow_min_max() { CSSNode root = new CSSNode(); root.JustifyContent = CSSJustify.Center; root.MinHeight = 100f; root.MaxHeight = 110f; CSSNode root_child0 = new CSSNode(); root_child0.Width = 50f; root_child0.Height = 50f; root.Insert(0, root_child0); CSSNode root_child1 = new CSSNode(); root_child1.Width = 50f; root_child1.Height = 50f; root.Insert(1, root_child1); CSSNode root_child2 = new CSSNode(); root_child2.Width = 50f; root_child2.Height = 50f; root.Insert(2, root_child2); root.StyleDirection = CSSDirection.LTR; root.CalculateLayout(); Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); Assert.AreEqual(50f, root.LayoutWidth); Assert.AreEqual(110f, root.LayoutHeight); Assert.AreEqual(0f, root_child0.LayoutX); Assert.AreEqual(-20f, root_child0.LayoutY); Assert.AreEqual(50f, root_child0.LayoutWidth); Assert.AreEqual(50f, root_child0.LayoutHeight); Assert.AreEqual(0f, root_child1.LayoutX); Assert.AreEqual(30f, root_child1.LayoutY); Assert.AreEqual(50f, root_child1.LayoutWidth); Assert.AreEqual(50f, root_child1.LayoutHeight); Assert.AreEqual(0f, root_child2.LayoutX); Assert.AreEqual(80f, root_child2.LayoutY); Assert.AreEqual(50f, root_child2.LayoutWidth); Assert.AreEqual(50f, root_child2.LayoutHeight); root.StyleDirection = CSSDirection.RTL; root.CalculateLayout(); Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); Assert.AreEqual(50f, root.LayoutWidth); Assert.AreEqual(110f, root.LayoutHeight); Assert.AreEqual(0f, root_child0.LayoutX); Assert.AreEqual(-20f, root_child0.LayoutY); Assert.AreEqual(50f, root_child0.LayoutWidth); Assert.AreEqual(50f, root_child0.LayoutHeight); Assert.AreEqual(0f, root_child1.LayoutX); Assert.AreEqual(30f, root_child1.LayoutY); Assert.AreEqual(50f, root_child1.LayoutWidth); Assert.AreEqual(50f, root_child1.LayoutHeight); Assert.AreEqual(0f, root_child2.LayoutX); Assert.AreEqual(80f, root_child2.LayoutY); Assert.AreEqual(50f, root_child2.LayoutWidth); Assert.AreEqual(50f, root_child2.LayoutHeight); }
public void testInvalidatesCacheWhenFloatPropertyChanges() { CSSNode root = new CSSNode(); CSSNode c0 = new CSSNode(); CSSNode c1 = new CSSNode(); CSSNode c0c0 = new CSSNode(); root.addChildAt(c0, 0); root.addChildAt(c1, 1); c0.addChildAt(c0c0, 0); root.calculateLayout(); markLayoutAppliedForTree(root); c1.SetMargin(CSSSpacingType.Left, 10); root.calculateLayout(); Assert.IsTrue(root.HasNewLayout); Assert.IsTrue(c1.HasNewLayout); Assert.IsTrue(c0.HasNewLayout); Assert.IsFalse(c0c0.HasNewLayout); }
public void Test_flex_shrink_to_zero() { CSSNode root = new CSSNode(); root.StyleHeight = 75; CSSNode root_child0 = new CSSNode(); root_child0.StyleWidth = 50; root_child0.StyleHeight = 50; root.Insert(0, root_child0); CSSNode root_child1 = new CSSNode(); root_child1.FlexShrink = 1; root_child1.StyleWidth = 50; root_child1.StyleHeight = 50; root.Insert(1, root_child1); CSSNode root_child2 = new CSSNode(); root_child2.StyleWidth = 50; root_child2.StyleHeight = 50; root.Insert(2, root_child2); root.StyleDirection = CSSDirection.LeftToRight; root.CalculateLayout(); Assert.AreEqual(0, root.LayoutX); Assert.AreEqual(0, root.LayoutY); Assert.AreEqual(50, root.LayoutWidth); Assert.AreEqual(75, root.LayoutHeight); Assert.AreEqual(0, root_child0.LayoutX); Assert.AreEqual(0, root_child0.LayoutY); Assert.AreEqual(50, root_child0.LayoutWidth); Assert.AreEqual(50, root_child0.LayoutHeight); Assert.AreEqual(0, root_child1.LayoutX); Assert.AreEqual(50, root_child1.LayoutY); Assert.AreEqual(50, root_child1.LayoutWidth); Assert.AreEqual(0, root_child1.LayoutHeight); Assert.AreEqual(0, root_child2.LayoutX); Assert.AreEqual(50, root_child2.LayoutY); Assert.AreEqual(50, root_child2.LayoutWidth); Assert.AreEqual(50, root_child2.LayoutHeight); root.StyleDirection = CSSDirection.RightToLeft; root.CalculateLayout(); Assert.AreEqual(0, root.LayoutX); Assert.AreEqual(0, root.LayoutY); Assert.AreEqual(50, root.LayoutWidth); Assert.AreEqual(75, root.LayoutHeight); Assert.AreEqual(0, root_child0.LayoutX); Assert.AreEqual(0, root_child0.LayoutY); Assert.AreEqual(50, root_child0.LayoutWidth); Assert.AreEqual(50, root_child0.LayoutHeight); Assert.AreEqual(0, root_child1.LayoutX); Assert.AreEqual(50, root_child1.LayoutY); Assert.AreEqual(50, root_child1.LayoutWidth); Assert.AreEqual(0, root_child1.LayoutHeight); Assert.AreEqual(0, root_child2.LayoutX); Assert.AreEqual(50, root_child2.LayoutY); Assert.AreEqual(50, root_child2.LayoutWidth); Assert.AreEqual(50, root_child2.LayoutHeight); }
public void Test_justify_content_row_flex_end() { CSSNode root = new CSSNode(); root.FlexDirection = CSSFlexDirection.Row; root.JustifyContent = CSSJustify.FlexEnd; root.Width = 102f; root.Height = 102f; CSSNode root_child0 = new CSSNode(); root_child0.Width = 10f; root.Insert(0, root_child0); CSSNode root_child1 = new CSSNode(); root_child1.Width = 10f; root.Insert(1, root_child1); CSSNode root_child2 = new CSSNode(); root_child2.Width = 10f; root.Insert(2, root_child2); root.StyleDirection = CSSDirection.LTR; root.CalculateLayout(); Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); Assert.AreEqual(102f, root.LayoutWidth); Assert.AreEqual(102f, root.LayoutHeight); Assert.AreEqual(72f, root_child0.LayoutX); Assert.AreEqual(0f, root_child0.LayoutY); Assert.AreEqual(10f, root_child0.LayoutWidth); Assert.AreEqual(102f, root_child0.LayoutHeight); Assert.AreEqual(82f, root_child1.LayoutX); Assert.AreEqual(0f, root_child1.LayoutY); Assert.AreEqual(10f, root_child1.LayoutWidth); Assert.AreEqual(102f, root_child1.LayoutHeight); Assert.AreEqual(92f, root_child2.LayoutX); Assert.AreEqual(0f, root_child2.LayoutY); Assert.AreEqual(10f, root_child2.LayoutWidth); Assert.AreEqual(102f, root_child2.LayoutHeight); root.StyleDirection = CSSDirection.RTL; root.CalculateLayout(); Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); Assert.AreEqual(102f, root.LayoutWidth); Assert.AreEqual(102f, root.LayoutHeight); Assert.AreEqual(20f, root_child0.LayoutX); Assert.AreEqual(0f, root_child0.LayoutY); Assert.AreEqual(10f, root_child0.LayoutWidth); Assert.AreEqual(102f, root_child0.LayoutHeight); Assert.AreEqual(10f, root_child1.LayoutX); Assert.AreEqual(0f, root_child1.LayoutY); Assert.AreEqual(10f, root_child1.LayoutWidth); Assert.AreEqual(102f, root_child1.LayoutHeight); Assert.AreEqual(0f, root_child2.LayoutX); Assert.AreEqual(0f, root_child2.LayoutY); Assert.AreEqual(10f, root_child2.LayoutWidth); Assert.AreEqual(102f, root_child2.LayoutHeight); }
public void Test_absolute_layout_within_border() { CSSNode root = new CSSNode(); root.SetMargin(CSSEdge.Left, 10f); root.SetMargin(CSSEdge.Top, 10f); root.SetMargin(CSSEdge.Right, 10f); root.SetMargin(CSSEdge.Bottom, 10f); root.SetPadding(CSSEdge.Left, 10f); root.SetPadding(CSSEdge.Top, 10f); root.SetPadding(CSSEdge.Right, 10f); root.SetPadding(CSSEdge.Bottom, 10f); root.SetBorder(CSSEdge.Left, 10f); root.SetBorder(CSSEdge.Top, 10f); root.SetBorder(CSSEdge.Right, 10f); root.SetBorder(CSSEdge.Bottom, 10f); root.Width = 100f; root.Height = 100f; CSSNode root_child0 = new CSSNode(); root_child0.PositionType = CSSPositionType.Absolute; root_child0.SetPosition(CSSEdge.Left, 0f); root_child0.SetPosition(CSSEdge.Top, 0f); root_child0.Width = 50f; root_child0.Height = 50f; root.Insert(0, root_child0); CSSNode root_child1 = new CSSNode(); root_child1.PositionType = CSSPositionType.Absolute; root_child1.SetPosition(CSSEdge.Right, 0f); root_child1.SetPosition(CSSEdge.Bottom, 0f); root_child1.Width = 50f; root_child1.Height = 50f; root.Insert(1, root_child1); root.StyleDirection = CSSDirection.LTR; root.CalculateLayout(); Assert.AreEqual(10f, root.LayoutX); Assert.AreEqual(10f, root.LayoutY); Assert.AreEqual(100f, root.LayoutWidth); Assert.AreEqual(100f, root.LayoutHeight); Assert.AreEqual(10f, root_child0.LayoutX); Assert.AreEqual(10f, root_child0.LayoutY); Assert.AreEqual(50f, root_child0.LayoutWidth); Assert.AreEqual(50f, root_child0.LayoutHeight); Assert.AreEqual(40f, root_child1.LayoutX); Assert.AreEqual(40f, root_child1.LayoutY); Assert.AreEqual(50f, root_child1.LayoutWidth); Assert.AreEqual(50f, root_child1.LayoutHeight); root.StyleDirection = CSSDirection.RTL; root.CalculateLayout(); Assert.AreEqual(10f, root.LayoutX); Assert.AreEqual(10f, root.LayoutY); Assert.AreEqual(100f, root.LayoutWidth); Assert.AreEqual(100f, root.LayoutHeight); Assert.AreEqual(10f, root_child0.LayoutX); Assert.AreEqual(10f, root_child0.LayoutY); Assert.AreEqual(50f, root_child0.LayoutWidth); Assert.AreEqual(50f, root_child0.LayoutHeight); Assert.AreEqual(40f, root_child1.LayoutX); Assert.AreEqual(40f, root_child1.LayoutY); Assert.AreEqual(50f, root_child1.LayoutWidth); Assert.AreEqual(50f, root_child1.LayoutHeight); }
private static MeasureOutput MeasurePicker(CSSNode node, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode) { return(new MeasureOutput(width, 40)); }
public void testInvalidatesFullTreeWhenParentWidthChanges() { CSSNode root = new CSSNode(); CSSNode c0 = new CSSNode(); CSSNode c1 = new CSSNode(); CSSNode c0c0 = new CSSNode(); CSSNode c1c0 = new CSSNode(); root.addChildAt(c0, 0); root.addChildAt(c1, 1); c0.addChildAt(c0c0, 0); c1.addChildAt(c1c0, 0); root.calculateLayout(); markLayoutAppliedForTree(root); c0.Height = 200; root.calculateLayout(); Assert.IsTrue(root.HasNewLayout); Assert.IsTrue(c0.HasNewLayout); Assert.IsTrue(c0c0.HasNewLayout); Assert.IsTrue(c1.HasNewLayout); Assert.IsFalse(c1c0.HasNewLayout); }
public static Inline Apply(CSSNode node) { return(s_instance.Visit(node)); }
public void testInvalidatesOnNewMeasureFunction() { CSSNode root = new CSSNode(); CSSNode c0 = new CSSNode(); CSSNode c1 = new CSSNode(); CSSNode c0c0 = new CSSNode(); root.addChildAt(c0, 0); root.addChildAt(c1, 1); c0.addChildAt(c0c0, 0); root.calculateLayout(); markLayoutAppliedForTree(root); c1.setMeasureFunction((node, width, height) => new MeasureOutput(100, 20)); root.calculateLayout(); Assert.IsTrue(root.HasNewLayout); Assert.IsTrue(c1.HasNewLayout); Assert.IsTrue(c0.HasNewLayout); Assert.IsFalse(c0c0.HasNewLayout); }
/// <summary> /// Measures the width and height of a <see cref="ProgressRing"/>. /// </summary> /// <param name="node">The css style of the rendered <see cref="ProgressRing"/>.</param> /// <param name="width">The parameterized native width of the control.</param> /// <param name="widthMode">The width measurement mode.</param> /// <param name="height">The parameterized native height of the control.</param> /// <param name="heightMode">The height measurement mode.</param> /// <returns>The measurement <see cref="MeasureOutput"/> for the <see cref="ProgressRing"/> component.</returns> private static MeasureOutput MeasureProgressRing(CSSNode node, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode) { var normalizedWidth = !CSSConstants.IsUndefined(width) ? width : 20; var normalizedHeight = !CSSConstants.IsUndefined(height) ? height : 20; return new MeasureOutput(normalizedWidth, normalizedHeight); }
public void Test_rounding_flex_basis_flex_shrink_row() { CSSNode.SetExperimentalFeatureEnabled(CSSExperimentalFeature.Rounding, true); CSSNode root = new CSSNode(); root.FlexDirection = CSSFlexDirection.Row; root.Width = 101f; root.Height = 100f; CSSNode root_child0 = new CSSNode(); root_child0.FlexShrink = 1f; root_child0.FlexBasis = 100f; root.Insert(0, root_child0); CSSNode root_child1 = new CSSNode(); root_child1.FlexBasis = 25f; root.Insert(1, root_child1); CSSNode root_child2 = new CSSNode(); root_child2.FlexBasis = 25f; root.Insert(2, root_child2); root.StyleDirection = CSSDirection.LTR; root.CalculateLayout(); Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); Assert.AreEqual(101f, root.LayoutWidth); Assert.AreEqual(100f, root.LayoutHeight); Assert.AreEqual(0f, root_child0.LayoutX); Assert.AreEqual(0f, root_child0.LayoutY); Assert.AreEqual(51f, root_child0.LayoutWidth); Assert.AreEqual(100f, root_child0.LayoutHeight); Assert.AreEqual(51f, root_child1.LayoutX); Assert.AreEqual(0f, root_child1.LayoutY); Assert.AreEqual(25f, root_child1.LayoutWidth); Assert.AreEqual(100f, root_child1.LayoutHeight); Assert.AreEqual(76f, root_child2.LayoutX); Assert.AreEqual(0f, root_child2.LayoutY); Assert.AreEqual(25f, root_child2.LayoutWidth); Assert.AreEqual(100f, root_child2.LayoutHeight); root.StyleDirection = CSSDirection.RTL; root.CalculateLayout(); Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); Assert.AreEqual(101f, root.LayoutWidth); Assert.AreEqual(100f, root.LayoutHeight); Assert.AreEqual(50f, root_child0.LayoutX); Assert.AreEqual(0f, root_child0.LayoutY); Assert.AreEqual(51f, root_child0.LayoutWidth); Assert.AreEqual(100f, root_child0.LayoutHeight); Assert.AreEqual(25f, root_child1.LayoutX); Assert.AreEqual(0f, root_child1.LayoutY); Assert.AreEqual(25f, root_child1.LayoutWidth); Assert.AreEqual(100f, root_child1.LayoutHeight); Assert.AreEqual(0f, root_child2.LayoutX); Assert.AreEqual(0f, root_child2.LayoutY); Assert.AreEqual(25f, root_child2.LayoutWidth); Assert.AreEqual(100f, root_child2.LayoutHeight); CSSNode.SetExperimentalFeatureEnabled(CSSExperimentalFeature.Rounding, false); }
public void Test_rounding_flex_basis_flex_grow_row_width_of_100() { CSSNode.SetExperimentalFeatureEnabled(CSSExperimentalFeature.Rounding, true); CSSNode root = new CSSNode(); root.FlexDirection = CSSFlexDirection.Row; root.Width = 100f; root.Height = 100f; CSSNode root_child0 = new CSSNode(); root_child0.FlexGrow = 1f; root.Insert(0, root_child0); CSSNode root_child1 = new CSSNode(); root_child1.FlexGrow = 1f; root.Insert(1, root_child1); CSSNode root_child2 = new CSSNode(); root_child2.FlexGrow = 1f; root.Insert(2, root_child2); root.StyleDirection = CSSDirection.LTR; root.CalculateLayout(); Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); Assert.AreEqual(100f, root.LayoutWidth); Assert.AreEqual(100f, root.LayoutHeight); Assert.AreEqual(0f, root_child0.LayoutX); Assert.AreEqual(0f, root_child0.LayoutY); Assert.AreEqual(33f, root_child0.LayoutWidth); Assert.AreEqual(100f, root_child0.LayoutHeight); Assert.AreEqual(33f, root_child1.LayoutX); Assert.AreEqual(0f, root_child1.LayoutY); Assert.AreEqual(34f, root_child1.LayoutWidth); Assert.AreEqual(100f, root_child1.LayoutHeight); Assert.AreEqual(67f, root_child2.LayoutX); Assert.AreEqual(0f, root_child2.LayoutY); Assert.AreEqual(33f, root_child2.LayoutWidth); Assert.AreEqual(100f, root_child2.LayoutHeight); root.StyleDirection = CSSDirection.RTL; root.CalculateLayout(); Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); Assert.AreEqual(100f, root.LayoutWidth); Assert.AreEqual(100f, root.LayoutHeight); Assert.AreEqual(67f, root_child0.LayoutX); Assert.AreEqual(0f, root_child0.LayoutY); Assert.AreEqual(33f, root_child0.LayoutWidth); Assert.AreEqual(100f, root_child0.LayoutHeight); Assert.AreEqual(33f, root_child1.LayoutX); Assert.AreEqual(0f, root_child1.LayoutY); Assert.AreEqual(34f, root_child1.LayoutWidth); Assert.AreEqual(100f, root_child1.LayoutHeight); Assert.AreEqual(0f, root_child2.LayoutX); Assert.AreEqual(0f, root_child2.LayoutY); Assert.AreEqual(33f, root_child2.LayoutWidth); Assert.AreEqual(100f, root_child2.LayoutHeight); CSSNode.SetExperimentalFeatureEnabled(CSSExperimentalFeature.Rounding, false); }
public void testInvalidatesCacheWhenEnumPropertyChanges() { CSSNode root = new CSSNode(); CSSNode c0 = new CSSNode(); CSSNode c1 = new CSSNode(); CSSNode c0c0 = new CSSNode(); root.addChildAt(c0, 0); root.addChildAt(c1, 1); c0.addChildAt(c0c0, 0); root.calculateLayout(); markLayoutAppliedForTree(root); c1.AlignSelf = CSSAlign.Center; root.calculateLayout(); Assert.IsTrue(root.HasNewLayout); Assert.IsTrue(c1.HasNewLayout); Assert.IsTrue(c0.HasNewLayout); Assert.IsFalse(c0c0.HasNewLayout); }
public void Test_rounding_total_fractial_nested() { CSSNode.SetExperimentalFeatureEnabled(CSSExperimentalFeature.Rounding, true); CSSNode root = new CSSNode(); root.Width = 87.4f; root.Height = 113.4f; CSSNode root_child0 = new CSSNode(); root_child0.FlexGrow = 0.7f; root_child0.FlexBasis = 50.3f; root_child0.Height = 20.3f; root.Insert(0, root_child0); CSSNode root_child0_child0 = new CSSNode(); root_child0_child0.FlexGrow = 1f; root_child0_child0.FlexBasis = 0.3f; root_child0_child0.SetPosition(CSSEdge.Bottom, 13.3f); root_child0_child0.Height = 9.9f; root_child0.Insert(0, root_child0_child0); CSSNode root_child0_child1 = new CSSNode(); root_child0_child1.FlexGrow = 4f; root_child0_child1.FlexBasis = 0.3f; root_child0_child1.SetPosition(CSSEdge.Top, 13.3f); root_child0_child1.Height = 1.1f; root_child0.Insert(1, root_child0_child1); CSSNode root_child1 = new CSSNode(); root_child1.FlexGrow = 1.6f; root_child1.Height = 10f; root.Insert(1, root_child1); CSSNode root_child2 = new CSSNode(); root_child2.FlexGrow = 1.1f; root_child2.Height = 10.7f; root.Insert(2, root_child2); root.StyleDirection = CSSDirection.LTR; root.CalculateLayout(); Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); Assert.AreEqual(87f, root.LayoutWidth); Assert.AreEqual(113f, root.LayoutHeight); Assert.AreEqual(0f, root_child0.LayoutX); Assert.AreEqual(0f, root_child0.LayoutY); Assert.AreEqual(87f, root_child0.LayoutWidth); Assert.AreEqual(59f, root_child0.LayoutHeight); Assert.AreEqual(0f, root_child0_child0.LayoutX); Assert.AreEqual(-13f, root_child0_child0.LayoutY); Assert.AreEqual(87f, root_child0_child0.LayoutWidth); Assert.AreEqual(12f, root_child0_child0.LayoutHeight); Assert.AreEqual(0f, root_child0_child1.LayoutX); Assert.AreEqual(25f, root_child0_child1.LayoutY); Assert.AreEqual(87f, root_child0_child1.LayoutWidth); Assert.AreEqual(47f, root_child0_child1.LayoutHeight); Assert.AreEqual(0f, root_child1.LayoutX); Assert.AreEqual(59f, root_child1.LayoutY); Assert.AreEqual(87f, root_child1.LayoutWidth); Assert.AreEqual(30f, root_child1.LayoutHeight); Assert.AreEqual(0f, root_child2.LayoutX); Assert.AreEqual(89f, root_child2.LayoutY); Assert.AreEqual(87f, root_child2.LayoutWidth); Assert.AreEqual(24f, root_child2.LayoutHeight); root.StyleDirection = CSSDirection.RTL; root.CalculateLayout(); Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); Assert.AreEqual(87f, root.LayoutWidth); Assert.AreEqual(113f, root.LayoutHeight); Assert.AreEqual(0f, root_child0.LayoutX); Assert.AreEqual(0f, root_child0.LayoutY); Assert.AreEqual(87f, root_child0.LayoutWidth); Assert.AreEqual(59f, root_child0.LayoutHeight); Assert.AreEqual(0f, root_child0_child0.LayoutX); Assert.AreEqual(-13f, root_child0_child0.LayoutY); Assert.AreEqual(87f, root_child0_child0.LayoutWidth); Assert.AreEqual(12f, root_child0_child0.LayoutHeight); Assert.AreEqual(0f, root_child0_child1.LayoutX); Assert.AreEqual(25f, root_child0_child1.LayoutY); Assert.AreEqual(87f, root_child0_child1.LayoutWidth); Assert.AreEqual(47f, root_child0_child1.LayoutHeight); Assert.AreEqual(0f, root_child1.LayoutX); Assert.AreEqual(59f, root_child1.LayoutY); Assert.AreEqual(87f, root_child1.LayoutWidth); Assert.AreEqual(30f, root_child1.LayoutHeight); Assert.AreEqual(0f, root_child2.LayoutX); Assert.AreEqual(89f, root_child2.LayoutY); Assert.AreEqual(87f, root_child2.LayoutWidth); Assert.AreEqual(24f, root_child2.LayoutHeight); CSSNode.SetExperimentalFeatureEnabled(CSSExperimentalFeature.Rounding, false); }
private static void test(String message, CSSNode style, CSSNode expectedLayout) { style.CalculateLayout(); assertLayoutsEqual(message, style, expectedLayout); }
public void Test_rounding_fractial_input_4() { CSSNode.SetExperimentalFeatureEnabled(CSSExperimentalFeature.Rounding, true); CSSNode root = new CSSNode(); root.SetPosition(CSSEdge.Top, 0.7f); root.Width = 100f; root.Height = 113.4f; CSSNode root_child0 = new CSSNode(); root_child0.FlexGrow = 1f; root_child0.FlexBasis = 50f; root_child0.Height = 20f; root.Insert(0, root_child0); CSSNode root_child1 = new CSSNode(); root_child1.FlexGrow = 1f; root_child1.Height = 10f; root.Insert(1, root_child1); CSSNode root_child2 = new CSSNode(); root_child2.FlexGrow = 1f; root_child2.Height = 10f; root.Insert(2, root_child2); root.StyleDirection = CSSDirection.LTR; root.CalculateLayout(); Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(1f, root.LayoutY); Assert.AreEqual(100f, root.LayoutWidth); Assert.AreEqual(113f, root.LayoutHeight); Assert.AreEqual(0f, root_child0.LayoutX); Assert.AreEqual(0f, root_child0.LayoutY); Assert.AreEqual(100f, root_child0.LayoutWidth); Assert.AreEqual(64f, root_child0.LayoutHeight); Assert.AreEqual(0f, root_child1.LayoutX); Assert.AreEqual(64f, root_child1.LayoutY); Assert.AreEqual(100f, root_child1.LayoutWidth); Assert.AreEqual(25f, root_child1.LayoutHeight); Assert.AreEqual(0f, root_child2.LayoutX); Assert.AreEqual(89f, root_child2.LayoutY); Assert.AreEqual(100f, root_child2.LayoutWidth); Assert.AreEqual(24f, root_child2.LayoutHeight); root.StyleDirection = CSSDirection.RTL; root.CalculateLayout(); Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(1f, root.LayoutY); Assert.AreEqual(100f, root.LayoutWidth); Assert.AreEqual(113f, root.LayoutHeight); Assert.AreEqual(0f, root_child0.LayoutX); Assert.AreEqual(0f, root_child0.LayoutY); Assert.AreEqual(100f, root_child0.LayoutWidth); Assert.AreEqual(64f, root_child0.LayoutHeight); Assert.AreEqual(0f, root_child1.LayoutX); Assert.AreEqual(64f, root_child1.LayoutY); Assert.AreEqual(100f, root_child1.LayoutWidth); Assert.AreEqual(25f, root_child1.LayoutHeight); Assert.AreEqual(0f, root_child2.LayoutX); Assert.AreEqual(89f, root_child2.LayoutY); Assert.AreEqual(100f, root_child2.LayoutWidth); Assert.AreEqual(24f, root_child2.LayoutHeight); CSSNode.SetExperimentalFeatureEnabled(CSSExperimentalFeature.Rounding, false); }
public void Test_align_content_center() { CSSNode root = new CSSNode(); root.AlignContent = CSSAlign.Center; root.Wrap = CSSWrap.Wrap; root.StyleWidth = 100; root.StyleHeight = 100; CSSNode root_child0 = new CSSNode(); root_child0.StyleWidth = 50; root_child0.StyleHeight = 10; root.Insert(0, root_child0); CSSNode root_child1 = new CSSNode(); root_child1.StyleWidth = 50; root_child1.StyleHeight = 10; root.Insert(1, root_child1); CSSNode root_child2 = new CSSNode(); root_child2.StyleWidth = 50; root_child2.StyleHeight = 10; root.Insert(2, root_child2); CSSNode root_child3 = new CSSNode(); root_child3.StyleWidth = 50; root_child3.StyleHeight = 10; root.Insert(3, root_child3); CSSNode root_child4 = new CSSNode(); root_child4.StyleWidth = 50; root_child4.StyleHeight = 10; root.Insert(4, root_child4); root.StyleDirection = CSSDirection.LeftToRight; root.CalculateLayout(); Assert.AreEqual(0, root.LayoutX); Assert.AreEqual(0, root.LayoutY); Assert.AreEqual(100, root.LayoutWidth); Assert.AreEqual(100, root.LayoutHeight); Assert.AreEqual(0, root_child0.LayoutX); Assert.AreEqual(0, root_child0.LayoutY); Assert.AreEqual(50, root_child0.LayoutWidth); Assert.AreEqual(10, root_child0.LayoutHeight); Assert.AreEqual(0, root_child1.LayoutX); Assert.AreEqual(10, root_child1.LayoutY); Assert.AreEqual(50, root_child1.LayoutWidth); Assert.AreEqual(10, root_child1.LayoutHeight); Assert.AreEqual(0, root_child2.LayoutX); Assert.AreEqual(20, root_child2.LayoutY); Assert.AreEqual(50, root_child2.LayoutWidth); Assert.AreEqual(10, root_child2.LayoutHeight); Assert.AreEqual(0, root_child3.LayoutX); Assert.AreEqual(30, root_child3.LayoutY); Assert.AreEqual(50, root_child3.LayoutWidth); Assert.AreEqual(10, root_child3.LayoutHeight); Assert.AreEqual(0, root_child4.LayoutX); Assert.AreEqual(40, root_child4.LayoutY); Assert.AreEqual(50, root_child4.LayoutWidth); Assert.AreEqual(10, root_child4.LayoutHeight); root.StyleDirection = CSSDirection.RightToLeft; root.CalculateLayout(); Assert.AreEqual(0, root.LayoutX); Assert.AreEqual(0, root.LayoutY); Assert.AreEqual(100, root.LayoutWidth); Assert.AreEqual(100, root.LayoutHeight); Assert.AreEqual(50, root_child0.LayoutX); Assert.AreEqual(0, root_child0.LayoutY); Assert.AreEqual(50, root_child0.LayoutWidth); Assert.AreEqual(10, root_child0.LayoutHeight); Assert.AreEqual(50, root_child1.LayoutX); Assert.AreEqual(10, root_child1.LayoutY); Assert.AreEqual(50, root_child1.LayoutWidth); Assert.AreEqual(10, root_child1.LayoutHeight); Assert.AreEqual(50, root_child2.LayoutX); Assert.AreEqual(20, root_child2.LayoutY); Assert.AreEqual(50, root_child2.LayoutWidth); Assert.AreEqual(10, root_child2.LayoutHeight); Assert.AreEqual(50, root_child3.LayoutX); Assert.AreEqual(30, root_child3.LayoutY); Assert.AreEqual(50, root_child3.LayoutWidth); Assert.AreEqual(10, root_child3.LayoutHeight); Assert.AreEqual(50, root_child4.LayoutX); Assert.AreEqual(40, root_child4.LayoutY); Assert.AreEqual(50, root_child4.LayoutWidth); Assert.AreEqual(10, root_child4.LayoutHeight); }
public void TestFull() { CSSNode node = CSSNode.Create( styleDirection: CSSDirection.RTL, flexDirection: CSSFlexDirection.RowReverse, justifyContent: CSSJustify.SpaceAround, alignContent: CSSAlign.Center, alignItems: CSSAlign.FlexEnd, alignSelf: CSSAlign.Stretch, positionType: CSSPositionType.Absolute, wrap: CSSWrap.Wrap, overflow: CSSOverflow.Scroll, flex: 1, flexGrow: 2, flexShrink: 3, flexBasis: 4, position: new Spacing(top: 5, bottom: 6, left: 7, right: 8), margin: new Spacing(top: 9, bottom: 10, left: 11, right: 12), padding: new Spacing(top: 13, bottom: 14, left: 15, right: 16), border: new Spacing(top: 17, bottom: 18, left: 19, right: 20), width: 21, height: 22, minWidth: 23, minHeight: 24, maxWidth: 25, maxHeight: 26); Assert.AreEqual(CSSDirection.RTL, node.StyleDirection); Assert.AreEqual(CSSFlexDirection.RowReverse, node.FlexDirection); Assert.AreEqual(CSSJustify.SpaceAround, node.JustifyContent); Assert.AreEqual(CSSAlign.Center, node.AlignContent); Assert.AreEqual(CSSAlign.FlexEnd, node.AlignItems); Assert.AreEqual(CSSAlign.Stretch, node.AlignSelf); Assert.AreEqual(CSSPositionType.Absolute, node.PositionType); Assert.AreEqual(CSSWrap.Wrap, node.Wrap); Assert.AreEqual(CSSOverflow.Scroll, node.Overflow); Assert.AreEqual(2, node.FlexGrow); Assert.AreEqual(3, node.FlexShrink); Assert.AreEqual(4, node.FlexBasis); node.FlexGrow = CSSConstants.Undefined; Assert.AreEqual(1, node.FlexGrow); Assert.AreEqual(5, node.GetPosition(CSSEdge.Top)); Assert.AreEqual(6, node.GetPosition(CSSEdge.Bottom)); Assert.AreEqual(7, node.GetPosition(CSSEdge.Left)); Assert.AreEqual(8, node.GetPosition(CSSEdge.Right)); Assert.AreEqual(9, node.GetMargin(CSSEdge.Top)); Assert.AreEqual(10, node.GetMargin(CSSEdge.Bottom)); Assert.AreEqual(11, node.GetMargin(CSSEdge.Left)); Assert.AreEqual(12, node.GetMargin(CSSEdge.Right)); Assert.AreEqual(13, node.GetPadding(CSSEdge.Top)); Assert.AreEqual(14, node.GetPadding(CSSEdge.Bottom)); Assert.AreEqual(15, node.GetPadding(CSSEdge.Left)); Assert.AreEqual(16, node.GetPadding(CSSEdge.Right)); Assert.AreEqual(17, node.GetBorder(CSSEdge.Top)); Assert.AreEqual(18, node.GetBorder(CSSEdge.Bottom)); Assert.AreEqual(19, node.GetBorder(CSSEdge.Left)); Assert.AreEqual(20, node.GetBorder(CSSEdge.Right)); Assert.AreEqual(21, node.Width); Assert.AreEqual(22, node.Height); Assert.AreEqual(23, node.MinWidth); Assert.AreEqual(24, node.MinHeight); Assert.AreEqual(25, node.MaxWidth); Assert.AreEqual(26, node.MaxHeight); }