VisualRoleEventArgs.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #nullable enable
  2. namespace Terminal.Gui.Drawing;
  3. using System;
  4. #pragma warning disable CS1711
  5. /// <summary>
  6. /// Provides data for cancellable workflow events that resolve an <see cref="Attribute"/> for a specific
  7. /// <see cref="VisualRole"/> in the Cancellable Work Pattern (CWP).
  8. /// </summary>
  9. /// <remarks>
  10. /// <para>
  11. /// Used in events like <see cref="View.GettingAttributeForRole"/> to allow customization or cancellation
  12. /// of attribute resolution for a <see cref="VisualRole"/>, such as determining the appearance of a
  13. /// <see cref="View"/> based on its state (e.g., focused, disabled).
  14. /// </para>
  15. /// <para>
  16. /// Inherits from <see cref="ResultEventArgs{T}"/> with <c>T = <see cref="Attribute"/></c>, providing a
  17. /// cancellable result workflow where event handlers can supply a custom <see cref="Attribute"/> or mark
  18. /// the operation as handled.
  19. /// </para>
  20. /// </remarks>
  21. /// <typeparam name="T">The type of the result, constrained to <see cref="Attribute"/>.</typeparam>
  22. /// <example>
  23. /// <code>
  24. /// View view = new();
  25. /// view.GettingAttributeForRole += (sender, args) =>
  26. /// {
  27. /// if (args.Role == VisualRole.Focus)
  28. /// {
  29. /// args.Result = new Attribute(Color.BrightCyan, Color.Black);
  30. /// args.Handled = true;
  31. /// }
  32. /// };
  33. /// Attribute attribute = view.GetAttributeForRole(VisualRole.Focus);
  34. /// </code>
  35. /// </example>
  36. /// <seealso cref="ResultEventArgs{T}"/>
  37. /// <seealso cref="VisualRole"/>
  38. /// <seealso cref="Attribute"/>
  39. /// <seealso cref="View.GetAttributeForRole"/>
  40. public class VisualRoleEventArgs : ResultEventArgs<Attribute?>
  41. {
  42. /// <summary>
  43. /// Gets the <see cref="VisualRole"/> for which an <see cref="Attribute"/> is being resolved.
  44. /// </summary>
  45. public VisualRole Role { get; }
  46. /// <summary>
  47. /// Initializes a new instance of the <see cref="VisualRoleEventArgs"/> class with the specified
  48. /// <see cref="VisualRole"/> and initial <see cref="Attribute"/> result.
  49. /// </summary>
  50. /// <param name="role">The <see cref="VisualRole"/> for which the attribute is being resolved.</param>
  51. /// <param name="result">The initial attribute result, which may be null if no result is provided.</param>
  52. public VisualRoleEventArgs (in VisualRole role, Attribute? result)
  53. : base (result)
  54. {
  55. Role = role;
  56. }
  57. }
  58. #pragma warning restore CS1711