From 5bb350b7f1eb27bacc43d0c99f9ed7bea3d403eb Mon Sep 17 00:00:00 2001 From: Tigger Kindel Date: Sat, 25 Feb 2023 17:22:45 -0700 Subject: [PATCH 01/48] re-merged changes lost from #2345 --- Terminal.Gui/Core/View.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index fa446f720..e303bb343 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -1521,14 +1521,12 @@ namespace Terminal.Gui { Driver.SetAttribute (HasFocus ? GetFocusColor () : GetNormalColor ()); } - var boundsAdjustedForBorder = Bounds; if (!IgnoreBorderPropertyOnRedraw && Border != null) { Border.DrawContent (this); - boundsAdjustedForBorder = Bounds;// new Rect (bounds.X + 1, bounds.Y + 1, Math.Max (bounds.Width, bounds.Width - 2), Math.Max (bounds.Height, bounds.Height - 2)); } else if (ustring.IsNullOrEmpty (TextFormatter.Text) && (GetType ().IsNestedPublic && !IsOverridden (this, "Redraw") || GetType ().Name == "View") && (!NeedDisplay.IsEmpty || ChildNeedsDisplay || LayoutNeeded)) { - + Clear (); SetChildNeedsDisplay (); } @@ -1541,8 +1539,8 @@ namespace Terminal.Gui { if (TextFormatter != null) { TextFormatter.NeedsFormat = true; } - TextFormatter?.Draw (ViewToScreen (boundsAdjustedForBorder), HasFocus ? ColorScheme.Focus : GetNormalColor (), - HasFocus ? ColorScheme.HotFocus : Enabled ? ColorScheme.HotNormal : ColorScheme.Disabled, + TextFormatter?.Draw (ViewToScreen (Bounds), HasFocus ? GetFocusColor () : GetNormalColor (), + HasFocus ? ColorScheme.HotFocus : GetHotNormalColor (), containerBounds); } @@ -1552,7 +1550,7 @@ namespace Terminal.Gui { if (subviews != null) { foreach (var view in subviews) { if (!view.NeedDisplay.IsEmpty || view.ChildNeedsDisplay || view.LayoutNeeded) { - if (view.Frame.IntersectsWith (clipRect) && (view.Frame.IntersectsWith (boundsAdjustedForBorder) || boundsAdjustedForBorder.X < 0 || bounds.Y < 0)) { + if (view.Frame.IntersectsWith (clipRect) && (view.Frame.IntersectsWith (bounds) || bounds.X < 0 || bounds.Y < 0)) { if (view.LayoutNeeded) { view.LayoutSubviews (); } @@ -2268,12 +2266,12 @@ namespace Terminal.Gui { } newDimension = AutoSize && autosize > newDimension ? autosize : newDimension; break; - + case Dim.DimFactor factor when !factor.IsFromRemaining (): newDimension = d.Anchor (dimension); newDimension = AutoSize && autosize > newDimension ? autosize : newDimension; break; - + case Dim.DimFill: default: newDimension = Math.Max (d.Anchor (dimension - location), 0); @@ -2448,8 +2446,8 @@ namespace Terminal.Gui { // return L (a topologically sorted order) return result; } // TopologicalSort - - + + /// /// Invoked when a view starts executing or when the dimensions of the view have changed, for example in /// response to the container view or terminal resizing. From 0e8cd6332aecaf47a9769001b3068a352aa7f890 Mon Sep 17 00:00:00 2001 From: Tigger Kindel Date: Sat, 25 Feb 2023 17:32:38 -0700 Subject: [PATCH 02/48] Fixed Border Comparsion Pos.Center bugs --- UICatalog/Scenarios/BordersComparisons.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/UICatalog/Scenarios/BordersComparisons.cs b/UICatalog/Scenarios/BordersComparisons.cs index 46c363c12..dd17e2261 100644 --- a/UICatalog/Scenarios/BordersComparisons.cs +++ b/UICatalog/Scenarios/BordersComparisons.cs @@ -38,7 +38,7 @@ namespace UICatalog.Scenarios { button.Clicked += () => MessageBox.Query (20, 7, "Hi", "I'm a Window?", "Yes", "No"); var label = new Label ("I'm a Window") { X = Pos.Center (), - Y = Pos.Center () - 3, + Y = Pos.Top (button) - 1 }; var tv = new TextView () { Y = Pos.AnchorEnd (2), @@ -77,7 +77,7 @@ namespace UICatalog.Scenarios { button2.Clicked += () => MessageBox.Query (20, 7, "Hi", "I'm a Toplevel?", "Yes", "No"); var label2 = new Label ("I'm a Toplevel") { X = Pos.Center (), - Y = Pos.Center () - 3, + Y = Pos.Top (button2) - 1 }; var tv2 = new TextView () { Y = Pos.AnchorEnd (2), @@ -113,7 +113,7 @@ namespace UICatalog.Scenarios { button3.Clicked += () => MessageBox.Query (20, 7, "Hi", "I'm a FrameView?", "Yes", "No"); var label3 = new Label ("I'm a FrameView") { X = Pos.Center (), - Y = Pos.Center () - 3, + Y = Pos.Top (button3) - 1 }; var tv3 = new TextView () { Y = Pos.AnchorEnd (2), From a9cd9ba2e735a4a852ad610aaf5711705398bf37 Mon Sep 17 00:00:00 2001 From: Tigger Kindel Date: Sat, 25 Feb 2023 17:37:57 -0700 Subject: [PATCH 03/48] Fixed Borders on XXX Pos.Center bugs --- UICatalog/Scenarios/BordersOnFrameView.cs | 2 +- UICatalog/Scenarios/BordersOnToplevel.cs | 2 +- UICatalog/Scenarios/BordersOnWindow.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/UICatalog/Scenarios/BordersOnFrameView.cs b/UICatalog/Scenarios/BordersOnFrameView.cs index 3412179ba..5b0740e50 100644 --- a/UICatalog/Scenarios/BordersOnFrameView.cs +++ b/UICatalog/Scenarios/BordersOnFrameView.cs @@ -45,7 +45,7 @@ namespace UICatalog.Scenarios { button.Clicked += () => MessageBox.Query (20, 7, "Hi", "I'm a FrameView?", "Yes", "No"); var label = new Label ("I'm a FrameView") { X = Pos.Center (), - Y = Pos.Center () - 3, + Y = Pos.Top (button) - 1, }; var tf2 = new TextField ("1234567890") { X = Pos.AnchorEnd (10), diff --git a/UICatalog/Scenarios/BordersOnToplevel.cs b/UICatalog/Scenarios/BordersOnToplevel.cs index 9b6f2c72b..7ef109b19 100644 --- a/UICatalog/Scenarios/BordersOnToplevel.cs +++ b/UICatalog/Scenarios/BordersOnToplevel.cs @@ -45,7 +45,7 @@ namespace UICatalog.Scenarios { button.Clicked += () => MessageBox.Query (20, 7, "Hi", "I'm a Toplevel?", "Yes", "No"); var label = new Label ("I'm a Toplevel") { X = Pos.Center (), - Y = Pos.Center () - 3, + Y = Pos.Top (button) - 1, }; var tf2 = new TextField ("1234567890") { X = Pos.AnchorEnd (10), diff --git a/UICatalog/Scenarios/BordersOnWindow.cs b/UICatalog/Scenarios/BordersOnWindow.cs index 7075af63b..d0c171b46 100644 --- a/UICatalog/Scenarios/BordersOnWindow.cs +++ b/UICatalog/Scenarios/BordersOnWindow.cs @@ -44,7 +44,7 @@ namespace UICatalog.Scenarios { button.Clicked += () => MessageBox.Query (20, 7, "Hi", "I'm a Window?", "Yes", "No"); var label = new Label ("I'm a Window") { X = Pos.Center (), - Y = Pos.Center () - 3, + Y = Pos.Top (button) - 1, }; var tf2 = new TextField ("1234567890") { X = Pos.AnchorEnd (10), From 28d7be721cbf2a48aa72f23c736d1e9649b60951 Mon Sep 17 00:00:00 2001 From: Tig Kindel Date: Tue, 21 Feb 2023 11:53:10 +1300 Subject: [PATCH 04/48] Revert "Illustrates #2331 (Scrollview not respecting clip) does not reproduce (#2332)" This reverts commit c85ff954aa8cebf0e0eb934d9d283551a6f63db8. --- Terminal.Gui/Core/View.cs | 25 +- UICatalog/Scenarios/ASCIICustomButton.cs | 313 ----------------------- UnitTests/Core/BorderTests.cs | 80 +----- UnitTests/Views/ScrollViewTests.cs | 228 +---------------- 4 files changed, 29 insertions(+), 617 deletions(-) delete mode 100644 UICatalog/Scenarios/ASCIICustomButton.cs diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index 018cf1384..19f086715 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -1109,8 +1109,15 @@ namespace Terminal.Gui { /// public void Clear () { - var h = Frame.Height; - var w = Frame.Width; + Rect containerBounds = GetContainerBounds (); + Rect viewBounds = Bounds; + if (!containerBounds.IsEmpty) { + viewBounds.Width = Math.Min (viewBounds.Width, containerBounds.Width); + viewBounds.Height = Math.Min (viewBounds.Height, containerBounds.Height); + } + + var h = viewBounds.Height; + var w = viewBounds.Width; for (var line = 0; line < h; line++) { Move (0, line); for (var col = 0; col < w; col++) @@ -1524,8 +1531,7 @@ namespace Terminal.Gui { } if (!ustring.IsNullOrEmpty (TextFormatter.Text)) { - Rect containerBounds = GetContainerBounds (); - Clear (ViewToScreen (GetNeedDisplay (containerBounds))); + Clear (); SetChildNeedsDisplay (); // Draw any Text if (TextFormatter != null) { @@ -1568,17 +1574,6 @@ namespace Terminal.Gui { ClearNeedsDisplay (); } - Rect GetNeedDisplay (Rect containerBounds) - { - Rect rect = NeedDisplay; - if (!containerBounds.IsEmpty) { - rect.Width = Math.Min (NeedDisplay.Width, containerBounds.Width); - rect.Height = Math.Min (NeedDisplay.Height, containerBounds.Height); - } - - return rect; - } - Rect GetContainerBounds () { var containerBounds = SuperView == null ? default : SuperView.ViewToScreen (SuperView.Bounds); diff --git a/UICatalog/Scenarios/ASCIICustomButton.cs b/UICatalog/Scenarios/ASCIICustomButton.cs deleted file mode 100644 index 77cacf8b9..000000000 --- a/UICatalog/Scenarios/ASCIICustomButton.cs +++ /dev/null @@ -1,313 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using Terminal.Gui; - -namespace UICatalog.Scenarios { - [ScenarioMetadata (Name: "ASCIICustomButtonTest", Description: "ASCIICustomButton sample")] - [ScenarioCategory ("Controls")] - public class ASCIICustomButtonTest : Scenario { - private static bool smallerWindow; - private ScrollViewTestWindow scrollViewTestWindow; - private MenuItem miSmallerWindow; - - public override void Init (ColorScheme colorScheme) - { - Application.Init (); - scrollViewTestWindow = new ScrollViewTestWindow (); - var menu = new MenuBar (new MenuBarItem [] { - new MenuBarItem("Window Size", new MenuItem [] { - miSmallerWindow = new MenuItem ("Smaller Window", "", ChangeWindowSize) { - CheckType = MenuItemCheckStyle.Checked - }, - null, - new MenuItem("Quit", "",() => Application.RequestStop(),null,null, Key.Q | Key.CtrlMask) - }) - }); - Application.Top.Add (menu, scrollViewTestWindow); - Application.Run (); - } - - private void ChangeWindowSize () - { - smallerWindow = miSmallerWindow.Checked = !miSmallerWindow.Checked; - scrollViewTestWindow.Dispose (); - Application.Top.Remove (scrollViewTestWindow); - scrollViewTestWindow = new ScrollViewTestWindow (); - Application.Top.Add (scrollViewTestWindow); - } - - public override void Run () - { - } - - public class ASCIICustomButton : Button { - public string Description => $"Description of: {id}"; - - public event Action PointerEnter; - - private Label fill; - private FrameView border; - private string id; - - public ASCIICustomButton (string text, Pos x, Pos y, int width, int height) : base (text) - { - CustomInitialize ("", text, x, y, width, height); - } - - public ASCIICustomButton (string id, string text, Pos x, Pos y, int width, int height) : base (text) - { - CustomInitialize (id, text, x, y, width, height); - } - - private void CustomInitialize (string id, string text, Pos x, Pos y, int width, int height) - { - this.id = id; - X = x; - Y = y; - - Frame = new Rect { - Width = width, - Height = height - }; - - border = new FrameView () { - Width = width, - Height = height - }; - - AutoSize = false; - - var fillText = new System.Text.StringBuilder (); - for (int i = 0; i < Bounds.Height; i++) { - if (i > 0) { - fillText.AppendLine (""); - } - for (int j = 0; j < Bounds.Width; j++) { - fillText.Append ("█"); - } - } - - fill = new Label (fillText.ToString ()) { - Visible = false, - CanFocus = false - }; - - var title = new Label (text) { - X = Pos.Center (), - Y = Pos.Center (), - }; - - border.MouseClick += This_MouseClick; - border.Subviews [0].MouseClick += This_MouseClick; - fill.MouseClick += This_MouseClick; - title.MouseClick += This_MouseClick; - - Add (border, fill, title); - } - - private void This_MouseClick (MouseEventArgs obj) - { - OnMouseEvent (obj.MouseEvent); - } - - public override bool OnMouseEvent (MouseEvent mouseEvent) - { - Debug.WriteLine ($"{mouseEvent.Flags}"); - if (mouseEvent.Flags == MouseFlags.Button1Clicked) { - if (!HasFocus && SuperView != null) { - if (!SuperView.HasFocus) { - SuperView.SetFocus (); - } - SetFocus (); - SetNeedsDisplay (); - } - - OnClicked (); - return true; - } - return base.OnMouseEvent (mouseEvent); - } - - public override bool OnEnter (View view) - { - border.Visible = false; - fill.Visible = true; - PointerEnter.Invoke (this); - view = this; - return base.OnEnter (view); - } - - public override bool OnLeave (View view) - { - border.Visible = true; - fill.Visible = false; - if (view == null) - view = this; - return base.OnLeave (view); - } - } - - public class ScrollViewTestWindow : Window { - private List