Respect minimum panel sizes and scenario support for toggle collapse

This commit is contained in:
tznind
2022-12-24 11:22:04 +00:00
parent 45d697d305
commit b1c7efea7f
3 changed files with 201 additions and 21 deletions

View File

@@ -95,6 +95,53 @@ namespace UnitTests {
TestHelpers.AssertDriverContentsAre (looksLike, output);
}
[Fact, AutoInitShutdown]
public void TestSplitContainer_Vertical_Panel1MinSize_Absolute ()
{
var splitContainer = Get11By3SplitContainer ();
splitContainer.EnsureFocus ();
splitContainer.FocusFirst ();
splitContainer.Panel1MinSize = 6;
// distance is too small (below 6)
splitContainer.SplitterDistance = 2;
// Should bound the value to the minimum distance
Assert.Equal(6,splitContainer.SplitterDistance);
splitContainer.Redraw (splitContainer.Bounds);
// so should ignore the 2 distance and stick to 6
string looksLike =
@"
111111│2222
│ ";
TestHelpers.AssertDriverContentsAre (looksLike, output);
// Keyboard movement on splitter should have no effect because it
// would take us below the minimum splitter size
splitContainer.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
splitContainer.SetNeedsDisplay ();
splitContainer.Redraw (splitContainer.Bounds);
TestHelpers.AssertDriverContentsAre (looksLike, output);
// but we can continue to move the splitter right if we want
splitContainer.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()));
splitContainer.SetNeedsDisplay ();
splitContainer.Redraw (splitContainer.Bounds);
looksLike =
@"
1111111│222
│ ";
TestHelpers.AssertDriverContentsAre (looksLike, output);
}
[Fact, AutoInitShutdown]
public void TestSplitContainer_Horizontal_Focused ()
{
@@ -132,10 +179,53 @@ namespace UnitTests {
─────◊─────
22222222222";
TestHelpers.AssertDriverContentsAre (looksLike, output);
}
[Fact, AutoInitShutdown]
public void TestSplitContainer_Horizontal_Panel1MinSize_Absolute ()
{
var splitContainer = Get11By3SplitContainer ();
splitContainer.Orientation = Terminal.Gui.Graphs.Orientation.Horizontal;
splitContainer.EnsureFocus ();
splitContainer.FocusFirst ();
splitContainer.Panel1MinSize = 1;
// 0 should not be allowed because it brings us below minimum size of Panel1
splitContainer.SplitterDistance = 0;
Assert.Equal((Pos)1,splitContainer.SplitterDistance);
splitContainer.Redraw (splitContainer.Bounds);
string looksLike =
@"
11111111111
─────◊─────
22222222222";
TestHelpers.AssertDriverContentsAre (looksLike, output);
// Now move splitter line down (allowed
splitContainer.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ()));
splitContainer.Redraw (splitContainer.Bounds);
looksLike =
@"
11111111111
─────◊─────";
TestHelpers.AssertDriverContentsAre (looksLike, output);
// And up 2 (only 1 is allowed because of minimum size of 1 on panel1)
splitContainer.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ()));
splitContainer.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ()));
splitContainer.Redraw (splitContainer.Bounds);
looksLike =
@"
11111111111
─────◊─────
22222222222";
TestHelpers.AssertDriverContentsAre (looksLike, output);
}
private SplitContainer Get11By3SplitContainer ()
{
var container = new SplitContainer () {