Padding.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. namespace Terminal.Gui;
  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>
  18. /// The color scheme for the Padding. If set to <see langword="null"/>, gets the <see cref="Adornment.Parent"/>
  19. /// scheme. color scheme.
  20. /// </summary>
  21. public override ColorScheme ColorScheme
  22. {
  23. get
  24. {
  25. if (base.ColorScheme is { })
  26. {
  27. return base.ColorScheme;
  28. }
  29. return Parent?.ColorScheme;
  30. }
  31. set
  32. {
  33. base.ColorScheme = value;
  34. Parent?.SetNeedsDraw ();
  35. }
  36. }
  37. /// <summary>Called when a mouse event occurs within the Padding.</summary>
  38. /// <remarks>
  39. /// <para>
  40. /// The coordinates are relative to <see cref="View.Viewport"/>.
  41. /// </para>
  42. /// <para>
  43. /// A mouse click on the Padding will cause the Parent to focus.
  44. /// </para>
  45. /// </remarks>
  46. /// <param name="mouseEvent"></param>
  47. /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
  48. protected override bool OnMouseEvent (MouseEventArgs mouseEvent)
  49. {
  50. if (Parent is null)
  51. {
  52. return false;
  53. }
  54. if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked))
  55. {
  56. if (Parent.CanFocus && !Parent.HasFocus)
  57. {
  58. Parent.SetFocus ();
  59. Parent.SetNeedsDraw ();
  60. return mouseEvent.Handled = true;
  61. }
  62. }
  63. return false;
  64. }
  65. }