Border.cs 2.9 KB

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