PowerArgs.Cli.Button.OnPaint C# (CSharp) Method

OnPaint() protected method

paints the button
protected OnPaint ( ConsoleBitmap context ) : void
context ConsoleBitmap drawing context
return void
        protected override void OnPaint(ConsoleBitmap context)
        {
            var drawState = new ConsoleString();

            drawState = "[".ToConsoleString(CanFocus ? Application.Theme.H1Color : Application.Theme.DisabledColor, Background = Background);
            if (Text != null)
            {
                ConsoleColor fg, bg;

                if(HasFocus)
                {
                    fg = Application.Theme.FocusContrastColor;
                    bg = Application.Theme.FocusColor;
                }
                else if(CanFocus)
                {
                    fg = Foreground;
                    bg = Background;
                }
                else
                {
                    fg = Application.Theme.DisabledColor;
                    bg = Background;
                }

                drawState += new ConsoleString(Text, fg, bg);

                if(Shortcut != null)
                {
                    if(Shortcut.Modifier.HasValue && Shortcut.Modifier == ConsoleModifiers.Alt)
                    {
                        drawState += new ConsoleString($" (ALT+{Shortcut.Key})", CanFocus ? Application.Theme.H1Color : Application.Theme.DisabledColor);
                    }
                    else if (Shortcut.Modifier.HasValue && Shortcut.Modifier == ConsoleModifiers.Shift)
                    {
                        drawState += new ConsoleString($" (SHIFT+{Shortcut.Key})", CanFocus ? Application.Theme.H1Color : Application.Theme.DisabledColor);
                    }
                    else if (Shortcut.Modifier.HasValue && Shortcut.Modifier == ConsoleModifiers.Control)
                    {
                        drawState += new ConsoleString($" (CTL+{Shortcut.Key})", CanFocus ? Application.Theme.H1Color : Application.Theme.DisabledColor);
                    }
                    else
                    {
                        drawState += new ConsoleString($" ({Shortcut.Key})", CanFocus ? Application.Theme.H1Color : Application.Theme.DisabledColor);
                    }
                }
            }

            drawState += "]".ToConsoleString(CanFocus ? Application.Theme.H1Color : Application.Theme.DisabledColor, Background);
            Width = drawState.Length;
            context.DrawString(drawState, 0, 0);
        }