ソースを参照

FrameView experiment

Tig Kindel 2 年 前
コミット
ccadf81b4d
2 ファイル変更135 行追加43 行削除
  1. 83 9
      Terminal.Gui/Views/FrameView.cs
  2. 52 34
      UICatalog/Scenarios/TileViewExperiment.cs

+ 83 - 9
Terminal.Gui/Views/FrameView.cs

@@ -12,6 +12,7 @@
 using System;
 using System.Linq;
 using NStack;
+using Terminal.Gui.Graphs;
 
 namespace Terminal.Gui {
 	/// <summary>
@@ -88,7 +89,7 @@ namespace Terminal.Gui {
 		public FrameView (Rect frame, ustring title = null, View [] views = null, Border border = null) //: base (frame)
 		{
 			//var cFrame = new Rect (1, 1, Math.Max (frame.Width - 2, 0), Math.Max (frame.Height - 2, 0));
-			
+
 			Initialize (frame, title, views, border);
 		}
 
@@ -230,14 +231,87 @@ namespace Terminal.Gui {
 
 			ClearNeedsDisplay ();
 
-			Driver.SetAttribute (GetNormalColor ());
-			//Driver.DrawWindowFrame (scrRect, padding + 1, padding + 1, padding + 1, padding + 1, border: true, fill: false);
-			Border.DrawContent (this, false);
-			if (HasFocus)
-				Driver.SetAttribute (ColorScheme.HotNormal);
-			if (Border.DrawMarginFrame)
-				Driver.DrawWindowTitle (scrRect, Title, padding.Left, padding.Top, padding.Right, padding.Bottom);
-			Driver.SetAttribute (GetNormalColor ());
+			if (!IgnoreBorderPropertyOnRedraw) {
+				Driver.SetAttribute (GetNormalColor ());
+				//Driver.DrawWindowFrame (scrRect, padding + 1, padding + 1, padding + 1, padding + 1, border: true, fill: false);
+				Border.DrawContent (this, false);
+				if (HasFocus)
+					Driver.SetAttribute (ColorScheme.HotNormal);
+				if (Border.DrawMarginFrame)
+					Driver.DrawWindowTitle (scrRect, Title, padding.Left, padding.Top, padding.Right, padding.Bottom);
+				Driver.SetAttribute (GetNormalColor ());
+			} else {
+				Driver.SetAttribute (ColorScheme.Normal);
+
+				var lc = new LineCanvas ();
+
+				if (Border?.BorderStyle != BorderStyle.None) {
+
+					lc.AddLine (new Point (0, 0), bounds.Width - 1, Orientation.Horizontal, Border.BorderStyle);
+					lc.AddLine (new Point (0, 0), bounds.Height - 1, Orientation.Vertical, Border.BorderStyle);
+
+					lc.AddLine (new Point (bounds.Width - 1, bounds.Height - 1), -bounds.Width + 1, Orientation.Horizontal, Border.BorderStyle);
+					lc.AddLine (new Point (bounds.Width - 1, bounds.Height - 1), -bounds.Height + 1, Orientation.Vertical, Border.BorderStyle);
+				}
+
+				foreach (var subview in contentView.Subviews) {
+					lc.AddLine (new Point (subview.Frame.X+1, subview.Frame.Y+1), subview.Frame.Width - 1, Orientation.Horizontal, subview.Border.BorderStyle);
+					lc.AddLine (new Point (subview.Frame.X+1, subview.Frame.Y+1), subview.Frame.Height - 1, Orientation.Vertical, subview.Border.BorderStyle);
+
+					lc.AddLine (new Point (subview.Frame.Width - 1, subview.Frame.Y + subview.Frame.Height), -subview.Frame.Width + 1, Orientation.Horizontal, subview.Border.BorderStyle);
+					lc.AddLine (new Point (subview.Frame.X + subview.Frame.Width, subview.Frame.Height - 1), -subview.Frame.Height + 1, Orientation.Vertical, subview.Border.BorderStyle);
+				}
+
+				//foreach (var line in allLines) {
+				//	bool isRoot = splitterLines.Contains (line);
+
+				//	line.ViewToScreen (0, 0, out var x1, out var y1);
+				//	var origin = ScreenToView (x1, y1);
+				//	var length = line.Orientation == Orientation.Horizontal ?
+				//			line.Frame.Width - 1 :
+				//			line.Frame.Height - 1;
+
+				//	if (!isRoot) {
+				//		if (line.Orientation == Orientation.Horizontal) {
+				//			origin.X -= 1;
+				//		} else {
+				//			origin.Y -= 1;
+				//		}
+				//		length += 2;
+				//	}
+
+				//	lc.AddLine (origin, length, line.Orientation, Border.BorderStyle);
+				//}
+
+
+				Driver.SetAttribute (ColorScheme.Normal);
+				lc.Draw (this, bounds);
+
+				//// Redraw the lines so that focus/drag symbol renders
+				//foreach (var line in allLines) {
+				//	line.DrawSplitterSymbol ();
+				//}
+
+				// Draw Titles over Border
+
+				//foreach (var titleToRender in allTitlesToRender) {
+				//	var renderAt = titleToRender.GetLocalCoordinateForTitle (this);
+
+				//	if (renderAt.Y < 0) {
+				//		// If we have no border then root level tiles
+				//		// have nowhere to render their titles.
+				//		continue;
+				//	}
+
+				//	// TODO: Render with focus color if focused
+
+				//	var title = titleToRender.GetTrimmedTitle ();
+
+				//	for (int i = 0; i < title.Length; i++) {
+				//		AddRune (renderAt.X + i, renderAt.Y, title [i]);
+				//	}
+				//}
+			}
 		}
 
 		/// <summary>

+ 52 - 34
UICatalog/Scenarios/TileViewExperiment.cs

@@ -9,28 +9,6 @@ namespace UICatalog.Scenarios {
 	[ScenarioCategory ("LineView")]
 	public class TileViewExperiment : Scenario {
 
-		class NewFrameView : FrameView {
-			public NewFrameView () : base ()
-			{
-				LayoutStarted += NewFrameView_LayoutStarted;
-			}
-
-			private void NewFrameView_LayoutStarted (LayoutEventArgs obj)
-			{
-				foreach (var subview in Subviews.ToArray () [0].Subviews) {
-					if (subview.Border?.BorderStyle != BorderStyle.None &&
-					subview.Text == "View 1 Text") {
-
-						subview.Text = subview.X.ToString ();
-
-					}
-				}
-			}
-		}
-
-		class TileFrameView : TileView {
-
-		}
 
 		public override void Init (ColorScheme colorScheme)
 		{
@@ -49,11 +27,12 @@ namespace UICatalog.Scenarios {
 
 			Application.Top.Add (menu);
 
-			var frame = new NewFrameView () {
+			var frame = new FrameView () {
 				X = 0,
 				Y = 1,
 				Width = Dim.Fill (),
 				Height = Dim.Fill (),
+				IgnoreBorderPropertyOnRedraw = true
 			};
 			frame.Border.BorderStyle = BorderStyle.Double;
 
@@ -61,29 +40,68 @@ namespace UICatalog.Scenarios {
 
 			var view1 = new FrameView () {
 				Title = "View 1",
-				Text = "View 1 Text",
+				Text = "View1 30%/50% Single",
 				X = -1,
 				Y = -1,
 				Width = Dim.Percent (30),
-				Height = Dim.Fill (-1),
-				ColorScheme = Colors.ColorSchemes ["Dialog"]
-				//Border = new Border () { BorderStyle = BorderStyle.Single }
+				Height = Dim.Percent (50),
+				ColorScheme = Colors.ColorSchemes ["Dialog"],
+				Border = new Border () { BorderStyle = BorderStyle.Single }
 			};
 
 			frame.Add (view1);
 
 			var view2 = new FrameView () {
 				Title = "View 2",
-				Text = "View 2 Text",
-				X = Pos.Right (view1),
-				Y = 0,
-				Width = Dim.Fill (),
-				Height = Dim.Fill (),
-				ColorScheme = Colors.ColorSchemes ["Error"]
-				//Border = new Border () { BorderStyle = BorderStyle.Single }
+				Text = "View2 right of view1, 30%/Fill Single.",
+				X = Pos.Right (view1) - 1,
+				Y = -1,
+				Width = Dim.Percent (30),
+				Height = Dim.Fill (-1),
+				ColorScheme = Colors.ColorSchemes ["Error"],
+				Border = new Border () { BorderStyle = BorderStyle.Single }
 			};
 
 			frame.Add (view2);
+
+			var view3 = new FrameView () {
+				Title = "View 3",
+				Text = "View3 right of View2 Fill/Fill Single",
+				X = Pos.Right (view2) - 1,
+				Y = -1,
+				Width = Dim.Fill (-1),
+				Height = Dim.Fill (-1),
+				ColorScheme = Colors.ColorSchemes ["Menu"],
+				Border = new Border () { BorderStyle = BorderStyle.Single }
+			};
+
+			frame.Add (view3);
+
+			var view4 = new FrameView () {
+				Title = "View 4",
+				Text = "View4 below View1 30%/5 Single",
+				X = -1,
+				Y = Pos.Bottom (view1)-1,
+				Width = Dim.Percent (30),
+				Height = 5,
+				ColorScheme = Colors.ColorSchemes ["TopLevel"],
+				Border = new Border () { BorderStyle = BorderStyle.Single }
+			};
+
+			frame.Add (view4);
+
+			var view5 = new FrameView () {
+				Title = "View 5",
+				Text = "View5 below View4 view4.Width/5 Double",
+				X = -1,
+				Y = Pos.Bottom (view4) - 1,
+				Width = view4.Width,
+				Height = 5,
+				ColorScheme = Colors.ColorSchemes ["TopLevel"],
+				Border = new Border () { BorderStyle = BorderStyle.Double }
+			};
+
+			frame.Add (view5);
 		}
 	}
 }