From 30a87c849a7902e6a96e63e0a0cce04ea7b65437 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 9 Apr 2023 12:22:15 +0100 Subject: [PATCH] Added the StringExtensions.cs file with a public class. --- Terminal.Gui/Drawing/Ruler.cs | 17 -------- Terminal.Gui/StringExtensions.cs | 32 +++++++++++++++ UICatalog/Scenarios/ComputedLayout.cs | 59 ++++++++------------------- UICatalog/Scenarios/Scrolling.cs | 1 - 4 files changed, 48 insertions(+), 61 deletions(-) create mode 100644 Terminal.Gui/StringExtensions.cs diff --git a/Terminal.Gui/Drawing/Ruler.cs b/Terminal.Gui/Drawing/Ruler.cs index b45f73ef4..78bdcb3d2 100644 --- a/Terminal.Gui/Drawing/Ruler.cs +++ b/Terminal.Gui/Drawing/Ruler.cs @@ -64,21 +64,4 @@ namespace Terminal.Gui { } } } - - internal static class StringExtensions { - public static string Repeat (this string instr, int n) - { - if (n <= 0) { - return null; - } - - if (string.IsNullOrEmpty (instr) || n == 1) { - return instr; - } - - return new StringBuilder (instr.Length * n) - .Insert (0, instr, n) - .ToString (); - } - } } \ No newline at end of file diff --git a/Terminal.Gui/StringExtensions.cs b/Terminal.Gui/StringExtensions.cs new file mode 100644 index 000000000..4242dec5c --- /dev/null +++ b/Terminal.Gui/StringExtensions.cs @@ -0,0 +1,32 @@ +using System.Text; + +namespace Terminal.Gui { + /// + /// Extension helper of to work with specific text manipulation./> + /// + public static class StringExtensions { + /// + /// Repeats the times. + /// + /// The text to repeat. + /// Number of times to repeat the text. + /// + /// The text repeated if is greater than zero, + /// otherwise . + /// + public static string Repeat (this string instr, int n) + { + if (n <= 0) { + return null; + } + + if (string.IsNullOrEmpty (instr) || n == 1) { + return instr; + } + + return new StringBuilder (instr.Length * n) + .Insert (0, instr, n) + .ToString (); + } + } +} diff --git a/UICatalog/Scenarios/ComputedLayout.cs b/UICatalog/Scenarios/ComputedLayout.cs index 62afd54d3..674ba0b31 100644 --- a/UICatalog/Scenarios/ComputedLayout.cs +++ b/UICatalog/Scenarios/ComputedLayout.cs @@ -54,7 +54,7 @@ namespace UICatalog.Scenarios { Application.Top.LayoutComplete += (s, a) => { horizontalRuler.Text = rule.Repeat ((int)Math.Ceiling ((double)(horizontalRuler.Bounds.Width) / (double)rule.Length)) [0..(horizontalRuler.Bounds.Width)]; - verticalRuler.Text = vrule.Repeat ((int)Math.Ceiling ((double)(verticalRuler.Bounds.Height * 2) / (double)rule.Length)) [0..(verticalRuler.Bounds.Height*2)]; + verticalRuler.Text = vrule.Repeat ((int)Math.Ceiling ((double)(verticalRuler.Bounds.Height * 2) / (double)rule.Length)) [0..(verticalRuler.Bounds.Height * 2)]; }; Application.Top.Add (verticalRuler); @@ -66,7 +66,7 @@ namespace UICatalog.Scenarios { }; Application.Top.Add (atButton); - // Throw in a literal absolute - Should funciton identically to above + // Throw in a literal absolute - Should function identically to above var absoluteButton = new Button ("X = 30, Y = 1") { X = 30, Y = 1 @@ -81,7 +81,7 @@ namespace UICatalog.Scenarios { Width = Dim.Fill (margin), Height = 7 }; - subWin.Title = $"{subWin.GetType().Name} {{X={subWin.X},Y={subWin.Y},Width={subWin.Width},Height={subWin.Height}}}"; + subWin.Title = $"{subWin.GetType ().Name} {{X={subWin.X},Y={subWin.Y},Width={subWin.Width},Height={subWin.Height}}}"; Application.Top.Add (subWin); int i = 1; @@ -95,7 +95,7 @@ namespace UICatalog.Scenarios { subWin.Add (labelList.ToArray ()); var frameView = new FrameView () { - X = 2, + X = 2, Y = Pos.Bottom (subWin), Width = 30, Height = 7 @@ -112,9 +112,9 @@ namespace UICatalog.Scenarios { Application.Top.Add (frameView); frameView = new FrameView () { - X = Pos.Right(frameView), + X = Pos.Right (frameView), Y = Pos.Top (frameView), - Width = Dim.Fill(), + Width = Dim.Fill (), Height = 7, }; frameView.Title = $"{frameView.GetType ().Name} {{X={frameView.X},Y={frameView.Y},Width={frameView.Width},Height={frameView.Height}}}"; @@ -168,7 +168,7 @@ namespace UICatalog.Scenarios { // This demonstrates nonsense: it the same as using Pos.AnchorEnd (100/2=50 + 100/2=50 = 100 - 50) // The `- Pos.Percent(5)` is there so at least something is visible oddballButton = new Button ("Center + Center - Percent(50)") { - X = Pos.Center () + Pos.Center () - Pos.Percent(50), + X = Pos.Center () + Pos.Center () - Pos.Percent (50), Y = Pos.Bottom (oddballButton) }; Application.Top.Add (oddballButton); @@ -199,7 +199,7 @@ namespace UICatalog.Scenarios { // This demonstrates combining Percents) oddballButton = new Button ("Percent(40) + Percent(10)") { - X = Pos.Percent (40) + Pos.Percent(10), + X = Pos.Percent (40) + Pos.Percent (10), Y = Pos.Bottom (oddballButton) }; Application.Top.Add (oddballButton); @@ -209,8 +209,8 @@ namespace UICatalog.Scenarios { Y = Pos.AnchorEnd () - 1, }; anchorButton.X = Pos.AnchorEnd () - (Pos.Right (anchorButton) - Pos.Left (anchorButton)); - anchorButton.Clicked += (s,e) => { - // Ths demonstrates how to have a dynamically sized button + anchorButton.Clicked += (s, e) => { + // This demonstrates how to have a dynamically sized button // Each time the button is clicked the button's text gets longer // The call to Application.Top.LayoutSubviews causes the Computed layout to // get updated. @@ -245,8 +245,8 @@ namespace UICatalog.Scenarios { var leftButton = new Button ("Left") { Y = Pos.AnchorEnd () - 1 // Pos.Combine }; - leftButton.Clicked += (s,e) => { - // Ths demonstrates how to have a dynamically sized button + leftButton.Clicked += (s, e) => { + // This demonstrates how to have a dynamically sized button // Each time the button is clicked the button's text gets longer // The call to Application.Top.LayoutSubviews causes the Computed layout to // get updated. @@ -260,8 +260,8 @@ namespace UICatalog.Scenarios { X = Pos.Center (), Y = Pos.AnchorEnd (1) // Pos.AnchorEnd(1) }; - centerButton.Clicked += (s,e) => { - // Ths demonstrates how to have a dynamically sized button + centerButton.Clicked += (s, e) => { + // This demonstrates how to have a dynamically sized button // Each time the button is clicked the button's text gets longer // The call to Application.Top.LayoutSubviews causes the Computed layout to // get updated. @@ -273,8 +273,8 @@ namespace UICatalog.Scenarios { var rightButton = new Button ("Right") { Y = Pos.Y (centerButton) }; - rightButton.Clicked += (s,e) => { - // Ths demonstrates how to have a dynamically sized button + rightButton.Clicked += (s, e) => { + // This demonstrates how to have a dynamically sized button // Each time the button is clicked the button's text gets longer // The call to Application.Top.LayoutSubviews causes the Computed layout to // get updated. @@ -290,32 +290,5 @@ namespace UICatalog.Scenarios { Application.Top.Add (centerButton); Application.Top.Add (rightButton); } - - public override void Run () - { - base.Run (); - } - - private void Quit () - { - Application.RequestStop (); - } - } - - internal static class StringExtensions { - public static string Repeat (this string instr, int n) - { - if (n <= 0) { - return null; - } - - if (string.IsNullOrEmpty (instr) || n == 1) { - return instr; - } - - return new StringBuilder (instr.Length * n) - .Insert (0, instr, n) - .ToString (); - } } } \ No newline at end of file diff --git a/UICatalog/Scenarios/Scrolling.cs b/UICatalog/Scenarios/Scrolling.cs index 50447789b..033e99e1c 100644 --- a/UICatalog/Scenarios/Scrolling.cs +++ b/UICatalog/Scenarios/Scrolling.cs @@ -154,7 +154,6 @@ namespace UICatalog.Scenarios { void Top_Loaded (object sender, EventArgs args) { - // BUGBUG: v2 - this broke somehow - fix later horizontalRuler.Text = rule.Repeat ((int)Math.Ceiling ((double)(horizontalRuler.Bounds.Width) / (double)rule.Length)) [0..(horizontalRuler.Bounds.Width)] + "\n" + "| ".Repeat ((int)Math.Ceiling ((double)(horizontalRuler.Bounds.Width) / (double)rule.Length)) [0..(horizontalRuler.Bounds.Width)]; verticalRuler.Text = vrule.Repeat ((int)Math.Ceiling ((double)(verticalRuler.Bounds.Height * 2) / (double)rule.Length)) [0..(verticalRuler.Bounds.Height * 2)];