From 36469b729886f90270dd8cd84fd84d81279c62fa Mon Sep 17 00:00:00 2001 From: BDisp Date: Thu, 11 Apr 2024 17:44:16 +0100 Subject: [PATCH 1/3] Fix horizontal scrolling in the ListView. --- Terminal.Gui/Views/ListView.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Terminal.Gui/Views/ListView.cs b/Terminal.Gui/Views/ListView.cs index 783d593889..f1de20abc1 100644 --- a/Terminal.Gui/Views/ListView.cs +++ b/Terminal.Gui/Views/ListView.cs @@ -912,7 +912,7 @@ public void Render ( int start = 0 ) { - container.Move (col, line); + container.Move (Math.Max (col - start, 0), line); object t = _source? [item]; if (t is null) @@ -1028,7 +1028,8 @@ private int GetMaxLengthItem () private void RenderUstr (ConsoleDriver driver, string ustr, int col, int line, int width, int start = 0) { - string u = TextFormatter.ClipAndJustify (ustr, width, TextAlignment.Left); + string str = start > ustr.GetColumns () ? string.Empty : ustr.Substring (Math.Min (start, ustr.ToRunes ().Length - 1)); + string u = TextFormatter.ClipAndJustify (str, width, TextAlignment.Left); driver.AddStr (u); width -= u.GetColumns (); From a121b62c770c83ef28f1e6226fb139db695585c2 Mon Sep 17 00:00:00 2001 From: BDisp Date: Thu, 11 Apr 2024 17:44:59 +0100 Subject: [PATCH 2/3] Fix size in the scenario. --- UICatalog/Scenarios/ListViewWithSelection.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UICatalog/Scenarios/ListViewWithSelection.cs b/UICatalog/Scenarios/ListViewWithSelection.cs index 4dd7d00adf..a926e50f9c 100644 --- a/UICatalog/Scenarios/ListViewWithSelection.cs +++ b/UICatalog/Scenarios/ListViewWithSelection.cs @@ -84,9 +84,9 @@ public override void Setup () _listView.DrawContent += (s, e) => { - scrollBar.Size = _listView.Source.Count - 1; + scrollBar.Size = _listView.Source.Count; scrollBar.Position = _listView.TopItem; - scrollBar.OtherScrollBarView.Size = _listView.MaxLength - 1; + scrollBar.OtherScrollBarView.Size = _listView.MaxLength; scrollBar.OtherScrollBarView.Position = _listView.LeftItem; scrollBar.Refresh (); }; From 24aef987be65ff60dc3058ba733cf93009f63eeb Mon Sep 17 00:00:00 2001 From: BDisp Date: Thu, 11 Apr 2024 18:00:12 +0100 Subject: [PATCH 3/3] Restoring unit test from v1. --- UnitTests/Views/ListViewTests.cs | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/UnitTests/Views/ListViewTests.cs b/UnitTests/Views/ListViewTests.cs index a7ee74fc7c..835d0fe4e4 100644 --- a/UnitTests/Views/ListViewTests.cs +++ b/UnitTests/Views/ListViewTests.cs @@ -759,4 +759,39 @@ public void Clicking_On_Border_Is_Ignored () Assert.Equal ("Three", selected); Assert.Equal (2, lv.SelectedItem); } + + [Fact] + [AutoInitShutdown] + public void LeftItem_TopItem_Tests () + { + var source = new List (); + for (int i = 0; i < 5; i++) { + source.Add ($"Item {i}"); + } + var lv = new ListView () { + X = 1, + Width = 10, + Height = 5, + Source = new ListWrapper (source) + }; + var top = new Toplevel (); + top.Add (lv); + Application.Begin (top); + + TestHelpers.AssertDriverContentsWithFrameAre (@" + Item 0 + Item 1 + Item 2 + Item 3 + Item 4", _output); + + lv.LeftItem = 1; + lv.TopItem = 1; + Application.Refresh (); + TestHelpers.AssertDriverContentsWithFrameAre (@" + tem 1 + tem 2 + tem 3 + tem 4", _output); + } }