TableStyle.cs 5.0 KB

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