From 213b7aa44b6adf8fd2a2006360bd11926c194f73 Mon Sep 17 00:00:00 2001 From: Ioannis Tsakpinis Date: Sat, 13 Jul 2024 15:49:07 +0300 Subject: [PATCH] fix(Yoga) synchronize tests --- .../lwjgl/util/yoga/YGAlignContentTest.java | 248 +++++++- .../lwjgl/util/yoga/YGIntrinsicSizeTest.java | 570 ++++++++++++++++++ .../java/org/lwjgl/util/yoga/YogaNode.java | 11 + 3 files changed, 797 insertions(+), 32 deletions(-) create mode 100644 modules/lwjgl/yoga/src/test/java/org/lwjgl/util/yoga/YGIntrinsicSizeTest.java diff --git a/modules/lwjgl/yoga/src/test/java/org/lwjgl/util/yoga/YGAlignContentTest.java b/modules/lwjgl/yoga/src/test/java/org/lwjgl/util/yoga/YGAlignContentTest.java index 60bab900a8..ef8ea41bd1 100644 --- a/modules/lwjgl/yoga/src/test/java/org/lwjgl/util/yoga/YGAlignContentTest.java +++ b/modules/lwjgl/yoga/src/test/java/org/lwjgl/util/yoga/YGAlignContentTest.java @@ -1735,6 +1735,98 @@ public void test_align_content_space_between_wrapped_negative_space() { assertEquals(20f, root_child0_child2.getLayoutHeight(), 0.0f); } + @Test + public void test_align_content_space_between_wrapped_negative_space_row_reverse() { + YogaConfig config = YogaConfigFactory.create(); + + YogaNode root = createNode(config); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setBorder(YogaEdge.LEFT, 60f); + root.setBorder(YogaEdge.TOP, 60f); + root.setBorder(YogaEdge.RIGHT, 60f); + root.setBorder(YogaEdge.BOTTOM, 60f); + root.setWidth(320f); + root.setHeight(320f); + + YogaNode root_child0 = createNode(config); + root_child0.setFlexDirection(YogaFlexDirection.ROW_REVERSE); + root_child0.setJustifyContent(YogaJustify.CENTER); + root_child0.setAlignContent(YogaAlign.SPACE_BETWEEN); + root_child0.setWrap(YogaWrap.WRAP); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + + YogaNode root_child0_child0 = createNode(config); + root_child0_child0.setWidthPercent(80f); + root_child0_child0.setHeight(20f); + root_child0.addChildAt(root_child0_child0, 0); + + YogaNode root_child0_child1 = createNode(config); + root_child0_child1.setWidthPercent(80f); + root_child0_child1.setHeight(20f); + root_child0.addChildAt(root_child0_child1, 1); + + YogaNode root_child0_child2 = createNode(config); + root_child0_child2.setWidthPercent(80f); + root_child0_child2.setHeight(20f); + root_child0.addChildAt(root_child0_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(320f, root.getLayoutWidth(), 0.0f); + assertEquals(320f, root.getLayoutHeight(), 0.0f); + + assertEquals(60f, root_child0.getLayoutX(), 0.0f); + assertEquals(60f, root_child0.getLayoutY(), 0.0f); + assertEquals(200f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(20f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(160f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0_child0.getLayoutHeight(), 0.0f); + + assertEquals(20f, root_child0_child1.getLayoutX(), 0.0f); + assertEquals(20f, root_child0_child1.getLayoutY(), 0.0f); + assertEquals(160f, root_child0_child1.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0_child1.getLayoutHeight(), 0.0f); + + assertEquals(20f, root_child0_child2.getLayoutX(), 0.0f); + assertEquals(40f, root_child0_child2.getLayoutY(), 0.0f); + assertEquals(160f, root_child0_child2.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(320f, root.getLayoutWidth(), 0.0f); + assertEquals(320f, root.getLayoutHeight(), 0.0f); + + assertEquals(60f, root_child0.getLayoutX(), 0.0f); + assertEquals(60f, root_child0.getLayoutY(), 0.0f); + assertEquals(200f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(20f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(160f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0_child0.getLayoutHeight(), 0.0f); + + assertEquals(20f, root_child0_child1.getLayoutX(), 0.0f); + assertEquals(20f, root_child0_child1.getLayoutY(), 0.0f); + assertEquals(160f, root_child0_child1.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0_child1.getLayoutHeight(), 0.0f); + + assertEquals(20f, root_child0_child2.getLayoutX(), 0.0f); + assertEquals(40f, root_child0_child2.getLayoutY(), 0.0f); + assertEquals(160f, root_child0_child2.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0_child2.getLayoutHeight(), 0.0f); + } + @Test public void test_align_content_space_between_wrapped_negative_space_gap() { YogaConfig config = YogaConfigFactory.create(); @@ -2096,17 +2188,17 @@ public void test_align_content_space_around_wrapped_negative_space() { assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); assertEquals(20f, root_child0_child0.getLayoutX(), 0.0f); - assertEquals(-25f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); assertEquals(160f, root_child0_child0.getLayoutWidth(), 0.0f); assertEquals(20f, root_child0_child0.getLayoutHeight(), 0.0f); assertEquals(20f, root_child0_child1.getLayoutX(), 0.0f); - assertEquals(-5f, root_child0_child1.getLayoutY(), 0.0f); + assertEquals(20f, root_child0_child1.getLayoutY(), 0.0f); assertEquals(160f, root_child0_child1.getLayoutWidth(), 0.0f); assertEquals(20f, root_child0_child1.getLayoutHeight(), 0.0f); assertEquals(20f, root_child0_child2.getLayoutX(), 0.0f); - assertEquals(15f, root_child0_child2.getLayoutY(), 0.0f); + assertEquals(40f, root_child0_child2.getLayoutY(), 0.0f); assertEquals(160f, root_child0_child2.getLayoutWidth(), 0.0f); assertEquals(20f, root_child0_child2.getLayoutHeight(), 0.0f); @@ -2124,17 +2216,109 @@ public void test_align_content_space_around_wrapped_negative_space() { assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); assertEquals(20f, root_child0_child0.getLayoutX(), 0.0f); - assertEquals(-25f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); assertEquals(160f, root_child0_child0.getLayoutWidth(), 0.0f); assertEquals(20f, root_child0_child0.getLayoutHeight(), 0.0f); assertEquals(20f, root_child0_child1.getLayoutX(), 0.0f); - assertEquals(-5f, root_child0_child1.getLayoutY(), 0.0f); + assertEquals(20f, root_child0_child1.getLayoutY(), 0.0f); assertEquals(160f, root_child0_child1.getLayoutWidth(), 0.0f); assertEquals(20f, root_child0_child1.getLayoutHeight(), 0.0f); assertEquals(20f, root_child0_child2.getLayoutX(), 0.0f); - assertEquals(15f, root_child0_child2.getLayoutY(), 0.0f); + assertEquals(40f, root_child0_child2.getLayoutY(), 0.0f); + assertEquals(160f, root_child0_child2.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0_child2.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_content_space_around_wrapped_negative_space_row_reverse() { + YogaConfig config = YogaConfigFactory.create(); + + YogaNode root = createNode(config); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setBorder(YogaEdge.LEFT, 60f); + root.setBorder(YogaEdge.TOP, 60f); + root.setBorder(YogaEdge.RIGHT, 60f); + root.setBorder(YogaEdge.BOTTOM, 60f); + root.setWidth(320f); + root.setHeight(320f); + + YogaNode root_child0 = createNode(config); + root_child0.setFlexDirection(YogaFlexDirection.ROW_REVERSE); + root_child0.setJustifyContent(YogaJustify.CENTER); + root_child0.setAlignContent(YogaAlign.SPACE_AROUND); + root_child0.setWrap(YogaWrap.WRAP); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + + YogaNode root_child0_child0 = createNode(config); + root_child0_child0.setWidthPercent(80f); + root_child0_child0.setHeight(20f); + root_child0.addChildAt(root_child0_child0, 0); + + YogaNode root_child0_child1 = createNode(config); + root_child0_child1.setWidthPercent(80f); + root_child0_child1.setHeight(20f); + root_child0.addChildAt(root_child0_child1, 1); + + YogaNode root_child0_child2 = createNode(config); + root_child0_child2.setWidthPercent(80f); + root_child0_child2.setHeight(20f); + root_child0.addChildAt(root_child0_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(320f, root.getLayoutWidth(), 0.0f); + assertEquals(320f, root.getLayoutHeight(), 0.0f); + + assertEquals(60f, root_child0.getLayoutX(), 0.0f); + assertEquals(60f, root_child0.getLayoutY(), 0.0f); + assertEquals(200f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(20f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(160f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0_child0.getLayoutHeight(), 0.0f); + + assertEquals(20f, root_child0_child1.getLayoutX(), 0.0f); + assertEquals(20f, root_child0_child1.getLayoutY(), 0.0f); + assertEquals(160f, root_child0_child1.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0_child1.getLayoutHeight(), 0.0f); + + assertEquals(20f, root_child0_child2.getLayoutX(), 0.0f); + assertEquals(40f, root_child0_child2.getLayoutY(), 0.0f); + assertEquals(160f, root_child0_child2.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(320f, root.getLayoutWidth(), 0.0f); + assertEquals(320f, root.getLayoutHeight(), 0.0f); + + assertEquals(60f, root_child0.getLayoutX(), 0.0f); + assertEquals(60f, root_child0.getLayoutY(), 0.0f); + assertEquals(200f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(20f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(160f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0_child0.getLayoutHeight(), 0.0f); + + assertEquals(20f, root_child0_child1.getLayoutX(), 0.0f); + assertEquals(20f, root_child0_child1.getLayoutY(), 0.0f); + assertEquals(160f, root_child0_child1.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0_child1.getLayoutHeight(), 0.0f); + + assertEquals(20f, root_child0_child2.getLayoutX(), 0.0f); + assertEquals(40f, root_child0_child2.getLayoutY(), 0.0f); assertEquals(160f, root_child0_child2.getLayoutWidth(), 0.0f); assertEquals(20f, root_child0_child2.getLayoutHeight(), 0.0f); } @@ -2190,17 +2374,17 @@ public void test_align_content_space_around_wrapped_negative_space_gap() { assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); assertEquals(20f, root_child0_child0.getLayoutX(), 0.0f); - assertEquals(-35f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); assertEquals(160f, root_child0_child0.getLayoutWidth(), 0.0f); assertEquals(20f, root_child0_child0.getLayoutHeight(), 0.0f); assertEquals(20f, root_child0_child1.getLayoutX(), 0.0f); - assertEquals(-5f, root_child0_child1.getLayoutY(), 0.0f); + assertEquals(30f, root_child0_child1.getLayoutY(), 0.0f); assertEquals(160f, root_child0_child1.getLayoutWidth(), 0.0f); assertEquals(20f, root_child0_child1.getLayoutHeight(), 0.0f); assertEquals(20f, root_child0_child2.getLayoutX(), 0.0f); - assertEquals(25f, root_child0_child2.getLayoutY(), 0.0f); + assertEquals(60f, root_child0_child2.getLayoutY(), 0.0f); assertEquals(160f, root_child0_child2.getLayoutWidth(), 0.0f); assertEquals(20f, root_child0_child2.getLayoutHeight(), 0.0f); @@ -2218,17 +2402,17 @@ public void test_align_content_space_around_wrapped_negative_space_gap() { assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); assertEquals(20f, root_child0_child0.getLayoutX(), 0.0f); - assertEquals(-35f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); assertEquals(160f, root_child0_child0.getLayoutWidth(), 0.0f); assertEquals(20f, root_child0_child0.getLayoutHeight(), 0.0f); assertEquals(20f, root_child0_child1.getLayoutX(), 0.0f); - assertEquals(-5f, root_child0_child1.getLayoutY(), 0.0f); + assertEquals(30f, root_child0_child1.getLayoutY(), 0.0f); assertEquals(160f, root_child0_child1.getLayoutWidth(), 0.0f); assertEquals(20f, root_child0_child1.getLayoutHeight(), 0.0f); assertEquals(20f, root_child0_child2.getLayoutX(), 0.0f); - assertEquals(25f, root_child0_child2.getLayoutY(), 0.0f); + assertEquals(60f, root_child0_child2.getLayoutY(), 0.0f); assertEquals(160f, root_child0_child2.getLayoutWidth(), 0.0f); assertEquals(20f, root_child0_child2.getLayoutHeight(), 0.0f); } @@ -2500,17 +2684,17 @@ public void test_align_content_space_evenly_wrapped_negative_space() { assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); assertEquals(20f, root_child0_child0.getLayoutX(), 0.0f); - assertEquals(-25f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); assertEquals(160f, root_child0_child0.getLayoutWidth(), 0.0f); assertEquals(20f, root_child0_child0.getLayoutHeight(), 0.0f); assertEquals(20f, root_child0_child1.getLayoutX(), 0.0f); - assertEquals(-5f, root_child0_child1.getLayoutY(), 0.0f); + assertEquals(20f, root_child0_child1.getLayoutY(), 0.0f); assertEquals(160f, root_child0_child1.getLayoutWidth(), 0.0f); assertEquals(20f, root_child0_child1.getLayoutHeight(), 0.0f); assertEquals(20f, root_child0_child2.getLayoutX(), 0.0f); - assertEquals(15f, root_child0_child2.getLayoutY(), 0.0f); + assertEquals(40f, root_child0_child2.getLayoutY(), 0.0f); assertEquals(160f, root_child0_child2.getLayoutWidth(), 0.0f); assertEquals(20f, root_child0_child2.getLayoutHeight(), 0.0f); @@ -2528,17 +2712,17 @@ public void test_align_content_space_evenly_wrapped_negative_space() { assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); assertEquals(20f, root_child0_child0.getLayoutX(), 0.0f); - assertEquals(-25f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); assertEquals(160f, root_child0_child0.getLayoutWidth(), 0.0f); assertEquals(20f, root_child0_child0.getLayoutHeight(), 0.0f); assertEquals(20f, root_child0_child1.getLayoutX(), 0.0f); - assertEquals(-5f, root_child0_child1.getLayoutY(), 0.0f); + assertEquals(20f, root_child0_child1.getLayoutY(), 0.0f); assertEquals(160f, root_child0_child1.getLayoutWidth(), 0.0f); assertEquals(20f, root_child0_child1.getLayoutHeight(), 0.0f); assertEquals(20f, root_child0_child2.getLayoutX(), 0.0f); - assertEquals(15f, root_child0_child2.getLayoutY(), 0.0f); + assertEquals(40f, root_child0_child2.getLayoutY(), 0.0f); assertEquals(160f, root_child0_child2.getLayoutWidth(), 0.0f); assertEquals(20f, root_child0_child2.getLayoutHeight(), 0.0f); } @@ -2594,17 +2778,17 @@ public void test_align_content_space_evenly_wrapped_negative_space_gap() { assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); assertEquals(20f, root_child0_child0.getLayoutX(), 0.0f); - assertEquals(-35f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); assertEquals(160f, root_child0_child0.getLayoutWidth(), 0.0f); assertEquals(20f, root_child0_child0.getLayoutHeight(), 0.0f); assertEquals(20f, root_child0_child1.getLayoutX(), 0.0f); - assertEquals(-5f, root_child0_child1.getLayoutY(), 0.0f); + assertEquals(30f, root_child0_child1.getLayoutY(), 0.0f); assertEquals(160f, root_child0_child1.getLayoutWidth(), 0.0f); assertEquals(20f, root_child0_child1.getLayoutHeight(), 0.0f); assertEquals(20f, root_child0_child2.getLayoutX(), 0.0f); - assertEquals(25f, root_child0_child2.getLayoutY(), 0.0f); + assertEquals(60f, root_child0_child2.getLayoutY(), 0.0f); assertEquals(160f, root_child0_child2.getLayoutWidth(), 0.0f); assertEquals(20f, root_child0_child2.getLayoutHeight(), 0.0f); @@ -2622,17 +2806,17 @@ public void test_align_content_space_evenly_wrapped_negative_space_gap() { assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); assertEquals(20f, root_child0_child0.getLayoutX(), 0.0f); - assertEquals(-35f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); assertEquals(160f, root_child0_child0.getLayoutWidth(), 0.0f); assertEquals(20f, root_child0_child0.getLayoutHeight(), 0.0f); assertEquals(20f, root_child0_child1.getLayoutX(), 0.0f); - assertEquals(-5f, root_child0_child1.getLayoutY(), 0.0f); + assertEquals(30f, root_child0_child1.getLayoutY(), 0.0f); assertEquals(160f, root_child0_child1.getLayoutWidth(), 0.0f); assertEquals(20f, root_child0_child1.getLayoutHeight(), 0.0f); assertEquals(20f, root_child0_child2.getLayoutX(), 0.0f); - assertEquals(25f, root_child0_child2.getLayoutY(), 0.0f); + assertEquals(60f, root_child0_child2.getLayoutY(), 0.0f); assertEquals(160f, root_child0_child2.getLayoutWidth(), 0.0f); assertEquals(20f, root_child0_child2.getLayoutHeight(), 0.0f); } @@ -4220,12 +4404,12 @@ public void test_align_content_space_evenly_with_max_cross_axis_violated() { assertEquals(300f, root.getLayoutHeight(), 0.0f); assertEquals(0f, root_child0.getLayoutX(), 0.0f); - assertEquals(-50f, root_child0.getLayoutY(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); assertEquals(400f, root_child0.getLayoutWidth(), 0.0f); assertEquals(200f, root_child0.getLayoutHeight(), 0.0f); assertEquals(0f, root_child1.getLayoutX(), 0.0f); - assertEquals(150f, root_child1.getLayoutY(), 0.0f); + assertEquals(200f, root_child1.getLayoutY(), 0.0f); assertEquals(400f, root_child1.getLayoutWidth(), 0.0f); assertEquals(200f, root_child1.getLayoutHeight(), 0.0f); @@ -4238,12 +4422,12 @@ public void test_align_content_space_evenly_with_max_cross_axis_violated() { assertEquals(300f, root.getLayoutHeight(), 0.0f); assertEquals(100f, root_child0.getLayoutX(), 0.0f); - assertEquals(-50f, root_child0.getLayoutY(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); assertEquals(400f, root_child0.getLayoutWidth(), 0.0f); assertEquals(200f, root_child0.getLayoutHeight(), 0.0f); assertEquals(100f, root_child1.getLayoutX(), 0.0f); - assertEquals(150f, root_child1.getLayoutY(), 0.0f); + assertEquals(200f, root_child1.getLayoutY(), 0.0f); assertEquals(400f, root_child1.getLayoutWidth(), 0.0f); assertEquals(200f, root_child1.getLayoutHeight(), 0.0f); } @@ -4286,12 +4470,12 @@ public void test_align_content_space_evenly_with_max_cross_axis_violated_padding assertEquals(300f, root.getLayoutHeight(), 0.0f); assertEquals(7f, root_child0.getLayoutX(), 0.0f); - assertEquals(-50f, root_child0.getLayoutY(), 0.0f); + assertEquals(7f, root_child0.getLayoutY(), 0.0f); assertEquals(400f, root_child0.getLayoutWidth(), 0.0f); assertEquals(200f, root_child0.getLayoutHeight(), 0.0f); assertEquals(7f, root_child1.getLayoutX(), 0.0f); - assertEquals(150f, root_child1.getLayoutY(), 0.0f); + assertEquals(207f, root_child1.getLayoutY(), 0.0f); assertEquals(400f, root_child1.getLayoutWidth(), 0.0f); assertEquals(200f, root_child1.getLayoutHeight(), 0.0f); @@ -4304,12 +4488,12 @@ public void test_align_content_space_evenly_with_max_cross_axis_violated_padding assertEquals(300f, root.getLayoutHeight(), 0.0f); assertEquals(93f, root_child0.getLayoutX(), 0.0f); - assertEquals(-50f, root_child0.getLayoutY(), 0.0f); + assertEquals(7f, root_child0.getLayoutY(), 0.0f); assertEquals(400f, root_child0.getLayoutWidth(), 0.0f); assertEquals(200f, root_child0.getLayoutHeight(), 0.0f); assertEquals(93f, root_child1.getLayoutX(), 0.0f); - assertEquals(150f, root_child1.getLayoutY(), 0.0f); + assertEquals(207f, root_child1.getLayoutY(), 0.0f); assertEquals(400f, root_child1.getLayoutWidth(), 0.0f); assertEquals(200f, root_child1.getLayoutHeight(), 0.0f); } diff --git a/modules/lwjgl/yoga/src/test/java/org/lwjgl/util/yoga/YGIntrinsicSizeTest.java b/modules/lwjgl/yoga/src/test/java/org/lwjgl/util/yoga/YGIntrinsicSizeTest.java new file mode 100644 index 0000000000..fefdffa3a8 --- /dev/null +++ b/modules/lwjgl/yoga/src/test/java/org/lwjgl/util/yoga/YGIntrinsicSizeTest.java @@ -0,0 +1,570 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @generated SignedSource<> + * generated by gentest/gentest-driver.ts from gentest/fixtures/YGIntrinsicSizeTest.html + */ + +package org.lwjgl.util.yoga; + +import org.testng.annotations.*; + +import static java.lang.Math.*; +import static org.lwjgl.util.yoga.Yoga.*; +import static org.lwjgl.util.yoga.YogaNode.*; +import static org.testng.AssertJUnit.assertEquals; + +public class YGIntrinsicSizeTest { + + private final YGMeasureFunc intrinsicMeasureFunction = YGMeasureFunc.create((node, width, widthMode, height, heightMode, __result) -> { + String text = (String)YogaNode.create(node).getData(); + + float measuredWidth; + float measuredHeight; + + if (widthMode == YGMeasureModeExactly) { + measuredWidth = width; + } else if (widthMode == YGMeasureModeAtMost) { + measuredWidth = min(text.length() * widthPerChar, width); + } else { + measuredWidth = text.length() * widthPerChar; + } + + if (heightMode == YGMeasureModeExactly) { + measuredHeight = height; + } else if (heightMode == YGMeasureModeAtMost) { + measuredHeight = min(calculateHeight(text, max(measuredWidth, getWidestWordWidth(text))), height); + } else { + measuredHeight = calculateHeight(text, max(measuredWidth, getWidestWordWidth(text))); + } + + __result + .width(measuredWidth) + .height(measuredHeight); + }); + + @AfterClass + private void cleanup() { + intrinsicMeasureFunction.free(); + } + + @Test + public void test_contains_inner_text_long_word() { + YogaConfig config = YogaConfigFactory.create(); + + YogaNode root = createNode(config); + root.setAlignItems(YogaNode.YogaAlign.FLEX_START); + root.setPositionType(YogaNode.YogaPositionType.ABSOLUTE); + root.setWidth(2000f); + root.setHeight(2000f); + + YogaNode root_child0 = createNode(config); + root_child0.setFlexDirection(YogaFlexDirection.ROW); + root.addChildAt(root_child0, 0); + root_child0.setData("LoremipsumdolorsitametconsecteturadipiscingelitSedeleifasdfettortoracauctorFuscerhoncusipsumtemporerosaliquamconsequatPraesentsoda"); + root_child0.setMeasureFunction(intrinsicMeasureFunction); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaNode.YogaConstants.UNDEFINED, YogaNode.YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(2000f, root.getLayoutWidth(), 0.0f); + assertEquals(2000f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(1300f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaNode.YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(2000f, root.getLayoutWidth(), 0.0f); + assertEquals(2000f, root.getLayoutHeight(), 0.0f); + + assertEquals(700f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(1300f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_contains_inner_text_no_width_no_height() { + YogaConfig config = YogaConfigFactory.create(); + + YogaNode root = createNode(config); + root.setAlignItems(YogaAlign.FLEX_START); + root.setPositionType(YogaNode.YogaPositionType.ABSOLUTE); + root.setWidth(2000f); + root.setHeight(2000f); + + YogaNode root_child0 = createNode(config); + root_child0.setFlexDirection(YogaFlexDirection.ROW); + root.addChildAt(root_child0, 0); + root_child0.setData("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eleifasd et tortor ac auctor. Integer at volutpat libero, sed elementum dui interdum id. Aliquam consectetur massa vel neque aliquet, quis consequat risus fringilla. Fusce rhoncus ipsum tempor eros aliquam, vel tempus metus ullamcorper. Nam at nulla sed tellus vestibulum fringilla vel sit amet ligula. Proin velit lectus, euismod sit amet quam vel ultricies dolor, vitae finibus lorem ipsum. Pellentesque molestie at mi sit amet dictum. Donec vehicula lacinia felis sit amet consectetur. Praesent sodales enim sapien, sed varius ipsum pellentesque vel. Aenean eu mi eu justo tincidunt finibus vel sit amet ipsum. Sed bibasdum purus vel ipsum sagittis, quis fermentum dolor lobortis. Etiam vulputate eleifasd lectus vel varius. Phasellus imperdiet lectus sit amet ipsum egestas, ut bibasdum ipsum malesuada. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed mollis eros sit amet elit porttitor, vel venenatis turpis venenatis. Nulla tempus tortor at eros efficitur, sit amet dapibus ipsum malesuada. Ut at mauris sed nunc malesuada convallis. Duis id sem vel magna varius eleifasd vel at est. Donec eget orci a ipsum tempor lobortis. Sed at consectetur ipsum."); + root_child0.setMeasureFunction(intrinsicMeasureFunction); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(2000f, root.getLayoutWidth(), 0.0f); + assertEquals(2000f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(2000f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(70f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(2000f, root.getLayoutWidth(), 0.0f); + assertEquals(2000f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(2000f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(70f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_contains_inner_text_no_width_no_height_long_word_in_paragraph() { + YogaConfig config = YogaConfigFactory.create(); + + YogaNode root = createNode(config); + root.setAlignItems(YogaAlign.FLEX_START); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(2000f); + root.setHeight(2000f); + + YogaNode root_child0 = createNode(config); + root_child0.setFlexDirection(YogaFlexDirection.ROW); + root.addChildAt(root_child0, 0); + root_child0.setData("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eleifasd et tortor ac auctor. Integer at volutpat libero, sed elementum dui interdum id. Aliquam consectetur massa vel neque aliquet, quis consequat risus fringilla. Fusce rhoncus ipsum tempor eros aliquam, vel tempus metus ullamcorper. Nam at nulla sed tellus vestibulum fringilla vel sit amet ligula. Proin velit lectus, euismod sit amet quam vel ultricies dolor, vitae finibus loremipsumloremipsumloremipsumloremipsumloremipsumloremipsumloremipsumloremipsumloremipsumloremipsumloremipsumloremipsumloremipsumlorem Pellentesque molestie at mi sit amet dictum. Donec vehicula lacinia felis sit amet consectetur. Praesent sodales enim sapien, sed varius ipsum pellentesque vel. Aenean eu mi eu justo tincidunt finibus vel sit amet ipsum. Sed bibasdum purus vel ipsum sagittis, quis fermentum dolor lobortis. Etiam vulputate eleifasd lectus vel varius. Phasellus imperdiet lectus sit amet ipsum egestas, ut bibasdum ipsum malesuada. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed mollis eros sit amet elit porttitor, vel venenatis turpis venenatis. Nulla tempus tortor at eros efficitur, sit amet dapibus ipsum malesuada. Ut at mauris sed nunc malesuada convallis. Duis id sem vel magna varius eleifasd vel at est. Donec eget orci a ipsum tempor lobortis. Sed at consectetur ipsum."); + root_child0.setMeasureFunction(intrinsicMeasureFunction); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(2000f, root.getLayoutWidth(), 0.0f); + assertEquals(2000f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(2000f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(70f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(2000f, root.getLayoutWidth(), 0.0f); + assertEquals(2000f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(2000f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(70f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_contains_inner_text_fixed_width() { + YogaConfig config = YogaConfigFactory.create(); + + YogaNode root = createNode(config); + root.setAlignItems(YogaAlign.FLEX_START); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(2000f); + root.setHeight(2000f); + + YogaNode root_child0 = createNode(config); + root_child0.setFlexDirection(YogaFlexDirection.ROW); + root_child0.setWidth(100f); + root.addChildAt(root_child0, 0); + root_child0.setData("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eleifasd et tortor ac auctor. Integer at volutpat libero, sed elementum dui interdum id. Aliquam consectetur massa vel neque aliquet, quis consequat risus fringilla. Fusce rhoncus ipsum tempor eros aliquam, vel tempus metus ullamcorper. Nam at nulla sed tellus vestibulum fringilla vel sit amet ligula. Proin velit lectus, euismod sit amet quam vel ultricies dolor, vitae finibus lorem ipsum. Pellentesque molestie at mi sit amet dictum. Donec vehicula lacinia felis sit amet consectetur. Praesent sodales enim sapien, sed varius ipsum pellentesque vel. Aenean eu mi eu justo tincidunt finibus vel sit amet ipsum. Sed bibasdum purus vel ipsum sagittis, quis fermentum dolor lobortis. Etiam vulputate eleifasd lectus vel varius. Phasellus imperdiet lectus sit amet ipsum egestas, ut bibasdum ipsum malesuada. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed mollis eros sit amet elit porttitor, vel venenatis turpis venenatis. Nulla tempus tortor at eros efficitur, sit amet dapibus ipsum malesuada. Ut at mauris sed nunc malesuada convallis. Duis id sem vel magna varius eleifasd vel at est. Donec eget orci a ipsum tempor lobortis. Sed at consectetur ipsum."); + root_child0.setMeasureFunction(intrinsicMeasureFunction); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(2000f, root.getLayoutWidth(), 0.0f); + assertEquals(2000f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(1290f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(2000f, root.getLayoutWidth(), 0.0f); + assertEquals(2000f, root.getLayoutHeight(), 0.0f); + + assertEquals(1900f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(1290f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_contains_inner_text_no_width_fixed_height() { + YogaConfig config = YogaConfigFactory.create(); + + YogaNode root = createNode(config); + root.setAlignItems(YogaAlign.FLEX_START); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(2000f); + root.setHeight(2000f); + + YogaNode root_child0 = createNode(config); + root_child0.setFlexDirection(YogaFlexDirection.ROW); + root_child0.setHeight(20f); + root.addChildAt(root_child0, 0); + root_child0.setData("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eleifasd et tortor ac auctor. Integer at volutpat libero, sed elementum dui interdum id. Aliquam consectetur massa vel neque aliquet, quis consequat risus fringilla. Fusce rhoncus ipsum tempor eros aliquam, vel tempus metus ullamcorper. Nam at nulla sed tellus vestibulum fringilla vel sit amet ligula. Proin velit lectus, euismod sit amet quam vel ultricies dolor, vitae finibus lorem ipsum. Pellentesque molestie at mi sit amet dictum. Donec vehicula lacinia felis sit amet consectetur. Praesent sodales enim sapien, sed varius ipsum pellentesque vel. Aenean eu mi eu justo tincidunt finibus vel sit amet ipsum. Sed bibasdum purus vel ipsum sagittis, quis fermentum dolor lobortis. Etiam vulputate eleifasd lectus vel varius. Phasellus imperdiet lectus sit amet ipsum egestas, ut bibasdum ipsum malesuada. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed mollis eros sit amet elit porttitor, vel venenatis turpis venenatis. Nulla tempus tortor at eros efficitur, sit amet dapibus ipsum malesuada. Ut at mauris sed nunc malesuada convallis. Duis id sem vel magna varius eleifasd vel at est. Donec eget orci a ipsum tempor lobortis. Sed at consectetur ipsum."); + root_child0.setMeasureFunction(intrinsicMeasureFunction); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(2000f, root.getLayoutWidth(), 0.0f); + assertEquals(2000f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(2000f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(2000f, root.getLayoutWidth(), 0.0f); + assertEquals(2000f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(2000f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_contains_inner_text_fixed_width_fixed_height() { + YogaConfig config = YogaConfigFactory.create(); + + YogaNode root = createNode(config); + root.setAlignItems(YogaAlign.FLEX_START); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(2000f); + root.setHeight(2000f); + + YogaNode root_child0 = createNode(config); + root_child0.setFlexDirection(YogaFlexDirection.ROW); + root_child0.setWidth(50f); + root_child0.setHeight(20f); + root.addChildAt(root_child0, 0); + root_child0.setData("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eleifasd et tortor ac auctor. Integer at volutpat libero, sed elementum dui interdum id. Aliquam consectetur massa vel neque aliquet, quis consequat risus fringilla. Fusce rhoncus ipsum tempor eros aliquam, vel tempus metus ullamcorper. Nam at nulla sed tellus vestibulum fringilla vel sit amet ligula. Proin velit lectus, euismod sit amet quam vel ultricies dolor, vitae finibus lorem ipsum. Pellentesque molestie at mi sit amet dictum. Donec vehicula lacinia felis sit amet consectetur. Praesent sodales enim sapien, sed varius ipsum pellentesque vel. Aenean eu mi eu justo tincidunt finibus vel sit amet ipsum. Sed bibasdum purus vel ipsum sagittis, quis fermentum dolor lobortis. Etiam vulputate eleifasd lectus vel varius. Phasellus imperdiet lectus sit amet ipsum egestas, ut bibasdum ipsum malesuada. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed mollis eros sit amet elit porttitor, vel venenatis turpis venenatis. Nulla tempus tortor at eros efficitur, sit amet dapibus ipsum malesuada. Ut at mauris sed nunc malesuada convallis. Duis id sem vel magna varius eleifasd vel at est. Donec eget orci a ipsum tempor lobortis. Sed at consectetur ipsum."); + root_child0.setMeasureFunction(intrinsicMeasureFunction); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(2000f, root.getLayoutWidth(), 0.0f); + assertEquals(2000f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(2000f, root.getLayoutWidth(), 0.0f); + assertEquals(2000f, root.getLayoutHeight(), 0.0f); + + assertEquals(1950f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_contains_inner_text_max_width_max_height() { + YogaConfig config = YogaConfigFactory.create(); + + YogaNode root = createNode(config); + root.setAlignItems(YogaAlign.FLEX_START); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(2000f); + root.setHeight(2000f); + + YogaNode root_child0 = createNode(config); + root_child0.setFlexDirection(YogaFlexDirection.ROW); + root_child0.setMaxWidth(50f); + root_child0.setMaxHeight(20f); + root.addChildAt(root_child0, 0); + root_child0.setData("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eleifasd et tortor ac auctor. Integer at volutpat libero, sed elementum dui interdum id. Aliquam consectetur massa vel neque aliquet, quis consequat risus fringilla. Fusce rhoncus ipsum tempor eros aliquam, vel tempus metus ullamcorper. Nam at nulla sed tellus vestibulum fringilla vel sit amet ligula. Proin velit lectus, euismod sit amet quam vel ultricies dolor, vitae finibus lorem ipsum. Pellentesque molestie at mi sit amet dictum. Donec vehicula lacinia felis sit amet consectetur. Praesent sodales enim sapien, sed varius ipsum pellentesque vel. Aenean eu mi eu justo tincidunt finibus vel sit amet ipsum. Sed bibasdum purus vel ipsum sagittis, quis fermentum dolor lobortis. Etiam vulputate eleifasd lectus vel varius. Phasellus imperdiet lectus sit amet ipsum egestas, ut bibasdum ipsum malesuada. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed mollis eros sit amet elit porttitor, vel venenatis turpis venenatis. Nulla tempus tortor at eros efficitur, sit amet dapibus ipsum malesuada. Ut at mauris sed nunc malesuada convallis. Duis id sem vel magna varius eleifasd vel at est. Donec eget orci a ipsum tempor lobortis. Sed at consectetur ipsum."); + root_child0.setMeasureFunction(intrinsicMeasureFunction); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(2000f, root.getLayoutWidth(), 0.0f); + assertEquals(2000f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(2000f, root.getLayoutWidth(), 0.0f); + assertEquals(2000f, root.getLayoutHeight(), 0.0f); + + assertEquals(1950f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_contains_inner_text_max_width() { + YogaConfig config = YogaConfigFactory.create(); + + YogaNode root = createNode(config); + root.setAlignItems(YogaAlign.FLEX_START); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(2000f); + root.setHeight(2000f); + + YogaNode root_child0 = createNode(config); + root_child0.setFlexDirection(YogaFlexDirection.ROW); + root_child0.setMaxWidth(100f); + root.addChildAt(root_child0, 0); + root_child0.setData("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eleifasd et tortor ac auctor. Integer at volutpat libero, sed elementum dui interdum id. Aliquam consectetur massa vel neque aliquet, quis consequat risus fringilla. Fusce rhoncus ipsum tempor eros aliquam, vel tempus metus ullamcorper. Nam at nulla sed tellus vestibulum fringilla vel sit amet ligula. Proin velit lectus, euismod sit amet quam vel ultricies dolor, vitae finibus lorem ipsum. Pellentesque molestie at mi sit amet dictum. Donec vehicula lacinia felis sit amet consectetur. Praesent sodales enim sapien, sed varius ipsum pellentesque vel. Aenean eu mi eu justo tincidunt finibus vel sit amet ipsum. Sed bibasdum purus vel ipsum sagittis, quis fermentum dolor lobortis. Etiam vulputate eleifasd lectus vel varius. Phasellus imperdiet lectus sit amet ipsum egestas, ut bibasdum ipsum malesuada. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed mollis eros sit amet elit porttitor, vel venenatis turpis venenatis. Nulla tempus tortor at eros efficitur, sit amet dapibus ipsum malesuada. Ut at mauris sed nunc malesuada convallis. Duis id sem vel magna varius eleifasd vel at est. Donec eget orci a ipsum tempor lobortis. Sed at consectetur ipsum."); + root_child0.setMeasureFunction(intrinsicMeasureFunction); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(2000f, root.getLayoutWidth(), 0.0f); + assertEquals(2000f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(1290f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(2000f, root.getLayoutWidth(), 0.0f); + assertEquals(2000f, root.getLayoutHeight(), 0.0f); + + assertEquals(1900f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(1290f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_contains_inner_text_fixed_width_shorter_text() { + YogaConfig config = YogaConfigFactory.create(); + + YogaNode root = createNode(config); + root.setAlignItems(YogaAlign.FLEX_START); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(2000f); + root.setHeight(2000f); + + YogaNode root_child0 = createNode(config); + root_child0.setFlexDirection(YogaFlexDirection.ROW); + root_child0.setWidth(100f); + root.addChildAt(root_child0, 0); + root_child0.setData("Lorem ipsum"); + root_child0.setMeasureFunction(intrinsicMeasureFunction); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(2000f, root.getLayoutWidth(), 0.0f); + assertEquals(2000f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(2000f, root.getLayoutWidth(), 0.0f); + assertEquals(2000f, root.getLayoutHeight(), 0.0f); + + assertEquals(1900f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_contains_inner_text_fixed_height_shorter_text() { + YogaConfig config = YogaConfigFactory.create(); + + YogaNode root = createNode(config); + root.setAlignItems(YogaAlign.FLEX_START); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(2000f); + root.setHeight(2000f); + + YogaNode root_child0 = createNode(config); + root_child0.setFlexDirection(YogaFlexDirection.ROW); + root_child0.setHeight(100f); + root.addChildAt(root_child0, 0); + root_child0.setData("Lorem ipsum"); + root_child0.setMeasureFunction(intrinsicMeasureFunction); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(2000f, root.getLayoutWidth(), 0.0f); + assertEquals(2000f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(110f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(2000f, root.getLayoutWidth(), 0.0f); + assertEquals(2000f, root.getLayoutHeight(), 0.0f); + + assertEquals(1890f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(110f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_contains_inner_text_max_height() { + YogaConfig config = YogaConfigFactory.create(); + + YogaNode root = createNode(config); + root.setAlignItems(YogaAlign.FLEX_START); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(2000f); + root.setHeight(2000f); + + YogaNode root_child0 = createNode(config); + root_child0.setFlexDirection(YogaFlexDirection.ROW); + root_child0.setMaxHeight(20f); + root.addChildAt(root_child0, 0); + root_child0.setData("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eleifasd et tortor ac auctor. Integer at volutpat libero, sed elementum dui interdum id. Aliquam consectetur massa vel neque aliquet, quis consequat risus fringilla. Fusce rhoncus ipsum tempor eros aliquam, vel tempus metus ullamcorper. Nam at nulla sed tellus vestibulum fringilla vel sit amet ligula. Proin velit lectus, euismod sit amet quam vel ultricies dolor, vitae finibus lorem ipsum. Pellentesque molestie at mi sit amet dictum. Donec vehicula lacinia felis sit amet consectetur. Praesent sodales enim sapien, sed varius ipsum pellentesque vel. Aenean eu mi eu justo tincidunt finibus vel sit amet ipsum. Sed bibasdum purus vel ipsum sagittis, quis fermentum dolor lobortis. Etiam vulputate eleifasd lectus vel varius. Phasellus imperdiet lectus sit amet ipsum egestas, ut bibasdum ipsum malesuada. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed mollis eros sit amet elit porttitor, vel venenatis turpis venenatis. Nulla tempus tortor at eros efficitur, sit amet dapibus ipsum malesuada. Ut at mauris sed nunc malesuada convallis. Duis id sem vel magna varius eleifasd vel at est. Donec eget orci a ipsum tempor lobortis. Sed at consectetur ipsum."); + root_child0.setMeasureFunction(intrinsicMeasureFunction); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(2000f, root.getLayoutWidth(), 0.0f); + assertEquals(2000f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(2000f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaNode.YogaDirection.RTL); + root.calculateLayout(YogaNode.YogaConstants.UNDEFINED, YogaNode.YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(2000f, root.getLayoutWidth(), 0.0f); + assertEquals(2000f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(2000f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0.getLayoutHeight(), 0.0f); + } + + private static final float widthPerChar = 10; + private static final float heightPerChar = 10; + + static float getWidestWordWidth(String text) { + int widestWordLength = 0; + + String[] words = text.split(" "); + for (String word : words) { + int wordLength = word.length(); + if (widestWordLength < wordLength) { + widestWordLength = wordLength; + } + } + + return widestWordLength * widthPerChar; + } + + static float calculateHeight(String text, float measuredWidth) { + if (text.length() * widthPerChar <= measuredWidth) { + return heightPerChar; + } + + String[] words = text.split(" "); + + float lines = 1; + float currentLineLength = 0; + for (String word : words) { + float wordWidth = word.length() * widthPerChar; + if (wordWidth > measuredWidth) { + if (currentLineLength > 0) { + lines++; + } + lines++; + currentLineLength = 0; + } else if (currentLineLength + wordWidth <= measuredWidth) { + currentLineLength += wordWidth + widthPerChar; + } else { + lines++; + currentLineLength = wordWidth + widthPerChar; + } + } + + return (currentLineLength == 0 ? lines - 1 : lines) * heightPerChar; + } +} diff --git a/modules/lwjgl/yoga/src/test/java/org/lwjgl/util/yoga/YogaNode.java b/modules/lwjgl/yoga/src/test/java/org/lwjgl/util/yoga/YogaNode.java index b9f8153311..10146ed6c2 100644 --- a/modules/lwjgl/yoga/src/test/java/org/lwjgl/util/yoga/YogaNode.java +++ b/modules/lwjgl/yoga/src/test/java/org/lwjgl/util/yoga/YogaNode.java @@ -39,6 +39,9 @@ class YogaNode { @Nullable private YogaNode owner; + @Nullable + private Object data; + YogaNode() { this(YGNodeNew()); } @@ -279,6 +282,14 @@ void setWrap(YogaWrap flexWrap) { YGNodeStyleSetFlexWrap(node, flexWrap.value); } + void setData(Object data) { + this.data = data; + } + + Object getData() { + return data; + } + void setMeasureFunction(YGMeasureFuncI measureFunction) { YGMeasureFunc func = YGMeasureFunc.create(measureFunction); this.measureFunc = func;