Core/Px.cs

Small helper class that wraps Sandbox.UI.Length.Pixels to produce a non-nullable Length value from int or float pixel amounts. It provides two static methods Of(int) and Of(float) that call Length.Pixels and fall back to default if null.

using Sandbox.UI;

namespace Goo;

// Non-nullable Length factory. Sandbox.UI.Length.Pixels returns Length? (CS0266 for 'static readonly Length x = Length.Pixels(16)'); Px.Of returns non-nullable so the explicit-unit factory works anywhere.
public static class Px
{
    public static Length Of(int pixels) => Length.Pixels(pixels) ?? default;
    public static Length Of(float pixels) => Length.Pixels(pixels) ?? default;
}