IListDataSource.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #nullable enable
  2. using System.Collections;
  3. using System.Collections.Specialized;
  4. namespace Terminal.Gui;
  5. /// <summary>Implement <see cref="IListDataSource"/> to provide custom rendering for a <see cref="ListView"/>.</summary>
  6. public interface IListDataSource : IDisposable
  7. {
  8. /// <summary>
  9. /// Event to raise when an item is added, removed, or moved, or the entire list is refreshed.
  10. /// </summary>
  11. event NotifyCollectionChangedEventHandler CollectionChanged;
  12. /// <summary>Returns the number of elements to display</summary>
  13. int Count { get; }
  14. /// <summary>Returns the maximum length of elements to display</summary>
  15. int Length { get; }
  16. /// <summary>
  17. /// Allow suspending the <see cref="CollectionChanged"/> event from being invoked,
  18. /// if <see langword="true"/>, otherwise is <see langword="false"/>.
  19. /// </summary>
  20. bool SuspendCollectionChangedEvent { get; set; }
  21. /// <summary>Should return whether the specified item is currently marked.</summary>
  22. /// <returns><see langword="true"/>, if marked, <see langword="false"/> otherwise.</returns>
  23. /// <param name="item">Item index.</param>
  24. bool IsMarked (int item);
  25. /// <summary>This method is invoked to render a specified item, the method should cover the entire provided width.</summary>
  26. /// <returns>The render.</returns>
  27. /// <param name="listView">The list view to render.</param>
  28. /// <param name="selected">Describes whether the item being rendered is currently selected by the user.</param>
  29. /// <param name="item">The index of the item to render, zero for the first item and so on.</param>
  30. /// <param name="col">The column where the rendering will start</param>
  31. /// <param name="line">The line where the rendering will be done.</param>
  32. /// <param name="width">The width that must be filled out.</param>
  33. /// <param name="start">The index of the string to be displayed.</param>
  34. /// <remarks>
  35. /// The default color will be set before this method is invoked, and will be based on whether the item is selected
  36. /// or not.
  37. /// </remarks>
  38. void Render (
  39. ListView listView,
  40. bool selected,
  41. int item,
  42. int col,
  43. int line,
  44. int width,
  45. int start = 0
  46. );
  47. /// <summary>Flags the item as marked.</summary>
  48. /// <param name="item">Item index.</param>
  49. /// <param name="value">If set to <see langword="true"/> value.</param>
  50. void SetMark (int item, bool value);
  51. /// <summary>Return the source as IList.</summary>
  52. /// <returns></returns>
  53. IList ToList ();
  54. }