Example #1
0
 private string AnnotatedCaption(ConsoleMenuOption opt)
 {
     if (opt.SubMenu != null)
     {
         return(opt.Caption.PadRight(longestLength - 1) + submenuIndicator);
     }
     else if (opt.RadioActive != null)
     {
         if (opt.RadioActive())
         {
             return($"({Symbols.dot}) {opt.Caption}".PadRight(longestLength));
         }
         else
         {
             return($"( ) {opt.Caption}".PadRight(longestLength));
         }
     }
     else
     {
         return(opt.Caption.PadRight(longestLength - opt.Key.Length) + opt.Key);
     }
 }
Example #2
0
        private void Draw(int right, int top)
        {
            if (options.Count > 0)
            {
                right = Formatting.ConvertCoord(right, Console.WindowWidth);
                top   = Formatting.ConvertCoord(top, Console.WindowHeight);
                Console.CursorVisible = false;
                // Space, vertical line, space, options, space, vertical line, space
                int w = longestLength + 6;
                // Horizontal lines before and after the options
                int h = options.Count + 2;

                Console.BackgroundColor = ConsoleTheme.Current.MenuBg;
                Console.ForegroundColor = ConsoleTheme.Current.MenuFg;
                string fullHorizLine = new string(Symbols.horizLine, longestLength + 2);
                for (int index = -1, y = top; y < top + h; ++index, ++y)
                {
                    Console.SetCursorPosition(right - w + 1, y);
                    // Left padding
                    Console.Write(" ");
                    if (index < 0)
                    {
                        // Draw top line
                        Console.Write(Symbols.upperLeftCorner + fullHorizLine + Symbols.upperRightCorner);
                    }
                    else if (index >= options.Count)
                    {
                        // Draw bottom line
                        Console.Write(Symbols.lowerLeftCorner + fullHorizLine + Symbols.lowerRightCorner);
                    }
                    else
                    {
                        ConsoleMenuOption opt = options[index];
                        if (opt == null)
                        {
                            // Draw separator
                            Console.Write(Symbols.leftTee + fullHorizLine + Symbols.rightTee);
                        }
                        else
                        {
                            // Draw menu option
                            Console.Write(Symbols.vertLine);
                            if (!opt.Enabled)
                            {
                                Console.ForegroundColor = ConsoleTheme.Current.MenuDisabledFg;
                            }
                            if (index == selectedOption)
                            {
                                // Draw highlighted menu option
                                Console.BackgroundColor = ConsoleTheme.Current.MenuSelectedBg;
                                Console.Write(" " + AnnotatedCaption(opt) + " ");
                                Console.BackgroundColor = ConsoleTheme.Current.MenuBg;
                            }
                            else
                            {
                                // Draw normal menu option
                                Console.Write(" " + AnnotatedCaption(opt) + " ");
                            }
                            if (!opt.Enabled)
                            {
                                Console.ForegroundColor = ConsoleTheme.Current.MenuFg;
                            }
                            Console.Write(Symbols.vertLine);
                        }
                    }
                    // Right padding
                    Console.Write(" ");
                }
                ConsoleDialog.DrawShadow(right - w + 1, top, right, top + h - 1);
                DrawFooter();
                Console.SetCursorPosition(right - longestLength - 3, top + selectedOption + 1);
                Console.CursorVisible = true;
            }
        }