Tile.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System.ComponentModel;
  2. namespace Terminal.Gui;
  3. /// <summary>
  4. /// A single <see cref="ContentView"/> presented in a <see cref="TileView"/>. To create new instances use
  5. /// <see cref="TileView.RebuildForTileCount(int)"/> or <see cref="TileView.InsertTile(int)"/>.
  6. /// </summary>
  7. public class Tile
  8. {
  9. private string _title = string.Empty;
  10. /// <summary>Creates a new instance of the <see cref="Tile"/> class.</summary>
  11. public Tile ()
  12. {
  13. ContentView = new View { Width = Dim.Fill (), Height = Dim.Fill () };
  14. #if DEBUG_IDISPOSABLE
  15. ContentView.Data = "Tile.ContentView";
  16. #endif
  17. Title = string.Empty;
  18. MinSize = 0;
  19. }
  20. /// <summary>
  21. /// The <see cref="ContentView"/> that is contained in this <see cref="TileView"/>. Add new child views to this
  22. /// member for multiple <see cref="ContentView"/>s within the <see cref="Tile"/>.
  23. /// </summary>
  24. public View ContentView { get; internal set; }
  25. /// <summary>
  26. /// Gets or Sets the minimum size you to allow when splitter resizing along parent
  27. /// <see cref="TileView.Orientation"/> direction.
  28. /// </summary>
  29. public int MinSize { get; set; }
  30. /// <summary>
  31. /// The text that should be displayed above the <see cref="ContentView"/>. This will appear over the splitter line
  32. /// or border (above the view client area).
  33. /// </summary>
  34. /// <remarks>Title are not rendered for root level tiles <see cref="Gui.LineStyle"/> is <see cref="LineStyle.None"/>.</remarks>
  35. public string Title
  36. {
  37. get => _title;
  38. set
  39. {
  40. if (!OnTitleChanging (_title, value))
  41. {
  42. string old = _title;
  43. _title = value;
  44. OnTitleChanged (old, _title);
  45. return;
  46. }
  47. _title = value;
  48. }
  49. }
  50. /// <summary>Called when the <see cref="Title"/> has been changed. Invokes the <see cref="TitleChanged"/> event.</summary>
  51. /// <param name="oldTitle">The <see cref="Title"/> that is/has been replaced.</param>
  52. /// <param name="newTitle">The new <see cref="Title"/> to be replaced.</param>
  53. public virtual void OnTitleChanged (string oldTitle, string newTitle)
  54. {
  55. var args = new CancelEventArgs<string> (oldTitle, newTitle);
  56. TitleChanged?.Invoke (this, args);
  57. }
  58. /// <summary>
  59. /// Called before the <see cref="Title"/> changes. Invokes the <see cref="TitleChanging"/> event, which can be
  60. /// cancelled.
  61. /// </summary>
  62. /// <param name="oldTitle">The <see cref="Title"/> that is/has been replaced.</param>
  63. /// <param name="newTitle">The new <see cref="Title"/> to be replaced.</param>
  64. /// <returns><c>true</c> if an event handler cancelled the Title change.</returns>
  65. public virtual bool OnTitleChanging (string oldTitle, string newTitle)
  66. {
  67. var args = new CancelEventArgs<string> (oldTitle, newTitle);
  68. TitleChanging?.Invoke (this, args);
  69. return args.Cancel;
  70. }
  71. /// <summary>Event fired after the <see cref="Title"/> has been changed.</summary>
  72. public event EventHandler<CancelEventArgs<string>> TitleChanged;
  73. /// <summary>
  74. /// Event fired when the <see cref="Title"/> is changing.
  75. /// <see cref="CancelEventArgs.Cancel"/> can be set to <c>true</c> to cancel the change.
  76. /// </summary>
  77. public event EventHandler<CancelEventArgs<string>> TitleChanging;
  78. }