From 8e58434e7200ac39ea4f5e3148bcab9edb8d490a Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Sun, 31 May 2020 19:48:21 -0600 Subject: [PATCH 1/3] fixed frame drawing, buttons, dialogs, messageboxes and more --- Terminal.Gui/Core/ConsoleDriver.cs | 4 +- Terminal.Gui/Core/View.cs | 2 +- Terminal.Gui/Core/Window.cs | 4 +- Terminal.Gui/Terminal.Gui.csproj | 9 +- Terminal.Gui/Views/Button.cs | 60 ++++--- Terminal.Gui/Views/FrameView.cs | 4 +- Terminal.Gui/Windows/Dialog.cs | 80 ++++++--- Terminal.Gui/Windows/MessageBox.cs | 110 +++++++++++-- UICatalog/Scenarios/Buttons.cs | 89 ++++++---- UICatalog/Scenarios/Dialogs.cs | 171 ++++++++++++++++++++ UICatalog/Scenarios/Editor.cs | 8 +- UICatalog/Scenarios/HexEditor.cs | 8 +- UICatalog/Scenarios/MessageBoxes.cs | 33 ++-- UICatalog/Scenarios/WindowsAndFrameViews.cs | 27 ++-- UICatalog/UICatalog.cs | 10 +- UICatalog/UICatalog.csproj | 1 + 16 files changed, 487 insertions(+), 133 deletions(-) create mode 100644 UICatalog/Scenarios/Dialogs.cs diff --git a/Terminal.Gui/Core/ConsoleDriver.cs b/Terminal.Gui/Core/ConsoleDriver.cs index fb3015893..72bd854b1 100644 --- a/Terminal.Gui/Core/ConsoleDriver.cs +++ b/Terminal.Gui/Core/ConsoleDriver.cs @@ -562,7 +562,7 @@ namespace Terminal.Gui { const char bottomChar = clearChar; #endif /// - /// Draws a frame for a window with padding aand n optional visible border inside the padding. + /// Draws a frame for a window with padding and an optional visible border inside the padding. /// /// Screen relative region where the frame will be drawn. /// Number of columns to pad on the left (if 0 the border will not appear on the left). @@ -724,7 +724,7 @@ namespace Terminal.Gui { // DrawFrame assumes the border is always at least one row/col thick // DrawWindowFrame assumes a padding of 0 means NO padding and no frame DrawWindowFrame (new Rect (region.X, region.Y, region.Width, region.Height), - padding + 1, padding + 1, padding + 1, padding + 1, fill: fill); + padding + 1, padding + 1, padding + 1, padding + 1, border: false, fill: fill); } diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index cef542eba..fa5988253 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -714,7 +714,7 @@ namespace Terminal.Gui { { var scrRect = ViewToScreen (region); var savedClip = ClipToBounds (); - Driver.DrawFrame (scrRect, padding, fill); + Driver.DrawWindowFrame (scrRect, padding + 1, padding + 1, padding + 1, padding + 1, border: true, fill: fill); Driver.Clip = savedClip; } diff --git a/Terminal.Gui/Core/Window.cs b/Terminal.Gui/Core/Window.cs index 2bf4d4bf1..37184cbf0 100644 --- a/Terminal.Gui/Core/Window.cs +++ b/Terminal.Gui/Core/Window.cs @@ -164,7 +164,7 @@ namespace Terminal.Gui { // BUGBUG: Why do we draw the frame twice? This call is here to clear the content area, I think. Why not just clear that area? if (NeedDisplay != null && !NeedDisplay.IsEmpty) { Driver.SetAttribute (ColorScheme.Normal); - Driver.DrawFrame (scrRect, padding, true); + Driver.DrawWindowFrame (scrRect, padding + 1, padding + 1, padding + 1, padding + 1, border: true, fill: true); } var savedClip = ClipToBounds (); @@ -173,7 +173,7 @@ namespace Terminal.Gui { ClearNeedsDisplay (); Driver.SetAttribute (ColorScheme.Normal); - Driver.DrawFrame (scrRect, padding, false); + Driver.DrawWindowFrame (scrRect, padding + 1, padding + 1, padding + 1, padding + 1, border: true, fill: false); if (HasFocus) Driver.SetAttribute (ColorScheme.HotNormal); diff --git a/Terminal.Gui/Terminal.Gui.csproj b/Terminal.Gui/Terminal.Gui.csproj index 01697a423..9f58408dd 100644 --- a/Terminal.Gui/Terminal.Gui.csproj +++ b/Terminal.Gui/Terminal.Gui.csproj @@ -5,11 +5,12 @@ Terminal.Gui bin\Release\Terminal.Gui.xml true + 0.82.0.0 true Terminal.Gui - 0.81 + 0.82 Miguel de Icaza MIT https://github.com/migueldeicaza/gui.cs/ @@ -18,8 +19,12 @@ Miguel de Icaza Application framework for creating modern console applications using .NET Gui.cs is a framework for creating console user interfaces - 0.81: Fix ncurses engine for macOS/Linux, it works again + +0.82: Many fixes +* ... +0.81: +* Fix ncurses engine for macOS/Linux, it works again * Fixes an issue with referencing views that have not been allocated yet causing a stack overflow * New OnCloseMenu event on menus * Button cursor position looks better diff --git a/Terminal.Gui/Views/Button.cs b/Terminal.Gui/Views/Button.cs index 7013079dc..eaf56b62f 100644 --- a/Terminal.Gui/Views/Button.cs +++ b/Terminal.Gui/Views/Button.cs @@ -55,29 +55,32 @@ namespace Terminal.Gui { public Action Clicked; /// - /// Initializes a new instance of based on the given text at position 0,0 + /// Initializes a new instance of using layout. /// /// - /// The size of the is computed based on the - /// text length. + /// The width of the is computed based on the + /// text length. The height will always be 1. /// /// The button's text - /// If set, this makes the button the default button in the current view. + /// + /// If true, a special decoration is used, and the user pressing the enter key + /// in a will implicitly activate this button. + /// public Button (ustring text, bool is_default = false) : base () { CanFocus = true; Text = text ?? string.Empty; this.IsDefault = is_default; int w = SetWidthHeight (text, is_default); - Frame = new Rect (0, 0, w, 1); + Frame = new Rect (Frame.Location, new Size (w, 1)); } /// - /// Initializes a new instance of at the given coordinates, based on the given text + /// Initializes a new instance of using layout, based on the given text /// /// - /// The size of the is computed based on the - /// text length. + /// The width of the is computed based on the + /// text length. The height will always be 1. /// /// X position where the button will be shown. /// Y position where the button will be shown. @@ -85,17 +88,19 @@ namespace Terminal.Gui { public Button (int x, int y, ustring text) : this (x, y, text, false) { } /// - /// Initializes a new instance of at the given coordinates, based on the given text, and with the specified value + /// Initializes a new instance of using layout, based on the given text. /// /// - /// If the value for is_default is true, a special - /// decoration is used, and the enter key on a - /// dialog would implicitly activate this button. + /// The width of the is computed based on the + /// text length. The height will always be 1. /// /// X position where the button will be shown. /// Y position where the button will be shown. /// The button's text - /// If set, this makes the button the default button in the current view, which means that if the user presses return on a view that does not handle return, it will be treated as if he had clicked on the button + /// + /// If true, a special decoration is used, and the user pressing the enter key + /// in a will implicitly activate this button. + /// public Button (int x, int y, ustring text, bool is_default) : base (new Rect (x, y, text.Length + 4 + (is_default ? 2 : 0), 1)) { @@ -110,6 +115,7 @@ namespace Terminal.Gui { int w = text.Length + 4 + (is_default ? 2 : 0); Width = w; Height = 1; + Frame = new Rect (Frame.Location, new Size (w, 1)); return w; } @@ -137,17 +143,27 @@ namespace Terminal.Gui { else shown_text = "[ " + text + " ]"; - hot_pos = -1; hot_key = (Rune)0; - int i = 0; - foreach (Rune c in shown_text) { - if (Rune.IsUpper (c)) { - hot_key = c; - hot_pos = i; - break; + hot_pos = shown_text.IndexOf ('_'); + + if (hot_pos == -1) { + // Use first upper-case char + int i = 0; + foreach (Rune c in shown_text) { + if (Rune.IsUpper (c)) { + hot_key = c; + hot_pos = i; + break; + } + i++; } - i++; + } else { + // Use char after '_' + var start = shown_text [0, hot_pos]; + shown_text = start + shown_text [hot_pos + 1, shown_text.Length]; + hot_key = Char.ToUpper((char)shown_text [hot_pos]); } + SetNeedsDisplay (); } @@ -214,7 +230,7 @@ namespace Terminal.Gui { } /// - public override bool MouseEvent(MouseEvent me) + public override bool MouseEvent (MouseEvent me) { if (me.Flags == MouseFlags.Button1Clicked) { SuperView.SetFocus (this); diff --git a/Terminal.Gui/Views/FrameView.cs b/Terminal.Gui/Views/FrameView.cs index cd60c1b4f..b2d44bb57 100644 --- a/Terminal.Gui/Views/FrameView.cs +++ b/Terminal.Gui/Views/FrameView.cs @@ -140,7 +140,7 @@ namespace Terminal.Gui { if (NeedDisplay != null && !NeedDisplay.IsEmpty) { Driver.SetAttribute (ColorScheme.Normal); - Driver.DrawFrame (scrRect, padding, true); + Driver.DrawWindowFrame (scrRect, padding + 1, padding + 1, padding + 1, padding + 1, border: true, fill: true); } var savedClip = ClipToBounds (); @@ -149,7 +149,7 @@ namespace Terminal.Gui { ClearNeedsDisplay (); Driver.SetAttribute (ColorScheme.Normal); - Driver.DrawFrame (scrRect, padding, false); + Driver.DrawWindowFrame (scrRect, padding + 1, padding + 1, padding + 1, padding + 1, border: true, fill: false); if (HasFocus) Driver.SetAttribute (ColorScheme.HotNormal); diff --git a/Terminal.Gui/Windows/Dialog.cs b/Terminal.Gui/Windows/Dialog.cs index 82d696d73..904d73491 100644 --- a/Terminal.Gui/Windows/Dialog.cs +++ b/Terminal.Gui/Windows/Dialog.cs @@ -4,15 +4,15 @@ // Authors: // Miguel de Icaza (miguel@gnome.org) // - using System; using System.Collections.Generic; +using System.Linq; using NStack; namespace Terminal.Gui { /// /// The is a that by default is centered and contains one - /// or more . It defaults to the color scheme and has a 1 cell padding around the edges. + /// or more s. It defaults to the color scheme and has a 1 cell padding around the edges. /// /// /// To run the modally, create the , and pass it to . @@ -21,21 +21,37 @@ namespace Terminal.Gui { /// public class Dialog : Window { List