From 8c766a183b75de5f0dcf3837e1c025f6837c5b55 Mon Sep 17 00:00:00 2001 From: tznind Date: Tue, 31 Jan 2023 05:59:12 +0000 Subject: [PATCH] Refactor to use new method IsValidNewSplitterPos --- Terminal.Gui/Views/TileView.cs | 67 +++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/Terminal.Gui/Views/TileView.cs b/Terminal.Gui/Views/TileView.cs index 9681e7bb4..06b653cde 100644 --- a/Terminal.Gui/Views/TileView.cs +++ b/Terminal.Gui/Views/TileView.cs @@ -315,36 +315,8 @@ namespace Terminal.Gui { var fullSpace = orientation == Orientation.Vertical ? Bounds.Width : Bounds.Height; - if(fullSpace != 0) { - int posUs = value.Anchor (fullSpace); - - // Cannot move off screen right - if (posUs >= fullSpace) { - return false; - } - - // Cannot move off screen left - if (posUs <= 0) { - return false; - } - - // Do not allow splitter to move left of the one before - if (idx > 0) { - int posLeft = splitterDistances [idx - 1].Anchor (fullSpace); - - if (posUs <= posLeft) { - return false; - } - } - - // Do not allow splitter to move right of the one after - if (idx+1 < splitterDistances.Count) { - int posLeft = splitterDistances [idx + 1].Anchor (fullSpace); - - if (posUs >= posLeft) { - return false; - } - } + if(fullSpace != 0 && !IsValidNewSplitterPos(idx,value,fullSpace)) { + return false; } splitterDistances [idx] = value; @@ -494,6 +466,41 @@ namespace Terminal.Gui { return true; } + private bool IsValidNewSplitterPos (int idx, Pos value, int fullSpace) + { + int newSize = value.Anchor (fullSpace); + bool isGettingBigger = newSize > splitterDistances [idx].Anchor (fullSpace); + + // Cannot move off screen right + if (newSize >= fullSpace - (HasBorder () ? 1 : 0)) { + return false; + } + + // Cannot move off screen left + if (newSize < (HasBorder()?1:0)) { + return false; + } + + // Do not allow splitter to move left of the one before + if (idx > 0) { + int posLeft = splitterDistances [idx - 1].Anchor (fullSpace); + + if (newSize <= posLeft) { + return false; + } + } + + // Do not allow splitter to move right of the one after + if (idx + 1 < splitterDistances.Count) { + int posLeft = splitterDistances [idx + 1].Anchor (fullSpace); + + if (newSize >= posLeft) { + return false; + } + } + + return true; + } private List GetAllLineViewsRecursively (View v) {