Window.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.Collections;
  3. using System.Text.Json.Serialization;
  4. using System.Text;
  5. using Terminal.Gui;
  6. using static Terminal.Gui.ConfigurationManager;
  7. namespace Terminal.Gui {
  8. /// <summary>
  9. /// A <see cref="Toplevel"/> <see cref="View"/> with <see cref="View.BorderStyle"/> set to <see cref="LineStyle.Single"/>.
  10. /// </summary>
  11. /// <remarks>
  12. /// <para>
  13. /// This is a helper class to simplify creating a <see cref="Toplevel"/> with a border.
  14. /// </para>
  15. /// </remarks>
  16. public class Window : Toplevel {
  17. /// <summary>
  18. /// Initializes a new instance of the <see cref="Window"/> class using <see cref="LayoutStyle.Computed"/> positioning.
  19. /// </summary>
  20. public Window () : base () {
  21. SetInitialProperties ();
  22. }
  23. /// <summary>
  24. /// Initializes a new instance of the <see cref="Window"/> class using <see cref="LayoutStyle.Computed"/> positioning.
  25. /// </summary>
  26. public Window (Rect frame) : base (frame)
  27. {
  28. SetInitialProperties ();
  29. }
  30. // TODO: enable this
  31. ///// <summary>
  32. ///// The default <see cref="LineStyle"/> for <see cref="Window"/>'s border. The default is <see cref="LineStyle.Single"/>.
  33. ///// </summary>
  34. ///// <remarks>
  35. ///// This property can be set in a Theme to change the default <see cref="LineStyle"/> for all <see cref="Window"/>s.
  36. ///// </remarks>
  37. /////[SerializableConfigurationProperty (Scope = typeof (ThemeScope)), JsonConverter (typeof (JsonStringEnumConverter))]
  38. ////public static ColorScheme DefaultColorScheme { get; set; } = Colors.Base;
  39. /// <summary>
  40. /// The default <see cref="LineStyle"/> for <see cref="Window"/>'s border. The default is <see cref="LineStyle.Single"/>.
  41. /// </summary>
  42. /// <remarks>
  43. /// This property can be set in a Theme to change the default <see cref="LineStyle"/> for all <see cref="Window"/>s.
  44. /// </remarks>
  45. [SerializableConfigurationProperty (Scope = typeof (ThemeScope)), JsonConverter (typeof (JsonStringEnumConverter))]
  46. public static LineStyle DefaultBorderStyle { get; set; } = LineStyle.Single;
  47. void SetInitialProperties ()
  48. {
  49. CanFocus = true;
  50. ColorScheme = Colors.Base; // TODO: make this a theme property
  51. BorderStyle = DefaultBorderStyle;
  52. }
  53. // TODO: Are these overrides really needed?
  54. /// <inheritdoc/>
  55. public override void Add (View view)
  56. {
  57. base.Add (view);
  58. if (view.CanFocus) {
  59. CanFocus = true;
  60. }
  61. AddMenuStatusBar (view);
  62. }
  63. /// <inheritdoc/>
  64. public override void Remove (View view)
  65. {
  66. if (view == null) {
  67. return;
  68. }
  69. SetNeedsDisplay ();
  70. base.Remove (view);
  71. RemoveMenuStatusBar (view);
  72. }
  73. }
  74. }