From 649680aab4561613242138b32266dc13930c6a1d Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Fri, 22 May 2020 15:59:57 -0600 Subject: [PATCH 1/2] working: --- UICatalog/Scenarios/ComputedLayout.cs | 45 +++++++++++++++++---- UICatalog/Scenarios/Progress.cs | 57 ++++++++++++++++++++------- 2 files changed, 80 insertions(+), 22 deletions(-) diff --git a/UICatalog/Scenarios/ComputedLayout.cs b/UICatalog/Scenarios/ComputedLayout.cs index 77f3d514b..d1dee2531 100644 --- a/UICatalog/Scenarios/ComputedLayout.cs +++ b/UICatalog/Scenarios/ComputedLayout.cs @@ -83,14 +83,13 @@ namespace UICatalog { textView.Text = "This text view should be half-way down the terminal,\n20% of its height, and 80% of its width."; Win.Add (textView); - //// Demonstrate AnchorEnd - Button anchored to bottom of textView - //var clearButton = new Button ("Clear") { - // X = Pos.AnchorEnd (), - // Y = Pos.AnchorEnd (), - // Width = 15, - // Height = 1 - //}; - //Win.Add (clearButton); + // Demonstrate AnchorEnd - Button anchored to bottom of textView + var clearButton = new Button ("Anchor End") { + Y = Pos.AnchorEnd () - 1 + }; + clearButton.X = Pos.AnchorEnd () - clearButton.Text.Length + 4; + + Win.Add (clearButton); // Demonstrate At - Absolute Layout using Pos var absoluteButton = new Button ("At(10,10)") { @@ -98,6 +97,36 @@ namespace UICatalog { Y = Pos.At(10) }; Win.Add (absoluteButton); + + // Centering multiple controls horizontally. + // This is intentionally convoluted to illustrate potential bugs. + var bottomLabel = new Label ("This should be the 2nd to last line (Bug #xxx).") { + TextAlignment = Terminal.Gui.TextAlignment.Centered, + ColorScheme = Colors.TopLevel, + Width = Dim.Fill (), + X = Pos.Center (), + Y = Pos.Bottom (Win) - 4 // BUGBUG: -2 should be two lines above border; but it has to be -4 + }; + Win.Add (bottomLabel); + + var leftButton = new Button ("Left") { + Y = Pos.Bottom (Win) - 2 + }; + var centerButton = new Button ("Center") { + X = Pos.Center (), + Y = Pos.AnchorEnd () - 1 + }; + var rightButton = new Button ("Right") { + Y = Pos.Y(centerButton) + }; + + leftButton.X = Pos.Left (centerButton) - leftButton.Frame.Width - 5; + rightButton.X = Pos.Right (centerButton) + 5; + + Win.Add (leftButton); + Win.Add (centerButton); + Win.Add (rightButton); + } public override void Run () diff --git a/UICatalog/Scenarios/Progress.cs b/UICatalog/Scenarios/Progress.cs index 082d0590a..8c88f2fe5 100644 --- a/UICatalog/Scenarios/Progress.cs +++ b/UICatalog/Scenarios/Progress.cs @@ -1,4 +1,5 @@ using System; +using System.Threading; using Terminal.Gui; namespace UICatalog { @@ -11,27 +12,31 @@ namespace UICatalog { private ProgressBar _activityProgressBar; private ProgressBar _pulseProgressBar; + private Timer _timer; + private object _timeoutToken = null; + public override void Setup () { - Win.Add (new Button ("Start") { - X = Pos.Center () - 20, + var pulseButton = new Button ("Pulse") { + X = Pos.Center (), Y = Pos.Center () - 5, + Clicked = () => Pulse () + }; + + Win.Add (new Button ("Start Timer") { + X = Pos.Left(pulseButton) - 20, + Y = Pos.Y(pulseButton), Clicked = () => Start () }); - Win.Add (new Button ("Pulse") { - X = Pos.Center () - 5, - Y = Pos.Center () - 5, - Clicked = () => Pulse () - }); - - - Win.Add (new Button ("Stop") { - X = Pos.Center () + 10, - Y = Pos.Center () - 5, + Win.Add (new Button ("Stop Timer") { + X = Pos.Right (pulseButton) + 20, // BUGBUG: Right is somehow adding additional width + Y = Pos.Y (pulseButton), Clicked = () => Stop() }); + Win.Add (pulseButton); + _activityProgressBar = new ProgressBar () { X = Pos.Center (), // BUGBUG: If you remove the +1 below the control is drawn at top?!?! @@ -50,24 +55,48 @@ namespace UICatalog { Win.Add (_pulseProgressBar); } + protected override void Dispose (bool disposing) + { + _timer?.Dispose (); + _timer = null; + if (_timeoutToken != null) { + Application.MainLoop.RemoveTimeout (_timeoutToken); + } + base.Dispose (disposing); + } + private void Pulse () { - if (_activityProgressBar.Fraction + 0.1F >= 1) { + if (_activityProgressBar.Fraction + 0.01F >= 1) { _activityProgressBar.Fraction = 0F; } else { - _activityProgressBar.Fraction += 0.1F; + _activityProgressBar.Fraction += 0.01F; } _pulseProgressBar.Pulse (); } private void Start () { + _timer?.Dispose (); + _timer = null; + _activityProgressBar.Fraction = 0F; _pulseProgressBar.Fraction = 0F; + + _timer = new Timer ((o) => { + // BUGBUG: #409 - Invoke does not cause Wakeup as it should + Application.MainLoop.Invoke (() => Pulse ()); + }, null, 0, 250); } private void Stop () { + _timer?.Dispose (); + _timer = null; + if (_timeoutToken != null) { + Application.MainLoop.RemoveTimeout (_timeoutToken); + } + _activityProgressBar.Fraction = 1F; _pulseProgressBar.Fraction = 1F; } From a12871e65ec4bfdd2f4035b2b1494fa16bf6f5db Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Fri, 22 May 2020 17:25:13 -0600 Subject: [PATCH 2/2] backed out pos.width poc --- Terminal.Gui/Types/PosDim.cs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Terminal.Gui/Types/PosDim.cs b/Terminal.Gui/Types/PosDim.cs index 2a1cbb6c1..fa4e33ec2 100644 --- a/Terminal.Gui/Types/PosDim.cs +++ b/Terminal.Gui/Types/PosDim.cs @@ -247,7 +247,6 @@ namespace Terminal.Gui { case 1: return Target.Frame.Y; case 2: return Target.Frame.Right; case 3: return Target.Frame.Bottom; - case 4: return Target.Frame.Right - Target.Frame.Left; default: return 0; } @@ -261,7 +260,6 @@ namespace Terminal.Gui { case 1: tside = "y"; break; case 2: tside = "right"; break; case 3: tside = "bottom"; break; - case 4: tside = "width"; break; default: tside = "unknown"; break; } return $"Pos.View(side={tside}, target={Target.ToString()}"; @@ -309,13 +307,6 @@ namespace Terminal.Gui { /// The Position that depends on the other view. /// The view that will be tracked. public static Pos Bottom (View view) => new PosView (view, 3); - - /// - /// Returns a Pos object tracks the Width (Right-Left) of the specified view. - /// - /// The Position that depends on the other view. - /// The view that will be tracked. - public static Pos Width (View view) => new PosView (view, 4); } ///