From 069089ee27bd4dca2f9d1830b0c56562e3342d6d Mon Sep 17 00:00:00 2001 From: Tig Date: Mon, 15 Apr 2024 17:08:12 -0600 Subject: [PATCH] Made Arrangement = ViewArrangement.Fixed the default for Toplevels --- Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs | 3 +- Terminal.Gui/Views/Dialog.cs | 1 + Terminal.Gui/Views/Toplevel.cs | 2 +- UICatalog/Scenarios/Adornments.cs | 1 + .../Scenarios/BackgroundWorkerCollection.cs | 5 +++ UICatalog/Scenarios/TextFormatterDemo.cs | 40 ++++++++++--------- UnitTests/Application/ApplicationTests.cs | 6 ++- UnitTests/Views/ToplevelTests.cs | 15 +++---- 8 files changed, 45 insertions(+), 28 deletions(-) diff --git a/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs b/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs index 142d305c2f..a274416304 100644 --- a/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs @@ -355,7 +355,8 @@ public void FillRect (Rectangle rect, Rune rune = default) { Contents [r, c] = new Cell { - Rune = (Rune)' ', Attribute = CurrentAttribute, IsDirty = true + Rune = (rune != default ? rune : (Rune)' '), + Attribute = CurrentAttribute, IsDirty = true }; _dirtyLines [r] = true; } diff --git a/Terminal.Gui/Views/Dialog.cs b/Terminal.Gui/Views/Dialog.cs index 501bd6c423..46787265e2 100644 --- a/Terminal.Gui/Views/Dialog.cs +++ b/Terminal.Gui/Views/Dialog.cs @@ -56,6 +56,7 @@ public enum ButtonAlignments /// public Dialog () { + Arrangement = ViewArrangement.Movable; X = Pos.Center (); Y = Pos.Center (); ValidatePosDim = true; diff --git a/Terminal.Gui/Views/Toplevel.cs b/Terminal.Gui/Views/Toplevel.cs index 326e674dad..e5f4b64b14 100644 --- a/Terminal.Gui/Views/Toplevel.cs +++ b/Terminal.Gui/Views/Toplevel.cs @@ -29,7 +29,7 @@ public partial class Toplevel : View /// public Toplevel () { - Arrangement = ViewArrangement.Movable; + Arrangement = ViewArrangement.Fixed; Width = Dim.Fill (); Height = Dim.Fill (); diff --git a/UICatalog/Scenarios/Adornments.cs b/UICatalog/Scenarios/Adornments.cs index f1701c4eb3..27aefbddc7 100644 --- a/UICatalog/Scenarios/Adornments.cs +++ b/UICatalog/Scenarios/Adornments.cs @@ -30,6 +30,7 @@ public override void Main () var window = new Window { Title = "The _Window", + Arrangement = ViewArrangement.Movable, X = Pos.Right(editor), Width = Dim.Percent (60), Height = Dim.Percent (80), diff --git a/UICatalog/Scenarios/BackgroundWorkerCollection.cs b/UICatalog/Scenarios/BackgroundWorkerCollection.cs index f5fa899714..e2d4b8c780 100644 --- a/UICatalog/Scenarios/BackgroundWorkerCollection.cs +++ b/UICatalog/Scenarios/BackgroundWorkerCollection.cs @@ -36,6 +36,7 @@ private class OverlappedMain : Toplevel public OverlappedMain () { + Arrangement = ViewArrangement.Movable; Data = "OverlappedMain"; IsOverlappedContainer = true; @@ -258,6 +259,8 @@ public StagingUIController (Staging staging, List list) : this () public StagingUIController () { + Arrangement = ViewArrangement.Movable; + X = Pos.Center (); Y = Pos.Center (); Width = Dim.Percent (85); @@ -338,6 +341,8 @@ private class WorkerApp : Toplevel public WorkerApp () { + Arrangement = ViewArrangement.Movable; + Data = "WorkerApp"; Title = "Worker collection Log"; diff --git a/UICatalog/Scenarios/TextFormatterDemo.cs b/UICatalog/Scenarios/TextFormatterDemo.cs index 629e567764..021359801d 100644 --- a/UICatalog/Scenarios/TextFormatterDemo.cs +++ b/UICatalog/Scenarios/TextFormatterDemo.cs @@ -10,18 +10,19 @@ namespace UICatalog.Scenarios; [ScenarioCategory ("Text and Formatting")] public class TextFormatterDemo : Scenario { - public override void Setup () + public override void Main () { - // TODO: Move this to another Scenario that specifically tests `Views` that have no subviews. - //Top.Text = "Press CTRL-Q to Quit. This is the Text for the TopLevel View. TextAlignment.Centered was specified. It is intentionally very long to illustrate word wrap.\n" + - // "<-- There is a new line here to show a hard line break. You should see this text bleed underneath the subviews, which start at Y = 3."; - //Top.TextAlignment = TextAlignment.Centered; - //Top.ColorScheme = Colors.ColorSchemes ["Base"]; + Application.Init (); + + var app = new Window () + { + Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}", + }; // Make Win smaller so sizing the window horizontally will make the // labels shrink to zero-width - Win.X = 10; - Win.Width = Dim.Fill (10); + app.X = 10; + app.Width = Dim.Fill (10); var text = "Hello world, how are you today? Pretty neat!\nSecond line\n\nFourth Line."; @@ -35,7 +36,7 @@ public override void Setup () Y = 0, AutoSize = false, Height = 10, - Width = Dim.Fill () + Width = Dim.Fill (), }; var block = new StringBuilder (); @@ -50,17 +51,17 @@ public override void Setup () block.AppendLine (" ░ ░ ░ ░ ░ ░ ░ "); block.AppendLine (" ░ ░ "); blockText.Text = block.ToString (); // .Replace(" ", "\u00A0"); // \u00A0 is 'non-breaking space - Win.Add (blockText); + app.Add (blockText); var unicodeCheckBox = new CheckBox { X = 0, Y = Pos.Bottom (blockText) + 1, Text = "Unicode", - Checked = Top.HotKeySpecifier == (Rune)' ' + Checked = app.HotKeySpecifier == (Rune)' ' }; - Win.Add (unicodeCheckBox); + app.Add (unicodeCheckBox); List alignments = Enum.GetValues (typeof (TextAlignment)).Cast ().ToList (); Label [] singleLines = new Label [alignments.Count]; @@ -97,26 +98,26 @@ public override void Setup () { Y = Pos.Bottom (unicodeCheckBox) + 1, Text = "Demonstrating multi-line and word wrap:" }; - Win.Add (label); + app.Add (label); foreach (TextAlignment alignment in alignments) { label = new Label { Y = Pos.Bottom (label), Text = $"{alignment}:" }; - Win.Add (label); + app.Add (label); singleLines [(int)alignment].Y = Pos.Bottom (label); - Win.Add (singleLines [(int)alignment]); + app.Add (singleLines [(int)alignment]); label = singleLines [(int)alignment]; } label = new Label { Y = Pos.Bottom (label), Text = "Demonstrating multi-line and word wrap:" }; - Win.Add (label); + app.Add (label); foreach (TextAlignment alignment in alignments) { label = new Label { Y = Pos.Bottom (label), Text = $"{alignment}:" }; - Win.Add (label); + app.Add (label); multipleLines [(int)alignment].Y = Pos.Bottom (label); - Win.Add (multipleLines [(int)alignment]); + app.Add (multipleLines [(int)alignment]); label = multipleLines [(int)alignment]; } @@ -128,5 +129,8 @@ public override void Setup () multipleLines [(int)alignment].Text = e.OldValue == true ? text : unicode; } }; + + Application.Run (app); + app.Dispose (); } } diff --git a/UnitTests/Application/ApplicationTests.cs b/UnitTests/Application/ApplicationTests.cs index 63493628ab..2ebc749196 100644 --- a/UnitTests/Application/ApplicationTests.cs +++ b/UnitTests/Application/ApplicationTests.cs @@ -809,7 +809,11 @@ public void Run_A_Modal_Toplevel_Refresh_Background_On_Moving () Init (); // Don't use Dialog here as it has more layout logic. Use Window instead. - var w = new Window { Width = 5, Height = 5 }; + var w = new Window + { + Width = 5, Height = 5, + Arrangement = ViewArrangement.Movable + }; ((FakeDriver)Application.Driver).SetBufferSize (10, 10); RunState rs = Application.Begin (w); diff --git a/UnitTests/Views/ToplevelTests.cs b/UnitTests/Views/ToplevelTests.cs index 6d81202c26..7ba9a46115 100644 --- a/UnitTests/Views/ToplevelTests.cs +++ b/UnitTests/Views/ToplevelTests.cs @@ -26,10 +26,10 @@ public void Constructor_Default () } [Fact] - public void Arrangement_Is_Movable () + public void Arrangement_Default_Is_Fixed () { var top = new Toplevel (); - Assert.Equal (ViewArrangement.Movable, top.Arrangement); + Assert.Equal (ViewArrangement.Fixed, top.Arrangement); } #if BROKE_IN_2927 @@ -869,7 +869,8 @@ public void Mouse_Drag_On_Top_With_Superview_Null () X = 2, Y = 2, Width = 10, - Height = 3 + Height = 3, + Arrangement = ViewArrangement.Movable }; Application.Run (testWindow); } @@ -964,7 +965,7 @@ public void Mouse_Drag_On_Top_With_Superview_Null () [AutoInitShutdown] public void Mouse_Drag_On_Top_With_Superview_Not_Null () { - var win = new Window { X = 3, Y = 2, Width = 10, Height = 5 }; + var win = new Window { X = 3, Y = 2, Width = 10, Height = 5, Arrangement = ViewArrangement.Movable }; Toplevel top = new (); top.Add (win); @@ -1331,7 +1332,7 @@ public void Toplevel_Inside_ScrollView_MouseGrabView () Height = 16, ContentSize = new (200, 100) }; - var win = new Window { X = 3, Y = 3, Width = Dim.Fill (3), Height = Dim.Fill (3) }; + var win = new Window { X = 3, Y = 3, Width = Dim.Fill (3), Height = Dim.Fill (3), Arrangement = ViewArrangement.Movable }; scrollView.Add (win); Toplevel top = new (); top.Add (scrollView); @@ -1380,7 +1381,7 @@ public void Toplevel_Inside_ScrollView_MouseGrabView () public void Window_Viewport_Bigger_Than_Driver_Cols_And_Rows_Allow_Drag_Beyond_Left_Right_And_Bottom () { Toplevel top = new (); - var window = new Window { Width = 20, Height = 3 }; + var window = new Window { Width = 20, Height = 3, Arrangement = ViewArrangement.Movable}; RunState rsTop = Application.Begin (top); ((FakeDriver)Application.Driver).SetBufferSize (40, 10); RunState rsWindow = Application.Begin (window); @@ -1471,7 +1472,7 @@ public void Window_Viewport_Bigger_Than_Driver_Cols_And_Rows_Allow_Drag_Beyond_L public void Modal_As_Top_Will_Drag_Cleanly () { // Don't use Dialog as a Top, use a Window instead - dialog has complex layout behavior that is not needed here. - var window = new Window { Width = 10, Height = 3 }; + var window = new Window { Width = 10, Height = 3, Arrangement = ViewArrangement.Movable }; window.Add ( new Label