From 01f868184673be85569b47754f65886eccf94b5f Mon Sep 17 00:00:00 2001 From: BDisp Date: Mon, 15 Jan 2024 20:57:17 +0000 Subject: [PATCH] Remove constructors with frame parameters from Label class. --- Terminal.Gui/Views/Label.cs | 10 +- UICatalog/Scenarios/BasicColors.cs | 187 ++--- UICatalog/Scenarios/LabelsAsButtons.cs | 607 ++++++++-------- UICatalog/Scenarios/Mouse.cs | 73 +- UICatalog/Scenarios/Progress.cs | 470 ++++++------ UnitTests/Views/LabelTests.cs | 62 +- UnitTests/Views/ScrollViewTests.cs | 953 ++++++++++++------------- 7 files changed, 1173 insertions(+), 1189 deletions(-) diff --git a/Terminal.Gui/Views/Label.cs b/Terminal.Gui/Views/Label.cs index b69418564..3503f0c6a 100644 --- a/Terminal.Gui/Views/Label.cs +++ b/Terminal.Gui/Views/Label.cs @@ -1,6 +1,6 @@ using System; -namespace Terminal.Gui; +namespace Terminal.Gui; /// /// The Label displays a string at a given position and supports multiple lines separated by newline @@ -21,19 +21,13 @@ public class Label : View { /// public Label (string text, bool autosize = true) : base (text) => SetInitialProperties (autosize); - /// - public Label (Rect rect, string text, bool autosize = false) : base (rect, text) => SetInitialProperties (autosize); - - /// - public Label (int x, int y, string text, bool autosize = true) : base (x, y, text) => SetInitialProperties (autosize); - /// public Label (string text, TextDirection direction, bool autosize = true) : base (text, direction) => SetInitialProperties (autosize); void SetInitialProperties (bool autosize = true) { - Height = 1; + Height = 1; AutoSize = autosize; // Things this view knows how to do AddCommand (Command.Default, () => { diff --git a/UICatalog/Scenarios/BasicColors.cs b/UICatalog/Scenarios/BasicColors.cs index e99c88db3..286de54a1 100644 --- a/UICatalog/Scenarios/BasicColors.cs +++ b/UICatalog/Scenarios/BasicColors.cs @@ -1,101 +1,102 @@ using Terminal.Gui; -namespace UICatalog.Scenarios { - [ScenarioMetadata (Name: "Basic Colors", Description: "Show all basic colors.")] - [ScenarioCategory ("Colors")] - [ScenarioCategory ("Text and Formatting")] - public class BasicColors : Scenario { - public override void Setup () - { - var vx = 30; - var x = 30; - var y = 14; - var colors = System.Enum.GetValues (typeof (ColorName)); +namespace UICatalog.Scenarios; +[ScenarioMetadata (Name: "Basic Colors", Description: "Show all basic colors.")] +[ScenarioCategory ("Colors")] +[ScenarioCategory ("Text and Formatting")] +public class BasicColors : Scenario { + public override void Setup () + { + var vx = 30; + var x = 30; + var y = 14; + var colors = System.Enum.GetValues (typeof (ColorName)); - - foreach (ColorName bg in colors) { - Attribute attr = new Attribute (bg, colors.Length - 1 - bg); - var vl = new Label (bg.ToString (), TextDirection.TopBottom_LeftRight) { - X = vx, - Y = 0, - Width = 1, - Height = 13, - VerticalTextAlignment = VerticalTextAlignment.Bottom, - ColorScheme = new ColorScheme () { Normal = attr } - }; - Win.Add (vl); - var hl = new Label (bg.ToString ()) { - X = 15, + + foreach (ColorName bg in colors) { + Attribute attr = new Attribute (bg, colors.Length - 1 - bg); + var vl = new Label (bg.ToString (), TextDirection.TopBottom_LeftRight) { + X = vx, + Y = 0, + Width = 1, + Height = 13, + VerticalTextAlignment = VerticalTextAlignment.Bottom, + ColorScheme = new ColorScheme () { Normal = attr } + }; + Win.Add (vl); + var hl = new Label (bg.ToString ()) { + X = 15, + Y = y, + Width = 13, + Height = 1, + TextAlignment = TextAlignment.Right, + ColorScheme = new ColorScheme () { Normal = attr } + }; + Win.Add (hl); + vx++; + foreach (ColorName fg in colors) { + var c = new Attribute (fg, bg); + var t = x.ToString (); + var l = new Label (t [t.Length - 1].ToString ()) { + X = x, Y = y, - Width = 13, - Height = 1, - TextAlignment = TextAlignment.Right, - ColorScheme = new ColorScheme () { Normal = attr } + ColorScheme = new ColorScheme () { Normal = c } }; - Win.Add (hl); - vx++; - foreach (ColorName fg in colors) { - var c = new Attribute (fg, bg); - var t = x.ToString (); - var l = new Label (x, y, t [t.Length - 1].ToString ()) { - ColorScheme = new ColorScheme () { Normal = c } - }; - Win.Add (l); - x++; - } - x = 30; - y++; + Win.Add (l); + x++; } - - Win.Add (new Label ("Mouse over to get the Attribute:") { - X = Pos.AnchorEnd (36), - }); - Win.Add (new Label ("Foreground:") { - X = Pos.AnchorEnd (35), - Y = 2 - }); - - var lblForeground = new Label () { - X = Pos.AnchorEnd (23), - Y = 2 - }; - Win.Add (lblForeground); - - var viewForeground = new View (" ") { - X = Pos.AnchorEnd (2), - Y = 2, - ColorScheme = new ColorScheme () - }; - Win.Add (viewForeground); - - Win.Add (new Label ("Background:") { - X = Pos.AnchorEnd (35), - Y = 4 - }); - - var lblBackground = new Label () { - X = Pos.AnchorEnd (23), - Y = 4 - }; - Win.Add (lblBackground); - - var viewBackground = new View (" ") { - X = Pos.AnchorEnd (2), - Y = 4, - ColorScheme = new ColorScheme () - }; - Win.Add (viewBackground); - - Application.MouseEvent += (s, e) => { - if (e.MouseEvent.View != null) { - var fore = e.MouseEvent.View.GetNormalColor ().Foreground; - var back = e.MouseEvent.View.GetNormalColor ().Background; - lblForeground.Text = $"#{fore.R:X2}{fore.G:X2}{fore.B:X2} {fore.ColorName} "; - viewForeground.ColorScheme.Normal = new Attribute (fore, fore); - lblBackground.Text = $"#{back.R:X2}{back.G:X2}{back.B:X2} {back.ColorName} "; - viewBackground.ColorScheme.Normal = new Attribute (back, back); - } - }; + x = 30; + y++; } + + Win.Add (new Label ("Mouse over to get the Attribute:") { + X = Pos.AnchorEnd (36), + }); + Win.Add (new Label ("Foreground:") { + X = Pos.AnchorEnd (35), + Y = 2 + }); + + var lblForeground = new Label () { + X = Pos.AnchorEnd (23), + Y = 2 + }; + Win.Add (lblForeground); + + var viewForeground = new View (" ") { + X = Pos.AnchorEnd (2), + Y = 2, + ColorScheme = new ColorScheme () + }; + Win.Add (viewForeground); + + Win.Add (new Label ("Background:") { + X = Pos.AnchorEnd (35), + Y = 4 + }); + + var lblBackground = new Label () { + X = Pos.AnchorEnd (23), + Y = 4 + }; + Win.Add (lblBackground); + + var viewBackground = new View (" ") { + X = Pos.AnchorEnd (2), + Y = 4, + ColorScheme = new ColorScheme () + }; + Win.Add (viewBackground); + + Application.MouseEvent += (s, e) => { + if (e.MouseEvent.View != null) { + var fore = e.MouseEvent.View.GetNormalColor ().Foreground; + var back = e.MouseEvent.View.GetNormalColor ().Background; + lblForeground.Text = $"#{fore.R:X2}{fore.G:X2}{fore.B:X2} {fore.ColorName} "; + viewForeground.ColorScheme.Normal = new Attribute (fore, fore); + lblBackground.Text = $"#{back.R:X2}{back.G:X2}{back.B:X2} {back.ColorName} "; + viewBackground.ColorScheme.Normal = new Attribute (back, back); + } + }; } -} \ No newline at end of file +} diff --git a/UICatalog/Scenarios/LabelsAsButtons.cs b/UICatalog/Scenarios/LabelsAsButtons.cs index 6932585db..3d887c420 100644 --- a/UICatalog/Scenarios/LabelsAsButtons.cs +++ b/UICatalog/Scenarios/LabelsAsButtons.cs @@ -1,312 +1,309 @@ using System.Text; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; using Terminal.Gui; -namespace UICatalog.Scenarios { - [ScenarioMetadata (Name: "Labels As Buttons", Description: "Illustrates that Button is really just a Label++")] - [ScenarioCategory ("Controls")] - [ScenarioCategory ("Proof of Concept")] - public class LabelsAsLabels : Scenario { - public override void Setup () +namespace UICatalog.Scenarios; +[ScenarioMetadata (Name: "Labels As Buttons", Description: "Illustrates that Button is really just a Label++")] +[ScenarioCategory ("Controls")] +[ScenarioCategory ("Proof of Concept")] +public class LabelsAsLabels : Scenario { + public override void Setup () + { + // Add a label & text field so we can demo IsDefault + var editLabel = new Label ("TextField (to demo IsDefault):") { + X = 0, + Y = 0, + }; + Win.Add (editLabel); + // Add a TextField using Absolute layout. + var edit = new TextField (31, 0, 15, ""); + Win.Add (edit); + + // This is the default Label (IsDefault = true); if user presses ENTER in the TextField + // the scenario will quit + var defaultLabel = new Label ("_Quit") { + X = Pos.Center (), + //TODO: Change to use Pos.AnchorEnd() + Y = Pos.Bottom (Win) - 3, + //IsDefault = true, + HotKeySpecifier = (Rune)'_', + CanFocus = true, + }; + defaultLabel.Clicked += (s, e) => Application.RequestStop (); + Win.Add (defaultLabel); + + var swapLabel = new Label ("S_wap Default (Absolute Layout)") { + X = 50, + HotKeySpecifier = (Rune)'_', + CanFocus = true, + }; + swapLabel.Clicked += (s, e) => { + //defaultLabel.IsDefault = !defaultLabel.IsDefault; + //swapLabel.IsDefault = !swapLabel.IsDefault; + }; + Win.Add (swapLabel); + + static void DoMessage (Label Label, string txt) { - // Add a label & text field so we can demo IsDefault - var editLabel = new Label ("TextField (to demo IsDefault):") { - X = 0, - Y = 0, + Label.Clicked += (s, e) => { + var btnText = Label.Text; + MessageBox.Query ("Message", $"Did you click {txt}?", "Yes", "No"); }; - Win.Add (editLabel); - // Add a TextField using Absolute layout. - var edit = new TextField (31, 0, 15, ""); - Win.Add (edit); - - // This is the default Label (IsDefault = true); if user presses ENTER in the TextField - // the scenario will quit - var defaultLabel = new Label ("_Quit") { - X = Pos.Center (), - //TODO: Change to use Pos.AnchorEnd() - Y = Pos.Bottom (Win) - 3, - //IsDefault = true, - HotKeySpecifier = (Rune)'_', - CanFocus = true, - }; - defaultLabel.Clicked += (s,e) => Application.RequestStop (); - Win.Add (defaultLabel); - - var swapLabel = new Label (50, 0, "S_wap Default (Absolute Layout)") { - HotKeySpecifier = (Rune)'_', - CanFocus = true, - }; - swapLabel.Clicked += (s,e) => { - //defaultLabel.IsDefault = !defaultLabel.IsDefault; - //swapLabel.IsDefault = !swapLabel.IsDefault; - }; - Win.Add (swapLabel); - - static void DoMessage (Label Label, string txt) - { - Label.Clicked += (s,e) => { - var btnText = Label.Text; - MessageBox.Query ("Message", $"Did you click {txt}?", "Yes", "No"); - }; - } - - var colorLabelsLabel = new Label ("Color Labels:") { - X = 0, - Y = Pos.Bottom (editLabel) + 1, - }; - Win.Add (colorLabelsLabel); - - //With this method there is no need to call Application.TopReady += () => Application.TopRedraw (Top.Bounds); - var x = Pos.Right (colorLabelsLabel) + 2; - foreach (var colorScheme in Colors.ColorSchemes) { - var colorLabel = new Label ($"{colorScheme.Key}") { - ColorScheme = colorScheme.Value, - X = x, - Y = Pos.Y (colorLabelsLabel), - HotKeySpecifier = (Rune)'_', - CanFocus = true, - }; - DoMessage (colorLabel, colorLabel.Text); - Win.Add (colorLabel); - x += colorLabel.Text.Length + 2; - } - Application.Top.Ready += (s,e) => Application.Top.Draw (); - - Label Label; - Win.Add (Label = new Label ("A super long _Label that will probably expose a bug in clipping or wrapping of text. Will it?") { - X = 2, - Y = Pos.Bottom (colorLabelsLabel) + 1, - HotKeySpecifier = (Rune)'_', - CanFocus = true, - }); - DoMessage (Label, Label.Text); - - // Note the 'N' in 'Newline' will be the hotkey - Win.Add (Label = new Label ("a Newline\nin the Label") { - X = 2, - Y = Pos.Bottom (Label) + 1, - HotKeySpecifier = (Rune)'_', - CanFocus = true, - TextAlignment = TextAlignment.Centered, - VerticalTextAlignment = VerticalTextAlignment.Middle - }); - Label.Clicked += (s,e) => MessageBox.Query ("Message", "Question?", "Yes", "No"); - - var textChanger = new Label ("Te_xt Changer") { - X = 2, - Y = Pos.Bottom (Label) + 1, - HotKeySpecifier = (Rune)'_', - CanFocus = true, - }; - Win.Add (textChanger); - textChanger.Clicked += (s,e) => textChanger.Text += "!"; - - Win.Add (Label = new Label ("Lets see if this will move as \"Text Changer\" grows") { - X = Pos.Right (textChanger) + 2, - Y = Pos.Y (textChanger), - HotKeySpecifier = (Rune)'_', - CanFocus = true, - }); - - var removeLabel = new Label ("Remove this Label") { - X = 2, - Y = Pos.Bottom (Label) + 1, - ColorScheme = Colors.Error, - HotKeySpecifier = (Rune)'_', - CanFocus = true, - }; - Win.Add (removeLabel); - // This in interesting test case because `moveBtn` and below are laid out relative to this one! - removeLabel.Clicked += (s,e) => { - // Now this throw a InvalidOperationException on the TopologicalSort method as is expected. - //Win.Remove (removeLabel); - - removeLabel.Visible = false; - Win.SetNeedsDisplay (); - }; - - var computedFrame = new FrameView ("Computed Layout") { - X = 0, - Y = Pos.Bottom (removeLabel) + 1, - Width = Dim.Percent (50), - Height = 5 - }; - Win.Add (computedFrame); - - // Demonstrates how changing the View.Frame property can move Views - var moveBtn = new Label ("Move This \u263b Label _via Pos") { - X = 0, - Y = Pos.Center () - 1, - Width = 30, - ColorScheme = Colors.Error, - HotKeySpecifier = (Rune)'_', - CanFocus = true, - }; - moveBtn.Clicked += (s,e) => { - moveBtn.X = moveBtn.Frame.X + 5; - // This is already fixed with the call to SetNeedDisplay() in the Pos Dim. - //computedFrame.LayoutSubviews (); // BUGBUG: This call should not be needed. View.X is not causing relayout correctly - }; - computedFrame.Add (moveBtn); - - // Demonstrates how changing the View.Frame property can SIZE Views (#583) - var sizeBtn = new Label ("Size This \u263a Label _via Pos") { - //var sizeBtn = new Label ("Size This x Label _via Pos") { - X = 0, - Y = Pos.Center () + 1, - Width = 30, - ColorScheme = Colors.Error, - HotKeySpecifier = (Rune)'_', - CanFocus = true, - AutoSize = false - }; - sizeBtn.Clicked += (s,e) => { - sizeBtn.Width = sizeBtn.Frame.Width + 5; - //computedFrame.LayoutSubviews (); // FIXED: This call should not be needed. View.X is not causing relayout correctly - }; - computedFrame.Add (sizeBtn); - - var absoluteFrame = new FrameView ("Absolute Layout") { - X = Pos.Right (computedFrame), - Y = Pos.Bottom (removeLabel) + 1, - Width = Dim.Fill (), - Height = 5 - }; - Win.Add (absoluteFrame); - - // Demonstrates how changing the View.Frame property can move Views - var moveBtnA = new Label (0, 0, "Move This Label via Frame") { - ColorScheme = Colors.Error, - HotKeySpecifier = (Rune)'_', - CanFocus = true, - }; - moveBtnA.Clicked += (s,e) => { - moveBtnA.Frame = new Rect (moveBtnA.Frame.X + 5, moveBtnA.Frame.Y, moveBtnA.Frame.Width, moveBtnA.Frame.Height); - }; - absoluteFrame.Add (moveBtnA); - - // Demonstrates how changing the View.Frame property can SIZE Views (#583) - var sizeBtnA = new Label (0, 2, " ~  s  gui.cs   master ↑10 = Со_хранить") { - ColorScheme = Colors.Error, - HotKeySpecifier = (Rune)'_', - CanFocus = true, - AutoSize = false - }; - sizeBtnA.Clicked += (s,e) => { - sizeBtnA.Frame = new Rect (sizeBtnA.Frame.X, sizeBtnA.Frame.Y, sizeBtnA.Frame.Width + 5, sizeBtnA.Frame.Height); - }; - absoluteFrame.Add (sizeBtnA); - - var label = new Label ("Text Alignment (changes the four Labels above): ") { - X = 2, - Y = Pos.Bottom (computedFrame) + 1, - HotKeySpecifier = (Rune)'_', - CanFocus = true, - }; - Win.Add (label); - - var radioGroup = new RadioGroup (new string [] { "Left", "Right", "Centered", "Justified" }) { - X = 4, - Y = Pos.Bottom (label) + 1, - SelectedItem = 2, - }; - Win.Add (radioGroup); - - // Demo changing hotkey - string MoveHotkey (string txt) - { - // Remove the '_' - var runes = txt.ToRuneList (); - - var i = runes.IndexOf ((Rune)'_'); - string start = ""; - if (i > -1) { - start = StringExtensions.ToString (runes.GetRange (0, i)); - } - txt = start + StringExtensions.ToString (runes.GetRange (i + 1, runes.Count - (i + 1))); - - runes = txt.ToRuneList (); - - // Move over one or go to start - i++; - if (i >= runes.Count) { - i = 0; - } - - // Slip in the '_' - start = StringExtensions.ToString (runes.GetRange (0, i)); - return start + '_' + StringExtensions.ToString (runes.GetRange (i, runes.Count - i)); - } - - var mhkb = "Click to Change th_is Label's Hotkey"; - var moveHotKeyBtn = new Label (mhkb) { - X = 2, - Y = Pos.Bottom (radioGroup) + 1, - Width = Dim.Width (computedFrame) - 2, - ColorScheme = Colors.TopLevel, - HotKeySpecifier = (Rune)'_', - CanFocus = true, - }; - moveHotKeyBtn.Clicked += (s,e) => { - moveHotKeyBtn.Text = MoveHotkey (moveHotKeyBtn.Text); - }; - Win.Add (moveHotKeyBtn); - - string muhkb = " ~  s  gui.cs   master ↑10 = Сохранить"; - var moveUnicodeHotKeyBtn = new Label (muhkb) { - X = Pos.Left (absoluteFrame) + 1, - Y = Pos.Bottom (radioGroup) + 1, - Width = Dim.Width (absoluteFrame) - 2, - ColorScheme = Colors.TopLevel, - HotKeySpecifier = (Rune)'_', - CanFocus = true, - }; - moveUnicodeHotKeyBtn.Clicked += (s,e) => { - moveUnicodeHotKeyBtn.Text = MoveHotkey (moveUnicodeHotKeyBtn.Text); - }; - Win.Add (moveUnicodeHotKeyBtn); - - radioGroup.SelectedItemChanged += (s,args) => { - switch (args.SelectedItem) { - case 0: - moveBtn.TextAlignment = TextAlignment.Left; - sizeBtn.TextAlignment = TextAlignment.Left; - moveBtnA.TextAlignment = TextAlignment.Left; - sizeBtnA.TextAlignment = TextAlignment.Left; - moveHotKeyBtn.TextAlignment = TextAlignment.Left; - moveUnicodeHotKeyBtn.TextAlignment = TextAlignment.Left; - break; - case 1: - moveBtn.TextAlignment = TextAlignment.Right; - sizeBtn.TextAlignment = TextAlignment.Right; - moveBtnA.TextAlignment = TextAlignment.Right; - sizeBtnA.TextAlignment = TextAlignment.Right; - moveHotKeyBtn.TextAlignment = TextAlignment.Right; - moveUnicodeHotKeyBtn.TextAlignment = TextAlignment.Right; - break; - case 2: - moveBtn.TextAlignment = TextAlignment.Centered; - sizeBtn.TextAlignment = TextAlignment.Centered; - moveBtnA.TextAlignment = TextAlignment.Centered; - sizeBtnA.TextAlignment = TextAlignment.Centered; - moveHotKeyBtn.TextAlignment = TextAlignment.Centered; - moveUnicodeHotKeyBtn.TextAlignment = TextAlignment.Centered; - break; - case 3: - moveBtn.TextAlignment = TextAlignment.Justified; - sizeBtn.TextAlignment = TextAlignment.Justified; - moveBtnA.TextAlignment = TextAlignment.Justified; - sizeBtnA.TextAlignment = TextAlignment.Justified; - moveHotKeyBtn.TextAlignment = TextAlignment.Justified; - moveUnicodeHotKeyBtn.TextAlignment = TextAlignment.Justified; - break; - } - }; - - Application.Top.Ready += (s,e) => radioGroup.Refresh (); } + + var colorLabelsLabel = new Label ("Color Labels:") { + X = 0, + Y = Pos.Bottom (editLabel) + 1, + }; + Win.Add (colorLabelsLabel); + + //With this method there is no need to call Application.TopReady += () => Application.TopRedraw (Top.Bounds); + var x = Pos.Right (colorLabelsLabel) + 2; + foreach (var colorScheme in Colors.ColorSchemes) { + var colorLabel = new Label ($"{colorScheme.Key}") { + ColorScheme = colorScheme.Value, + X = x, + Y = Pos.Y (colorLabelsLabel), + HotKeySpecifier = (Rune)'_', + CanFocus = true, + }; + DoMessage (colorLabel, colorLabel.Text); + Win.Add (colorLabel); + x += colorLabel.Text.Length + 2; + } + Application.Top.Ready += (s, e) => Application.Top.Draw (); + + Label Label; + Win.Add (Label = new Label ("A super long _Label that will probably expose a bug in clipping or wrapping of text. Will it?") { + X = 2, + Y = Pos.Bottom (colorLabelsLabel) + 1, + HotKeySpecifier = (Rune)'_', + CanFocus = true, + }); + DoMessage (Label, Label.Text); + + // Note the 'N' in 'Newline' will be the hotkey + Win.Add (Label = new Label ("a Newline\nin the Label") { + X = 2, + Y = Pos.Bottom (Label) + 1, + HotKeySpecifier = (Rune)'_', + CanFocus = true, + TextAlignment = TextAlignment.Centered, + VerticalTextAlignment = VerticalTextAlignment.Middle + }); + Label.Clicked += (s, e) => MessageBox.Query ("Message", "Question?", "Yes", "No"); + + var textChanger = new Label ("Te_xt Changer") { + X = 2, + Y = Pos.Bottom (Label) + 1, + HotKeySpecifier = (Rune)'_', + CanFocus = true, + }; + Win.Add (textChanger); + textChanger.Clicked += (s, e) => textChanger.Text += "!"; + + Win.Add (Label = new Label ("Lets see if this will move as \"Text Changer\" grows") { + X = Pos.Right (textChanger) + 2, + Y = Pos.Y (textChanger), + HotKeySpecifier = (Rune)'_', + CanFocus = true, + }); + + var removeLabel = new Label ("Remove this Label") { + X = 2, + Y = Pos.Bottom (Label) + 1, + ColorScheme = Colors.Error, + HotKeySpecifier = (Rune)'_', + CanFocus = true, + }; + Win.Add (removeLabel); + // This in interesting test case because `moveBtn` and below are laid out relative to this one! + removeLabel.Clicked += (s, e) => { + // Now this throw a InvalidOperationException on the TopologicalSort method as is expected. + //Win.Remove (removeLabel); + + removeLabel.Visible = false; + Win.SetNeedsDisplay (); + }; + + var computedFrame = new FrameView ("Computed Layout") { + X = 0, + Y = Pos.Bottom (removeLabel) + 1, + Width = Dim.Percent (50), + Height = 5 + }; + Win.Add (computedFrame); + + // Demonstrates how changing the View.Frame property can move Views + var moveBtn = new Label ("Move This \u263b Label _via Pos") { + X = 0, + Y = Pos.Center () - 1, + Width = 30, + ColorScheme = Colors.Error, + HotKeySpecifier = (Rune)'_', + CanFocus = true, + }; + moveBtn.Clicked += (s, e) => { + moveBtn.X = moveBtn.Frame.X + 5; + // This is already fixed with the call to SetNeedDisplay() in the Pos Dim. + //computedFrame.LayoutSubviews (); // BUGBUG: This call should not be needed. View.X is not causing relayout correctly + }; + computedFrame.Add (moveBtn); + + // Demonstrates how changing the View.Frame property can SIZE Views (#583) + var sizeBtn = new Label ("Size This \u263a Label _via Pos") { + //var sizeBtn = new Label ("Size This x Label _via Pos") { + X = 0, + Y = Pos.Center () + 1, + Width = 30, + ColorScheme = Colors.Error, + HotKeySpecifier = (Rune)'_', + CanFocus = true, + AutoSize = false + }; + sizeBtn.Clicked += (s, e) => { + sizeBtn.Width = sizeBtn.Frame.Width + 5; + //computedFrame.LayoutSubviews (); // FIXED: This call should not be needed. View.X is not causing relayout correctly + }; + computedFrame.Add (sizeBtn); + + var absoluteFrame = new FrameView ("Absolute Layout") { + X = Pos.Right (computedFrame), + Y = Pos.Bottom (removeLabel) + 1, + Width = Dim.Fill (), + Height = 5 + }; + Win.Add (absoluteFrame); + + // Demonstrates how changing the View.Frame property can move Views + var moveBtnA = new Label ("Move This Label via Frame") { + ColorScheme = Colors.Error, + HotKeySpecifier = (Rune)'_', + CanFocus = true, + }; + moveBtnA.Clicked += (s, e) => { + moveBtnA.Frame = new Rect (moveBtnA.Frame.X + 5, moveBtnA.Frame.Y, moveBtnA.Frame.Width, moveBtnA.Frame.Height); + }; + absoluteFrame.Add (moveBtnA); + + // Demonstrates how changing the View.Frame property can SIZE Views (#583) + var sizeBtnA = new Label (" ~  s  gui.cs   master ↑10 = Со_хранить") { + Y = 2, + ColorScheme = Colors.Error, + HotKeySpecifier = (Rune)'_', + CanFocus = true, + AutoSize = false + }; + sizeBtnA.Clicked += (s, e) => { + sizeBtnA.Frame = new Rect (sizeBtnA.Frame.X, sizeBtnA.Frame.Y, sizeBtnA.Frame.Width + 5, sizeBtnA.Frame.Height); + }; + absoluteFrame.Add (sizeBtnA); + + var label = new Label ("Text Alignment (changes the four Labels above): ") { + X = 2, + Y = Pos.Bottom (computedFrame) + 1, + HotKeySpecifier = (Rune)'_', + CanFocus = true, + }; + Win.Add (label); + + var radioGroup = new RadioGroup (new string [] { "Left", "Right", "Centered", "Justified" }) { + X = 4, + Y = Pos.Bottom (label) + 1, + SelectedItem = 2, + }; + Win.Add (radioGroup); + + // Demo changing hotkey + string MoveHotkey (string txt) + { + // Remove the '_' + var runes = txt.ToRuneList (); + + var i = runes.IndexOf ((Rune)'_'); + string start = ""; + if (i > -1) { + start = StringExtensions.ToString (runes.GetRange (0, i)); + } + txt = start + StringExtensions.ToString (runes.GetRange (i + 1, runes.Count - (i + 1))); + + runes = txt.ToRuneList (); + + // Move over one or go to start + i++; + if (i >= runes.Count) { + i = 0; + } + + // Slip in the '_' + start = StringExtensions.ToString (runes.GetRange (0, i)); + return start + '_' + StringExtensions.ToString (runes.GetRange (i, runes.Count - i)); + } + + var mhkb = "Click to Change th_is Label's Hotkey"; + var moveHotKeyBtn = new Label (mhkb) { + X = 2, + Y = Pos.Bottom (radioGroup) + 1, + Width = Dim.Width (computedFrame) - 2, + ColorScheme = Colors.TopLevel, + HotKeySpecifier = (Rune)'_', + CanFocus = true, + }; + moveHotKeyBtn.Clicked += (s, e) => { + moveHotKeyBtn.Text = MoveHotkey (moveHotKeyBtn.Text); + }; + Win.Add (moveHotKeyBtn); + + string muhkb = " ~  s  gui.cs   master ↑10 = Сохранить"; + var moveUnicodeHotKeyBtn = new Label (muhkb) { + X = Pos.Left (absoluteFrame) + 1, + Y = Pos.Bottom (radioGroup) + 1, + Width = Dim.Width (absoluteFrame) - 2, + ColorScheme = Colors.TopLevel, + HotKeySpecifier = (Rune)'_', + CanFocus = true, + }; + moveUnicodeHotKeyBtn.Clicked += (s, e) => { + moveUnicodeHotKeyBtn.Text = MoveHotkey (moveUnicodeHotKeyBtn.Text); + }; + Win.Add (moveUnicodeHotKeyBtn); + + radioGroup.SelectedItemChanged += (s, args) => { + switch (args.SelectedItem) { + case 0: + moveBtn.TextAlignment = TextAlignment.Left; + sizeBtn.TextAlignment = TextAlignment.Left; + moveBtnA.TextAlignment = TextAlignment.Left; + sizeBtnA.TextAlignment = TextAlignment.Left; + moveHotKeyBtn.TextAlignment = TextAlignment.Left; + moveUnicodeHotKeyBtn.TextAlignment = TextAlignment.Left; + break; + case 1: + moveBtn.TextAlignment = TextAlignment.Right; + sizeBtn.TextAlignment = TextAlignment.Right; + moveBtnA.TextAlignment = TextAlignment.Right; + sizeBtnA.TextAlignment = TextAlignment.Right; + moveHotKeyBtn.TextAlignment = TextAlignment.Right; + moveUnicodeHotKeyBtn.TextAlignment = TextAlignment.Right; + break; + case 2: + moveBtn.TextAlignment = TextAlignment.Centered; + sizeBtn.TextAlignment = TextAlignment.Centered; + moveBtnA.TextAlignment = TextAlignment.Centered; + sizeBtnA.TextAlignment = TextAlignment.Centered; + moveHotKeyBtn.TextAlignment = TextAlignment.Centered; + moveUnicodeHotKeyBtn.TextAlignment = TextAlignment.Centered; + break; + case 3: + moveBtn.TextAlignment = TextAlignment.Justified; + sizeBtn.TextAlignment = TextAlignment.Justified; + moveBtnA.TextAlignment = TextAlignment.Justified; + sizeBtnA.TextAlignment = TextAlignment.Justified; + moveHotKeyBtn.TextAlignment = TextAlignment.Justified; + moveUnicodeHotKeyBtn.TextAlignment = TextAlignment.Justified; + break; + } + }; + + Application.Top.Ready += (s, e) => radioGroup.Refresh (); } -} \ No newline at end of file +} diff --git a/UICatalog/Scenarios/Mouse.cs b/UICatalog/Scenarios/Mouse.cs index 05f722c5a..927c8bfbf 100644 --- a/UICatalog/Scenarios/Mouse.cs +++ b/UICatalog/Scenarios/Mouse.cs @@ -1,46 +1,43 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.Collections.Generic; using Terminal.Gui; -namespace UICatalog.Scenarios { - [ScenarioMetadata (Name: "Mouse", Description: "Demonstrates how to capture mouse events")] - [ScenarioCategory ("Mouse and Keyboard")] - public class Mouse : Scenario { - public override void Setup () - { - Label ml; - int count = 0; - ml = new Label (new Rect (1, 1, 50, 1), "Mouse: "); - List rme = new List (); +namespace UICatalog.Scenarios; +[ScenarioMetadata (Name: "Mouse", Description: "Demonstrates how to capture mouse events")] +[ScenarioCategory ("Mouse and Keyboard")] +public class Mouse : Scenario { + public override void Setup () + { + Label ml; + int count = 0; + ml = new Label ("Mouse: ") { X = 1, Y = 1, Width = 50, Height = 1 }; + List rme = new List (); - var test = new Label (1, 2, "Se iniciará el análisis"); - Win.Add (test); - Win.Add (ml); + var test = new Label ("Se iniciará el análisis") { X = 1, Y = 2 }; + Win.Add (test); + Win.Add (ml); - var rmeList = new ListView (rme) { - X = Pos.Right (test) + 25, - Y = Pos.Top (test) + 1, - Width = Dim.Fill () - 1, - Height = Dim.Fill (), - ColorScheme = Colors.TopLevel - }; - Win.Add (rmeList); + var rmeList = new ListView (rme) { + X = Pos.Right (test) + 25, + Y = Pos.Top (test) + 1, + Width = Dim.Fill () - 1, + Height = Dim.Fill (), + ColorScheme = Colors.TopLevel + }; + Win.Add (rmeList); - Application.MouseEvent += (sender, a) => { - ml.Text = $"Mouse: ({a.MouseEvent.X},{a.MouseEvent.Y}) - {a.MouseEvent.Flags} {count}"; - rme.Add ($"({a.MouseEvent.X},{a.MouseEvent.Y}) - {a.MouseEvent.Flags} {count++}"); - rmeList.MoveDown (); - }; + Application.MouseEvent += (sender, a) => { + ml.Text = $"Mouse: ({a.MouseEvent.X},{a.MouseEvent.Y}) - {a.MouseEvent.Flags} {count}"; + rme.Add ($"({a.MouseEvent.X},{a.MouseEvent.Y}) - {a.MouseEvent.Flags} {count++}"); + rmeList.MoveDown (); + }; - // I have no idea what this was intended to show off in demo.c - var drag = new Label ("Drag: ") { X = 1, Y = 4 }; - var dragText = new TextField ("") { - X = Pos.Right (drag), - Y = Pos.Top (drag), - Width = 40 - }; - Win.Add (drag, dragText); - } + // I have no idea what this was intended to show off in demo.c + var drag = new Label ("Drag: ") { X = 1, Y = 4 }; + var dragText = new TextField ("") { + X = Pos.Right (drag), + Y = Pos.Top (drag), + Width = 40 + }; + Win.Add (drag, dragText); } } diff --git a/UICatalog/Scenarios/Progress.cs b/UICatalog/Scenarios/Progress.cs index 859c40621..5802f25d7 100644 --- a/UICatalog/Scenarios/Progress.cs +++ b/UICatalog/Scenarios/Progress.cs @@ -1,271 +1,269 @@ -using System.Text; -using System; +using System; using System.Threading; using Terminal.Gui; using System.Linq; -namespace UICatalog.Scenarios { - // - // This would be a great scenario to show of threading (Issue #471) - // - [ScenarioMetadata (Name: "Progress", Description: "Shows off ProgressBar and Threading.")] - [ScenarioCategory ("Controls")] - [ScenarioCategory ("Threading"), ScenarioCategory ("Progress")] - public class Progress : Scenario { +namespace UICatalog.Scenarios; +// +// This would be a great scenario to show of threading (Issue #471) +// +[ScenarioMetadata (Name: "Progress", Description: "Shows off ProgressBar and Threading.")] +[ScenarioCategory ("Controls")] +[ScenarioCategory ("Threading"), ScenarioCategory ("Progress")] +public class Progress : Scenario { - class ProgressDemo : FrameView { - const int _verticalSpace = 1; + class ProgressDemo : FrameView { + const int _verticalSpace = 1; - internal FrameView LeftFrame { get; private set; } - internal TextField Speed { get; private set; } - internal ProgressBar ActivityProgressBar { get; private set; } - internal ProgressBar PulseProgressBar { get; private set; } - internal SpinnerView Spinner { get; private set; } - internal Action StartBtnClick; - internal Action StopBtnClick; - internal Action PulseBtnClick = null; - private Label _startedLabel; - internal bool Started { - get { - return _startedLabel.Text == "Started"; - } - private set { - _startedLabel.Text = value ? "Started" : "Stopped"; - } + internal FrameView LeftFrame { get; private set; } + internal TextField Speed { get; private set; } + internal ProgressBar ActivityProgressBar { get; private set; } + internal ProgressBar PulseProgressBar { get; private set; } + internal SpinnerView Spinner { get; private set; } + internal Action StartBtnClick; + internal Action StopBtnClick; + internal Action PulseBtnClick = null; + private Label _startedLabel; + internal bool Started { + get { + return _startedLabel.Text == "Started"; } - - internal ProgressDemo (string title) : base (title) - { - ColorScheme = Colors.Dialog; - - LeftFrame = new FrameView ("Settings") { - X = 0, - Y = 0, - Height = Dim.Percent (100), - Width = Dim.Percent (25) - }; - var lbl = new Label (1, 1, "Tick every (ms):"); - LeftFrame.Add (lbl); - Speed = new TextField ("") { - X = Pos.X (lbl), - Y = Pos.Bottom (lbl), - Width = 7, - }; - LeftFrame.Add (Speed); - - Add (LeftFrame); - - var startButton = new Button ("Start Timer") { - X = Pos.Right (LeftFrame) + 1, - Y = 0, - }; - startButton.Clicked += (s,e) => Start (); - var pulseButton = new Button ("Pulse") { - X = Pos.Right (startButton) + 2, - Y = Pos.Y (startButton), - }; - pulseButton.Clicked += (s,e) => Pulse (); - var stopbutton = new Button ("Stop Timer") { - X = Pos.Right (pulseButton) + 2, - Y = Pos.Top (pulseButton), - }; - stopbutton.Clicked += (s,e) => Stop (); - - Add (startButton); - Add (pulseButton); - Add (stopbutton); - - ActivityProgressBar = new ProgressBar () { - X = Pos.Right (LeftFrame) + 1, - Y = Pos.Bottom (startButton) + 1, - Width = Dim.Fill () - 1, - Height = 1, - Fraction = 0.25F, - ColorScheme = Colors.Error - }; - Add (ActivityProgressBar); - - Spinner = new SpinnerView () { - Style = new SpinnerStyle.Dots2 (), - SpinReverse = true, - Y = ActivityProgressBar.Y, - Visible = false - }; - ActivityProgressBar.Width = Dim.Fill () - Spinner.Width; - Spinner.X = Pos.Right (ActivityProgressBar); - - - Add (Spinner); - - PulseProgressBar = new ProgressBar () { - X = Pos.Right (LeftFrame) + 1, - Y = Pos.Bottom (ActivityProgressBar) + 1, - Width = Dim.Fill () - Spinner.Width, - Height = 1, - ColorScheme = Colors.Error - }; - Add (PulseProgressBar); - - _startedLabel = new Label ("Stopped") { - X = Pos.Right (LeftFrame) + 1, - Y = Pos.Bottom (PulseProgressBar), - }; - Add (_startedLabel); - - // TODO: Great use of Dim.Auto - Initialized += (s, e) => { - // Set height to height of controls + spacing + frame - Height = 2 + _verticalSpace + startButton.Frame.Height + _verticalSpace + ActivityProgressBar.Frame.Height + _verticalSpace + PulseProgressBar.Frame.Height + _verticalSpace; - }; - } - - internal void Start () - { - Started = true; - StartBtnClick?.Invoke (); - Application.Invoke(()=>{ - Spinner.Visible = true; - ActivityProgressBar.Width = Dim.Fill () - Spinner.Width; - this.LayoutSubviews(); - }); - } - - internal void Stop () - { - Started = false; - StopBtnClick?.Invoke (); - - Application.Invoke(()=>{ - Spinner.Visible = false; - ActivityProgressBar.Width = Dim.Fill () - Spinner.Width; - this.LayoutSubviews(); - }); - } - - internal void Pulse () - { - Spinner.Visible = true; - if (PulseBtnClick != null) { - PulseBtnClick?.Invoke (); - - } else { - if (ActivityProgressBar.Fraction + 0.01F >= 1) { - ActivityProgressBar.Fraction = 0F; - } else { - ActivityProgressBar.Fraction += 0.01F; - } - PulseProgressBar.Pulse (); - Spinner.AdvanceAnimation (); - } + private set { + _startedLabel.Text = value ? "Started" : "Stopped"; } } - private Timer _systemTimer = null; - private uint _systemTimerTick = 100; // ms - private object _mainLoopTimeout = null; - private uint _mainLooopTimeoutTick = 100; // ms - public override void Setup () + internal ProgressDemo (string title) : base (title) { - // Demo #1 - Use System.Timer (and threading) - var systemTimerDemo = new ProgressDemo ("System.Timer (threads)") { + ColorScheme = Colors.Dialog; + + LeftFrame = new FrameView ("Settings") { X = 0, Y = 0, - Width = Dim.Percent (100), + Height = Dim.Percent (100), + Width = Dim.Percent (25) }; - systemTimerDemo.StartBtnClick = () => { - _systemTimer?.Dispose (); - _systemTimer = null; - - systemTimerDemo.ActivityProgressBar.Fraction = 0F; - systemTimerDemo.PulseProgressBar.Fraction = 0F; - - _systemTimer = new Timer ((o) => { - // Note the check for Mainloop being valid. System.Timers can run after they are Disposed. - // This code must be defensive for that. - Application.Invoke (() => systemTimerDemo.Pulse ()); - }, null, 0, _systemTimerTick); + var lbl = new Label ("Tick every (ms):") { X = 1, Y = 1 }; + LeftFrame.Add (lbl); + Speed = new TextField ("") { + X = Pos.X (lbl), + Y = Pos.Bottom (lbl), + Width = 7, }; + LeftFrame.Add (Speed); - systemTimerDemo.StopBtnClick = () => { - _systemTimer?.Dispose (); - _systemTimer = null; + Add (LeftFrame); - systemTimerDemo.ActivityProgressBar.Fraction = 1F; - systemTimerDemo.PulseProgressBar.Fraction = 1F; + var startButton = new Button ("Start Timer") { + X = Pos.Right (LeftFrame) + 1, + Y = 0, }; - systemTimerDemo.Speed.Text = $"{_systemTimerTick}"; - systemTimerDemo.Speed.TextChanged += (s, a) => { - uint result; - if (uint.TryParse (systemTimerDemo.Speed.Text.ToString(), out result)) { - _systemTimerTick = result; - System.Diagnostics.Debug.WriteLine ($"{_systemTimerTick}"); - if (systemTimerDemo.Started) { - systemTimerDemo.Start (); - } - - } else { - System.Diagnostics.Debug.WriteLine ("bad entry"); - } + startButton.Clicked += (s, e) => Start (); + var pulseButton = new Button ("Pulse") { + X = Pos.Right (startButton) + 2, + Y = Pos.Y (startButton), }; - Win.Add (systemTimerDemo); - - // Demo #2 - Use Application.AddTimeout (no threads) - var mainLoopTimeoutDemo = new ProgressDemo ("Application.AddTimer (no threads)") { - X = 0, - Y = Pos.Bottom (systemTimerDemo), - Width = Dim.Percent (100), + pulseButton.Clicked += (s, e) => Pulse (); + var stopbutton = new Button ("Stop Timer") { + X = Pos.Right (pulseButton) + 2, + Y = Pos.Top (pulseButton), }; - mainLoopTimeoutDemo.StartBtnClick = () => { - mainLoopTimeoutDemo.StopBtnClick (); + stopbutton.Clicked += (s, e) => Stop (); - mainLoopTimeoutDemo.ActivityProgressBar.Fraction = 0F; - mainLoopTimeoutDemo.PulseProgressBar.Fraction = 0F; + Add (startButton); + Add (pulseButton); + Add (stopbutton); - _mainLoopTimeout = Application.AddTimeout (TimeSpan.FromMilliseconds (_mainLooopTimeoutTick), () => { - mainLoopTimeoutDemo.Pulse (); - - return true; - }); + ActivityProgressBar = new ProgressBar () { + X = Pos.Right (LeftFrame) + 1, + Y = Pos.Bottom (startButton) + 1, + Width = Dim.Fill () - 1, + Height = 1, + Fraction = 0.25F, + ColorScheme = Colors.Error }; - mainLoopTimeoutDemo.StopBtnClick = () => { - if (_mainLoopTimeout != null) { - Application.RemoveTimeout (_mainLoopTimeout); - _mainLoopTimeout = null; - } + Add (ActivityProgressBar); - mainLoopTimeoutDemo.ActivityProgressBar.Fraction = 1F; - mainLoopTimeoutDemo.PulseProgressBar.Fraction = 1F; + Spinner = new SpinnerView () { + Style = new SpinnerStyle.Dots2 (), + SpinReverse = true, + Y = ActivityProgressBar.Y, + Visible = false }; + ActivityProgressBar.Width = Dim.Fill () - Spinner.Width; + Spinner.X = Pos.Right (ActivityProgressBar); - mainLoopTimeoutDemo.Speed.Text = $"{_mainLooopTimeoutTick}"; - mainLoopTimeoutDemo.Speed.TextChanged += (s, a) => { - uint result; - if (uint.TryParse (mainLoopTimeoutDemo.Speed.Text, out result)) { - _mainLooopTimeoutTick = result; - if (mainLoopTimeoutDemo.Started) { - mainLoopTimeoutDemo.Start (); - } - } - }; - Win.Add (mainLoopTimeoutDemo); - var startBoth = new Button ("Start Both") { - X = Pos.Center (), - Y = Pos.Bottom(mainLoopTimeoutDemo) + 1, + Add (Spinner); + + PulseProgressBar = new ProgressBar () { + X = Pos.Right (LeftFrame) + 1, + Y = Pos.Bottom (ActivityProgressBar) + 1, + Width = Dim.Fill () - Spinner.Width, + Height = 1, + ColorScheme = Colors.Error }; - startBoth.Clicked += (s,e) => { - systemTimerDemo.Start (); - mainLoopTimeoutDemo.Start (); + Add (PulseProgressBar); + + _startedLabel = new Label ("Stopped") { + X = Pos.Right (LeftFrame) + 1, + Y = Pos.Bottom (PulseProgressBar), + }; + Add (_startedLabel); + + // TODO: Great use of Dim.Auto + Initialized += (s, e) => { + // Set height to height of controls + spacing + frame + Height = 2 + _verticalSpace + startButton.Frame.Height + _verticalSpace + ActivityProgressBar.Frame.Height + _verticalSpace + PulseProgressBar.Frame.Height + _verticalSpace; }; - Win.Add (startBoth); } - protected override void Dispose (bool disposing) + internal void Start () { - foreach (var v in Win.Subviews.OfType()) { - v?.StopBtnClick (); + Started = true; + StartBtnClick?.Invoke (); + Application.Invoke (() => { + Spinner.Visible = true; + ActivityProgressBar.Width = Dim.Fill () - Spinner.Width; + this.LayoutSubviews (); + }); + } + + internal void Stop () + { + Started = false; + StopBtnClick?.Invoke (); + + Application.Invoke (() => { + Spinner.Visible = false; + ActivityProgressBar.Width = Dim.Fill () - Spinner.Width; + this.LayoutSubviews (); + }); + } + + internal void Pulse () + { + Spinner.Visible = true; + if (PulseBtnClick != null) { + PulseBtnClick?.Invoke (); + + } else { + if (ActivityProgressBar.Fraction + 0.01F >= 1) { + ActivityProgressBar.Fraction = 0F; + } else { + ActivityProgressBar.Fraction += 0.01F; + } + PulseProgressBar.Pulse (); + Spinner.AdvanceAnimation (); } - base.Dispose (disposing); } } -} \ No newline at end of file + + private Timer _systemTimer = null; + private uint _systemTimerTick = 100; // ms + private object _mainLoopTimeout = null; + private uint _mainLooopTimeoutTick = 100; // ms + public override void Setup () + { + // Demo #1 - Use System.Timer (and threading) + var systemTimerDemo = new ProgressDemo ("System.Timer (threads)") { + X = 0, + Y = 0, + Width = Dim.Percent (100), + }; + systemTimerDemo.StartBtnClick = () => { + _systemTimer?.Dispose (); + _systemTimer = null; + + systemTimerDemo.ActivityProgressBar.Fraction = 0F; + systemTimerDemo.PulseProgressBar.Fraction = 0F; + + _systemTimer = new Timer ((o) => { + // Note the check for Mainloop being valid. System.Timers can run after they are Disposed. + // This code must be defensive for that. + Application.Invoke (() => systemTimerDemo.Pulse ()); + }, null, 0, _systemTimerTick); + }; + + systemTimerDemo.StopBtnClick = () => { + _systemTimer?.Dispose (); + _systemTimer = null; + + systemTimerDemo.ActivityProgressBar.Fraction = 1F; + systemTimerDemo.PulseProgressBar.Fraction = 1F; + }; + systemTimerDemo.Speed.Text = $"{_systemTimerTick}"; + systemTimerDemo.Speed.TextChanged += (s, a) => { + uint result; + if (uint.TryParse (systemTimerDemo.Speed.Text.ToString (), out result)) { + _systemTimerTick = result; + System.Diagnostics.Debug.WriteLine ($"{_systemTimerTick}"); + if (systemTimerDemo.Started) { + systemTimerDemo.Start (); + } + + } else { + System.Diagnostics.Debug.WriteLine ("bad entry"); + } + }; + Win.Add (systemTimerDemo); + + // Demo #2 - Use Application.AddTimeout (no threads) + var mainLoopTimeoutDemo = new ProgressDemo ("Application.AddTimer (no threads)") { + X = 0, + Y = Pos.Bottom (systemTimerDemo), + Width = Dim.Percent (100), + }; + mainLoopTimeoutDemo.StartBtnClick = () => { + mainLoopTimeoutDemo.StopBtnClick (); + + mainLoopTimeoutDemo.ActivityProgressBar.Fraction = 0F; + mainLoopTimeoutDemo.PulseProgressBar.Fraction = 0F; + + _mainLoopTimeout = Application.AddTimeout (TimeSpan.FromMilliseconds (_mainLooopTimeoutTick), () => { + mainLoopTimeoutDemo.Pulse (); + + return true; + }); + }; + mainLoopTimeoutDemo.StopBtnClick = () => { + if (_mainLoopTimeout != null) { + Application.RemoveTimeout (_mainLoopTimeout); + _mainLoopTimeout = null; + } + + mainLoopTimeoutDemo.ActivityProgressBar.Fraction = 1F; + mainLoopTimeoutDemo.PulseProgressBar.Fraction = 1F; + }; + + mainLoopTimeoutDemo.Speed.Text = $"{_mainLooopTimeoutTick}"; + mainLoopTimeoutDemo.Speed.TextChanged += (s, a) => { + uint result; + if (uint.TryParse (mainLoopTimeoutDemo.Speed.Text, out result)) { + _mainLooopTimeoutTick = result; + if (mainLoopTimeoutDemo.Started) { + mainLoopTimeoutDemo.Start (); + } + } + }; + Win.Add (mainLoopTimeoutDemo); + + var startBoth = new Button ("Start Both") { + X = Pos.Center (), + Y = Pos.Bottom (mainLoopTimeoutDemo) + 1, + }; + startBoth.Clicked += (s, e) => { + systemTimerDemo.Start (); + mainLoopTimeoutDemo.Start (); + }; + Win.Add (startBoth); + } + + protected override void Dispose (bool disposing) + { + foreach (var v in Win.Subviews.OfType ()) { + v?.StopBtnClick (); + } + base.Dispose (disposing); + } +} diff --git a/UnitTests/Views/LabelTests.cs b/UnitTests/Views/LabelTests.cs index 871b84b47..8ed3e6030 100644 --- a/UnitTests/Views/LabelTests.cs +++ b/UnitTests/Views/LabelTests.cs @@ -5,9 +5,9 @@ using Xunit.Abstractions; namespace Terminal.Gui.ViewsTests; public class LabelTests { - readonly ITestOutputHelper output; + readonly ITestOutputHelper _output; - public LabelTests (ITestOutputHelper output) => this.output = output; + public LabelTests (ITestOutputHelper output) => this._output = output; [Fact] [AutoInitShutdown] @@ -24,7 +24,7 @@ public class LabelTests { Assert.Equal (new Rect (0, 0, 0, 1), label.Frame); Assert.Equal (KeyCode.Null, label.HotKey); var expected = @""; - TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Application.End (rs); label = new Label ("ARGS") { Text = "Test" }; @@ -38,10 +38,10 @@ public class LabelTests { expected = @" Test "; - TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Application.End (rs); - label = new Label (3, 4, "Test"); + label = new Label ("Test") { X = 3, Y = 4 }; Assert.Equal ("Test", label.Text); Application.Top.Add (label); rs = Application.Begin (Application.Top); @@ -51,7 +51,7 @@ Test expected = @" Test "; - TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Application.End (rs); } @@ -102,7 +102,7 @@ Test │ │ └────────────────────────────┘ "; - var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (0, 0, 30, 5), pos); } @@ -141,7 +141,7 @@ Test └────────────────────────────┘ "; - var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (0, 0, 30, 5), pos); } @@ -178,7 +178,7 @@ Test └────────────────────────────┘ "; - TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); } [Fact] @@ -210,7 +210,7 @@ Test └────────────────────────────┘ "; - TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.True (label.AutoSize); label.Text = "Say Hello 你 changed"; @@ -224,7 +224,7 @@ Test └────────────────────────────┘ "; - TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); } [Fact] @@ -257,7 +257,7 @@ Test └────────────────────────────┘ "; - TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.True (label.AutoSize); label.Text = "Say Hello 你 changed"; @@ -271,7 +271,7 @@ Test └────────────────────────────┘ "; - TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); } [Fact] @@ -301,7 +301,7 @@ Test └────────────────────────────┘ "; - TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); } [Fact] @@ -333,7 +333,7 @@ Test │ │ └────────────────────────────┘ "; - TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); } [Fact] @@ -415,7 +415,7 @@ Test └───┘ "; - var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (0, 0, width + 2, height + 2), pos); } @@ -455,7 +455,7 @@ Test └────────┘ "; - var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (0, 0, width + 2, height + 2), pos); } @@ -511,7 +511,7 @@ Test └──────┘ "; - var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (0, 0, width + 2, height + 2), pos); } @@ -552,7 +552,7 @@ Test └────────┘ "; - var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (0, 0, width + 2, height + 2), pos); } @@ -577,7 +577,7 @@ Test "; Assert.Equal (new Rect (0, 0, width, 1), lblJust.Frame); - var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (0, 0, width + 2, 3), pos); } @@ -596,7 +596,7 @@ Test Demo Simple Rune "; - var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (0, 0, 16, 1), pos); } @@ -632,7 +632,7 @@ n e "; - var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (0, 0, 1, 16), pos); } @@ -651,7 +651,7 @@ e デモエムポンズ "; - var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (0, 0, 14, 1), pos); } @@ -675,7 +675,7 @@ e ズ "; - var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (0, 0, 2, 7), pos); } @@ -705,7 +705,7 @@ e ズ "; - var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (0, 0, 2, 7), pos); } @@ -761,7 +761,7 @@ e └────────────────────┘ "; - var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (0, 0, width + 2, 6), pos); } @@ -833,7 +833,7 @@ e └───────┘ "; - var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (0, 0, 9, height + 2), pos); } @@ -873,7 +873,7 @@ e └─────────────────────────┘ "; - var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (0, 0, width + 2, 6), pos); } @@ -933,7 +933,7 @@ e └───────────┘ "; - var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (0, 0, 13, height + 2), pos); } @@ -962,7 +962,7 @@ e This view needs to be cleared before rewritten. This TextFormatter (tf1) without fill will not be cleared on rewritten. This TextFormatter (tf2) with fill will be cleared on rewritten. -", output); +", _output); view.Text = "This view is rewritten."; view.Draw (); @@ -977,6 +977,6 @@ This TextFormatter (tf2) with fill will be cleared on rewritten. This view is rewritten. This TextFormatter (tf1) is rewritten.will not be cleared on rewritten. This TextFormatter (tf2) is rewritten. -", output); +", _output); } } \ No newline at end of file diff --git a/UnitTests/Views/ScrollViewTests.cs b/UnitTests/Views/ScrollViewTests.cs index f84d1d05f..226faa28c 100644 --- a/UnitTests/Views/ScrollViewTests.cs +++ b/UnitTests/Views/ScrollViewTests.cs @@ -1,200 +1,198 @@ -using Microsoft.VisualStudio.TestPlatform.Utilities; -using System.Text; -using Xunit; +using Xunit; using Xunit.Abstractions; -namespace Terminal.Gui.ViewsTests { - public class ScrollViewTests { - readonly ITestOutputHelper output; +namespace Terminal.Gui.ViewsTests; +public class ScrollViewTests { + readonly ITestOutputHelper _output; - public ScrollViewTests (ITestOutputHelper output) - { - this.output = output; - } + public ScrollViewTests (ITestOutputHelper output) + { + this._output = output; + } - [Fact] - public void Constructors_Defaults () - { - var sv = new ScrollView (); - Assert.Equal (LayoutStyle.Absolute, sv.LayoutStyle); - Assert.True (sv.CanFocus); - Assert.Equal (new Rect (0, 0, 0, 0), sv.Frame); - Assert.Equal (Rect.Empty, sv.Frame); - Assert.Equal (Point.Empty, sv.ContentOffset); - Assert.Equal (Size.Empty, sv.ContentSize); - Assert.True (sv.AutoHideScrollBars); - Assert.True (sv.KeepContentAlwaysInViewport); + [Fact] + public void Constructors_Defaults () + { + var sv = new ScrollView (); + Assert.Equal (LayoutStyle.Absolute, sv.LayoutStyle); + Assert.True (sv.CanFocus); + Assert.Equal (new Rect (0, 0, 0, 0), sv.Frame); + Assert.Equal (Rect.Empty, sv.Frame); + Assert.Equal (Point.Empty, sv.ContentOffset); + Assert.Equal (Size.Empty, sv.ContentSize); + Assert.True (sv.AutoHideScrollBars); + Assert.True (sv.KeepContentAlwaysInViewport); - sv = new ScrollView (new Rect (1, 2, 20, 10)); - Assert.Equal (LayoutStyle.Absolute, sv.LayoutStyle); - Assert.True (sv.CanFocus); - Assert.Equal (new Rect (1, 2, 20, 10), sv.Frame); - Assert.Equal (Point.Empty, sv.ContentOffset); - Assert.Equal (Size.Empty, sv.ContentSize); - Assert.True (sv.AutoHideScrollBars); - Assert.True (sv.KeepContentAlwaysInViewport); - } + sv = new ScrollView (new Rect (1, 2, 20, 10)); + Assert.Equal (LayoutStyle.Absolute, sv.LayoutStyle); + Assert.True (sv.CanFocus); + Assert.Equal (new Rect (1, 2, 20, 10), sv.Frame); + Assert.Equal (Point.Empty, sv.ContentOffset); + Assert.Equal (Size.Empty, sv.ContentSize); + Assert.True (sv.AutoHideScrollBars); + Assert.True (sv.KeepContentAlwaysInViewport); + } - [Fact] - public void Adding_Views () - { - var sv = new ScrollView (new Rect (0, 0, 20, 10)) { - ContentSize = new Size (30, 20) - }; - sv.Add (new View () { Width = 10, Height = 5 }, - new View () { X = 12, Y = 7, Width = 10, Height = 5 }); + [Fact] + public void Adding_Views () + { + var sv = new ScrollView (new Rect (0, 0, 20, 10)) { + ContentSize = new Size (30, 20) + }; + sv.Add (new View () { Width = 10, Height = 5 }, + new View () { X = 12, Y = 7, Width = 10, Height = 5 }); - Assert.Equal (new Size (30, 20), sv.ContentSize); - Assert.Equal (2, sv.Subviews [0].Subviews.Count); - } + Assert.Equal (new Size (30, 20), sv.ContentSize); + Assert.Equal (2, sv.Subviews [0].Subviews.Count); + } - [Fact] - public void KeyBindings_Command () - { - var sv = new ScrollView (new Rect (0, 0, 20, 10)) { - ContentSize = new Size (40, 20) - }; - sv.Add (new View () { Width = 20, Height = 5 }, - new View () { X = 22, Y = 7, Width = 10, Height = 5 }); + [Fact] + public void KeyBindings_Command () + { + var sv = new ScrollView (new Rect (0, 0, 20, 10)) { + ContentSize = new Size (40, 20) + }; + sv.Add (new View () { Width = 20, Height = 5 }, + new View () { X = 22, Y = 7, Width = 10, Height = 5 }); - sv.BeginInit (); sv.EndInit (); + sv.BeginInit (); sv.EndInit (); - Assert.True (sv.KeepContentAlwaysInViewport); - Assert.True (sv.AutoHideScrollBars); - Assert.Equal (new Point (0, 0), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new (KeyCode.CursorUp))); - Assert.Equal (new Point (0, 0), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new (KeyCode.CursorDown))); - Assert.Equal (new Point (0, -1), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new (KeyCode.CursorUp))); - Assert.Equal (new Point (0, 0), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new (KeyCode.PageUp))); - Assert.Equal (new Point (0, 0), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new (KeyCode.PageDown))); - Assert.Equal (new Point (0, -10), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new (KeyCode.PageDown))); - Assert.Equal (new Point (0, -10), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new (KeyCode.CursorDown))); - Assert.Equal (new Point (0, -10), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new ((KeyCode)'v' | KeyCode.AltMask))); - Assert.Equal (new Point (0, 0), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new (KeyCode.V | KeyCode.CtrlMask))); - Assert.Equal (new Point (0, -10), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new (KeyCode.CursorLeft))); - Assert.Equal (new Point (0, -10), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new (KeyCode.CursorRight))); - Assert.Equal (new Point (-1, -10), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new (KeyCode.CursorLeft))); - Assert.Equal (new Point (0, -10), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new (KeyCode.PageUp | KeyCode.CtrlMask))); - Assert.Equal (new Point (0, -10), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new (KeyCode.PageDown | KeyCode.CtrlMask))); - Assert.Equal (new Point (-20, -10), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new (KeyCode.CursorRight))); - Assert.Equal (new Point (-20, -10), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new (KeyCode.Home))); - Assert.Equal (new Point (-20, 0), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new (KeyCode.Home))); - Assert.Equal (new Point (-20, 0), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new (KeyCode.End))); - Assert.Equal (new Point (-20, -10), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new (KeyCode.End))); - Assert.Equal (new Point (-20, -10), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new (KeyCode.Home | KeyCode.CtrlMask))); - Assert.Equal (new Point (0, -10), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new (KeyCode.Home | KeyCode.CtrlMask))); - Assert.Equal (new Point (0, -10), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new (KeyCode.End | KeyCode.CtrlMask))); - Assert.Equal (new Point (-20, -10), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new (KeyCode.End | KeyCode.CtrlMask))); - Assert.Equal (new Point (-20, -10), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new (KeyCode.Home))); - Assert.Equal (new Point (-20, 0), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new (KeyCode.Home | KeyCode.CtrlMask))); - Assert.Equal (new Point (0, 0), sv.ContentOffset); + Assert.True (sv.KeepContentAlwaysInViewport); + Assert.True (sv.AutoHideScrollBars); + Assert.Equal (new Point (0, 0), sv.ContentOffset); + Assert.False (sv.OnKeyDown (new (KeyCode.CursorUp))); + Assert.Equal (new Point (0, 0), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new (KeyCode.CursorDown))); + Assert.Equal (new Point (0, -1), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new (KeyCode.CursorUp))); + Assert.Equal (new Point (0, 0), sv.ContentOffset); + Assert.False (sv.OnKeyDown (new (KeyCode.PageUp))); + Assert.Equal (new Point (0, 0), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new (KeyCode.PageDown))); + Assert.Equal (new Point (0, -10), sv.ContentOffset); + Assert.False (sv.OnKeyDown (new (KeyCode.PageDown))); + Assert.Equal (new Point (0, -10), sv.ContentOffset); + Assert.False (sv.OnKeyDown (new (KeyCode.CursorDown))); + Assert.Equal (new Point (0, -10), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new ((KeyCode)'v' | KeyCode.AltMask))); + Assert.Equal (new Point (0, 0), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new (KeyCode.V | KeyCode.CtrlMask))); + Assert.Equal (new Point (0, -10), sv.ContentOffset); + Assert.False (sv.OnKeyDown (new (KeyCode.CursorLeft))); + Assert.Equal (new Point (0, -10), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new (KeyCode.CursorRight))); + Assert.Equal (new Point (-1, -10), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new (KeyCode.CursorLeft))); + Assert.Equal (new Point (0, -10), sv.ContentOffset); + Assert.False (sv.OnKeyDown (new (KeyCode.PageUp | KeyCode.CtrlMask))); + Assert.Equal (new Point (0, -10), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new (KeyCode.PageDown | KeyCode.CtrlMask))); + Assert.Equal (new Point (-20, -10), sv.ContentOffset); + Assert.False (sv.OnKeyDown (new (KeyCode.CursorRight))); + Assert.Equal (new Point (-20, -10), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new (KeyCode.Home))); + Assert.Equal (new Point (-20, 0), sv.ContentOffset); + Assert.False (sv.OnKeyDown (new (KeyCode.Home))); + Assert.Equal (new Point (-20, 0), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new (KeyCode.End))); + Assert.Equal (new Point (-20, -10), sv.ContentOffset); + Assert.False (sv.OnKeyDown (new (KeyCode.End))); + Assert.Equal (new Point (-20, -10), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new (KeyCode.Home | KeyCode.CtrlMask))); + Assert.Equal (new Point (0, -10), sv.ContentOffset); + Assert.False (sv.OnKeyDown (new (KeyCode.Home | KeyCode.CtrlMask))); + Assert.Equal (new Point (0, -10), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new (KeyCode.End | KeyCode.CtrlMask))); + Assert.Equal (new Point (-20, -10), sv.ContentOffset); + Assert.False (sv.OnKeyDown (new (KeyCode.End | KeyCode.CtrlMask))); + Assert.Equal (new Point (-20, -10), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new (KeyCode.Home))); + Assert.Equal (new Point (-20, 0), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new (KeyCode.Home | KeyCode.CtrlMask))); + Assert.Equal (new Point (0, 0), sv.ContentOffset); - sv.KeepContentAlwaysInViewport = false; - Assert.False (sv.KeepContentAlwaysInViewport); - Assert.True (sv.AutoHideScrollBars); - Assert.Equal (new Point (0, 0), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new (KeyCode.CursorUp))); - Assert.Equal (new Point (0, 0), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new (KeyCode.CursorDown))); - Assert.Equal (new Point (0, -1), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new (KeyCode.CursorUp))); - Assert.Equal (new Point (0, 0), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new (KeyCode.PageUp))); - Assert.Equal (new Point (0, 0), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new (KeyCode.PageDown))); - Assert.Equal (new Point (0, -10), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new (KeyCode.PageDown))); - Assert.Equal (new Point (0, -19), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new (KeyCode.PageDown))); - Assert.Equal (new Point (0, -19), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new (KeyCode.CursorDown))); - Assert.Equal (new Point (0, -19), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new ((KeyCode)'v' | KeyCode.AltMask))); - Assert.Equal (new Point (0, -9), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new (KeyCode.V | KeyCode.CtrlMask))); - Assert.Equal (new Point (0, -19), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new (KeyCode.CursorLeft))); - Assert.Equal (new Point (0, -19), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new (KeyCode.CursorRight))); - Assert.Equal (new Point (-1, -19), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new (KeyCode.CursorLeft))); - Assert.Equal (new Point (0, -19), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new (KeyCode.PageUp | KeyCode.CtrlMask))); - Assert.Equal (new Point (0, -19), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new (KeyCode.PageDown | KeyCode.CtrlMask))); - Assert.Equal (new Point (-20, -19), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new (KeyCode.PageDown | KeyCode.CtrlMask))); - Assert.Equal (new Point (-39, -19), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new (KeyCode.PageDown | KeyCode.CtrlMask))); - Assert.Equal (new Point (-39, -19), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new (KeyCode.CursorRight))); - Assert.Equal (new Point (-39, -19), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new (KeyCode.PageUp | KeyCode.CtrlMask))); - Assert.Equal (new Point (-19, -19), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new (KeyCode.Home))); - Assert.Equal (new Point (-19, 0), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new (KeyCode.Home))); - Assert.Equal (new Point (-19, 0), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new (KeyCode.End))); - Assert.Equal (new Point (-19, -19), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new (KeyCode.End))); - Assert.Equal (new Point (-19, -19), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new (KeyCode.Home | KeyCode.CtrlMask))); - Assert.Equal (new Point (0, -19), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new (KeyCode.Home | KeyCode.CtrlMask))); - Assert.Equal (new Point (0, -19), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new (KeyCode.End | KeyCode.CtrlMask))); - Assert.Equal (new Point (-39, -19), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new (KeyCode.End | KeyCode.CtrlMask))); - Assert.Equal (new Point (-39, -19), sv.ContentOffset); - } + sv.KeepContentAlwaysInViewport = false; + Assert.False (sv.KeepContentAlwaysInViewport); + Assert.True (sv.AutoHideScrollBars); + Assert.Equal (new Point (0, 0), sv.ContentOffset); + Assert.False (sv.OnKeyDown (new (KeyCode.CursorUp))); + Assert.Equal (new Point (0, 0), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new (KeyCode.CursorDown))); + Assert.Equal (new Point (0, -1), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new (KeyCode.CursorUp))); + Assert.Equal (new Point (0, 0), sv.ContentOffset); + Assert.False (sv.OnKeyDown (new (KeyCode.PageUp))); + Assert.Equal (new Point (0, 0), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new (KeyCode.PageDown))); + Assert.Equal (new Point (0, -10), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new (KeyCode.PageDown))); + Assert.Equal (new Point (0, -19), sv.ContentOffset); + Assert.False (sv.OnKeyDown (new (KeyCode.PageDown))); + Assert.Equal (new Point (0, -19), sv.ContentOffset); + Assert.False (sv.OnKeyDown (new (KeyCode.CursorDown))); + Assert.Equal (new Point (0, -19), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new ((KeyCode)'v' | KeyCode.AltMask))); + Assert.Equal (new Point (0, -9), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new (KeyCode.V | KeyCode.CtrlMask))); + Assert.Equal (new Point (0, -19), sv.ContentOffset); + Assert.False (sv.OnKeyDown (new (KeyCode.CursorLeft))); + Assert.Equal (new Point (0, -19), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new (KeyCode.CursorRight))); + Assert.Equal (new Point (-1, -19), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new (KeyCode.CursorLeft))); + Assert.Equal (new Point (0, -19), sv.ContentOffset); + Assert.False (sv.OnKeyDown (new (KeyCode.PageUp | KeyCode.CtrlMask))); + Assert.Equal (new Point (0, -19), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new (KeyCode.PageDown | KeyCode.CtrlMask))); + Assert.Equal (new Point (-20, -19), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new (KeyCode.PageDown | KeyCode.CtrlMask))); + Assert.Equal (new Point (-39, -19), sv.ContentOffset); + Assert.False (sv.OnKeyDown (new (KeyCode.PageDown | KeyCode.CtrlMask))); + Assert.Equal (new Point (-39, -19), sv.ContentOffset); + Assert.False (sv.OnKeyDown (new (KeyCode.CursorRight))); + Assert.Equal (new Point (-39, -19), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new (KeyCode.PageUp | KeyCode.CtrlMask))); + Assert.Equal (new Point (-19, -19), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new (KeyCode.Home))); + Assert.Equal (new Point (-19, 0), sv.ContentOffset); + Assert.False (sv.OnKeyDown (new (KeyCode.Home))); + Assert.Equal (new Point (-19, 0), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new (KeyCode.End))); + Assert.Equal (new Point (-19, -19), sv.ContentOffset); + Assert.False (sv.OnKeyDown (new (KeyCode.End))); + Assert.Equal (new Point (-19, -19), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new (KeyCode.Home | KeyCode.CtrlMask))); + Assert.Equal (new Point (0, -19), sv.ContentOffset); + Assert.False (sv.OnKeyDown (new (KeyCode.Home | KeyCode.CtrlMask))); + Assert.Equal (new Point (0, -19), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new (KeyCode.End | KeyCode.CtrlMask))); + Assert.Equal (new Point (-39, -19), sv.ContentOffset); + Assert.False (sv.OnKeyDown (new (KeyCode.End | KeyCode.CtrlMask))); + Assert.Equal (new Point (-39, -19), sv.ContentOffset); + } - [Fact, AutoInitShutdown] - public void AutoHideScrollBars_False_ShowHorizontalScrollIndicator_ShowVerticalScrollIndicator () - { - var sv = new ScrollView { - Width = 10, - Height = 10, - AutoHideScrollBars = false - }; + [Fact, AutoInitShutdown] + public void AutoHideScrollBars_False_ShowHorizontalScrollIndicator_ShowVerticalScrollIndicator () + { + var sv = new ScrollView { + Width = 10, + Height = 10, + AutoHideScrollBars = false + }; - sv.ShowHorizontalScrollIndicator = true; - sv.ShowVerticalScrollIndicator = true; + sv.ShowHorizontalScrollIndicator = true; + sv.ShowVerticalScrollIndicator = true; - Application.Top.Add (sv); - Application.Begin (Application.Top); + Application.Top.Add (sv); + Application.Begin (Application.Top); - Assert.Equal (new Rect (0, 0, 10, 10), sv.Bounds); + Assert.Equal (new Rect (0, 0, 10, 10), sv.Bounds); - Assert.False (sv.AutoHideScrollBars); - Assert.True (sv.ShowHorizontalScrollIndicator); - Assert.True (sv.ShowVerticalScrollIndicator); - sv.Draw (); - TestHelpers.AssertDriverContentsAre (@" + Assert.False (sv.AutoHideScrollBars); + Assert.True (sv.ShowHorizontalScrollIndicator); + Assert.True (sv.ShowVerticalScrollIndicator); + sv.Draw (); + TestHelpers.AssertDriverContentsAre (@" ▲ ┬ │ @@ -205,18 +203,18 @@ namespace Terminal.Gui.ViewsTests { ┴ ▼ ◄├─────┤► -", output); +", _output); - sv.ShowHorizontalScrollIndicator = false; - Assert.Equal (new Rect (0, 0, 10, 10), sv.Bounds); - sv.ShowVerticalScrollIndicator = true; - Assert.Equal (new Rect (0, 0, 10, 10), sv.Bounds); + sv.ShowHorizontalScrollIndicator = false; + Assert.Equal (new Rect (0, 0, 10, 10), sv.Bounds); + sv.ShowVerticalScrollIndicator = true; + Assert.Equal (new Rect (0, 0, 10, 10), sv.Bounds); - Assert.False (sv.AutoHideScrollBars); - Assert.False (sv.ShowHorizontalScrollIndicator); - Assert.True (sv.ShowVerticalScrollIndicator); - sv.Draw (); - TestHelpers.AssertDriverContentsAre (@" + Assert.False (sv.AutoHideScrollBars); + Assert.False (sv.ShowHorizontalScrollIndicator); + Assert.True (sv.ShowVerticalScrollIndicator); + sv.Draw (); + TestHelpers.AssertDriverContentsAre (@" ▲ ┬ │ @@ -227,16 +225,16 @@ namespace Terminal.Gui.ViewsTests { │ ┴ ▼ -", output); +", _output); - sv.ShowHorizontalScrollIndicator = true; - sv.ShowVerticalScrollIndicator = false; + sv.ShowHorizontalScrollIndicator = true; + sv.ShowVerticalScrollIndicator = false; - Assert.False (sv.AutoHideScrollBars); - Assert.True (sv.ShowHorizontalScrollIndicator); - Assert.False (sv.ShowVerticalScrollIndicator); - sv.Draw (); - TestHelpers.AssertDriverContentsAre (@" + Assert.False (sv.AutoHideScrollBars); + Assert.True (sv.ShowHorizontalScrollIndicator); + Assert.False (sv.ShowVerticalScrollIndicator); + sv.Draw (); + TestHelpers.AssertDriverContentsAre (@" @@ -247,16 +245,16 @@ namespace Terminal.Gui.ViewsTests { ◄├──────┤► -", output); +", _output); - sv.ShowHorizontalScrollIndicator = false; - sv.ShowVerticalScrollIndicator = false; + sv.ShowHorizontalScrollIndicator = false; + sv.ShowVerticalScrollIndicator = false; - Assert.False (sv.AutoHideScrollBars); - Assert.False (sv.ShowHorizontalScrollIndicator); - Assert.False (sv.ShowVerticalScrollIndicator); - sv.Draw (); - TestHelpers.AssertDriverContentsAre (@" + Assert.False (sv.AutoHideScrollBars); + Assert.False (sv.ShowHorizontalScrollIndicator); + Assert.False (sv.ShowVerticalScrollIndicator); + sv.Draw (); + TestHelpers.AssertDriverContentsAre (@" @@ -267,31 +265,31 @@ namespace Terminal.Gui.ViewsTests { -", output); - } +", _output); + } - [Fact, AutoInitShutdown] - public void AutoHideScrollBars_ShowHorizontalScrollIndicator_ShowVerticalScrollIndicator () - { - var sv = new ScrollView { - Width = 10, - Height = 10 - }; + [Fact, AutoInitShutdown] + public void AutoHideScrollBars_ShowHorizontalScrollIndicator_ShowVerticalScrollIndicator () + { + var sv = new ScrollView { + Width = 10, + Height = 10 + }; - Application.Top.Add (sv); - Application.Begin (Application.Top); + Application.Top.Add (sv); + Application.Begin (Application.Top); - Assert.True (sv.AutoHideScrollBars); - Assert.False (sv.ShowHorizontalScrollIndicator); - Assert.False (sv.ShowVerticalScrollIndicator); - TestHelpers.AssertDriverContentsWithFrameAre ("", output); + Assert.True (sv.AutoHideScrollBars); + Assert.False (sv.ShowHorizontalScrollIndicator); + Assert.False (sv.ShowVerticalScrollIndicator); + TestHelpers.AssertDriverContentsWithFrameAre ("", _output); - sv.AutoHideScrollBars = false; - sv.ShowHorizontalScrollIndicator = true; - sv.ShowVerticalScrollIndicator = true; - sv.LayoutSubviews (); - sv.Draw (); - TestHelpers.AssertDriverContentsWithFrameAre (@" + sv.AutoHideScrollBars = false; + sv.ShowHorizontalScrollIndicator = true; + sv.ShowVerticalScrollIndicator = true; + sv.LayoutSubviews (); + sv.Draw (); + TestHelpers.AssertDriverContentsWithFrameAre (@" ▲ ┬ │ @@ -302,27 +300,27 @@ namespace Terminal.Gui.ViewsTests { ┴ ▼ ◄├─────┤► -", output); - } +", _output); + } - [Fact, AutoInitShutdown] - public void ContentSize_AutoHideScrollBars_ShowHorizontalScrollIndicator_ShowVerticalScrollIndicator () - { - var sv = new ScrollView { - Width = 10, - Height = 10, - ContentSize = new Size (50, 50) - }; + [Fact, AutoInitShutdown] + public void ContentSize_AutoHideScrollBars_ShowHorizontalScrollIndicator_ShowVerticalScrollIndicator () + { + var sv = new ScrollView { + Width = 10, + Height = 10, + ContentSize = new Size (50, 50) + }; - Application.Top.Add (sv); - Application.Begin (Application.Top); + Application.Top.Add (sv); + Application.Begin (Application.Top); - Assert.Equal (50, sv.ContentSize.Width); - Assert.Equal (50, sv.ContentSize.Height); - Assert.True (sv.AutoHideScrollBars); - Assert.True (sv.ShowHorizontalScrollIndicator); - Assert.True (sv.ShowVerticalScrollIndicator); - TestHelpers.AssertDriverContentsWithFrameAre (@" + Assert.Equal (50, sv.ContentSize.Width); + Assert.Equal (50, sv.ContentSize.Height); + Assert.True (sv.AutoHideScrollBars); + Assert.True (sv.ShowHorizontalScrollIndicator); + Assert.True (sv.ShowVerticalScrollIndicator); + TestHelpers.AssertDriverContentsWithFrameAre (@" ▲ ┬ ┴ @@ -333,30 +331,30 @@ namespace Terminal.Gui.ViewsTests { ░ ▼ ◄├┤░░░░░► -", output); - } +", _output); + } - [Fact, AutoInitShutdown] - public void ContentOffset_ContentSize_AutoHideScrollBars_ShowHorizontalScrollIndicator_ShowVerticalScrollIndicator () - { - var sv = new ScrollView { - Width = 10, - Height = 10, - ContentSize = new Size (50, 50), - ContentOffset = new Point (25, 25) - }; + [Fact, AutoInitShutdown] + public void ContentOffset_ContentSize_AutoHideScrollBars_ShowHorizontalScrollIndicator_ShowVerticalScrollIndicator () + { + var sv = new ScrollView { + Width = 10, + Height = 10, + ContentSize = new Size (50, 50), + ContentOffset = new Point (25, 25) + }; - Application.Top.Add (sv); - Application.Begin (Application.Top); + Application.Top.Add (sv); + Application.Begin (Application.Top); - Assert.Equal (-25, sv.ContentOffset.X); - Assert.Equal (-25, sv.ContentOffset.Y); - Assert.Equal (50, sv.ContentSize.Width); - Assert.Equal (50, sv.ContentSize.Height); - Assert.True (sv.AutoHideScrollBars); - Assert.True (sv.ShowHorizontalScrollIndicator); - Assert.True (sv.ShowVerticalScrollIndicator); - TestHelpers.AssertDriverContentsWithFrameAre (@" + Assert.Equal (-25, sv.ContentOffset.X); + Assert.Equal (-25, sv.ContentOffset.Y); + Assert.Equal (50, sv.ContentSize.Width); + Assert.Equal (50, sv.ContentSize.Height); + Assert.True (sv.AutoHideScrollBars); + Assert.True (sv.ShowHorizontalScrollIndicator); + Assert.True (sv.ShowVerticalScrollIndicator); + TestHelpers.AssertDriverContentsWithFrameAre (@" ▲ ░ ░ @@ -367,27 +365,27 @@ namespace Terminal.Gui.ViewsTests { ░ ▼ ◄░░░├─┤░► -", output); +", _output); + } + + // There still have an issue with lower right corner of the scroll view + [Fact, AutoInitShutdown] + public void Frame_And_Labels_Does_Not_Overspill_ScrollView () + { + var sv = new ScrollView { + X = 3, + Y = 3, + Width = 10, + Height = 10, + ContentSize = new Size (50, 50) + }; + for (int i = 0; i < 8; i++) { + sv.Add (new CustomButton ("█", $"Button {i}", 20, 3) { Y = i * 3 }); } + Application.Top.Add (sv); + Application.Begin (Application.Top); - // There still have an issue with lower right corner of the scroll view - [Fact, AutoInitShutdown] - public void Frame_And_Labels_Does_Not_Overspill_ScrollView () - { - var sv = new ScrollView { - X = 3, - Y = 3, - Width = 10, - Height = 10, - ContentSize = new Size (50, 50) - }; - for (int i = 0; i < 8; i++) { - sv.Add (new CustomButton ("█", $"Button {i}", 20, 3) { Y = i * 3 }); - } - Application.Top.Add (sv); - Application.Begin (Application.Top); - - TestHelpers.AssertDriverContentsWithFrameAre (@" + TestHelpers.AssertDriverContentsWithFrameAre (@" █████████▲ ██████But┬ █████████┴ @@ -397,12 +395,12 @@ namespace Terminal.Gui.ViewsTests { ┌────────░ │ But░ └────────▼ - ◄├┤░░░░░►─", output); + ◄├┤░░░░░►─", _output); - sv.ContentOffset = new Point (5, 5); - sv.LayoutSubviews (); - Application.Refresh (); - TestHelpers.AssertDriverContentsWithFrameAre (@" + sv.ContentOffset = new Point (5, 5); + sv.LayoutSubviews (); + Application.Refresh (); + TestHelpers.AssertDriverContentsWithFrameAre (@" ─────────▲ ─────────┬ Button 2│ @@ -412,74 +410,74 @@ namespace Terminal.Gui.ViewsTests { ─────────░ ─────────░ Button 4▼ - ◄├─┤░░░░►─", output); - } + ◄├─┤░░░░►─", _output); + } - private class CustomButton : FrameView { - private Label labelFill; - private Label labelText; + private class CustomButton : FrameView { + private Label labelFill; + private Label labelText; - public CustomButton (string fill, string text, int width, int height) : base () - { - Width = width; - Height = height; - //labelFill = new Label () { AutoSize = false, X = Pos.Center (), Y = Pos.Center (), Width = Dim.Fill (), Height = Dim.Fill (), Visible = false }; - labelFill = new Label () { AutoSize = false, Width = Dim.Fill (), Height = Dim.Fill (), Visible = false }; - labelFill.LayoutComplete += (s, e) => { - var fillText = new System.Text.StringBuilder (); - for (int i = 0; i < labelFill.Bounds.Height; i++) { - if (i > 0) { - fillText.AppendLine (""); - } - for (int j = 0; j < labelFill.Bounds.Width; j++) { - fillText.Append (fill); - } - } - labelFill.Text = fillText.ToString (); - }; - - labelText = new Label (text) { X = Pos.Center (), Y = Pos.Center () }; - Add (labelFill, labelText); - CanFocus = true; - } - - public override bool OnEnter (View view) - { - Border.LineStyle = LineStyle.None; - Border.Thickness = new Thickness (0); - labelFill.Visible = true; - view = this; - return base.OnEnter (view); - } - - public override bool OnLeave (View view) - { - Border.LineStyle = LineStyle.Single; - Border.Thickness = new Thickness (1); - labelFill.Visible = false; - if (view == null) - view = this; - return base.OnLeave (view); - } - } - // There are still issue with the lower right corner of the scroll view - [Fact, AutoInitShutdown] - public void Clear_Window_Inside_ScrollView () + public CustomButton (string fill, string text, int width, int height) : base () { - var topLabel = new Label ("At 15,0") { X = 15 }; - var sv = new ScrollView { - X = 3, - Y = 3, - Width = 10, - Height = 10, - ContentSize = new Size (23, 23), - KeepContentAlwaysInViewport = false + Width = width; + Height = height; + //labelFill = new Label () { AutoSize = false, X = Pos.Center (), Y = Pos.Center (), Width = Dim.Fill (), Height = Dim.Fill (), Visible = false }; + labelFill = new Label () { AutoSize = false, Width = Dim.Fill (), Height = Dim.Fill (), Visible = false }; + labelFill.LayoutComplete += (s, e) => { + var fillText = new System.Text.StringBuilder (); + for (int i = 0; i < labelFill.Bounds.Height; i++) { + if (i > 0) { + fillText.AppendLine (""); + } + for (int j = 0; j < labelFill.Bounds.Width; j++) { + fillText.Append (fill); + } + } + labelFill.Text = fillText.ToString (); }; - var bottomLabel = new Label ("At 15,15") { X = 15, Y = 15 }; - Application.Top.Add (topLabel, sv, bottomLabel); - Application.Begin (Application.Top); - TestHelpers.AssertDriverContentsWithFrameAre (@" + labelText = new Label (text) { X = Pos.Center (), Y = Pos.Center () }; + Add (labelFill, labelText); + CanFocus = true; + } + + public override bool OnEnter (View view) + { + Border.LineStyle = LineStyle.None; + Border.Thickness = new Thickness (0); + labelFill.Visible = true; + view = this; + return base.OnEnter (view); + } + + public override bool OnLeave (View view) + { + Border.LineStyle = LineStyle.Single; + Border.Thickness = new Thickness (1); + labelFill.Visible = false; + if (view == null) + view = this; + return base.OnLeave (view); + } + } + // There are still issue with the lower right corner of the scroll view + [Fact, AutoInitShutdown] + public void Clear_Window_Inside_ScrollView () + { + var topLabel = new Label ("At 15,0") { X = 15 }; + var sv = new ScrollView { + X = 3, + Y = 3, + Width = 10, + Height = 10, + ContentSize = new Size (23, 23), + KeepContentAlwaysInViewport = false + }; + var bottomLabel = new Label ("At 15,15") { X = 15, Y = 15 }; + Application.Top.Add (topLabel, sv, bottomLabel); + Application.Begin (Application.Top); + + TestHelpers.AssertDriverContentsWithFrameAre (@" At 15,0 @@ -495,15 +493,15 @@ namespace Terminal.Gui.ViewsTests { ◄├┤░░░░░► - At 15,15", output); + At 15,15", _output); - var attributes = new Attribute [] { + var attributes = new Attribute [] { Colors.TopLevel.Normal, Colors.TopLevel.Focus, Colors.Base.Normal }; - TestHelpers.AssertDriverAttributesAre (@" + TestHelpers.AssertDriverAttributesAre (@" 00000000000000000000000 00000000000000000000000 00000000000000000000000 @@ -521,10 +519,10 @@ namespace Terminal.Gui.ViewsTests { 00000000000000000000000 00000000000000000000000", null, attributes); - sv.Add (new Window { X = 3, Y = 3, Width = 20, Height = 20 }); + sv.Add (new Window { X = 3, Y = 3, Width = 20, Height = 20 }); - Application.Refresh (); - TestHelpers.AssertDriverContentsWithFrameAre (@" + Application.Refresh (); + TestHelpers.AssertDriverContentsWithFrameAre (@" At 15,0 @@ -540,9 +538,9 @@ namespace Terminal.Gui.ViewsTests { ◄├┤░░░░░► - At 15,15", output); + At 15,15", _output); - TestHelpers.AssertDriverAttributesAre (@" + TestHelpers.AssertDriverAttributesAre (@" 00000000000000000000000 00000000000000000000000 00000000000000000000000 @@ -560,9 +558,9 @@ namespace Terminal.Gui.ViewsTests { 00000000000000000000000 00000000000000000000000", null, attributes); - sv.ContentOffset = new Point (20, 20); - Application.Refresh (); - TestHelpers.AssertDriverContentsWithFrameAre (@" + sv.ContentOffset = new Point (20, 20); + Application.Refresh (); + TestHelpers.AssertDriverContentsWithFrameAre (@" At 15,0 @@ -578,9 +576,9 @@ namespace Terminal.Gui.ViewsTests { ◄░░░░├─┤► - At 15,15", output); + At 15,15", _output); - TestHelpers.AssertDriverAttributesAre (@" + TestHelpers.AssertDriverAttributesAre (@" 00000000000000000000000 00000000000000000000000 00000000000000000000000 @@ -597,29 +595,29 @@ namespace Terminal.Gui.ViewsTests { 00000000000000000000000 00000000000000000000000 00000000000000000000000", null, attributes); - } + } - [Fact, AutoInitShutdown] - public void DrawTextFormatter_Respects_The_Clip_Bounds () - { - var rule = "0123456789"; - var size = new Size (40, 40); - var view = new View (new Rect (Point.Empty, size)); - view.Add (new Label (rule.Repeat (size.Width / rule.Length)) { AutoSize = false, Width = Dim.Fill () }); - view.Add (new Label (rule.Repeat (size.Height / rule.Length), TextDirection.TopBottom_LeftRight) { Height = Dim.Fill (), AutoSize = false }); - view.Add (new Label (1, 1, "[ Press me! ]")); - var scrollView = new ScrollView (new Rect (1, 1, 15, 10)) { - ContentSize = size, - ShowHorizontalScrollIndicator = true, - ShowVerticalScrollIndicator = true - }; - scrollView.Add (view); - var win = new Window (new Rect (1, 1, 20, 14)); - win.Add (scrollView); - Application.Top.Add (win); - Application.Begin (Application.Top); + [Fact, AutoInitShutdown] + public void DrawTextFormatter_Respects_The_Clip_Bounds () + { + var rule = "0123456789"; + var size = new Size (40, 40); + var view = new View (new Rect (Point.Empty, size)); + view.Add (new Label (rule.Repeat (size.Width / rule.Length)) { AutoSize = false, Width = Dim.Fill () }); + view.Add (new Label (rule.Repeat (size.Height / rule.Length), TextDirection.TopBottom_LeftRight) { Height = Dim.Fill (), AutoSize = false }); + view.Add (new Label ("[ Press me! ]") { X = 1, Y = 1 }); + var scrollView = new ScrollView (new Rect (1, 1, 15, 10)) { + ContentSize = size, + ShowHorizontalScrollIndicator = true, + ShowVerticalScrollIndicator = true + }; + scrollView.Add (view); + var win = new Window (new Rect (1, 1, 20, 14)); + win.Add (scrollView); + Application.Top.Add (win); + Application.Begin (Application.Top); - var expected = @" + var expected = @" ┌──────────────────┐ │ │ │ 01234567890123▲ │ @@ -635,15 +633,15 @@ namespace Terminal.Gui.ViewsTests { │ │ └──────────────────┘ " - ; + ; - var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - Assert.Equal (new Rect (1, 1, 21, 14), pos); + var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); + Assert.Equal (new Rect (1, 1, 21, 14), pos); - Assert.True (scrollView.OnKeyDown (new (KeyCode.CursorRight))); - Application.Top.Draw (); + Assert.True (scrollView.OnKeyDown (new (KeyCode.CursorRight))); + Application.Top.Draw (); - expected = @" + expected = @" ┌──────────────────┐ │ │ │ 12345678901234▲ │ @@ -659,15 +657,15 @@ namespace Terminal.Gui.ViewsTests { │ │ └──────────────────┘ " - ; + ; - pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - Assert.Equal (new Rect (1, 1, 21, 14), pos); + pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); + Assert.Equal (new Rect (1, 1, 21, 14), pos); - Assert.True (scrollView.OnKeyDown (new (KeyCode.CursorRight))); - Application.Top.Draw (); + Assert.True (scrollView.OnKeyDown (new (KeyCode.CursorRight))); + Application.Top.Draw (); - expected = @" + expected = @" ┌──────────────────┐ │ │ │ 23456789012345▲ │ @@ -683,15 +681,15 @@ namespace Terminal.Gui.ViewsTests { │ │ └──────────────────┘ " - ; + ; - pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - Assert.Equal (new Rect (1, 1, 21, 14), pos); + pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); + Assert.Equal (new Rect (1, 1, 21, 14), pos); - Assert.True (scrollView.OnKeyDown (new (KeyCode.CursorRight))); - Application.Top.Draw (); + Assert.True (scrollView.OnKeyDown (new (KeyCode.CursorRight))); + Application.Top.Draw (); - expected = @" + expected = @" ┌──────────────────┐ │ │ │ 34567890123456▲ │ @@ -707,15 +705,15 @@ namespace Terminal.Gui.ViewsTests { │ │ └──────────────────┘ " - ; + ; - pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - Assert.Equal (new Rect (1, 1, 21, 14), pos); + pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); + Assert.Equal (new Rect (1, 1, 21, 14), pos); - Assert.True (scrollView.OnKeyDown (new (KeyCode.CursorRight))); - Application.Top.Draw (); + Assert.True (scrollView.OnKeyDown (new (KeyCode.CursorRight))); + Application.Top.Draw (); - expected = @" + expected = @" ┌──────────────────┐ │ │ │ 45678901234567▲ │ @@ -731,15 +729,15 @@ namespace Terminal.Gui.ViewsTests { │ │ └──────────────────┘ " - ; + ; - pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - Assert.Equal (new Rect (1, 1, 21, 14), pos); + pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); + Assert.Equal (new Rect (1, 1, 21, 14), pos); - Assert.True (scrollView.OnKeyDown (new (KeyCode.CursorRight))); - Application.Top.Draw (); + Assert.True (scrollView.OnKeyDown (new (KeyCode.CursorRight))); + Application.Top.Draw (); - expected = @" + expected = @" ┌──────────────────┐ │ │ │ 56789012345678▲ │ @@ -755,15 +753,15 @@ namespace Terminal.Gui.ViewsTests { │ │ └──────────────────┘ " - ; + ; - pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - Assert.Equal (new Rect (1, 1, 21, 14), pos); + pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); + Assert.Equal (new Rect (1, 1, 21, 14), pos); - Assert.True (scrollView.OnKeyDown (new (KeyCode.CursorRight))); - Application.Top.Draw (); + Assert.True (scrollView.OnKeyDown (new (KeyCode.CursorRight))); + Application.Top.Draw (); - expected = @" + expected = @" ┌──────────────────┐ │ │ │ 67890123456789▲ │ @@ -779,15 +777,15 @@ namespace Terminal.Gui.ViewsTests { │ │ └──────────────────┘ " - ; + ; - pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - Assert.Equal (new Rect (1, 1, 21, 14), pos); + pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); + Assert.Equal (new Rect (1, 1, 21, 14), pos); - Assert.True (scrollView.OnKeyDown (new (KeyCode.CursorRight))); - Application.Top.Draw (); + Assert.True (scrollView.OnKeyDown (new (KeyCode.CursorRight))); + Application.Top.Draw (); - expected = @" + expected = @" ┌──────────────────┐ │ │ │ 78901234567890▲ │ @@ -804,13 +802,13 @@ namespace Terminal.Gui.ViewsTests { └──────────────────┘ "; - pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - Assert.Equal (new Rect (1, 1, 21, 14), pos); + pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); + Assert.Equal (new Rect (1, 1, 21, 14), pos); - Assert.True (scrollView.OnKeyDown (new (KeyCode.CtrlMask | KeyCode.End))); - Application.Top.Draw (); + Assert.True (scrollView.OnKeyDown (new (KeyCode.CtrlMask | KeyCode.End))); + Application.Top.Draw (); - expected = @" + expected = @" ┌──────────────────┐ │ │ │ 67890123456789▲ │ @@ -827,14 +825,14 @@ namespace Terminal.Gui.ViewsTests { └──────────────────┘ "; - pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - Assert.Equal (new Rect (1, 1, 21, 14), pos); + pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); + Assert.Equal (new Rect (1, 1, 21, 14), pos); - Assert.True (scrollView.OnKeyDown (new (KeyCode.CtrlMask | KeyCode.Home))); - Assert.True (scrollView.OnKeyDown (new (KeyCode.CursorDown))); - Application.Top.Draw (); + Assert.True (scrollView.OnKeyDown (new (KeyCode.CtrlMask | KeyCode.Home))); + Assert.True (scrollView.OnKeyDown (new (KeyCode.CursorDown))); + Application.Top.Draw (); - expected = @" + expected = @" ┌──────────────────┐ │ │ │ 1[ Press me! ]▲ │ @@ -851,13 +849,13 @@ namespace Terminal.Gui.ViewsTests { └──────────────────┘ "; - pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - Assert.Equal (new Rect (1, 1, 21, 14), pos); + pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); + Assert.Equal (new Rect (1, 1, 21, 14), pos); - Assert.True (scrollView.OnKeyDown (new (KeyCode.CursorDown))); - Application.Top.Draw (); + Assert.True (scrollView.OnKeyDown (new (KeyCode.CursorDown))); + Application.Top.Draw (); - expected = @" + expected = @" ┌──────────────────┐ │ │ │ 2 ▲ │ @@ -874,13 +872,13 @@ namespace Terminal.Gui.ViewsTests { └──────────────────┘ "; - pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - Assert.Equal (new Rect (1, 1, 21, 14), pos); + pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); + Assert.Equal (new Rect (1, 1, 21, 14), pos); - Assert.True (scrollView.OnKeyDown (new (KeyCode.CursorDown))); - Application.Top.Draw (); + Assert.True (scrollView.OnKeyDown (new (KeyCode.CursorDown))); + Application.Top.Draw (); - expected = @" + expected = @" ┌──────────────────┐ │ │ │ 3 ▲ │ @@ -897,13 +895,13 @@ namespace Terminal.Gui.ViewsTests { └──────────────────┘ "; - pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - Assert.Equal (new Rect (1, 1, 21, 14), pos); + pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); + Assert.Equal (new Rect (1, 1, 21, 14), pos); - Assert.True (scrollView.OnKeyDown (new (KeyCode.End))); - Application.Top.Draw (); + Assert.True (scrollView.OnKeyDown (new (KeyCode.End))); + Application.Top.Draw (); - expected = @" + expected = @" ┌──────────────────┐ │ │ │ 1 ▲ │ @@ -920,31 +918,30 @@ namespace Terminal.Gui.ViewsTests { └──────────────────┘ "; - pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - Assert.Equal (new Rect (1, 1, 21, 14), pos); - } + pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); + Assert.Equal (new Rect (1, 1, 21, 14), pos); + } - [Fact, AutoInitShutdown] - public void Remove_Added_View_Is_Allowed () - { - var sv = new ScrollView () { - Width = 20, - Height = 20, - ContentSize = new Size (100, 100) - }; - sv.Add (new View () { Width = Dim.Fill (), Height = Dim.Fill (50), Id = "View1" }, - new View () { Y = 51, Width = Dim.Fill (), Height = Dim.Fill (), Id = "View2" }); + [Fact, AutoInitShutdown] + public void Remove_Added_View_Is_Allowed () + { + var sv = new ScrollView () { + Width = 20, + Height = 20, + ContentSize = new Size (100, 100) + }; + sv.Add (new View () { Width = Dim.Fill (), Height = Dim.Fill (50), Id = "View1" }, + new View () { Y = 51, Width = Dim.Fill (), Height = Dim.Fill (), Id = "View2" }); - Application.Top.Add (sv); - Application.Begin (Application.Top); + Application.Top.Add (sv); + Application.Begin (Application.Top); - Assert.Equal (4, sv.Subviews.Count); - Assert.Equal (2, sv.Subviews [0].Subviews.Count); + Assert.Equal (4, sv.Subviews.Count); + Assert.Equal (2, sv.Subviews [0].Subviews.Count); - sv.Remove (sv.Subviews [0].Subviews [1]); - Assert.Equal (4, sv.Subviews.Count); - Assert.Single (sv.Subviews [0].Subviews); - Assert.Equal ("View1", sv.Subviews [0].Subviews [0].Id); - } + sv.Remove (sv.Subviews [0].Subviews [1]); + Assert.Equal (4, sv.Subviews.Count); + Assert.Single (sv.Subviews [0].Subviews); + Assert.Equal ("View1", sv.Subviews [0].Subviews [0].Id); } }