2
0

Padding.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #nullable enable
  2. namespace Terminal.Gui.ViewBase;
  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>Called when a mouse event occurs within the Padding.</summary>
  19. /// <remarks>
  20. /// <para>
  21. /// The coordinates are relative to <see cref="View.Viewport"/>.
  22. /// </para>
  23. /// <para>
  24. /// A mouse click on the Padding will cause the Parent to focus.
  25. /// </para>
  26. /// </remarks>
  27. /// <param name="mouseEvent"></param>
  28. /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
  29. protected override bool OnMouseEvent (MouseEventArgs mouseEvent)
  30. {
  31. if (Parent is null)
  32. {
  33. return false;
  34. }
  35. if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked))
  36. {
  37. if (Parent.CanFocus && !Parent.HasFocus)
  38. {
  39. Parent.SetFocus ();
  40. Parent.SetNeedsDraw ();
  41. return mouseEvent.Handled = true;
  42. }
  43. }
  44. return false;
  45. }
  46. }