Padding.cs 1.5 KB

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