Border.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using NStack;
  2. using System;
  3. using Terminal.Gui.Graphs;
  4. using System.Text.Json.Serialization;
  5. using System.Data;
  6. using System.Text;
  7. using System.Collections.Generic;
  8. namespace Terminal.Gui {
  9. /// <summary>
  10. /// Specifies the border style for a <see cref="View"/> and to be used by the <see cref="Border"/> class.
  11. /// </summary>
  12. public enum BorderStyle {
  13. /// <summary>
  14. /// No border is drawn.
  15. /// </summary>
  16. None,
  17. /// <summary>
  18. /// The border is drawn using single-width line glyphs.
  19. /// </summary>
  20. Single,
  21. /// <summary>
  22. /// The border is drawn using double-width line glyphs.
  23. /// </summary>
  24. Double,
  25. /// <summary>
  26. /// The border is drawn using single-width line glyphs with rounded corners.
  27. /// </summary>
  28. Rounded,
  29. // TODO: Support Ruler
  30. ///// <summary>
  31. ///// The border is drawn as a diagnostic ruler ("|123456789...").
  32. ///// </summary>
  33. //Ruler
  34. }
  35. /// <summary>
  36. /// Defines the visual border for a <see cref="Frame"/>. Also provides helper APIS for rendering the border.
  37. /// </summary>
  38. public class Border {
  39. /// <summary>
  40. /// Raised if any of the properties that define the border are changed.
  41. /// </summary>
  42. public event Action<Border> BorderChanged;
  43. private BorderStyle _style;
  44. private Color _forgroundColor;
  45. private Color _backgroundColor;
  46. /// <summary>
  47. /// Specifies the <see cref="Gui.BorderStyle"/> for a view.
  48. /// </summary>
  49. [JsonInclude, JsonConverter (typeof (JsonStringEnumConverter))]
  50. public BorderStyle BorderStyle {
  51. get => _style;
  52. set {
  53. _style = value;
  54. OnBorderChanged ();
  55. }
  56. }
  57. /// <summary>
  58. /// Gets or sets the <see cref="Color"/> that draws the outer border color.
  59. /// </summary>
  60. [JsonInclude, JsonConverter (typeof (Configuration.ColorJsonConverter))]
  61. public Color ForgroundColor {
  62. get => _forgroundColor;
  63. set {
  64. _forgroundColor = value;
  65. OnBorderChanged ();
  66. }
  67. }
  68. /// <summary>
  69. /// Gets or sets the <see cref="Color"/> that fills the area between the bounds of a <see cref="Border"/>.
  70. /// </summary>
  71. [JsonInclude, JsonConverter (typeof (Configuration.ColorJsonConverter))]
  72. public Color BackgroundColor {
  73. get => _backgroundColor;
  74. set {
  75. _backgroundColor = value;
  76. OnBorderChanged ();
  77. }
  78. }
  79. // TODO: These are all temporary to keep code compiling
  80. /// <summary>
  81. ///
  82. /// </summary>
  83. public bool DrawMarginFrame { get; set; }
  84. /// <summary>
  85. ///
  86. /// </summary>
  87. public Point Effect3DOffset { get; set; } = new Point (1, 1);
  88. /// <summary>
  89. ///
  90. /// </summary>
  91. public bool Effect3D { get; set; }
  92. /// <summary>
  93. ///
  94. /// </summary>
  95. public Thickness BorderThickness { get; set; } = new Thickness (0);
  96. /// <summary>
  97. ///
  98. /// </summary>
  99. public object Effect3DBrush { get; set; }
  100. /// <summary>
  101. ///
  102. /// </summary>
  103. public Thickness PaddingThickness { get; set; } = new Thickness (0);
  104. /// <summary>
  105. /// Invoke the <see cref="BorderChanged"/> event.
  106. /// </summary>
  107. public virtual void OnBorderChanged ()
  108. {
  109. BorderChanged?.Invoke (this);
  110. }
  111. }
  112. }