diff --git a/Terminal.Gui/View/View.Drawing.cs b/Terminal.Gui/View/View.Drawing.cs index bf3cc75df..9762ba98b 100644 --- a/Terminal.Gui/View/View.Drawing.cs +++ b/Terminal.Gui/View/View.Drawing.cs @@ -202,11 +202,6 @@ public partial class View // Drawing APIs /// public void Draw () { - if (!CanBeVisible (this)) - { - return; - } - OnDrawAdornments (); if (ColorScheme is { }) @@ -477,6 +472,11 @@ public partial class View // Drawing APIs Clear (); } + if (!CanBeVisible (this)) + { + return; + } + if (!string.IsNullOrEmpty (TextFormatter.Text)) { if (TextFormatter is { }) diff --git a/Terminal.Gui/View/View.cs b/Terminal.Gui/View/View.cs index 134928ebd..fcf904c7c 100644 --- a/Terminal.Gui/View/View.cs +++ b/Terminal.Gui/View/View.cs @@ -373,10 +373,6 @@ public partial class View : Responder, ISupportInitializeNotification { HasFocus = false; } - if (IsInitialized && ClearOnVisibleFalse) - { - Clear (); - } } if (_visible && CanFocus && Enabled && !HasFocus @@ -393,9 +389,6 @@ public partial class View : Responder, ISupportInitializeNotification /// Method invoked when the property from a view is changed. public virtual void OnVisibleChanged () { VisibleChanged?.Invoke (this, EventArgs.Empty); } - /// Gets or sets whether a view is cleared if the property is . - public bool ClearOnVisibleFalse { get; set; } = true; - /// Event fired when the value is being changed. public event EventHandler? VisibleChanged; diff --git a/Terminal.Gui/Views/ScrollBarView.cs b/Terminal.Gui/Views/ScrollBarView.cs index e8b5e487c..d39e168c3 100644 --- a/Terminal.Gui/Views/ScrollBarView.cs +++ b/Terminal.Gui/Views/ScrollBarView.cs @@ -38,7 +38,6 @@ public class ScrollBarView : View public ScrollBarView () { WantContinuousButtonPressed = true; - ClearOnVisibleFalse = false; Added += (s, e) => CreateBottomRightCorner (e.Parent); Initialized += ScrollBarView_Initialized; @@ -103,7 +102,6 @@ public class ScrollBarView : View ShowScrollIndicator = true; CreateBottomRightCorner (Host); - ClearOnVisibleFalse = false; } /// If true the vertical/horizontal scroll bars won't be showed if it's not needed. @@ -216,7 +214,7 @@ public class ScrollBarView : View /// true if show vertical or horizontal scroll indicator; otherwise, false. public bool ShowScrollIndicator { - get => _showScrollIndicator; + get => _showScrollIndicator && Visible; set { //if (value == showScrollIndicator) { @@ -266,7 +264,7 @@ public class ScrollBarView : View } } - private bool _showBothScrollIndicator => OtherScrollBarView?._showScrollIndicator == true && _showScrollIndicator; + private bool _showBothScrollIndicator => OtherScrollBarView?.ShowScrollIndicator == true && ShowScrollIndicator; /// This event is raised when the position on the scrollbar has changed. public event EventHandler ChangedPosition; @@ -316,7 +314,7 @@ public class ScrollBarView : View return true; } - if (_showScrollIndicator + if (ShowScrollIndicator && (mouseEvent.Flags == MouseFlags.WheeledDown || mouseEvent.Flags == MouseFlags.WheeledUp || mouseEvent.Flags == MouseFlags.WheeledRight @@ -448,9 +446,9 @@ public class ScrollBarView : View /// public override void OnDrawContent (Rectangle viewport) { - if (ColorScheme is null || ((!_showScrollIndicator || Size == 0) && AutoHideScrollBars && Visible)) + if (ColorScheme is null || ((!ShowScrollIndicator || Size == 0) && AutoHideScrollBars && Visible)) { - if ((!_showScrollIndicator || Size == 0) && AutoHideScrollBars && Visible) + if ((!ShowScrollIndicator || Size == 0) && AutoHideScrollBars && Visible) { ShowHideScrollBars (false); } @@ -696,7 +694,7 @@ public class ScrollBarView : View if (barsize == 0 || barsize >= scrollBarView._size) { - if (scrollBarView._showScrollIndicator) + if (scrollBarView.ShowScrollIndicator) { scrollBarView.ShowScrollIndicator = false; } @@ -708,7 +706,7 @@ public class ScrollBarView : View } else if (barsize > 0 && barsize == scrollBarView._size && scrollBarView.OtherScrollBarView is { } && pending) { - if (scrollBarView._showScrollIndicator) + if (scrollBarView.ShowScrollIndicator) { scrollBarView.ShowScrollIndicator = false; } @@ -747,7 +745,7 @@ public class ScrollBarView : View } } - if (!scrollBarView._showScrollIndicator) + if (!scrollBarView.ShowScrollIndicator) { scrollBarView.ShowScrollIndicator = true; } @@ -953,13 +951,13 @@ public class ScrollBarView : View ? Host != SuperView ? Dim.Height (Host) - 1 : Dim.Fill () - 1 : 1; } - else if (_showScrollIndicator) + else if (ShowScrollIndicator) { Width = _vertical ? 1 : Host != SuperView ? Dim.Width (Host) : Dim.Fill (); Height = _vertical ? Host != SuperView ? Dim.Height (Host) : Dim.Fill () : 1; } - else if (_otherScrollBarView?._showScrollIndicator == true) + else if (_otherScrollBarView?.ShowScrollIndicator == true) { _otherScrollBarView.Width = _otherScrollBarView._vertical ? 1 : Host != SuperView ? Dim.Width (Host) : Dim.Fill () - 0; @@ -1014,7 +1012,7 @@ public class ScrollBarView : View _otherScrollBarView._contentBottomRightCorner.Visible = true; } } - else if (!_showScrollIndicator) + else if (!ShowScrollIndicator) { if (_contentBottomRightCorner is { }) { @@ -1039,12 +1037,12 @@ public class ScrollBarView : View _otherScrollBarView._contentBottomRightCorner.Visible = false; } - if (Host?.Visible == true && _showScrollIndicator && !Visible) + if (Host?.Visible == true && ShowScrollIndicator && !Visible) { Visible = true; } - if (Host?.Visible == true && _otherScrollBarView?._showScrollIndicator == true && !_otherScrollBarView.Visible) + if (Host?.Visible == true && _otherScrollBarView?.ShowScrollIndicator == true && !_otherScrollBarView.Visible) { _otherScrollBarView.Visible = true; } @@ -1054,12 +1052,12 @@ public class ScrollBarView : View return; } - if (_showScrollIndicator) + if (ShowScrollIndicator) { Draw (); } - if (_otherScrollBarView is { } && _otherScrollBarView._showScrollIndicator) + if (_otherScrollBarView is { } && _otherScrollBarView.ShowScrollIndicator) { _otherScrollBarView.Draw (); } @@ -1078,7 +1076,6 @@ public class ScrollBarView : View { public ContentBottomRightCorner () { - ClearOnVisibleFalse = false; ColorScheme = ColorScheme; } } diff --git a/UICatalog/Scenarios/BackgroundWorkerCollection.cs b/UICatalog/Scenarios/BackgroundWorkerCollection.cs index d1ce6b825..23ce04aea 100644 --- a/UICatalog/Scenarios/BackgroundWorkerCollection.cs +++ b/UICatalog/Scenarios/BackgroundWorkerCollection.cs @@ -77,7 +77,7 @@ public class BackgroundWorkerCollection : Scenario () => Quit (), null, null, - (KeyCode)Application.QuitKey + Application.QuitKey ) } ), @@ -281,7 +281,7 @@ public class BackgroundWorkerCollection : Scenario _listView = new ListView { X = 0, Y = 2, Width = Dim.Fill (), Height = Dim.Fill (2), Enabled = false }; Add (_listView); - _start = new Button { Text = "Start", IsDefault = true, ClearOnVisibleFalse = false }; + _start = new Button { Text = "Start", IsDefault = true }; _start.Accept += (s, e) => { @@ -302,19 +302,28 @@ public class BackgroundWorkerCollection : Scenario } }; - LayoutStarted += (s, e) => - { - int btnsWidth = _start.Frame.Width + _close.Frame.Width + 2 - 1; - int shiftLeft = Math.Max ((Viewport.Width - btnsWidth) / 2 - 2, 0); + LayoutStarted += StagingUIController_LayoutStarted; + Disposing += StagingUIController_Disposing; + } - shiftLeft += _close.Frame.Width + 1; - _close.X = Pos.AnchorEnd (shiftLeft); - _close.Y = Pos.AnchorEnd (1); + private void StagingUIController_Disposing (object sender, EventArgs e) + { + LayoutStarted -= StagingUIController_LayoutStarted; + Disposing -= StagingUIController_Disposing; + } - shiftLeft += _start.Frame.Width + 1; - _start.X = Pos.AnchorEnd (shiftLeft); - _start.Y = Pos.AnchorEnd (1); - }; + private void StagingUIController_LayoutStarted (object sender, LayoutEventArgs e) + { + int btnsWidth = _start.Frame.Width + _close.Frame.Width + 2 - 1; + int shiftLeft = Math.Max ((Viewport.Width - btnsWidth) / 2 - 2, 0); + + shiftLeft += _close.Frame.Width + 1; + _close.X = Pos.AnchorEnd (shiftLeft); + _close.Y = Pos.AnchorEnd (1); + + shiftLeft += _start.Frame.Width + 1; + _start.X = Pos.AnchorEnd (shiftLeft); + _start.Y = Pos.AnchorEnd (1); } public Staging Staging { get; private set; } @@ -371,11 +380,12 @@ public class BackgroundWorkerCollection : Scenario { CancelWorker (); } + private void WorkerApp_Closing (object sender, ToplevelClosingEventArgs e) { Toplevel top = ApplicationOverlapped.OverlappedChildren!.Find (x => x.Data.ToString () == "WorkerApp"); - if (Visible && top == this) + if (e.RequestingTop == this && Visible && top == this) { Visible = false; e.Cancel = true; diff --git a/UnitTests/Views/ScrollBarViewTests.cs b/UnitTests/Views/ScrollBarViewTests.cs index 15c463d78..103ab4e3e 100644 --- a/UnitTests/Views/ScrollBarViewTests.cs +++ b/UnitTests/Views/ScrollBarViewTests.cs @@ -294,7 +294,7 @@ public class ScrollBarViewTests [Fact] [AutoInitShutdown] - public void ClearOnVisibleFalse_Gets_Sets () + public void Visible_Gets_Sets () { var text = "This is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test"; @@ -302,7 +302,7 @@ public class ScrollBarViewTests var top = new Toplevel (); top.Add (label); - var sbv = new ScrollBarView (label, true, false) { Size = 100, ClearOnVisibleFalse = false }; + var sbv = new ScrollBarView (label, true, false) { Size = 100 }; Application.Begin (top); Assert.True (sbv.Visible); @@ -351,18 +351,18 @@ This is a tesā–¼ _output ); - sbv.ClearOnVisibleFalse = true; sbv.Visible = false; Assert.False (sbv.Visible); + top.Draw (); TestHelpers.AssertDriverContentsWithFrameAre ( @" -This is a tes -This is a tes -This is a tes -This is a tes -This is a tes -This is a tes +This is a test +This is a test +This is a test +This is a test +This is a test +This is a test ", _output );