Label.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // Label.cs: Label control
  3. //
  4. // Authors:
  5. // Miguel de Icaza ([email protected])
  6. //
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text.RegularExpressions;
  11. using NStack;
  12. namespace Terminal.Gui {
  13. /// <summary>
  14. /// The Label <see cref="View"/> displays a string at a given position and supports multiple lines separted by newline characters. Multi-line Labels support word wrap.
  15. /// </summary>
  16. /// <remarks>
  17. /// The <see cref="Label"/> view is functionality identical to <see cref="View"/> and is included for API backwards compatibilty.
  18. /// </remarks>
  19. public class Label : View {
  20. /// <inheritdoc/>
  21. public Label ()
  22. {
  23. }
  24. /// <inheritdoc/>
  25. public Label (Rect frame) : base (frame)
  26. {
  27. }
  28. /// <inheritdoc/>
  29. public Label (ustring text) : base (text)
  30. {
  31. }
  32. /// <inheritdoc/>
  33. public Label (Rect rect, ustring text) : base (rect, text)
  34. {
  35. }
  36. /// <inheritdoc/>
  37. public Label (int x, int y, ustring text) : base (x, y, text)
  38. {
  39. }
  40. /// <summary>
  41. /// Clicked <see cref="Action"/>, raised when the user clicks the primary mouse button within the Bounds of this <see cref="View"/>
  42. /// or if the user presses the action key while this view is focused. (TODO: IsDefault)
  43. /// </summary>
  44. /// <remarks>
  45. /// Client code can hook up to this event, it is
  46. /// raised when the button is activated either with
  47. /// the mouse or the keyboard.
  48. /// </remarks>
  49. public Action Clicked;
  50. /// <summary>
  51. /// Method invoked when a mouse event is generated
  52. /// </summary>
  53. /// <param name="mouseEvent"></param>
  54. /// <returns><c>true</c>, if the event was handled, <c>false</c> otherwise.</returns>
  55. public override bool OnMouseEvent (MouseEvent mouseEvent)
  56. {
  57. MouseEventArgs args = new MouseEventArgs (mouseEvent);
  58. MouseClick?.Invoke (args);
  59. if (args.Handled)
  60. return true;
  61. if (MouseEvent (mouseEvent))
  62. return true;
  63. if (mouseEvent.Flags == MouseFlags.Button1Clicked) {
  64. if (!HasFocus && SuperView != null) {
  65. SuperView.SetFocus (this);
  66. SetNeedsDisplay ();
  67. }
  68. Clicked?.Invoke ();
  69. return true;
  70. }
  71. return false;
  72. }
  73. }
  74. }