Tile.cs 3.1 KB

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