TableStyle.cs 5.2 KB

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