A small static helper for the standings UI. Given a rank and base font size, it returns a CSS font-size string that shrinks the rank text once its digit count exceeds three, or null when no scaling is needed.
namespace BlockParty;
using System;
using System.Globalization;
/// <summary>Keeps standings ranks inside their fixed-width columns as digit counts grow.</summary>
public static class StandingsRank
{
public static string FontStyle( long rank, int fontSize, int fullSizeDigits = 3 )
{
int digits = rank.ToString( CultureInfo.InvariantCulture ).Length;
if ( digits <= fullSizeDigits ) return null;
int size = (int)Math.Floor( (double)fontSize * fullSizeDigits / digits );
return FormattableString.Invariant( $"font-size: {size}px;" );
}
}