/// <summary>
        /// Shows a window prompt with two buttons for the user to click.
        /// </summary>
        /// <param name="message">The text to display. (background color is ignored)</param>
        /// <param name="yesPrompt">The yes button's text.</param>
        /// <param name="noPrompt">The no button's text.</param>
        /// <param name="resultCallback">Callback with the yes (true) or no (false) result.</param>
        public static void Prompt(ColoredString message, string yesPrompt, string noPrompt, Action <bool> resultCallback)
        {
            Window window = new Window(message.ToString().Length + 4, 6);

            message.IgnoreBackground = true;

            window.Print(2, 2, message);

            Button yesButton = new Button(yesPrompt.Length + 2);
            Button noButton  = new Button(noPrompt.Length + 2);

            yesButton.Position = new Point(2, window.textSurface.Height - 2);
            noButton.Position  = new Point(window.textSurface.Width - noButton.Width - 2, window.textSurface.Height - 2);

            yesButton.Text = yesPrompt;
            noButton.Text  = noPrompt;

            yesButton.Click += (o, e) => { window.DialogResult = true; window.Hide(); };
            noButton.Click  += (o, e) => { window.DialogResult = false; window.Hide(); };

            window.Add(yesButton);
            window.Add(noButton);

            window.Closed += (o, e) =>
            {
                resultCallback(window.DialogResult);
            };

            window.Show(true);
            window.Center();
        }
Beispiel #2
0
        /// <summary>
        /// Displays a dialog to the user with a specific message.
        /// </summary>
        /// <param name="message">The message. (background color is ignored)</param>
        /// <param name="closeButtonText">The text of the dialog's close button.</param>
        /// <param name="closedCallback">A callback indicating the message was dismissed.</param>
        public static void Message(ColoredString message, string closeButtonText, Action closedCallback = null)
        {
            var width       = message.ToString().Length + 4;
            var buttonWidth = closeButtonText.Length + 2;

            if (buttonWidth < 9)
            {
                buttonWidth = 9;
            }

            if (width < buttonWidth + 4)
            {
                width = buttonWidth + 4;
            }

            Window window = new Window(width, 6);

            message.IgnoreBackground = true;

            window.Print(2, 2, message);

            Button closeButton = new Button(buttonWidth, 1);

            closeButton.Position = new Point(2, window.Height - 2);

            closeButton.Text = closeButtonText;

            closeButton.Click += (o, e) => { window.DialogResult = true; window.Hide(); closedCallback?.Invoke(); };

            window.Add(closeButton);
            window.CloseOnESC = true;
            window.Show(true);
            window.Center();
        }
        /// <summary>
        /// Shows a window prompt with two buttons for the user to click.
        /// </summary>
        /// <param name="message">The text to display. (background color is ignored)</param>
        /// <param name="yesPrompt">The yes button's text.</param>
        /// <param name="noPrompt">The no button's text.</param>
        /// <param name="resultCallback">Callback with the yes (true) or no (false) result.</param>
        public static void Prompt(ColoredString message, string yesPrompt, string noPrompt, Action <bool> resultCallback)
        {
            message.IgnoreBackground = true;

            Themes.Library.Default.ButtonTheme = new Themes.ButtonLinesTheme();

            Button yesButton = new Button(yesPrompt.Length + 2, 1);
            Button noButton  = new Button(noPrompt.Length + 2, 1);

            Window window = new Window(message.ToString().Length + 4, 5 + yesButton.Surface.Height);

            window.Print(2, 2, message);

            yesButton.Position = new Point(2, window.Height - 1 - yesButton.Surface.Height);
            noButton.Position  = new Point(window.Width - noButton.Width - 2, window.Height - 1 - yesButton.Surface.Height);

            yesButton.Text = yesPrompt;
            noButton.Text  = noPrompt;

            yesButton.Click += (o, e) => { window.DialogResult = true; window.Hide(); };
            noButton.Click  += (o, e) => { window.DialogResult = false; window.Hide(); };

            window.Add(yesButton);
            window.Add(noButton);

            window.Closed += (o, e) =>
            {
                resultCallback?.Invoke(window.DialogResult);
            };

            window.Show(true);
            window.Center();
        }
        /// <summary>
        /// Shows a window prompt with two buttons for the user to click.
        /// </summary>
        /// <param name="message">The text to display. (background color is ignored)</param>
        /// <param name="yesPrompt">The yes button's text.</param>
        /// <param name="noPrompt">The no button's text.</param>
        /// <param name="resultCallback">Callback with the yes (true) or no (false) result.</param>
        /// <param name="library">The library to theme the message box. If <see langword="null"/>, then the theme will be set to <see cref="Themes.Library.Default"/>.</param>
        public static void Prompt(ColoredString message, string yesPrompt, string noPrompt, Action <bool> resultCallback, Themes.Library library = null)
        {
            message.IgnoreBackground = true;

            if (library == null)
            {
                library = Themes.Library.Default;
            }

            var yesButton = new Button(yesPrompt.Length + 2, 1);
            var noButton  = new Button(noPrompt.Length + 2, 1);

            yesButton.Theme = library.GetControlTheme(typeof(Button));
            noButton.Theme  = library.GetControlTheme(typeof(Button));

            var window = new Window(message.ToString().Length + 4, 5 + yesButton.Surface.Height)
            {
                Theme = library.WindowTheme
            };

            var printArea = new DrawingSurface(window.Width, window.Height)
            {
                OnDraw = (ds) =>
                {
                    Cell appearance = ((Themes.DrawingSurfaceTheme)ds.Theme).Appearance;
                    ds.Surface.Fill(appearance.Foreground, appearance.Background, null);
                    ds.Surface.Print(2, 2, message);
                }
            };

            yesButton.Position = new Point(2, window.Height - 1 - yesButton.Surface.Height);
            noButton.Position  = new Point(window.Width - noButton.Width - 2, window.Height - 1 - yesButton.Surface.Height);

            yesButton.Text = yesPrompt;
            noButton.Text  = noPrompt;

            yesButton.Click += (o, e) => { window.DialogResult = true; window.Hide(); };
            noButton.Click  += (o, e) => { window.DialogResult = false; window.Hide(); };

            yesButton.Theme = null;
            noButton.Theme  = null;

            window.Add(printArea);
            window.Add(yesButton);
            window.Add(noButton);

            noButton.IsFocused = true;

            window.Closed += (o, e) =>
            {
                resultCallback?.Invoke(window.DialogResult);
            };

            window.Show(true);
            window.Center();
        }
        /// <summary>
        /// Displays a dialog to the user with a specific message.
        /// </summary>
        /// <param name="message">The message. (background color is ignored)</param>
        /// <param name="closeButtonText">The text of the dialog's close button.</param>
        /// <param name="closedCallback">A callback indicating the message was dismissed.</param>
        /// <param name="library">The library to theme the message box. If <see langword="null"/>, then the theme will be set to <see cref="Themes.Library.Default"/>.</param>
        public static void Message(ColoredString message, string closeButtonText, Action closedCallback = null, Themes.Library library = null)
        {
            int width       = message.ToString().Length + 4;
            int buttonWidth = closeButtonText.Length + 2;

            if (library == null)
            {
                library = Themes.Library.Default;
            }

            if (buttonWidth < 9)
            {
                buttonWidth = 9;
            }

            if (width < buttonWidth + 4)
            {
                width = buttonWidth + 4;
            }

            var closeButton = new Button(buttonWidth, 1)
            {
                Text  = closeButtonText,
                Theme = library.GetControlTheme(typeof(Button))
            };

            var window = new Window(width, 5 + closeButton.Surface.Height)
            {
                Theme = library.WindowTheme
            };

            message.IgnoreBackground = true;

            var printArea = new DrawingSurface(window.Width, window.Height)
            {
                OnDraw = (ds) =>
                {
                    Cell appearance = ((Themes.DrawingSurfaceTheme)ds.Theme).Appearance;
                    ds.Surface.Fill(appearance.Foreground, appearance.Background, null);
                    ds.Surface.Print(2, 2, message);
                }
            };

            window.Add(printArea);

            closeButton.Position = new Point(2, window.Height - 1 - closeButton.Surface.Height);
            closeButton.Click   += (o, e) => { window.DialogResult = true; window.Hide(); closedCallback?.Invoke(); };
            closeButton.Theme    = null;

            window.Add(closeButton);
            closeButton.IsFocused = true;
            window.CloseOnEscKey  = true;
            window.Show(true);
            window.Center();
        }
