calculating layout does not set all properties #1158

Open
opened 2022-08-27 07:34:58 -07:00 by Martmists-GH · 1 comment
Martmists-GH commented 2022-08-27 07:34:58 -07:00 (Migrated from github.com)

Report

Issues and Steps to Reproduce

Code:

fun main()
    val root = YGNodeNew()
    YGNodeStyleSetWidth(root, 200f)
    YGNodeStyleSetHeight(root, 200f)

    val child = YGNodeNew()
    YGNodeStyleSetWidth(child, 100f)
    YGNodeStyleSetHeight(child, 100f)
    YGNodeStyleSetPosition(child, YGEdgeLeft, 10f)
    YGNodeStyleSetPosition(child, YGEdgeTop, 10f)
    YGNodeInsertChild(root, child, 0)

    YGNodeCalculateLayout(root, 200f, 200f, YGDirectionLTR)
    println(YGNodeLayoutGetLeft(child))
    println(YGNodeLayoutGetTop(child))
    println(YGNodeLayoutGetRight(child))
    println(YGNodeLayoutGetBottom(child))

    YGNodeFree(child)
    YGNodeFree(root)
}

Expected Behavior

it should print 10, 10, 110, 110 because right and bottom are 100 away from the other sides

Actual Behavior

it prints 10, 10, 10, 10 meaning the height and width are ignored

Link to Code

See above

# Report - [x] I have searched [existing issues](https://github.com/facebook/yoga/issues) and this is not a duplicate # Issues and Steps to Reproduce Code: ```kotlin fun main() val root = YGNodeNew() YGNodeStyleSetWidth(root, 200f) YGNodeStyleSetHeight(root, 200f) val child = YGNodeNew() YGNodeStyleSetWidth(child, 100f) YGNodeStyleSetHeight(child, 100f) YGNodeStyleSetPosition(child, YGEdgeLeft, 10f) YGNodeStyleSetPosition(child, YGEdgeTop, 10f) YGNodeInsertChild(root, child, 0) YGNodeCalculateLayout(root, 200f, 200f, YGDirectionLTR) println(YGNodeLayoutGetLeft(child)) println(YGNodeLayoutGetTop(child)) println(YGNodeLayoutGetRight(child)) println(YGNodeLayoutGetBottom(child)) YGNodeFree(child) YGNodeFree(root) } ``` # Expected Behavior it should print 10, 10, 110, 110 because right and bottom are 100 away from the other sides # Actual Behavior it prints 10, 10, 10, 10 meaning the height and width are ignored # Link to Code See above
NickGerleman commented 2022-10-02 21:33:25 -07:00 (Migrated from github.com)

I am able to reproduce the same behavior of YGNodeLayoutGetRight and YGNodeLayoutGetBottom with the below test. Width and height are returned correctly, and seems to be what the generated tests are using for assertions.

There doesn't seem to be any usages within Meta which calls the APIs (at least the C/C++ version), so I took a look at unit tests to try to understand what the expected value would be (e.g. offsets vs insets). Looking at YGEdgeTest, I think the values of GetRight and GetBottom are intended to be insets relative to the right and bottom edge of the parent container. So I think "90" would be the correct value, since we are 90px away from the bottom and right edges of the parent container.

"10" doesn't seem to make sense under either scheme, and seems like a bug to me.

TEST(YogaTest, gh_layout) {
  const YGConfigRef config = YGConfigNew();

  const YGNodeRef root = YGNodeNewWithConfig(config);
  YGNodeStyleSetWidth(root, 200);
  YGNodeStyleSetHeight(root, 200);

  const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
  YGNodeStyleSetPosition(root_child0, YGEdgeLeft, 10);
  YGNodeStyleSetPosition(root_child0, YGEdgeTop, 10);
  YGNodeStyleSetWidth(root_child0, 100);
  YGNodeStyleSetHeight(root_child0, 100);
  YGNodeInsertChild(root, root_child0, 0);
  YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

  ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
  ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
  ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
  ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));

  ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0));
  ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0));
  ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0));
  ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0));

  // These fail
  ASSERT_FLOAT_EQ(110, YGNodeLayoutGetRight(root_child0)); // 10
  ASSERT_FLOAT_EQ(110, YGNodeLayoutGetBottom(root_child0)); // 10 

  YGNodeFreeRecursive(root);
  YGConfigFree(config);
}
I am able to reproduce the same behavior of `YGNodeLayoutGetRight` and `YGNodeLayoutGetBottom` with the below test. Width and height are returned correctly, and seems to be what the generated tests are using for assertions. There doesn't seem to be any usages within Meta which calls the APIs (at least the C/C++ version), so I took a look at unit tests to try to understand what the expected value would be (e.g. offsets vs insets). Looking at `YGEdgeTest`, I think the values of `GetRight` and `GetBottom` are intended to be insets relative to the right and bottom edge of the parent container. So I think "90" would be the correct value, since we are 90px away from the bottom and right edges of the parent container. "10" doesn't seem to make sense under either scheme, and seems like a bug to me. ```cpp TEST(YogaTest, gh_layout) { const YGConfigRef config = YGConfigNew(); const YGNodeRef root = YGNodeNewWithConfig(config); YGNodeStyleSetWidth(root, 200); YGNodeStyleSetHeight(root, 200); const YGNodeRef root_child0 = YGNodeNewWithConfig(config); YGNodeStyleSetPosition(root_child0, YGEdgeLeft, 10); YGNodeStyleSetPosition(root_child0, YGEdgeTop, 10); YGNodeStyleSetWidth(root_child0, 100); YGNodeStyleSetHeight(root_child0, 100); YGNodeInsertChild(root, root_child0, 0); YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root)); ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); // These fail ASSERT_FLOAT_EQ(110, YGNodeLayoutGetRight(root_child0)); // 10 ASSERT_FLOAT_EQ(110, YGNodeLayoutGetBottom(root_child0)); // 10 YGNodeFreeRecursive(root); YGConfigFree(config); } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DaddyFrosty/yoga#1158
No description provided.