TableStyle.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #nullable disable
  2. namespace Terminal.Gui.Views;
  3. /// <summary>
  4. /// Defines rendering options that affect how the table is displayed.
  5. /// <a href="../docs/tableview.md">See TableView Deep Dive for more information</a>.
  6. /// </summary>
  7. public class TableStyle
  8. {
  9. /// <summary>When scrolling down always lock the column headers in place as the first row of the table</summary>
  10. public bool AlwaysShowHeaders { get; set; } = false;
  11. /// <summary>
  12. /// Gets or sets a flag indicating whether to force <see cref="Scheme.Normal"/> use when rendering vertical
  13. /// cell lines (even when <see cref="TableView.FullRowSelect"/> is on).
  14. /// </summary>
  15. public bool AlwaysUseNormalColorForVerticalCellLines { get; set; } = false;
  16. /// <summary>Collection of columns for which you want special rendering (e.g. custom column lengths, text justification, etc.)</summary>
  17. public Dictionary<int, ColumnStyle> ColumnStyles { get; set; } = new ();
  18. /// <summary>
  19. /// Determines rendering when the last column in the table is visible, but it's content or
  20. /// <see cref="ColumnStyle.MaxWidth"/> is less than the remaining space in the control. True (the default) will expand
  21. /// the column to fill the remaining bounds of the control. False will draw a column ending line and leave a blank
  22. /// column that cannot be selected in the remaining space.
  23. /// </summary>
  24. /// <value></value>
  25. public bool ExpandLastColumn { get; set; } = true;
  26. /// <summary>
  27. /// True to invert the colors of the first symbol of the selected cell in the <see cref="TableView"/>. This gives
  28. /// the appearance of a cursor for when the <see cref="IDriver"/> doesn't otherwise show this
  29. /// </summary>
  30. public bool InvertSelectedCellFirstCharacter { get; set; } = false;
  31. /// <summary>
  32. /// Delegate for coloring specific rows in a different color. For cell color
  33. /// <see cref="ColumnStyle.ColorGetter"/>
  34. /// </summary>
  35. /// <value></value>
  36. public RowColorGetterDelegate RowColorGetter { get; set; }
  37. /// <summary>
  38. /// Gets or sets a flag indicating whether to render headers of a <see cref="TableView"/>. Defaults to
  39. /// <see langword="true"/>.
  40. /// </summary>
  41. /// <remarks>
  42. /// <see cref="ShowHorizontalHeaderOverline"/>, <see cref="ShowHorizontalHeaderUnderline"/> etc may still be used
  43. /// even if <see cref="ShowHeaders"/> is <see langword="false"/>.
  44. /// </remarks>
  45. public bool ShowHeaders { get; set; } = true;
  46. /// <summary>
  47. /// Gets or sets a flag indicating whether there should be a horizontal line after all the data in the table.
  48. /// Defaults to <see langword="false"/>.
  49. /// </summary>
  50. public bool ShowHorizontalBottomline { get; set; } = false;
  51. /// <summary>True to render a solid line above the headers</summary>
  52. public bool ShowHorizontalHeaderOverline { get; set; } = true;
  53. /// <summary>True to render a solid line under the headers</summary>
  54. public bool ShowHorizontalHeaderUnderline { get; set; } = true;
  55. /// <summary>
  56. /// True to render a arrows on the right/left of the table when there are more column(s) that can be scrolled to.
  57. /// Requires <see cref="ShowHorizontalHeaderUnderline"/> to be true. Defaults to true
  58. /// </summary>
  59. public bool ShowHorizontalScrollIndicators { get; set; } = true;
  60. /// <summary>True to render a solid line vertical line between cells</summary>
  61. public bool ShowVerticalCellLines { get; set; } = true;
  62. /// <summary>True to render a solid line vertical line between headers</summary>
  63. public bool ShowVerticalHeaderLines { get; set; } = true;
  64. /// <summary>
  65. /// <para>
  66. /// Determines how <see cref="TableView.ColumnOffset"/> is updated when scrolling right off the end of the
  67. /// currently visible area.
  68. /// </para>
  69. /// <para>
  70. /// If true then when scrolling right the scroll offset is increased the minimum required to show the new column.
  71. /// This may be slow if you have an incredibly large number of columns in your table and/or slow
  72. /// <see cref="ColumnStyle.RepresentationGetter"/> implementations
  73. /// </para>
  74. /// <para>If false then scroll offset is set to the currently selected column (i.e. PageRight).</para>
  75. /// </summary>
  76. public bool SmoothHorizontalScrolling { get; set; } = true;
  77. /// <summary>
  78. /// Returns the entry from <see cref="ColumnStyles"/> for the given <paramref name="col"/> or null if no custom
  79. /// styling is defined for it
  80. /// </summary>
  81. /// <param name="col"></param>
  82. /// <returns></returns>
  83. public ColumnStyle GetColumnStyleIfAny (int col) { return ColumnStyles.TryGetValue (col, out ColumnStyle result) ? result : null; }
  84. /// <summary>
  85. /// Returns an existing <see cref="ColumnStyle"/> for the given <paramref name="col"/> or creates a new one with
  86. /// default options
  87. /// </summary>
  88. /// <param name="col"></param>
  89. /// <returns></returns>
  90. public ColumnStyle GetOrCreateColumnStyle (int col)
  91. {
  92. if (!ColumnStyles.ContainsKey (col))
  93. {
  94. ColumnStyles.Add (col, new ColumnStyle ());
  95. }
  96. return ColumnStyles [col];
  97. }
  98. }