From a50f9cd2dee879f706f747ce94deb4286b8bbb79 Mon Sep 17 00:00:00 2001 From: tznind Date: Sun, 22 Jan 2023 11:50:56 +0000 Subject: [PATCH] Add InsertTile method --- Terminal.Gui/Views/SplitView.cs | 28 ++++++++++++++++++++++++++++ UnitTests/SplitViewTests.cs | 21 ++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/Terminal.Gui/Views/SplitView.cs b/Terminal.Gui/Views/SplitView.cs index 8b4b3a687..4456c0b1f 100644 --- a/Terminal.Gui/Views/SplitView.cs +++ b/Terminal.Gui/Views/SplitView.cs @@ -116,6 +116,34 @@ namespace Terminal.Gui { LayoutSubviews (); } + /// + /// Adds a new to the collection at . + /// This will also add another splitter line + /// + /// + /// + internal void InsertTile (int idx) + { + var oldTiles = Tiles.ToArray (); + RebuildForTileCount (oldTiles.Length + 1); + + for(int i=0;i idx ? i - 1 : i]; + + // remove the new empty View + Remove (tiles [i].View); + + // restore old Tile and View + tiles [i] = oldTile; + Add (tiles [i].View); + } + } + SetNeedsDisplay (); + LayoutSubviews (); + } + /// /// Orientation of the dividing line (Horizontal or Vertical). /// diff --git a/UnitTests/SplitViewTests.cs b/UnitTests/SplitViewTests.cs index 3aa38762c..48c599292 100644 --- a/UnitTests/SplitViewTests.cs +++ b/UnitTests/SplitViewTests.cs @@ -379,8 +379,27 @@ namespace UnitTests { └──┴──────┘"; TestHelpers.AssertDriverContentsAre (looksLike, output); - } + + [Fact, AutoInitShutdown] + public void TestSplitView_InsertPanelAtStart () + { + var splitContainer = Get11By3SplitView (out var line, true); + SetInputFocusLine (splitContainer); + + splitContainer.InsertTile (0); + + splitContainer.Redraw (splitContainer.Bounds); + + // so should ignore the 2 distance and stick to 6 + string looksLike = +@" +┌──┬───┬──┐ +│ │111│22│ +└──┴───┴──┘"; + TestHelpers.AssertDriverContentsAre (looksLike, output); + } + [Fact, AutoInitShutdown] public void TestSplitView_Horizontal_Focused () {