Aspect ratio is different as document described #313

Closed
opened 2017-01-03 00:43:49 -08:00 by anql · 2 comments
anql commented 2017-01-03 00:43:49 -08:00 (Migrated from github.com)

As yoga's document - Aspect Ratio described, the Height should be Width * Aspect ratio. However, Height was calculated with Width / Aspect ratio by the code.

default

TestCase

int main(int argc, const char * argv[]) {
    const YGNodeRef root = YGNodeNew();
    YGNodeStyleSetWidth(root, 1000);
    YGNodeStyleSetHeight(root, 1000);
    
    const YGNodeRef root_child0 = YGNodeNew();
    YGNodeStyleSetWidth(root_child0, 100);
    // YGNodeStyleSetHeight(root_child0, 100);
    YGNodeStyleSetAspectRatio(root_child0, 2);
    YGNodeInsertChild(root, root_child0, 0);
    YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
    
    YGNodeFreeRecursive(root);
    
    return 0;
}

Print tree

{layout: {width: 1000, height: 1000, top: 0, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, overflow: 'visible', width: 1000px, height: 1000px, children: [
  {layout: {width: 100, height: 50, top: 0, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, overflow: 'visible', width: 100px, },
]},

I'm not good at English, wish this is clear. Thanks.

As yoga's document - [Aspect Ratio](https://facebook.github.io/yoga/docs/aspect-ratio/) described, the Height should be **Width * Aspect ratio**. However, Height was calculated with **Width / Aspect ratio** by the code. ![default](https://cloud.githubusercontent.com/assets/6122573/21602678/a5c45eba-d1d1-11e6-87cd-c18638638c7c.png) ## TestCase ```C int main(int argc, const char * argv[]) { const YGNodeRef root = YGNodeNew(); YGNodeStyleSetWidth(root, 1000); YGNodeStyleSetHeight(root, 1000); const YGNodeRef root_child0 = YGNodeNew(); YGNodeStyleSetWidth(root_child0, 100); // YGNodeStyleSetHeight(root_child0, 100); YGNodeStyleSetAspectRatio(root_child0, 2); YGNodeInsertChild(root, root_child0, 0); YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); YGNodeFreeRecursive(root); return 0; } ``` ## Print tree ``` {layout: {width: 1000, height: 1000, top: 0, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, overflow: 'visible', width: 1000px, height: 1000px, children: [ {layout: {width: 100, height: 50, top: 0, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, overflow: 'visible', width: 100px, }, ]}, ``` I'm not good at English, wish this is clear. Thanks.
emilsjolander commented 2017-01-10 04:02:05 -08:00 (Migrated from github.com)

Yes the documentation is wrong 👍 Thanks for finding this. Fixing now.

Yes the documentation is wrong 👍 Thanks for finding this. Fixing now.
anql commented 2017-01-10 19:33:19 -08:00 (Migrated from github.com)

Thanks for fixing it. Yoga is really an awesome project.👍

Thanks for fixing it. Yoga is really an awesome project.👍
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DaddyFrosty/yoga#313
No description provided.