xamarin / flex

Flex is a flexible box layout system written in C, designed to be easy to consume from other languages
MIT License
194 stars 28 forks source link

flex-basis issue #33

Closed StephaneDelcroix closed 6 years ago

StephaneDelcroix commented 6 years ago

here's what I'm expecting

2017-12-06_1459

here's what I'm getting

2017-12-06_1501

which is the result without the flex-basis at all

lrz commented 6 years ago

Should be fixed by 98a4b67912d2ea938d78f4a80a82fa36216bc52a. Setting 0 values to the basis property used to be ignored and they are now taken into account (not sure why I implemented it that way). As a result, the default value of basis is no longer 0 but NaN. Negative values are still ignored.

StephaneDelcroix commented 6 years ago

The problem is still present is self_sizing is set

static void
self_sizing25(struct flex_item *item, float size[2])
{
    size[0] = 100;
    size[1] = 20;
}

void
test_wrap25(void)
{
    struct flex_item *root = flex_item_with_size(150, 100);
    flex_item_set_wrap(root, FLEX_WRAP_WRAP);
    flex_item_set_direction(root, FLEX_DIRECTION_ROW);

    struct flex_item *child1 = flex_item_new();
    flex_item_set_width(child1, 50);
    flex_item_set_self_sizing(child1, self_sizing25);
    flex_item_add(root, child1);

    struct flex_item *child2 = flex_item_new();
    flex_item_set_width(child2, 50);
    flex_item_set_basis(child2, 0);
    flex_item_set_self_sizing(child2, self_sizing25);
    flex_item_add(root, child2);

    struct flex_item *child3 = flex_item_new();
    flex_item_set_width(child3, 50);
    flex_item_set_self_sizing(child3, self_sizing25);
    flex_item_add(root, child3);

    struct flex_item *child4 = flex_item_new();
    flex_item_set_width(child4, 50);
    flex_item_set_basis(child4, 0);
    flex_item_set_self_sizing(child4, self_sizing25);
    flex_item_add(root, child4);

    struct flex_item *child5 = flex_item_new();
    flex_item_set_width(child5, 50);
    flex_item_set_self_sizing(child5, self_sizing25);
    flex_item_add(root, child5);

    flex_layout(root);

    TEST_FRAME_EQUAL(child1, 0, 0, 50, 100);
    TEST_FRAME_EQUAL(child2, 50, 0, 0, 100);
    TEST_FRAME_EQUAL(child3, 50, 0, 50, 100);
    TEST_FRAME_EQUAL(child4, 100, 0, 0, 100);
    TEST_FRAME_EQUAL(child5, 100, 0, 50, 100);

    flex_item_free(root);
}
StephaneDelcroix commented 6 years ago

I'm getting, as a result

//child1
test_wrap25 (test_wrap.c:850): failed test `flex_item_get_frame_width(_item) == 50.0' (is 100.0)
test_wrap25 (test_wrap.c:850): failed test `flex_item_get_frame_height(_item) == 100.0' (is 20.0)
//child2
test_wrap25 (test_wrap.c:851): failed test `flex_item_get_frame_x(_item) == 50.0' (is 0.0)
test_wrap25 (test_wrap.c:851): failed test `flex_item_get_frame_y(_item) == 0.0' (is 20.0)
test_wrap25 (test_wrap.c:851): failed test `flex_item_get_frame_width(_item) == 0.0' (is 100.0)
test_wrap25 (test_wrap.c:851): failed test `flex_item_get_frame_height(_item) == 100.0' (is 20.0)
//child3
test_wrap25 (test_wrap.c:852): failed test `flex_item_get_frame_x(_item) == 50.0' (is 0.0)
test_wrap25 (test_wrap.c:852): failed test `flex_item_get_frame_y(_item) == 0.0' (is 40.0)
test_wrap25 (test_wrap.c:852): failed test `flex_item_get_frame_width(_item) == 50.0' (is 100.0)
test_wrap25 (test_wrap.c:852): failed test `flex_item_get_frame_height(_item) == 100.0' (is 20.0)
//child4
test_wrap25 (test_wrap.c:853): failed test `flex_item_get_frame_x(_item) == 100.0' (is 0.0)
test_wrap25 (test_wrap.c:853): failed test `flex_item_get_frame_y(_item) == 0.0' (is 60.0)
test_wrap25 (test_wrap.c:853): failed test `flex_item_get_frame_width(_item) == 0.0' (is 100.0)
test_wrap25 (test_wrap.c:853): failed test `flex_item_get_frame_height(_item) == 100.0' (is 20.0)
//child5
test_wrap25 (test_wrap.c:854): failed test `flex_item_get_frame_x(_item) == 100.0' (is 0.0)
test_wrap25 (test_wrap.c:854): failed test `flex_item_get_frame_y(_item) == 0.0' (is 80.0)
test_wrap25 (test_wrap.c:854): failed test `flex_item_get_frame_width(_item) == 50.0' (is 100.0)
test_wrap25 (test_wrap.c:854): failed test `flex_item_get_frame_height(_item) == 100.0' (is 20.0)
lrz commented 6 years ago

Indeed, we are calling the self-sizing callback after honoring the basis property, this should be fixed.

However the test will not work as is, because the self-sizing callback returns a width of 100 (which will override the set_width 50 value). It should either set the width to 50 or not set any width.

static void
self_sizing25(struct flex_item *item, float size[2])
{
    size[1] = 20;
}
lrz commented 6 years ago

Should be fixed by 21dfb07aca7a96a0f1e06584d345a558f4a44f59