FrameView.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System.Linq;
  2. using System.Text.Json.Serialization;
  3. using NStack;
  4. using static Terminal.Gui.Configuration.ConfigurationManager;
  5. namespace Terminal.Gui {
  6. /// <summary>
  7. /// The FrameView is a container frame that draws a frame around the contents. It is similar to
  8. /// a GroupBox in Windows.
  9. /// </summary>
  10. public class FrameView : View {
  11. /// <summary>
  12. /// Initializes a new instance of the <see cref="Gui.FrameView"/> class using <see cref="LayoutStyle.Absolute"/> layout.
  13. /// </summary>
  14. /// <param name="frame">Frame.</param>
  15. /// <param name="title">Title.</param>
  16. /// <param name="views">Views.</param>
  17. /// <param name="border">The <see cref="Border"/>.</param>
  18. public FrameView (Rect frame, ustring title = null, View [] views = null, Border border = null) : base (frame)
  19. {
  20. Initialize (frame, title, views, border);
  21. }
  22. /// <summary>
  23. /// Initializes a new instance of the <see cref="Gui.FrameView"/> class using <see cref="LayoutStyle.Computed"/> layout.
  24. /// </summary>
  25. /// <param name="title">Title.</param>
  26. /// <param name="border">The <see cref="Border"/>.</param>
  27. public FrameView (ustring title, Border border = null)
  28. {
  29. Initialize (Rect.Empty, title, null, border);
  30. }
  31. /// <summary>
  32. /// Initializes a new instance of the <see cref="Gui.FrameView"/> class using <see cref="LayoutStyle.Computed"/> layout.
  33. /// </summary>
  34. public FrameView () : this (title: string.Empty) { }
  35. /// <summary>
  36. /// The default <see cref="BorderStyle"/> for <see cref="FrameView"/>. The default is <see cref="BorderStyle.Single"/>.
  37. /// </summary>
  38. /// <remarks>
  39. /// This property can be set in a Theme to change the default <see cref="BorderStyle"/> for all <see cref="FrameView"/>s.
  40. /// </remarks>
  41. [SerializableConfigurationProperty (Scope = typeof (ThemeScope)), JsonConverter (typeof (JsonStringEnumConverter))]
  42. public static BorderStyle DefaultBorderStyle { get; set; } = BorderStyle.Single;
  43. void Initialize (Rect frame, ustring title, View [] views = null, Border border = null)
  44. {
  45. if (title == null) title = ustring.Empty;
  46. this.Title = title;
  47. if (border == null) {
  48. Border = new Border () {
  49. BorderStyle = DefaultBorderStyle
  50. };
  51. } else {
  52. Border = border;
  53. }
  54. }
  55. ///<inheritdoc/>
  56. public override bool OnEnter (View view)
  57. {
  58. if (Subviews.Count == 0 || !Subviews.Any (subview => subview.CanFocus)) {
  59. Application.Driver?.SetCursorVisibility (CursorVisibility.Invisible);
  60. }
  61. return base.OnEnter (view);
  62. }
  63. }
  64. }