From e89a6122df3b73e4f5597f9a0ee711d26212f17e Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Wed, 16 Oct 2019 10:45:58 -0400 Subject: [PATCH] View.{BrinbSubviewForward,SendSubviewBackwards,SendSubviewToBack,BringSubviewToFront --- Terminal.Gui/Core.cs | 76 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/Terminal.Gui/Core.cs b/Terminal.Gui/Core.cs index 3ac2e08d5..de6ba991e 100644 --- a/Terminal.Gui/Core.cs +++ b/Terminal.Gui/Core.cs @@ -545,6 +545,82 @@ namespace Terminal.Gui { } } + void PerformActionForSubview (View subview, Action action) + { + if (subviews.Contains (subview)) { + action (subview); + } + + SetNeedsDisplay (); + subview.SetNeedsDisplay (); + } + + /// + /// Brings the specified subview to the front so it is drawn on top of any other views. + /// + /// The subview to send to the front + /// + /// . + /// + public void BringSubviewToFront (View subview) + { + PerformActionForSubview (subview, x => { + subviews.Remove (x); + subviews.Add (x); + }); + } + + /// + /// Sends the specified subview to the front so it is the first view drawn + /// + /// The subview to send to the front + /// + /// . + /// + public void SendSubviewToBack (View subview) + { + PerformActionForSubview (subview, x => { + subviews.Remove (x); + subviews.Insert (0, subview); + }); + } + + /// + /// Moves the subview backwards in the hierarchy, only one step + /// + /// The subview to send backwards + /// + /// If you want to send the view all the way to the back use SendSubviewToBack. + /// + public void SendSubviewBackwards (View subview) + { + PerformActionForSubview (subview, x => { + var idx = subviews.IndexOf (x); + if (idx > 0) { + subviews.Remove (x); + subviews.Insert (idx - 1, x); + } + }); + } + + /// + /// Moves the subview backwards in the hierarchy, only one step + /// + /// The subview to send backwards + /// + /// If you want to send the view all the way to the back use SendSubviewToBack. + /// + public void BringSubviewForward (View subview) + { + PerformActionForSubview (subview, x => { + var idx = subviews.IndexOf (x); + if (idx+1 < subviews.Count) { + subviews.Remove (x); + subviews.Insert (idx+1, x); + } + }); + } + /// /// Clears the view region with the current color. ///