Tile.cs 3.3 KB

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