FrameView.cs 2.8 KB

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