Padding.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #nullable enable
  2. namespace Terminal.Gui;
  3. /// <summary>The Padding for a <see cref="View"/>. Accessed via <see cref="View.Padding"/></summary>
  4. /// <remarks>
  5. /// <para>See the <see cref="Adornment"/> class.</para>
  6. /// </remarks>
  7. public class Padding : Adornment
  8. {
  9. /// <inheritdoc/>
  10. public Padding ()
  11. { /* Do nothing; A parameter-less constructor is required to support all views unit tests. */
  12. }
  13. /// <inheritdoc/>
  14. public Padding (View parent) : base (parent)
  15. {
  16. /* Do nothing; View.CreateAdornment requires a constructor that takes a parent */
  17. }
  18. /// <summary>
  19. /// The color scheme for the Padding. If set to <see langword="null"/>, gets the <see cref="Adornment.Parent"/>
  20. /// scheme. color scheme.
  21. /// </summary>
  22. public override ColorScheme? ColorScheme
  23. {
  24. get => base.ColorScheme ?? Parent?.ColorScheme;
  25. set
  26. {
  27. base.ColorScheme = value;
  28. Parent?.SetNeedsDraw ();
  29. }
  30. }
  31. /// <summary>Called when a mouse event occurs within the Padding.</summary>
  32. /// <remarks>
  33. /// <para>
  34. /// The coordinates are relative to <see cref="View.Viewport"/>.
  35. /// </para>
  36. /// <para>
  37. /// A mouse click on the Padding will cause the Parent to focus.
  38. /// </para>
  39. /// </remarks>
  40. /// <param name="mouseEvent"></param>
  41. /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
  42. protected override bool OnMouseEvent (MouseEventArgs mouseEvent)
  43. {
  44. if (Parent is null)
  45. {
  46. return false;
  47. }
  48. if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked))
  49. {
  50. if (Parent.CanFocus && !Parent.HasFocus)
  51. {
  52. Parent.SetFocus ();
  53. Parent.SetNeedsDraw ();
  54. return mouseEvent.Handled = true;
  55. }
  56. }
  57. return false;
  58. }
  59. }