diff --git a/Terminal.Gui/Views/TreeView/Branch.cs b/Terminal.Gui/Views/TreeView/Branch.cs index a6c4e93bc..03839d5e4 100644 --- a/Terminal.Gui/Views/TreeView/Branch.cs +++ b/Terminal.Gui/Views/TreeView/Branch.cs @@ -201,10 +201,21 @@ namespace Terminal.Gui { )); } - foreach(var cell in cells) - { - driver.SetAttribute(cell.ColorScheme.Normal); - driver.AddRune(cell.Rune); + var e = new DrawTreeViewLineEventArgs{ + Model = Model, + Y = y, + RuneCells = cells, + Tree = tree + }; + tree.OnDrawLine(e); + + if(!e.Handled) + { + foreach(var cell in cells) + { + driver.SetAttribute(cell.ColorScheme.Normal); + driver.AddRune(cell.Rune); + } } driver.SetAttribute (colorScheme.Normal); diff --git a/Terminal.Gui/Views/TreeView/TreeView.cs b/Terminal.Gui/Views/TreeView/TreeView.cs index 318b0ffae..5dc30c58d 100644 --- a/Terminal.Gui/Views/TreeView/TreeView.cs +++ b/Terminal.Gui/Views/TreeView/TreeView.cs @@ -169,6 +169,12 @@ namespace Terminal.Gui { /// public event EventHandler> SelectionChanged; + /// + /// Called once for each visible row during rendering. Can be used + /// to make last minute changes to color or text rendered + /// + public event EventHandler> DrawLine; + /// /// The root objects in the tree, note that this collection is of root objects only. /// @@ -1421,8 +1427,58 @@ namespace Terminal.Gui { { SelectionChanged?.Invoke (this, e); } + + /// + /// Raises the DrawLine event + /// + /// + internal void OnDrawLine (DrawTreeViewLineEventArgs e) + { + DrawLine?.Invoke(this,e); + } + } + /// + /// Event args for the event + /// + /// + public class DrawTreeViewLineEventArgs where T : class{ + + /// + /// The object at this line in the tree + /// + public T Model {get;init;} + + /// + /// The that is performing the + /// rendering. + /// + public TreeView Tree {get; init;} + + /// + /// The line within tree view bounds that is being rendered + /// + public int Y {get;init;} + + /// + /// Set to true to cancel drawing (e.g. if you have already manually + /// drawn content). + /// + public bool Handled {get;set;} + + /// + /// The rune and color of each symbol that will be rendered. Note + /// that only is respected. You + /// can modify these to change what is rendered. + /// + /// + /// Changing the length of this collection may result in corrupt rendering + /// + public List RuneCells {get; init;} + } + + class TreeSelection where T : class { public Branch Origin { get; }