calculation error of 'display' feature #443

Closed
opened 2017-02-27 07:40:59 -08:00 by anql · 1 comment
anql commented 2017-02-27 07:40:59 -08:00 (Migrated from github.com)

The leaf node‘s measure result is error while 'YGNodeStyleSetDisplay' be called several times before calculating.

#include <iostream>
#include "Yoga.h"

void toggle(const YGNodeRef tab1, const YGNodeRef tab2, const YGNodeRef root, const YGNodeRef label, bool tab1Display) {
    YGNodeStyleSetDisplay(tab1, tab1Display ? YGDisplayFlex : YGDisplayNone);
    YGNodeStyleSetDisplay(tab2, tab1Display ? YGDisplayNone : YGDisplayFlex);
    YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
    
    float w = YGNodeLayoutGetWidth(label);
    float h = YGNodeLayoutGetHeight(label);
    printf("label display:%s, w=%f, h=%f\n", tab1Display ? "false": "true",  w, h);
    
    if (tab1Display) {
        assert(w == 0 && h == 0);
    } else {
        assert(w == 8 && h == 16);
    }
}


/*
 <div id="root">
 <div id="tab1" style="flex-grow:1;display:flex">
 
 </div>
 
 <div id="tab2" style="flex-grow:1;display:none">
 <div id="div1">
 <div id="label" style="width:8; height:16;"></div>
 </div>
 </div>
 </div>
 */
int main(int argc, const char * argv[]) {
    const YGNodeRef root = YGNodeNew();
    YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
    YGNodeStyleSetHeight(root, 100);
    
    const YGNodeRef tab1 = YGNodeNew();
    YGNodeStyleSetFlexGrow(tab1, 1);
    const YGNodeRef tab2 = YGNodeNew();
    YGNodeStyleSetFlexGrow(tab2, 1);
    
    const YGNodeRef div1 = YGNodeNew();
    const YGNodeRef label = YGNodeNew();
    YGNodeStyleSetWidth(label, 8);
    YGNodeStyleSetHeight(label, 16);
    
    YGNodeInsertChild(div1, label, 0);
    
    YGNodeInsertChild(tab2, div1, 0);
    YGNodeInsertChild(root, tab1, 0);
    YGNodeInsertChild(root, tab2, 0);
    
    toggle(tab1, tab2, root, label, true);//OK
    toggle(tab1, tab2, root, label, false);//OK
    toggle(tab1, tab2, root, label, true);//OK
    toggle(tab1, tab2, root, label, false);//FAILED!
    
    YGNodeFreeRecursive(root);
    return 0;
}
The leaf node‘s measure result is error while 'YGNodeStyleSetDisplay' be called several times before calculating. ```C #include <iostream> #include "Yoga.h" void toggle(const YGNodeRef tab1, const YGNodeRef tab2, const YGNodeRef root, const YGNodeRef label, bool tab1Display) { YGNodeStyleSetDisplay(tab1, tab1Display ? YGDisplayFlex : YGDisplayNone); YGNodeStyleSetDisplay(tab2, tab1Display ? YGDisplayNone : YGDisplayFlex); YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); float w = YGNodeLayoutGetWidth(label); float h = YGNodeLayoutGetHeight(label); printf("label display:%s, w=%f, h=%f\n", tab1Display ? "false": "true", w, h); if (tab1Display) { assert(w == 0 && h == 0); } else { assert(w == 8 && h == 16); } } /* <div id="root"> <div id="tab1" style="flex-grow:1;display:flex"> </div> <div id="tab2" style="flex-grow:1;display:none"> <div id="div1"> <div id="label" style="width:8; height:16;"></div> </div> </div> </div> */ int main(int argc, const char * argv[]) { const YGNodeRef root = YGNodeNew(); YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); YGNodeStyleSetHeight(root, 100); const YGNodeRef tab1 = YGNodeNew(); YGNodeStyleSetFlexGrow(tab1, 1); const YGNodeRef tab2 = YGNodeNew(); YGNodeStyleSetFlexGrow(tab2, 1); const YGNodeRef div1 = YGNodeNew(); const YGNodeRef label = YGNodeNew(); YGNodeStyleSetWidth(label, 8); YGNodeStyleSetHeight(label, 16); YGNodeInsertChild(div1, label, 0); YGNodeInsertChild(tab2, div1, 0); YGNodeInsertChild(root, tab1, 0); YGNodeInsertChild(root, tab2, 0); toggle(tab1, tab2, root, label, true);//OK toggle(tab1, tab2, root, label, false);//OK toggle(tab1, tab2, root, label, true);//OK toggle(tab1, tab2, root, label, false);//FAILED! YGNodeFreeRecursive(root); return 0; } ```
jmmiracle commented 2017-03-01 01:48:45 -08:00 (Migrated from github.com)

we also have this question, seems could not calculate right

we also have this question, seems could not calculate right
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DaddyFrosty/yoga#443
No description provided.