FrameView.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. public FrameView (Rect frame, ustring title = null, View [] views = null) : base (frame)
  19. {
  20. SetInitialProperties (frame, title, views);
  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. public FrameView (ustring title)
  27. {
  28. SetInitialProperties (Rect.Empty, title, null);
  29. }
  30. /// <summary>
  31. /// Initializes a new instance of the <see cref="Gui.FrameView"/> class using <see cref="LayoutStyle.Computed"/> layout.
  32. /// </summary>
  33. public FrameView () : this (title: string.Empty) {
  34. }
  35. /// <summary>
  36. /// The default <see cref="LineStyle"/> for <see cref="FrameView"/>'s border. The default is <see cref="LineStyle.Single"/>.
  37. /// </summary>
  38. /// <remarks>
  39. /// This property can be set in a Theme to change the default <see cref="LineStyle"/> for all <see cref="FrameView"/>s.
  40. /// </remarks>
  41. [SerializableConfigurationProperty (Scope = typeof (ThemeScope)), JsonConverter (typeof (JsonStringEnumConverter))]
  42. public static LineStyle DefaultBorderStyle { get; set; } = LineStyle.Single;
  43. void SetInitialProperties (Rect frame, ustring title, View [] views = null)
  44. {
  45. this.Title = title;
  46. Border.Thickness = new Thickness (1);
  47. Border.BorderStyle = DefaultBorderStyle;
  48. //Border.ColorScheme = ColorScheme;
  49. Border.Data = "Border";
  50. }
  51. ///<inheritdoc/>
  52. public override bool OnEnter (View view)
  53. {
  54. if (Subviews.Count == 0 || !Subviews.Any (subview => subview.CanFocus)) {
  55. Application.Driver?.SetCursorVisibility (CursorVisibility.Invisible);
  56. }
  57. return base.OnEnter (view);
  58. }
  59. }
  60. }