diff --git a/Terminal.Gui/Views/ListView.cs b/Terminal.Gui/Views/ListView.cs index 729a898c5..ec3450ff0 100644 --- a/Terminal.Gui/Views/ListView.cs +++ b/Terminal.Gui/Views/ListView.cs @@ -95,68 +95,6 @@ namespace Terminal.Gui { int top; int selected; - // - // This class is the built-in IListDataSource that renders arbitrary - // IList instances - // - class ListWrapper : IListDataSource { - IList src; - BitArray marks; - int count; - - public ListWrapper (IList source) - { - count = source.Count; - marks = new BitArray (count); - this.src = source; - } - - public int Count => src.Count; - - void RenderUstr (ConsoleDriver driver, ustring ustr, int col, int line, int width) - { - int byteLen = ustr.Length; - int used = 0; - for (int i = 0; i < byteLen;) { - (var rune, var size) = Utf8.DecodeRune (ustr, i, i - byteLen); - var count = Rune.ColumnWidth (rune); - if (used+count >= width) - break; - driver.AddRune (rune); - used += count; - i += size; - } - for (; used < width; used++) { - driver.AddRune (' '); - } - } - - public void Render (ListView container, ConsoleDriver driver, bool marked, int item, int col, int line, int width) - { - container.Move (col, line); - var t = src [item]; - if (t is ustring) { - RenderUstr (driver, (ustring)t, col, line, width); - } else if (t is string) { - RenderUstr (driver, (string)t, col, line, width); - } else - RenderUstr (driver, t.ToString (), col, line, width); - } - - public bool IsMarked (int item) - { - if (item >= 0 && item < count) - return marks [item]; - return false; - } - - public void SetMark (int item, bool value) - { - if (item >= 0 && item < count) - marks [item] = value; - } - } - IListDataSource source; /// /// Gets or sets the IListDataSource backing this view, use SetSource() if you want to set a new IList source. @@ -437,4 +375,66 @@ namespace Terminal.Gui { return true; } } + + /// + /// This class is the built-in IListDataSource that renders arbitrary + /// IList instances + /// + public class ListWrapper : IListDataSource { + IList src; + BitArray marks; + int count; + + public ListWrapper (IList source) + { + count = source.Count; + marks = new BitArray (count); + this.src = source; + } + + public int Count => src.Count; + + void RenderUstr (ConsoleDriver driver, ustring ustr, int col, int line, int width) + { + int byteLen = ustr.Length; + int used = 0; + for (int i = 0; i < byteLen;) { + (var rune, var size) = Utf8.DecodeRune (ustr, i, i - byteLen); + var count = Rune.ColumnWidth (rune); + if (used+count >= width) + break; + driver.AddRune (rune); + used += count; + i += size; + } + for (; used < width; used++) { + driver.AddRune (' '); + } + } + + public void Render (ListView container, ConsoleDriver driver, bool marked, int item, int col, int line, int width) + { + container.Move (col, line); + var t = src [item]; + if (t is ustring) { + RenderUstr (driver, (ustring)t, col, line, width); + } else if (t is string) { + RenderUstr (driver, (string)t, col, line, width); + } else + RenderUstr (driver, t.ToString (), col, line, width); + } + + public bool IsMarked (int item) + { + if (item >= 0 && item < count) + return marks [item]; + return false; + } + + public void SetMark (int item, bool value) + { + if (item >= 0 && item < count) + marks [item] = value; + } + } }