mirror of
				https://github.com/nicbarker/clay.git
				synced 2025-11-04 08:36:17 +00:00 
			
		
		
		
	[Core] Don't divide zero by zero (#200)
Co-authored-by: Nic Barker <contact+github@nicbarker.com>
This commit is contained in:
		
							parent
							
								
									814c9392c6
								
							
						
					
					
						commit
						cd82ce6fcf
					
				
							
								
								
									
										22
									
								
								clay.h
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								clay.h
									
									
									
									
									
								
							| 
						 | 
					@ -2117,9 +2117,9 @@ void Clay__InitializePersistentMemory(Clay_Context* context) {
 | 
				
			||||||
void Clay__CompressChildrenAlongAxis(bool xAxis, float totalSizeToDistribute, Clay__int32_tArray resizableContainerBuffer) {
 | 
					void Clay__CompressChildrenAlongAxis(bool xAxis, float totalSizeToDistribute, Clay__int32_tArray resizableContainerBuffer) {
 | 
				
			||||||
    Clay_Context* context = Clay_GetCurrentContext();
 | 
					    Clay_Context* context = Clay_GetCurrentContext();
 | 
				
			||||||
    Clay__int32_tArray largestContainers = context->openClipElementStack;
 | 
					    Clay__int32_tArray largestContainers = context->openClipElementStack;
 | 
				
			||||||
    largestContainers.length = 0;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    while (totalSizeToDistribute > 0.1) {
 | 
					    while (totalSizeToDistribute > 0.1) {
 | 
				
			||||||
 | 
					        largestContainers.length = 0;
 | 
				
			||||||
        float largestSize = 0;
 | 
					        float largestSize = 0;
 | 
				
			||||||
        float targetSize = 0;
 | 
					        float targetSize = 0;
 | 
				
			||||||
        for (int32_t i = 0; i < resizableContainerBuffer.length; ++i) {
 | 
					        for (int32_t i = 0; i < resizableContainerBuffer.length; ++i) {
 | 
				
			||||||
| 
						 | 
					@ -2141,23 +2141,29 @@ void Clay__CompressChildrenAlongAxis(bool xAxis, float totalSizeToDistribute, Cl
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (largestContainers.length == 0) {
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        targetSize = CLAY__MAX(targetSize, (largestSize * largestContainers.length) - totalSizeToDistribute) / largestContainers.length;
 | 
					        targetSize = CLAY__MAX(targetSize, (largestSize * largestContainers.length) - totalSizeToDistribute) / largestContainers.length;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (int32_t childOffset = 0; childOffset < largestContainers.length; childOffset++) {
 | 
					        for (int32_t childOffset = 0; childOffset < largestContainers.length; childOffset++) {
 | 
				
			||||||
            Clay_LayoutElement *childElement = Clay_LayoutElementArray_Get(&context->layoutElements, Clay__int32_tArray_Get(&largestContainers, childOffset));
 | 
					            int32_t childIndex = Clay__int32_tArray_Get(&largestContainers, childOffset);
 | 
				
			||||||
 | 
					            Clay_LayoutElement *childElement = Clay_LayoutElementArray_Get(&context->layoutElements, childIndex);
 | 
				
			||||||
            float *childSize = xAxis ? &childElement->dimensions.width : &childElement->dimensions.height;
 | 
					            float *childSize = xAxis ? &childElement->dimensions.width : &childElement->dimensions.height;
 | 
				
			||||||
            float childMinSize = xAxis ? childElement->minDimensions.width : childElement->minDimensions.height;
 | 
					            float childMinSize = xAxis ? childElement->minDimensions.width : childElement->minDimensions.height;
 | 
				
			||||||
            float oldChildSize = *childSize;
 | 
					            float oldChildSize = *childSize;
 | 
				
			||||||
            *childSize = CLAY__MAX(childMinSize, targetSize);
 | 
					            *childSize = CLAY__MAX(childMinSize, targetSize);
 | 
				
			||||||
            totalSizeToDistribute -= (oldChildSize - *childSize);
 | 
					            totalSizeToDistribute -= (oldChildSize - *childSize);
 | 
				
			||||||
            if (*childSize == childMinSize) {
 | 
					            if (*childSize == childMinSize) {
 | 
				
			||||||
                Clay__int32_tArray_RemoveSwapback(&largestContainers, childOffset);
 | 
					                for (int32_t i = 0; i < resizableContainerBuffer.length; i++) {
 | 
				
			||||||
                childOffset--;
 | 
					                    if (Clay__int32_tArray_Get(&resizableContainerBuffer, i) == childIndex) {
 | 
				
			||||||
 | 
					                        Clay__int32_tArray_RemoveSwapback(&resizableContainerBuffer, i);
 | 
				
			||||||
 | 
					                        break;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (largestContainers.length == 0) {
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue