UI/Foundation/OMRUITextFormat.cs
using Sandbox;
using Sandbox.UI;
using System;

/// <summary>Optional text overrides. Disabled preserves the existing stylesheet.</summary>
public sealed class OMRUITextFormat
{
	[Property, Title( "Override Text Style" )]
	public bool Enabled { get; set; }

	[Property, ShowIf( nameof( Enabled ), true ), Range( 100, 900 ), Step( 100 )]
	public int Weight { get; set; } = 400;

	[Property, ShowIf( nameof( Enabled ), true )]
	public bool Bold { get; set; }
	[Property, ShowIf( nameof( Enabled ), true )]
	public bool Italic { get; set; }
	[Property, ShowIf( nameof( Enabled ), true )]
	public bool Underline { get; set; }
	[Property, ShowIf( nameof( Enabled ), true )]
	public bool Strikethrough { get; set; }

	public int ContentHash() => HashCode.Combine( Enabled, Weight, Bold, Italic, Underline, Strikethrough );

	public static void Apply( Panel panel, OMRUITextFormat format )
	{
		bool enabled = format?.Enabled == true;
		panel.Style.FontWeight = enabled
			? (format.Bold ? Math.Max( 700, Math.Clamp( format.Weight, 100, 900 ) ) : Math.Clamp( format.Weight, 100, 900 ))
			: (int?)null;
		panel.Style.FontStyle = enabled
			? (format.Italic ? FontStyle.Italic : FontStyle.None) : (FontStyle?)null;
		panel.Style.TextDecorationLine = enabled
			? ((format.Underline ? TextDecoration.Underline : TextDecoration.None)
				| (format.Strikethrough ? TextDecoration.LineThrough : TextDecoration.None))
			: (TextDecoration?)null;
	}
}