clay icon indicating copy to clipboard operation
clay copied to clipboard

[Layout] Scroll content height incorrectly considers padding

Open pdoane opened this issue 8 months ago • 1 comments

When the number of elements in a container exceeds its size / padding, then each additional element increases the scroll container dimension by the padding size.

For example, with the loop set to 82 elements this computes a container height of 1000 as expected. Increasing it to 83 reports 1008, and increasing it to 84 reports 1020.

        float padding = 12;

        Clay_SetLayoutDimensions((Clay_Dimensions){.width = 1600, .height = 1000});

        CLAY({
            .id = CLAY_ID("Thumbnails"),
            .layout = {
                .sizing = {.width = CLAY_SIZING_PERCENT(0.2f), .height = CLAY_SIZING_GROW(0)},
                .layoutDirection = CLAY_TOP_TO_BOTTOM,
                .padding = CLAY_PADDING_ALL(padding),
                .childGap = padding,
            },
            .clip = {.horizontal = false, .vertical = true, .childOffset = Clay_GetScrollOffset()},
        })
        {
            Clay_ElementId id = Clay_GetElementId(CLAY_STRING("Thumbnails"));
            Clay_ScrollContainerData scrollContainerData = Clay_GetScrollContainerData(id);
            printf("Scroll container height: %f\n", scrollContainerData.scrollContainerDimensions.height);

            for (size_t i = 0; i < 83; ++i)
            {
                CLAY({
                    .layout = {
                        .sizing = {.width = CLAY_SIZING_FIXED(100), .height = CLAY_SIZING_FIXED(100)},
                    },
                    .backgroundColor = (Clay_Color){0, 0, 0, 255},
                    .border = {
                        .width = CLAY_BORDER_OUTSIDE(2),
                        .color = Clay_Hovered() ? (Clay_Color){255, 255, 255, 255} : (Clay_Color){0, 0, 0, 0},
                    },
                })
                {}
            }
        }

pdoane avatar May 02 '25 18:05 pdoane

That definitely sounds like a bug, will take a look! Thanks for reporting 🙂

nicbarker avatar May 06 '25 00:05 nicbarker

Sorry about the delay getting to this one, should be fixed here: https://github.com/nicbarker/clay/commit/3ccfa0f8faad419aad4be48786230f15222bcc14

nicbarker avatar Jun 11 '25 00:06 nicbarker

I think this one should be all good to close now!

nicbarker avatar Jun 22 '25 23:06 nicbarker