FrameView.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System.Text.Json.Serialization;
  2. namespace Terminal.Gui;
  3. /// <summary>
  4. /// The FrameView is a container frame that draws a frame around the contents. It is similar to a GroupBox in
  5. /// Windows.
  6. /// </summary>
  7. public class FrameView : View
  8. {
  9. /// <summary>
  10. /// Initializes a new instance of the <see cref="Gui.FrameView"/> class using <see cref="LayoutStyle.Computed"/>
  11. /// layout.
  12. /// </summary>
  13. public FrameView ()
  14. {
  15. Border.Thickness = new Thickness (1);
  16. Border.LineStyle = DefaultBorderStyle;
  17. //Border.ColorScheme = ColorScheme;
  18. Border.Data = "Border";
  19. MouseClick += FrameView_MouseClick;
  20. }
  21. private void FrameView_MouseClick (object sender, MouseEventEventArgs e)
  22. {
  23. e.Handled = InvokeCommand (Command.HotKey) == true;
  24. }
  25. /// <summary>
  26. /// The default <see cref="LineStyle"/> for <see cref="FrameView"/>'s border. The default is
  27. /// <see cref="LineStyle.Single"/>.
  28. /// </summary>
  29. /// <remarks>
  30. /// This property can be set in a Theme to change the default <see cref="LineStyle"/> for all
  31. /// <see cref="FrameView"/>s.
  32. /// </remarks>
  33. [SerializableConfigurationProperty (Scope = typeof (ThemeScope))]
  34. [JsonConverter (typeof (JsonStringEnumConverter))]
  35. public static LineStyle DefaultBorderStyle { get; set; } = LineStyle.Single;
  36. /// <inheritdoc/>
  37. public override bool OnEnter (View view)
  38. {
  39. if (Subviews.Count == 0 || !Subviews.Any (subview => subview.CanFocus))
  40. {
  41. Application.Driver?.SetCursorVisibility (CursorVisibility.Invisible);
  42. }
  43. return base.OnEnter (view);
  44. }
  45. }