diff --git a/Terminal.Gui/Core/Border.cs b/Terminal.Gui/Core/Border.cs index e90c26ef7..55d73a65c 100644 --- a/Terminal.Gui/Core/Border.cs +++ b/Terminal.Gui/Core/Border.cs @@ -1,4 +1,5 @@ -using System; +using NStack; +using System; namespace Terminal.Gui { /// @@ -138,7 +139,7 @@ namespace Terminal.Gui { /// /// Initializes with default null values. /// - public ToplevelContainer () : this (null, null) { } + public ToplevelContainer () : this (null, string.Empty) { } /// /// Initializes a with a @@ -147,7 +148,7 @@ namespace Terminal.Gui { /// The title. public ToplevelContainer (Border border, string title = null) { - Initialize (Rect.Empty, border, title); + Initialize (Rect.Empty, border, title ?? string.Empty); } /// @@ -158,17 +159,17 @@ namespace Terminal.Gui { /// The title. public ToplevelContainer (Rect frame, Border border, string title = null) : base (frame) { - Initialize (frame, border, title); + Initialize (frame, border, title ?? string.Empty); } - private void Initialize (Rect frame, Border border, string title = null) + private void Initialize (Rect frame, Border border, string title) { ColorScheme = Colors.TopLevel; - Text = title ?? ""; if (border == null) { Border = new Border () { BorderStyle = BorderStyle.Single, - BorderBrush = ColorScheme.Normal.Background + BorderBrush = ColorScheme.Normal.Background, + Title = (ustring)title }; } else { Border = border; @@ -266,8 +267,12 @@ namespace Terminal.Gui { Border.DrawContent (this, false); if (HasFocus) Driver.SetAttribute (ColorScheme.HotNormal); - if (Border.DrawMarginFrame) - Border.DrawTitle (this, Frame); + if (Border.DrawMarginFrame) { + if (!ustring.IsNullOrEmpty (Border.Title)) + Border.DrawTitle (this); + else + Border.DrawTitle (this, Frame); + } Driver.SetAttribute (GetNormalColor ()); // Checks if there are any SuperView view which intersect with this window. @@ -306,16 +311,20 @@ namespace Terminal.Gui { } /// - /// Event to be invoked when any border property change. + /// Invoked when any property of Border changes (except ). /// public event Action BorderChanged; private BorderStyle borderStyle; private bool drawMarginFrame; private Thickness borderThickness; + private Color borderBrush; + private Color background; private Thickness padding; private bool effect3D; private Point effect3DOffset = new Point (1, 1); + private Attribute? effect3DBrush; + private ustring title = ustring.Empty; /// /// Specifies the for a view. @@ -363,12 +372,24 @@ namespace Terminal.Gui { /// /// Gets or sets the that draws the outer border color. /// - public Color BorderBrush { get; set; } + public Color BorderBrush { + get => borderBrush; + set { + borderBrush = value; + OnBorderChanged (); + } + } /// /// Gets or sets the that fills the area between the bounds of a . /// - public Color Background { get; set; } + public Color Background { + get => background; + set { + background = value; + OnBorderChanged (); + } + } /// /// Gets or sets a value that describes the amount of space between a @@ -448,7 +469,24 @@ namespace Terminal.Gui { /// /// Gets or sets the color for the /// - public Attribute? Effect3DBrush { get; set; } + public Attribute? Effect3DBrush { + get => effect3DBrush; + set { + effect3DBrush = value; + OnBorderChanged (); + } + } + + /// + /// The title to be displayed for this view. + /// + public ustring Title { + get => title; + set { + title = value; + OnBorderChanged (); + } + } /// /// Calculate the sum of the and the @@ -677,6 +715,7 @@ namespace Terminal.Gui { }; if (rect.Width > 0 && rect.Height > 0) { driver.DrawWindowFrame (rect, 1, 1, 1, 1, BorderStyle != BorderStyle.None, fill, this); + DrawTitle (Child); } } @@ -831,6 +870,7 @@ namespace Terminal.Gui { }; if (rect.Width > 0 && rect.Height > 0) { driver.DrawWindowFrame (rect, 1, 1, 1, 1, BorderStyle != BorderStyle.None, fill, this); + DrawTitle (Parent); } } @@ -900,18 +940,47 @@ namespace Terminal.Gui { } /// - /// Drawn the view text from a . + /// Draws the view to the screen. /// + /// The view. + public void DrawTitle (View view) + { + var driver = Application.Driver; + if (DrawMarginFrame) { + driver.SetAttribute (Child.GetNormalColor ()); + if (Child.HasFocus) + driver.SetAttribute (Child.ColorScheme.HotNormal); + var padding = view.Border.GetSumThickness (); + Rect scrRect; + if (view == Child) { + scrRect = view.ViewToScreen (new Rect (0, 0, view.Frame.Width + 2, view.Frame.Height + 2)); + scrRect = new Rect (scrRect.X - 1, scrRect.Y - 1, scrRect.Width, scrRect.Height); + driver.DrawWindowTitle (scrRect, Title, 0, 0, 0, 0); + } else { + scrRect = view.ViewToScreen (new Rect (0, 0, view.Frame.Width, view.Frame.Height)); + driver.DrawWindowTitle (scrRect, Title, + padding.Left, padding.Top, padding.Right, padding.Bottom); + } + } + driver.SetAttribute (Child.GetNormalColor ()); + } + + /// + /// Draws the to the screen. + /// + /// The view. + /// The frame. public void DrawTitle (View view, Rect rect) { var driver = Application.Driver; - if (BorderStyle != BorderStyle.None) { + if (DrawMarginFrame) { driver.SetAttribute (view.GetNormalColor ()); if (view.HasFocus) { driver.SetAttribute (view.ColorScheme.HotNormal); } - var padding = GetSumThickness (); - driver.DrawWindowTitle (rect, view.Text, + var padding = Parent.Border.GetSumThickness (); + var scrRect = Parent.ViewToScreen (new Rect (0, 0, rect.Width, rect.Height)); + driver.DrawWindowTitle (scrRect, view.Text, padding.Left, padding.Top, padding.Right, padding.Bottom); } driver.SetAttribute (view.GetNormalColor ()); diff --git a/Terminal.Gui/Views/PanelView.cs b/Terminal.Gui/Views/PanelView.cs index 12fdbfcab..2bcef2745 100644 --- a/Terminal.Gui/Views/PanelView.cs +++ b/Terminal.Gui/Views/PanelView.cs @@ -236,6 +236,7 @@ namespace Terminal.Gui { { if (!NeedDisplay.IsEmpty) { Driver.SetAttribute (Child.GetNormalColor ()); + Clear (); Child.Border.DrawContent (Border.Child); } var savedClip = childContentView.ClipToBounds (); diff --git a/UICatalog/Scenarios/Borders.cs b/UICatalog/Scenarios/Borders.cs index 0a4410ae6..cca533d43 100644 --- a/UICatalog/Scenarios/Borders.cs +++ b/UICatalog/Scenarios/Borders.cs @@ -30,8 +30,10 @@ namespace UICatalog.Scenarios { BorderBrush = borderBrush, Padding = padding, Background = background, - Effect3D = effect3D + Effect3D = effect3D, + Title = "Panel" }, + ColorScheme = Colors.TopLevel }; smartPanel.Add (new Label () { // Or smartPanel.Child = X = 0, @@ -79,7 +81,8 @@ namespace UICatalog.Scenarios { BorderBrush = borderBrush, Padding = padding, Background = background, - Effect3D = effect3D + Effect3D = effect3D, + Title = "Label" }, ColorScheme = Colors.TopLevel, Text = "This is a test\nwithout a \nPanelView", diff --git a/UICatalog/Scenarios/BordersComparisons.cs b/UICatalog/Scenarios/BordersComparisons.cs index 80230f954..b07c76e52 100644 --- a/UICatalog/Scenarios/BordersComparisons.cs +++ b/UICatalog/Scenarios/BordersComparisons.cs @@ -65,9 +65,9 @@ namespace UICatalog.Scenarios { BorderBrush = borderBrush, Padding = padding, Background = background, - Effect3D = effect3D - }, - "Test2") { + Effect3D = effect3D, + Title = "Test2" + }) { ColorScheme = Colors.Base, }; diff --git a/UICatalog/Scenarios/BordersOnFrameView.cs b/UICatalog/Scenarios/BordersOnFrameView.cs index 09611a740..4eaf21c31 100644 --- a/UICatalog/Scenarios/BordersOnFrameView.cs +++ b/UICatalog/Scenarios/BordersOnFrameView.cs @@ -30,7 +30,8 @@ namespace UICatalog.Scenarios { BorderBrush = borderBrush, Padding = padding, Background = background, - Effect3D = effect3D + Effect3D = effect3D, + Title = "Frame" }, ColorScheme = Colors.TopLevel }; diff --git a/UICatalog/Scenarios/BordersOnToplevel.cs b/UICatalog/Scenarios/BordersOnToplevel.cs index 31e63c5e1..7364549a8 100644 --- a/UICatalog/Scenarios/BordersOnToplevel.cs +++ b/UICatalog/Scenarios/BordersOnToplevel.cs @@ -30,7 +30,8 @@ namespace UICatalog.Scenarios { BorderBrush = borderBrush, Padding = padding, Background = background, - Effect3D = effect3D + Effect3D = effect3D, + Title = "Toplevel" }, ColorScheme = Colors.TopLevel }; diff --git a/UICatalog/Scenarios/BordersOnWindow.cs b/UICatalog/Scenarios/BordersOnWindow.cs index 3f2199d85..5aaf97466 100644 --- a/UICatalog/Scenarios/BordersOnWindow.cs +++ b/UICatalog/Scenarios/BordersOnWindow.cs @@ -30,7 +30,8 @@ namespace UICatalog.Scenarios { BorderBrush = borderBrush, Padding = padding, Background = background, - Effect3D = effect3D + Effect3D = effect3D, + Title = "Window" }, ColorScheme = Colors.TopLevel }; diff --git a/UnitTests/BorderTests.cs b/UnitTests/BorderTests.cs index 75d137df4..860b0ebfa 100644 --- a/UnitTests/BorderTests.cs +++ b/UnitTests/BorderTests.cs @@ -26,6 +26,7 @@ namespace Terminal.Gui.Core { Assert.False (b.Effect3D); Assert.Equal (new Point (1, 1), b.Effect3DOffset); Assert.Null (b.Effect3DBrush); + Assert.Equal (NStack.ustring.Empty, b.Title); } [Fact]