Skip to content

Commit c3f2baf

Browse files
committed
Fix a bug with scroll offset in scroll containers with GROW where contents were smaller than container
1 parent c02db35 commit c3f2baf

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

clay.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -3182,14 +3182,14 @@ void Clay_UpdateScrollContainers(bool enableDragScrolling, Clay_Vector2 scrollDe
31823182
if ((scrollData->scrollMomentum.x > -0.1f && scrollData->scrollMomentum.x < 0.1f) || scrollOccurred) {
31833183
scrollData->scrollMomentum.x = 0;
31843184
}
3185-
scrollData->scrollPosition.x = CLAY__MAX(CLAY__MIN(scrollData->scrollPosition.x, 0), -(scrollData->contentSize.width - scrollData->layoutElement->dimensions.width));
3185+
scrollData->scrollPosition.x = CLAY__MIN(CLAY__MAX(scrollData->scrollPosition.x, -(CLAY__MAX(scrollData->contentSize.width - scrollData->layoutElement->dimensions.width, 0))), 0);
31863186

31873187
scrollData->scrollPosition.y += scrollData->scrollMomentum.y;
31883188
scrollData->scrollMomentum.y *= 0.95f;
31893189
if ((scrollData->scrollMomentum.y > -0.1f && scrollData->scrollMomentum.y < 0.1f) || scrollOccurred) {
31903190
scrollData->scrollMomentum.y = 0;
31913191
}
3192-
scrollData->scrollPosition.y = CLAY__MAX(CLAY__MIN(scrollData->scrollPosition.y, 0), -(scrollData->contentSize.height - scrollData->layoutElement->dimensions.height));
3192+
scrollData->scrollPosition.y = CLAY__MIN(CLAY__MAX(scrollData->scrollPosition.y, -(CLAY__MAX(scrollData->contentSize.height - scrollData->layoutElement->dimensions.height, 0))), 0);
31933193

31943194
for (int j = 0; j < Clay__pointerOverIds.length; ++j) { // TODO n & m are small here but this being n*m gives me the creeps
31953195
if (scrollData->layoutElement->id == Clay__ElementIdArray_Get(&Clay__pointerOverIds, j)->id) {

0 commit comments

Comments
 (0)