From 86564d53400a1da96cc00cee9d02dd647417d9c8 Mon Sep 17 00:00:00 2001 From: tznind Date: Sat, 14 Jan 2023 20:03:51 +0000 Subject: [PATCH] Fix subcontainers in SplitContainerNesting example not having Titles --- Terminal.Gui/Views/SplitContainer.cs | 47 +++++++++++++++----- UICatalog/Scenarios/SplitContainerNesting.cs | 21 +++++---- 2 files changed, 49 insertions(+), 19 deletions(-) diff --git a/Terminal.Gui/Views/SplitContainer.cs b/Terminal.Gui/Views/SplitContainer.cs index 294d291e8..65637fdee 100644 --- a/Terminal.Gui/Views/SplitContainer.cs +++ b/Terminal.Gui/Views/SplitContainer.cs @@ -1,6 +1,7 @@ using NStack; using System; using System.Collections.Generic; +using System.Linq; using Terminal.Gui.Graphs; namespace Terminal.Gui { @@ -104,17 +105,17 @@ namespace Terminal.Gui { contentArea = new Rect( contentArea.X + 1, contentArea.Y + 1, - contentArea.Width - 2, - contentArea.Height - 2); + Math.Max (0, contentArea.Width - 2), + Math.Max (0, contentArea.Height - 2)); } - else if(HasAnyTitles()) + else if(HasAnyTitles() && IsRootSplitContainer()) { // TODO: Bound with Max/Min contentArea = new Rect( contentArea.X, contentArea.Y + 1, contentArea.Width, - contentArea.Height - 1); + Math.Max(0,contentArea.Height - 1)); } Setup (contentArea); @@ -155,6 +156,8 @@ namespace Terminal.Gui { /// public override void Redraw (Rect bounds) { + var childTitles = new List (); + Driver.SetAttribute (ColorScheme.Normal); Clear (); base.Redraw (bounds); @@ -174,7 +177,7 @@ namespace Terminal.Gui { lc.AddLine (new Point (bounds.Width - 1, bounds.Height - 1), -bounds.Height + 1, Orientation.Vertical, IntegratedBorder); } - foreach (var line in allLines) + foreach (var line in allLines.Where(l=>l.Visible)) { bool isRoot = line == splitterLine; @@ -192,7 +195,9 @@ namespace Terminal.Gui { } length += 2; - // TODO: Render this title too + childTitles.Add ( + new ChildSplitterLine(line)); + } lc.AddLine(origin,length,line.Orientation,IntegratedBorder); @@ -207,8 +212,12 @@ namespace Terminal.Gui { line.DrawSplitterSymbol (); } + foreach(var child in childTitles) { + child.DrawTitles (); + } + // Draw Titles over Border - var screen = ViewToScreen (bounds); + var screen = ViewToScreen (new Rect(0,0,bounds.Width,1)); if (Panel1.Visible && Panel1Title.Length > 0) { Driver.SetAttribute (Panel1.HasFocus ? ColorScheme.HotNormal : ColorScheme.Normal); Driver.DrawWindowTitle (new Rect (screen.X, screen.Y, Panel1.Frame.Width, 0), Panel1Title, 0, 0, 0, 0); @@ -226,12 +235,12 @@ namespace Terminal.Gui { if (Panel2.Visible && Panel2Title?.Length > 0) { Driver.SetAttribute (Panel2.HasFocus ? ColorScheme.HotNormal : ColorScheme.Normal); - Driver.DrawWindowTitle (new Rect (screen.X + 1, screen.Y, Panel2.Bounds.Width, 1), Panel2Title, 0, 0, 0, 0); + Driver.DrawWindowTitle (new Rect (screen.X, screen.Y, Panel2.Bounds.Width, 1), Panel2Title, 0, 0, 0, 0); } } else { if (Panel2.Visible && Panel2Title?.Length > 0) { Driver.SetAttribute (Panel2.HasFocus ? ColorScheme.HotNormal : ColorScheme.Normal); - Driver.DrawWindowTitle (new Rect (screen.X + 1, screen.Y, Panel2.Bounds.Width, 1), Panel2Title, 0, 0, 0, 0); + Driver.DrawWindowTitle (new Rect (screen.X, screen.Y, Panel2.Bounds.Width, 1), Panel2Title, 0, 0, 0, 0); } } } @@ -384,7 +393,6 @@ namespace Terminal.Gui { // this splitter position is fine, there is enough space for everyone return pos; } - private class SplitContainerLineView : LineView { public SplitContainer Parent { get; private set; } @@ -615,6 +623,25 @@ namespace Terminal.Gui { return Panel1Title.Length > 0 || Panel2Title.Length > 0; } + + private class ChildSplitterLine { + + readonly SplitContainerLineView currentLine; + internal ChildSplitterLine (SplitContainerLineView currentLine) + { + this.currentLine = currentLine; + } + + internal void DrawTitles () + { + if(currentLine.Orientation == Orientation.Horizontal) + { + var screenRect = currentLine.ViewToScreen ( + new Rect(0,0,currentLine.Frame.Width,currentLine.Frame.Height)); + Driver.DrawWindowTitle (screenRect, currentLine.Parent.Panel2Title, 0, 0, 0, 0); + } + } + } } /// diff --git a/UICatalog/Scenarios/SplitContainerNesting.cs b/UICatalog/Scenarios/SplitContainerNesting.cs index 527d4343f..95fa978be 100644 --- a/UICatalog/Scenarios/SplitContainerNesting.cs +++ b/UICatalog/Scenarios/SplitContainerNesting.cs @@ -95,15 +95,13 @@ namespace UICatalog.Scenarios { return; } - var root = CreateSplitContainer (startHorizontal ? + var root = CreateSplitContainer (1,startHorizontal ? Terminal.Gui.Graphs.Orientation.Horizontal : Terminal.Gui.Graphs.Orientation.Vertical, false); root.Panel1.Add (CreateTextView (1)); - root.Panel1Title = titles ? "Panel 1" : string.Empty; - root.Panel2.Add (CreateTextView (2)); - root.Panel2Title = titles ? "Panel 2" : string.Empty; + root.IntegratedBorder = border ? BorderStyle.Rounded : BorderStyle.None; @@ -162,31 +160,34 @@ namespace UICatalog.Scenarios { // we can split Panel1 var tv = (TextView)to.Panel1.Subviews.Single (); - var newContainer = CreateSplitContainer (to.Orientation, true); + panelsCreated++; + + var newContainer = CreateSplitContainer (panelsCreated, to.Orientation, true); to.Remove (to.Panel1); to.Add (newContainer); to.Panel1 = newContainer; newContainer.Panel1.Add (tv); - newContainer.Panel2.Add (CreateTextView (++panelsCreated)); + newContainer.Panel2.Add (CreateTextView (panelsCreated)); } private void SplitRight(SplitContainer to) { // we can split Panel2 var tv = (TextView)to.Panel2.Subviews.Single (); + panelsCreated++; - var newContainer = CreateSplitContainer (to.Orientation, true); + var newContainer = CreateSplitContainer (panelsCreated, to.Orientation, true); to.Remove (to.Panel2); to.Add (newContainer); to.Panel2 = newContainer; newContainer.Panel2.Add (tv); - newContainer.Panel1.Add (CreateTextView (++panelsCreated)); + newContainer.Panel1.Add (CreateTextView (panelsCreated)); } - private SplitContainer CreateSplitContainer (Orientation orientation, bool flip) + private SplitContainer CreateSplitContainer (int titleNumber, Orientation orientation, bool flip) { var toReturn = new SplitContainer { Width = Dim.Fill (), @@ -200,6 +201,8 @@ namespace UICatalog.Scenarios { Orientation.Horizontal : Orientation.Vertical; } + toReturn.Panel1Title = cbTitles.Checked ? $"Panel {titleNumber}" : string.Empty; + toReturn.Panel2Title = cbTitles.Checked ? $"Panel {titleNumber+1}" : string.Empty; return toReturn; }