clay icon indicating copy to clipboard operation
clay copied to clipboard

[Question] Should Clay_ScrollContainerData consider padding for first frame

Open pdoane opened this issue 8 months ago • 3 comments

On the first frame rendering, scrollContainerDimensions is (0,0) but it seems to me like it should be (padding.left + padding.right, padding.top + padding.bottom)?

Various layout equations need to subtract padding so I've taken to extending this in my own code:

        Clay_Dimensions dims = scrollContainerData.scrollContainerDimensions;
        dims.width = max(dims.width, padding * 2);
        dims.height = max(dims.height, padding * 2);

pdoane avatar May 02 '25 22:05 pdoane

Yes you're right, unfortunately we have the classic 1 frame of latency for dimensions (I should document this somewhere)

Just to clarify - if the scroll container has contents, its dimensions will change on the second frame (regardless of if we include the padding on the first frame or not). Could you give me a bit more info on your specific use case?

nicbarker avatar May 05 '25 00:05 nicbarker

This came from developing a thumbnail viewer. I was computing the number of columns and got a negative value that went to SIZE_MAX. It’s fine that the first frame doesn’t know how big it is, but things would be a little safer including those padding values.

pdoane avatar May 05 '25 14:05 pdoane

I've implemented this in my wrapper layer and happy to provide any PRs that you would like.

Related to usage, I think a utility to get the current open element ID would be useful?

    Clay_LayoutElement* openLayoutElement = Clay__GetOpenLayoutElement();
    if (openLayoutElement->id == 0)
        Clay__GenerateIdForAnonymousElement(openLayoutElement);

    Clay_ElementId elementId = {.id = openLayoutElement->id};
    return elementId;

Or alternatively could get scroll data for the open element:

Clay_ScrollContainerData Clay_GetCurrentScrollContainerData(void);

pdoane avatar May 05 '25 16:05 pdoane