[Question] Should Clay_ScrollContainerData consider padding for first frame
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);
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?
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.
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);