From 81d7c614444d637e6488982c5da2e728ceaaf6e7 Mon Sep 17 00:00:00 2001 From: BDisp Date: Tue, 25 Oct 2022 15:20:10 +0100 Subject: [PATCH 1/3] Fixes #2135. Character Map scenario doesn't show the content view. --- Terminal.Gui/Views/ScrollView.cs | 22 +++++++++++++++-- UnitTests/ScrollViewTests.cs | 42 ++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs index fc186bc0e..c42308dd0 100644 --- a/Terminal.Gui/Views/ScrollView.cs +++ b/Terminal.Gui/Views/ScrollView.cs @@ -29,7 +29,13 @@ namespace Terminal.Gui { /// /// public class ScrollView : View { - View contentView = null; + private class ContentView : View { + public ContentView (Rect frame) : base (frame) + { + } + } + + ContentView contentView; ScrollBarView vertical, horizontal; /// @@ -52,7 +58,7 @@ namespace Terminal.Gui { void Initialize (Rect frame) { - contentView = new View (frame); + contentView = new ContentView (frame); vertical = new ScrollBarView (1, 0, isVertical: true) { X = Pos.AnchorEnd (1), Y = 0, @@ -177,6 +183,12 @@ namespace Terminal.Gui { set { if (autoHideScrollBars != value) { autoHideScrollBars = value; + if (Subviews.Contains (vertical)) { + vertical.AutoHideScrollBars = value; + } + if (Subviews.Contains (horizontal)) { + horizontal.AutoHideScrollBars = value; + } SetNeedsDisplay (); } } @@ -251,6 +263,8 @@ namespace Terminal.Gui { SetNeedsLayout (); if (value) { base.Add (horizontal); + horizontal.ShowScrollIndicator = value; + horizontal.AutoHideScrollBars = autoHideScrollBars; horizontal.OtherScrollBarView = vertical; horizontal.OtherScrollBarView.ShowScrollIndicator = value; horizontal.MouseEnter += View_MouseEnter; @@ -290,6 +304,8 @@ namespace Terminal.Gui { SetNeedsLayout (); if (value) { base.Add (vertical); + vertical.ShowScrollIndicator = value; + vertical.AutoHideScrollBars = autoHideScrollBars; vertical.OtherScrollBarView = horizontal; vertical.OtherScrollBarView.ShowScrollIndicator = value; vertical.MouseEnter += View_MouseEnter; @@ -322,10 +338,12 @@ namespace Terminal.Gui { ShowHideScrollBars (); } else { if (ShowVerticalScrollIndicator) { + vertical.SetRelativeLayout (Bounds); vertical.Redraw (vertical.Bounds); } if (ShowHorizontalScrollIndicator) { + horizontal.SetRelativeLayout (Bounds); horizontal.Redraw (horizontal.Bounds); } } diff --git a/UnitTests/ScrollViewTests.cs b/UnitTests/ScrollViewTests.cs index 8d8a6b4b0..8fa8ae381 100644 --- a/UnitTests/ScrollViewTests.cs +++ b/UnitTests/ScrollViewTests.cs @@ -4,9 +4,17 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Xunit; +using Xunit.Abstractions; namespace Terminal.Gui.Views { public class ScrollViewTests { + readonly ITestOutputHelper output; + + public ScrollViewTests (ITestOutputHelper output) + { + this.output = output; + } + [Fact] public void Constructors_Defaults () { @@ -173,5 +181,39 @@ namespace Terminal.Gui.Views { Assert.False (sv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ()))); Assert.Equal (new Point (-39, -19), sv.ContentOffset); } + + [Fact, AutoInitShutdown] + public void AutoHideScrollBars_ShowHorizontalScrollIndicator_ShowVerticalScrollIndicator () + { + var sv = new ScrollView { + Width = 10, + Height = 10 + }; + + Application.Top.Add (sv); + Application.Begin (Application.Top); + + Assert.True (sv.AutoHideScrollBars); + Assert.False (sv.ShowHorizontalScrollIndicator); + Assert.False (sv.ShowVerticalScrollIndicator); + GraphViewTests.AssertDriverContentsWithFrameAre ("", output); + + sv.AutoHideScrollBars = false; + sv.ShowHorizontalScrollIndicator = true; + sv.ShowVerticalScrollIndicator = true; + sv.Redraw (sv.Bounds); + GraphViewTests.AssertDriverContentsWithFrameAre (@" + ▲ + ┬ + │ + │ + │ + │ + │ + ┴ + ▼ +◄├─────┤► +", output); + } } } \ No newline at end of file From 6a509bd0f268fe7db45a8c4c1385bc13745f1abf Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 26 Oct 2022 12:34:13 +0100 Subject: [PATCH 2/3] Added one more unit test. --- UnitTests/ScrollViewTests.cs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/UnitTests/ScrollViewTests.cs b/UnitTests/ScrollViewTests.cs index 8fa8ae381..55085f017 100644 --- a/UnitTests/ScrollViewTests.cs +++ b/UnitTests/ScrollViewTests.cs @@ -213,6 +213,35 @@ namespace Terminal.Gui.Views { ┴ ▼ ◄├─────┤► +", output); + } + + [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); + + Assert.True (sv.AutoHideScrollBars); + Assert.True (sv.ShowHorizontalScrollIndicator); + Assert.True (sv.ShowVerticalScrollIndicator); + GraphViewTests.AssertDriverContentsWithFrameAre (@" + ▲ + ┬ + ┴ + ░ + ░ + ░ + ░ + ░ + ▼ +◄├┤░░░░░► ", output); } } From 60a94ebab30c09210a03f8330b566b65c774085d Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 26 Oct 2022 12:54:23 +0100 Subject: [PATCH 3/3] Added ContentOffset and ContentSize unit tests. --- UnitTests/ScrollViewTests.cs | 38 +++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/UnitTests/ScrollViewTests.cs b/UnitTests/ScrollViewTests.cs index 55085f017..434f06ddb 100644 --- a/UnitTests/ScrollViewTests.cs +++ b/UnitTests/ScrollViewTests.cs @@ -228,6 +228,8 @@ namespace Terminal.Gui.Views { 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); @@ -242,7 +244,41 @@ namespace Terminal.Gui.Views { ░ ▼ ◄├┤░░░░░► +", 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) + }; + + 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); + GraphViewTests.AssertDriverContentsWithFrameAre (@" + ▲ + ░ + ░ + ░ + ┬ + │ + ┴ + ░ + ▼ +◄░░░├─┤░► ", output); } } -} \ No newline at end of file +}