Browse Source

Add FrameView

Miguel de Icaza 7 years ago
parent
commit
6025594f61

+ 1 - 1
Terminal.Gui/Core.cs

@@ -931,7 +931,7 @@ namespace Terminal.Gui {
 		}
 
 		/// <summary>
-		/// Initializes a new instance of the <see cref="T:Terminal.Window"/> class with an optioanl title
+		/// Initializes a new instance of the <see cref="T:Terminal.Gui.Window"/> class with an optioanl title
 		/// </summary>
 		/// <param name="frame">Frame.</param>
 		/// <param name="title">Title.</param>

+ 6 - 0
Terminal.Gui/Terminal.Gui.csproj

@@ -34,6 +34,10 @@
     <Reference Include="NStack">
       <HintPath>..\packages\NStack.Core.0.7.0\lib\netstandard1.5\NStack.dll</HintPath>
     </Reference>
+    <Reference Include="System.ValueTuple">
+      <HintPath>..\packages\System.ValueTuple.4.4.0\lib\net461\System.ValueTuple.dll</HintPath>
+    </Reference>
+    <Reference Include="mscorlib" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Properties\" />
@@ -61,6 +65,8 @@
     <Compile Include="MonoCurses\constants.cs" />
     <Compile Include="MonoCurses\handles.cs" />
     <Compile Include="MonoCurses\mainloop.cs" />
+    <Compile Include="Views\FrameView.cs" />
+    <Compile Include="Views\ListView.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="packages.config" />

+ 85 - 0
Terminal.Gui/Views/FrameView.cs

@@ -0,0 +1,85 @@
+//
+// FrameView.cs: Frame control
+//
+// Authors:
+//   Miguel de Icaza ([email protected])
+//
+	using System;
+	using System.Collections;
+	using System.Collections.Generic;
+	using NStack;
+
+namespace Terminal.Gui {
+	/// <summary>
+	/// The FrameView is a container frame that draws a frame around the contents
+	/// </summary>
+	public class FrameView : View {
+		View contentView;
+		ustring title;
+
+		/// <summary>
+		/// The title to be displayed for this window.
+		/// </summary>
+		/// <value>The title.</value>
+		public ustring Title {
+			get => title;
+			set {
+				title = value;
+				SetNeedsDisplay ();
+			}
+		}
+
+		class ContentView : View {
+			public ContentView (Rect frame) : base (frame) { }
+		}
+
+		/// <summary>
+		/// Initializes a new instance of the <see cref="T:Terminal.Gui.FrameView"/> class with
+		/// a title.
+		/// </summary>
+		/// <param name="frame">Frame.</param>
+		/// <param name="title">Title.</param>
+		public FrameView (Rect frame, ustring title) : base (frame)
+		{
+			var cFrame = new Rect (1, 1 , frame.Width - 2, frame.Height - 2);
+			contentView = new ContentView (cFrame);
+			base.Add (contentView);
+			Title = title;
+		}
+
+		void DrawFrame ()
+		{
+			DrawFrame (new Rect (0, 0, Frame.Width, Frame.Height), 0, fill: true);
+		}
+
+		/// <summary>
+		/// Add the specified view to the ContentView.
+		/// </summary>
+		/// <param name="view">View to add to the window.</param>
+		public override void Add (View view)
+		{
+			contentView.Add (view);
+		}
+
+		public override void Redraw (Rect bounds)
+		{
+			if (!NeedDisplay.IsEmpty) {
+				Driver.SetAttribute (ColorScheme.Normal);
+				DrawFrame ();
+				if (HasFocus)
+					Driver.SetAttribute (ColorScheme.Normal);
+				var width = Frame.Width;
+				if (Title != null && width > 4) {
+					Move (1, 0);
+					Driver.AddRune (' ');
+					var str = Title.Length > width ? Title [0, width - 4] : Title;
+					Driver.AddStr (str);
+					Driver.AddRune (' ');
+				}
+				Driver.SetAttribute (ColorScheme.Normal);
+			}
+			contentView.Redraw (contentView.Bounds);
+			ClearNeedsDisplay ();
+		}
+	}
+}

+ 26 - 0
Terminal.Gui/Views/ListView.cs

@@ -0,0 +1,26 @@
+//
+// ListView.cs: ListView control
+//
+// Authors:
+//   Miguel de Icaza ([email protected])
+//
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using NStack;
+
+namespace Terminal.Gui {
+	public interface IListDataSource {
+		int Count { get; }
+
+	}
+
+	/// <summary>
+	/// ListView widget renders a list of data.
+	/// </summary>
+	public class ListView : View {
+		public ListView (Rect rect, IListDataSource source, (ustring title, int width) [] headers = null) : base (rect)
+		{
+		}
+	}
+}

+ 1 - 0
Terminal.Gui/packages.config

@@ -1,4 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
   <package id="NStack.Core" version="0.7.0" targetFramework="net461" />
+  <package id="System.ValueTuple" version="4.4.0" targetFramework="net461" />
 </packages>

+ 7 - 5
demo.cs

@@ -17,10 +17,12 @@ class Demo {
 			new TextField (14, 6, 40, ""),
 			new Label (3, 8, "Password: "),
 			new TextField (14, 8, 40, "") { Secret = true },
-			new CheckBox (3, 10, "Remember me"),
-			new RadioGroup (3, 12, new [] { "_Personal", "_Company" }),
-			new Button (3, 18, "Ok"),
-			new Button (10, 18, "Cancel"),
+			new FrameView (new Rect (3, 10, 25, 6), "Options"){
+				new CheckBox (1, 0, "Remember me"),
+				new RadioGroup (1, 2, new [] { "_Personal", "_Company" }),
+			},
+			new Button (3, 19, "Ok"),
+			new Button (10, 19, "Cancel"),
 			new Label (3, 22, "Press ESC and 9 to activate the menubar")
 		);
 	}
@@ -73,7 +75,7 @@ class Demo {
 
 		ShowEntries (win);
 		int count = 0;
-		ml = new Label (new Rect (3, 16, 50, 1), "Mouse: ");
+		ml = new Label (new Rect (3, 17, 50, 1), "Mouse: ");
 		Application.RootMouseEvent += delegate (MouseEvent me) {
 
 			ml.Text = $"Mouse: ({me.X},{me.Y}) - {me.Flags} {count++}";