Static helper for virtual list layout. Provides ClampScroll to constrain scroll position based on item count, row height and viewport height, and Pixels to format a float as a CSS pixel string using invariant culture without exponent notation.
using System;
using System.Globalization;
namespace BlockParty;
internal static class VirtualListLayout
{
public static float ClampScroll( float scroll, int count, float rowHeight, float viewportHeight )
=> Math.Clamp( scroll, 0f, MathF.Max( 0f, count * rowHeight - viewportHeight ) );
// Scroll interpolation can leave tiny residuals. The UI CSS parser rejects exponent notation
// (e.g. 5.722046E-06px), and CSS always needs a dot regardless of the user's culture.
public static string Pixels( float value ) => value.ToString( "0.###", CultureInfo.InvariantCulture ) + "px";
}