mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
Merge pull request #2136 from BDisp/scrollview-content-view-fix
Fixes #2135. Character Map scenario doesn't show the content view.
This commit is contained in:
@@ -29,7 +29,13 @@ namespace Terminal.Gui {
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public class ScrollView : View {
|
||||
View contentView = null;
|
||||
private class ContentView : View {
|
||||
public ContentView (Rect frame) : base (frame)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
ContentView contentView;
|
||||
ScrollBarView vertical, horizontal;
|
||||
|
||||
/// <summary>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,104 @@ 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);
|
||||
}
|
||||
|
||||
[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.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);
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user