VisualRoleEventArgs.cs 2.5 KB

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