Beispiel #6
0
        /// <summary>
        /// Displays a dialog to the user with a specific message.
        /// </summary>
        /// <param name="message">The message. (background color is ignored)</param>
        /// <param name="closeButtonText">The text of the dialog's close button.</param>
        /// <param name="closedCallback">A callback indicating the message was dismissed.</param>
        /// <param name="library">The library to theme the message box. If <see langword="null"/>, then the theme will be set to <see cref="Themes.Library.Default"/>.</param>
        public static void Message(ColoredString message, string closeButtonText, Action closedCallback = null, Themes.Library library = null)
        {
            var width       = message.ToString().Length + 4;
            var buttonWidth = closeButtonText.Length + 2;

            if (library == null)
            {
                library = Themes.Library.Default;
            }

            if (buttonWidth < 9)
            {
                buttonWidth = 9;
            }

            if (width < buttonWidth + 4)
            {
                width = buttonWidth + 4;
            }

            var closeButton = new Button(buttonWidth, 1)
            {
                Text  = closeButtonText,
                Theme = library.ButtonTheme
            };

            var window = new Window(width, 5 + closeButton.Surface.Height);

            window.Theme = library;

            message.IgnoreBackground = true;

            var printArea = new DrawingSurface(window.Width, window.Height);

            printArea.OnDraw = (ds) => ds.Surface.Print(2, 2, message);
            window.Add(printArea);

            closeButton.Position = new Point(2, window.Height - 1 - closeButton.Surface.Height);
            closeButton.Click   += (o, e) => { window.DialogResult = true; window.Hide(); closedCallback?.Invoke(); };
            closeButton.Theme    = null;

            window.Add(closeButton);
            closeButton.IsFocused = true;
            window.CloseOnEscKey  = true;
            window.Show(true);
            window.Center();
        }
        /// <summary>
        /// Displays a dialog to the user with a specific message.
        /// </summary>
        /// <param name="message">The message. (background color is ignored)</param>
        /// <param name="closeButtonText">The text of the dialog's close button.</param>
        /// <param name="closedCallback">A callback indicating the message was dismissed.</param>
        public static void Message(ColoredString message, string closeButtonText, Action closedCallback = null)
        {
            Window window = new Window(message.ToString().Length + 4, 6);

            message.IgnoreBackground = true;

            window.Print(2, 2, message);

            Button closeButton = new Button(closeButtonText.Length + 2);

            closeButton.Position = new Point(2, window.textSurface.Height - 2);

            closeButton.Text = closeButtonText;

            closeButton.Click += (o, e) => { window.DialogResult = true; window.Hide(); closedCallback?.Invoke(); };

            window.Add(closeButton);
            window.CloseOnESC = true;
            window.Show(true);
            window.Center();
        }