Skip to content

Commit

Permalink
Merge pull request gui-cs#3399 from BDisp/v2_listview-scrolling-fix_3396
Browse files Browse the repository at this point in the history
V2 Fixes gui-cs#3396. ListViewWIthSelection scenario does not show all rows and other issues
  • Loading branch information
tig authored Apr 14, 2024
2 parents 78bde18 + 24aef98 commit 0a73396
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
5 changes: 3 additions & 2 deletions Terminal.Gui/Views/ListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 ();

Expand Down
4 changes: 2 additions & 2 deletions UICatalog/Scenarios/ListViewWithSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
};
Expand Down
35 changes: 35 additions & 0 deletions UnitTests/Views/ListViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> ();
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);
}
}

0 comments on commit 0a73396

Please sign in to comment.