From 54fc9fce610cfc89b9bfc4885394cb3e06443662 Mon Sep 17 00:00:00 2001 From: Tigger Kindel Date: Sun, 19 Mar 2023 23:30:15 -0600 Subject: [PATCH] More progress --- Terminal.Gui/Core/Frame.cs | 47 ++++++++++++++++++++------ Terminal.Gui/Core/View.cs | 9 ++--- Terminal.Gui/Core/Window.cs | 2 +- Terminal.Gui/Views/FrameView.cs | 2 +- UICatalog/Scenarios/Frames.cs | 10 +++--- UICatalog/Scenarios/ViewExperiments.cs | 42 +++++++++++++++-------- 6 files changed, 75 insertions(+), 37 deletions(-) diff --git a/Terminal.Gui/Core/Frame.cs b/Terminal.Gui/Core/Frame.cs index 9b33958bb..0417f67e0 100644 --- a/Terminal.Gui/Core/Frame.cs +++ b/Terminal.Gui/Core/Frame.cs @@ -18,7 +18,7 @@ namespace Terminal.Gui { public class Frame : View { private Thickness _thickness; - internal override void CreateFrames (){ /* Do nothing - Frames do not have Frames */ } + internal override void CreateFrames () { /* Do nothing - Frames do not have Frames */ } /// /// The Parent of this Frame (the View this Frame surrounds). @@ -91,6 +91,8 @@ namespace Terminal.Gui { if (ColorScheme != null) { Driver.SetAttribute (ColorScheme.Normal); + } else { + Driver.SetAttribute (Parent.GetNormalColor ()); } var prevClip = SetClip (Frame); @@ -100,22 +102,45 @@ namespace Terminal.Gui { //OnDrawSubviews (bounds); - if (BorderStyle != BorderStyle.None) { + // TODO: v2 - this will eventually be two controls: "BorderView" and "Label" (for the title) + if (Id == "BorderFrame" && BorderStyle != BorderStyle.None) { var lc = new LineCanvas (); - lc.AddLine (screenBounds.Location, Frame.Width - 1, Orientation.Horizontal, BorderStyle); - lc.AddLine (screenBounds.Location, Frame.Height - 1, Orientation.Vertical, BorderStyle); + if (Thickness.Top > 0) { + if (ustring.IsNullOrEmpty (Parent?.Title)) { + lc.AddLine (screenBounds.Location, Frame.Width - 1, Orientation.Horizontal, BorderStyle); + } else { - lc.AddLine (new Point (screenBounds.X, screenBounds.Y + screenBounds.Height - 1), screenBounds.Width - 1, Orientation.Horizontal, BorderStyle); - lc.AddLine (new Point (screenBounds.X + screenBounds.Width - 1, screenBounds.Y), screenBounds.Height - 1, Orientation.Vertical, BorderStyle); + lc.AddLine (screenBounds.Location, Frame.Width - 1, Orientation.Horizontal, BorderStyle); + + //// ╔╡ Title ╞═════╗ + //// Add a short horiz line for ╔╡ + //lc.AddLine (screenBounds.Location, 1, Orientation.Horizontal, BorderStyle); + //// Add a short vert line for ╔╡ + //lc.AddLine (new Point (screenBounds.X + 1, screenBounds.Location.Y - 1), 1, Orientation.Vertical, BorderStyle.Single); + //// Add a short vert line for ╞ + //lc.AddLine (new Point (screenBounds.X + (Parent.Title.Length + 3), screenBounds.Location.Y - 1), 1, Orientation.Vertical, BorderStyle.Single); + //// Add the right hand line for ╞═════╗ + //lc.AddLine (new Point (screenBounds.X + (Parent.Title.Length + 3), screenBounds.Location.Y), Frame.Width - 1 - (Parent.Title.Length + 2), Orientation.Horizontal, BorderStyle); + } + } + if (Thickness.Left > 0) { + lc.AddLine (screenBounds.Location, Frame.Height - 1, Orientation.Vertical, BorderStyle); + } + if (Thickness.Bottom > 0) { + lc.AddLine (new Point (screenBounds.X, screenBounds.Y + screenBounds.Height - 1), screenBounds.Width - 1, Orientation.Horizontal, BorderStyle); + } + if (Thickness.Right > 0) { + lc.AddLine (new Point (screenBounds.X + screenBounds.Width - 1, screenBounds.Y), screenBounds.Height - 1, Orientation.Vertical, BorderStyle); + } foreach (var p in lc.GenerateImage (screenBounds)) { Driver.Move (p.Key.X, p.Key.Y); Driver.AddRune (p.Value); } + } + if (Id == "BorderFrame" && Thickness.Top > 0 && !ustring.IsNullOrEmpty (Parent?.Title)) { - if (!ustring.IsNullOrEmpty (Parent?.Title)) { - Driver.SetAttribute (Parent.HasFocus ? Parent.GetHotNormalColor () : Parent.GetNormalColor ()); - Driver.DrawWindowTitle (screenBounds, Parent?.Title, 0, 0, 0, 0); - } + Driver.SetAttribute (Parent.HasFocus ? Parent.GetHotNormalColor () : Parent.GetNormalColor ()); + Driver.DrawWindowTitle (screenBounds, Parent?.Title, 0, 0, 0, 0); } Driver.Clip = prevClip; @@ -138,7 +163,7 @@ namespace Terminal.Gui { if (prev != _thickness) { OnThicknessChanged (); } - + } } diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index a9066b87b..4dd8c0344 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -530,7 +530,6 @@ namespace Terminal.Gui { Margin = new Frame () { Id = "Margin", Thickness = new Thickness (0) }; Margin.ThicknessChanged += ThicknessChangedHandler; Margin.Parent = this; - //Margin.DiagnosticsLabel.Text = "Margin"; if (BorderFrame != null) { BorderFrame.ThicknessChanged -= ThicknessChangedHandler; @@ -540,6 +539,7 @@ namespace Terminal.Gui { BorderFrame = new Frame () { Id = "BorderFrame", Thickness = new Thickness (0), BorderStyle = BorderStyle.Single }; BorderFrame.ThicknessChanged += ThicknessChangedHandler; BorderFrame.Parent = this; + // TODO: Create View.AddAdornment if (Padding != null) { @@ -552,8 +552,8 @@ namespace Terminal.Gui { } /// - /// Lays out the views s objects (, , and - /// as needed. Causes each Frame to Layout it's subviews. + /// Lays out the view's objects (, , and + /// as needed. Causes each Frame to Layout its SubViews. /// public void LayoutFrames () { @@ -593,7 +593,8 @@ namespace Terminal.Gui { ustring title; /// - /// The title to be displayed for this . + /// The title to be displayed for this . The title will be displayed if . + /// is greater than 0. /// /// The title. public ustring Title { diff --git a/Terminal.Gui/Core/Window.cs b/Terminal.Gui/Core/Window.cs index 2cec6000e..2853496ae 100644 --- a/Terminal.Gui/Core/Window.cs +++ b/Terminal.Gui/Core/Window.cs @@ -116,7 +116,7 @@ namespace Terminal.Gui { } BorderFrame.Thickness = new Thickness (1); BorderFrame.BorderStyle = Border.BorderStyle; - BorderFrame.ColorScheme = ColorScheme; + //BorderFrame.ColorScheme = ColorScheme; BorderFrame.Data = "BorderFrame"; // TODO: Hack until Border is refactored diff --git a/Terminal.Gui/Views/FrameView.cs b/Terminal.Gui/Views/FrameView.cs index 85b5fe8db..60da81941 100644 --- a/Terminal.Gui/Views/FrameView.cs +++ b/Terminal.Gui/Views/FrameView.cs @@ -75,7 +75,7 @@ namespace Terminal.Gui { public FrameView () : this (title: string.Empty) { BorderFrame.Thickness = new Thickness (1); BorderFrame.BorderStyle = Border.BorderStyle; - BorderFrame.ColorScheme = ColorScheme; + //BorderFrame.ColorScheme = ColorScheme; BorderFrame.Data = "BorderFrame"; } diff --git a/UICatalog/Scenarios/Frames.cs b/UICatalog/Scenarios/Frames.cs index b6c1db618..5da07f002 100644 --- a/UICatalog/Scenarios/Frames.cs +++ b/UICatalog/Scenarios/Frames.cs @@ -74,7 +74,7 @@ namespace UICatalog.Scenarios { Add (leftEdit); var rightEdit = new TextField ("") { - X = Pos.Right (topEdit) + 1, + X = Pos.Right (topEdit), Y = Pos.Bottom (topEdit), Width = 5 }; @@ -183,10 +183,10 @@ namespace UICatalog.Scenarios { }; Add (rbBorderStyle); - //rbBorderStyle.SelectedItemChanged += (e) => { - // viewToEdit.BorderFrame.BorderStyle = (BorderStyle)e.SelectedItem; - // viewToEdit.SetNeedsDisplay (); - //}; + rbBorderStyle.SelectedItemChanged += (e) => { + viewToEdit.BorderFrame.BorderStyle = (BorderStyle)e.SelectedItem; + viewToEdit.SetNeedsDisplay (); + }; //Add (new Label ("Background:") { // Y = 5 diff --git a/UICatalog/Scenarios/ViewExperiments.cs b/UICatalog/Scenarios/ViewExperiments.cs index dc1214e3c..3394d907d 100644 --- a/UICatalog/Scenarios/ViewExperiments.cs +++ b/UICatalog/Scenarios/ViewExperiments.cs @@ -23,7 +23,7 @@ namespace UICatalog.Scenarios { public ThicknessEditor () { - Margin.Thickness = new Thickness (1); + Margin.Thickness = new Thickness (0); BorderFrame.Thickness = new Thickness (1); } @@ -71,7 +71,7 @@ namespace UICatalog.Scenarios { Add (leftEdit); var rightEdit = new TextField ("") { - X = Pos.Right (topEdit) + 1, + X = Pos.Right (topEdit), Y = Pos.Bottom (topEdit), Width = 5 }; @@ -132,11 +132,12 @@ namespace UICatalog.Scenarios { { viewToEdit.Margin.ColorScheme = Colors.ColorSchemes ["Toplevel"]; var marginEditor = new ThicknessEditor () { - X = 20, + X = 0, Y = 0, Title = "Margin", Thickness = viewToEdit.Margin.Thickness, }; + marginEditor.Margin.Thickness = new Thickness (0, 0, 1, 0); marginEditor.ThicknessChanged += (s, a) => { viewToEdit.Margin.Thickness = a.Thickness; }; @@ -149,14 +150,35 @@ namespace UICatalog.Scenarios { Title = "Border", Thickness = viewToEdit.BorderFrame.Thickness, }; + borderEditor.Margin.Thickness = new Thickness (0, 0, 1, 0); borderEditor.ThicknessChanged += (s, a) => { viewToEdit.BorderFrame.Thickness = a.Thickness; }; Add (borderEditor); + var styleLabel = new Label ("BorderStyle: ") { + X = Pos.Right (borderEditor), + Y = 0 + }; + Add (styleLabel); + + var borderStyleEnum = Enum.GetValues (typeof (BorderStyle)).Cast ().ToList (); + var rbBorderStyle = new RadioGroup (borderStyleEnum.Select ( + e => NStack.ustring.Make (e.ToString ())).ToArray ()) { + X = Pos.Left (styleLabel), + Y = Pos.Bottom (styleLabel), + SelectedItem = (int)viewToEdit.BorderFrame.BorderStyle + }; + + rbBorderStyle.SelectedItemChanged += (e) => { + viewToEdit.BorderFrame.BorderStyle = (BorderStyle)e.SelectedItem; + viewToEdit.SetNeedsDisplay (); + }; + Add (rbBorderStyle); + viewToEdit.Padding.ColorScheme = Colors.ColorSchemes ["Error"]; var paddingEditor = new ThicknessEditor () { - X = Pos.Right (borderEditor), + X = Pos.Right (styleLabel), Y = 0, Title = "Padding", Thickness = viewToEdit.Padding.Thickness, @@ -168,17 +190,7 @@ namespace UICatalog.Scenarios { viewToEdit.Y = Pos.Center () + 4; - Add (new Label ("BorderStyle:")); - var borderStyleEnum = Enum.GetValues (typeof (BorderStyle)).Cast ().ToList (); - var rbBorderStyle = new RadioGroup (borderStyleEnum.Select ( - e => NStack.ustring.Make (e.ToString ())).ToArray ()) { - - X = 2, - Y = 1, - SelectedItem = (int)viewToEdit.BorderFrame.BorderStyle - }; - Add (rbBorderStyle); //rbBorderStyle.SelectedItemChanged += (e) => { // viewToEdit.BorderFrame.BorderStyle = (BorderStyle)e.SelectedItem; @@ -223,7 +235,7 @@ namespace UICatalog.Scenarios { //}; //Add (rbBorderBrush); - Height = 9; + Height = 8; Title = title; } }