An editor-side button used across the Advanced Mapping Tools panels. It replaces the default button paint with a left-aligned icon and label, clips long names to a single line, and tints the background based on hover, checked and disabled state.
namespace AdvancedMappingTools;
/// <summary>
/// The button of every Davelix Construct panel. The editor button centers its text, which
/// makes a column of tool names hard to scan; this one sets icon and text on the left, and
/// cuts a name that does not fit instead of letting it run under the next control.
/// </summary>
public class ListButton : Button
{
const float Padding = 8.0f;
const float IconSize = 14.0f;
const float IconGap = 6.0f;
public ListButton( string text, string icon = null ) : base( text, icon )
{
FixedHeight = Theme.ControlHeight;
}
protected override void OnPaint()
{
var rect = LocalRect;
Paint.ClearPen();
Paint.SetBrush( !Enabled ? Theme.ButtonBackground.WithAlpha( 0.5f ) : IsChecked ? Theme.Primary : Paint.HasMouseOver ? Theme.ButtonBackground.Lighten( 0.25f ) : Theme.ButtonBackground );
Paint.DrawRect( rect, Theme.ControlRadius );
var inner = rect.Shrink( Padding, 0.0f, Padding, 0.0f );
Paint.SetPen( Enabled ? Theme.TextControl : Theme.TextDisabled );
if ( !string.IsNullOrEmpty( Icon ) )
{
Paint.DrawIcon( inner with { Width = IconSize }, Icon, IconSize, TextFlag.LeftCenter );
inner.Left += IconSize + IconGap;
}
Paint.DrawText( inner, Text, TextFlag.LeftCenter | TextFlag.SingleLine );
}
}