浏览代码

ComboBox. Color/Dim.Fill() issues when hosted inside a dialog

Ross Ferguson 5 年之前
父节点
当前提交
36a658d3e8
共有 2 个文件被更改,包括 41 次插入46 次删除
  1. 5 6
      Example/demo.cs
  2. 36 40
      Terminal.Gui/Views/ComboBox.cs

+ 5 - 6
Example/demo.cs

@@ -426,14 +426,13 @@ static class Demo {
 		IList<string> items = new List<string> ();
 		IList<string> items = new List<string> ();
 		foreach (var dir in new [] { "/etc", @"\windows\System32" }) {
 		foreach (var dir in new [] { "/etc", @"\windows\System32" }) {
 			if (Directory.Exists (dir)) {
 			if (Directory.Exists (dir)) {
-				items = Directory.GetFiles (dir)
-				.Select (Path.GetFileName)
-				.Where (x => char.IsLetterOrDigit (x [0]))
-				.Distinct ()
-				.OrderBy (x => x).ToList ();
+				items = Directory.GetFiles (dir).Union (Directory.GetDirectories (dir))
+					.Select (Path.GetFileName)
+					.Where (x => char.IsLetterOrDigit (x [0]))
+					.OrderBy (x => x).ToList ();
 			}
 			}
 		}
 		}
-		var list = new ComboBox () { X = 0, Y = 0, Width = 36, Height = 7 };
+		var list = new ComboBox () { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill() };
 		list.SetSource(items.ToList());
 		list.SetSource(items.ToList());
 		list.SelectedItemChanged += (object sender, ustring text) => { Application.RequestStop (); };
 		list.SelectedItemChanged += (object sender, ustring text) => { Application.RequestStop (); };
 
 

+ 36 - 40
Terminal.Gui/Views/ComboBox.cs

@@ -4,11 +4,14 @@
 // Authors:
 // Authors:
 //   Ross Ferguson ([email protected])
 //   Ross Ferguson ([email protected])
 //
 //
+// TODO:
+//  LayoutComplete() resize Height implement
+//	Cursor rolls of end of list when Height = Dim.Fill() and list fills frame
+//
 
 
 using System;
 using System;
 using System.Collections;
 using System.Collections;
 using System.Collections.Generic;
 using System.Collections.Generic;
-using System.Diagnostics;
 using System.Linq;
 using System.Linq;
 using NStack;
 using NStack;
 
 
@@ -18,7 +21,6 @@ namespace Terminal.Gui {
 	/// </summary>
 	/// </summary>
 	public class ComboBox : View {
 	public class ComboBox : View {
 
 
-
 		IListDataSource source;
 		IListDataSource source;
 		/// <summary>
 		/// <summary>
 		/// Gets or sets the <see cref="IListDataSource"/> backing this <see cref="ComboBox"/>, enabling custom rendering.
 		/// Gets or sets the <see cref="IListDataSource"/> backing this <see cref="ComboBox"/>, enabling custom rendering.
@@ -62,10 +64,8 @@ namespace Terminal.Gui {
 
 
 		IList searchset;
 		IList searchset;
 		ustring text = "";
 		ustring text = "";
-		TextField search;
-		ListView listview;
-		int x = 0;
-		int y = 0;
+		readonly TextField search;
+		readonly ListView listview;
 		int height;
 		int height;
 		int width;
 		int width;
 		bool autoHide = true;
 		bool autoHide = true;
@@ -75,33 +75,28 @@ namespace Terminal.Gui {
 		/// </summary>
 		/// </summary>
 		public ComboBox () : base()
 		public ComboBox () : base()
 		{
 		{
-			ColorScheme = Colors.Base;
-
 			search = new TextField ("");
 			search = new TextField ("");
 			listview = new ListView () { LayoutStyle = LayoutStyle.Computed, CanFocus = true };
 			listview = new ListView () { LayoutStyle = LayoutStyle.Computed, CanFocus = true };
 
 
 			Initialize ();
 			Initialize ();
 		}
 		}
 
 
-		///// <summary>
-		///// Public constructor
-		///// </summary>
-		///// <param name="rect"></param>
-		///// <param name="source"></param>
-		//public ComboBox (Rect rect, IList source) : base (rect)
-		//{
-		//	SetSource (source);
-		//	this.x = rect.X;
-		//	this.y = rect.Y;
-		//	this.height = rect.Height;
-		//	this.width = rect.Width;
-
-		//	search = new TextField ("") { X = rect.X, Y = rect.Y, Width = width };
+		/// <summary>
+		/// Public constructor
+		/// </summary>
+		/// <param name="rect"></param>
+		/// <param name="source"></param>
+		public ComboBox (Rect rect, IList source) : base (rect)
+		{
+			SetSource (source);
+			this.height = rect.Height;
+			this.width = rect.Width;
 
 
-		//	listview = new ListView (new Rect (rect.X, rect.Y + 1, width, 0), source) { LayoutStyle = LayoutStyle.Computed};
+			search = new TextField ("") { Width = width };
+			listview = new ListView (rect, source) { LayoutStyle = LayoutStyle.Computed };
 
 
-		//	Initialize ();
-		//}
+			Initialize ();
+		}
 
 
 		static IListDataSource MakeWrapper (IList source)
 		static IListDataSource MakeWrapper (IList source)
 		{
 		{
@@ -110,6 +105,8 @@ namespace Terminal.Gui {
 
 
 		private void Initialize()
 		private void Initialize()
 		{
 		{
+			ColorScheme = Colors.Base;
+
 			search.TextChanged += Search_Changed;
 			search.TextChanged += Search_Changed;
 
 
 			// On resize
 			// On resize
@@ -136,21 +133,17 @@ namespace Terminal.Gui {
 
 
 				ResetSearchSet ();
 				ResetSearchSet ();
 
 
+				ColorScheme = autoHide ? Colors.Base : ColorScheme = null;
+
 				// Needs to be re-applied for LayoutStyle.Computed
 				// Needs to be re-applied for LayoutStyle.Computed
 				// If Dim or Pos are null, these are the from the parametrized constructor
 				// If Dim or Pos are null, these are the from the parametrized constructor
-				if (X == null) 
-					listview.X = x;
-
-				if (Y == null)
-					listview.Y = y + 1;
-				else
-					listview.Y = Pos.Bottom (search);
+				listview.Y = 1;
 
 
 				if (Width == null) {
 				if (Width == null) {
 					listview.Width = CalculateWidth ();
 					listview.Width = CalculateWidth ();
 					search.Width = width;
 					search.Width = width;
 				} else {
 				} else {
-					width = GetDimAsInt (Width, a, vertical: false);
+					width = GetDimAsInt (Width, vertical: false);
 					search.Width = width;
 					search.Width = width;
 					listview.Width = CalculateWidth ();
 					listview.Width = CalculateWidth ();
 				}
 				}
@@ -161,7 +154,7 @@ namespace Terminal.Gui {
 					this.Height = h + 1; // adjust view to account for search box
 					this.Height = h + 1; // adjust view to account for search box
 				} else {
 				} else {
 					if (height == 0)
 					if (height == 0)
-						height = GetDimAsInt (Height, a, vertical: true);
+						height = GetDimAsInt (Height, vertical: true);
 
 
 					listview.Height = CalculatetHeight ();
 					listview.Height = CalculatetHeight ();
 					this.Height = height + 1; // adjust view to account for search box
 					this.Height = height + 1; // adjust view to account for search box
@@ -359,18 +352,21 @@ namespace Terminal.Gui {
 		}
 		}
 
 
 		/// <summary>
 		/// <summary>
-		/// Get DimAbsolute as integer value
+		/// Get Dim as integer value
 		/// </summary>
 		/// </summary>
 		/// <param name="dim"></param>
 		/// <param name="dim"></param>
-		/// <param name="a"></param>
 		/// <param name="vertical"></param>
 		/// <param name="vertical"></param>
-		/// <returns></returns>
-		private int GetDimAsInt (Dim dim, Application.ResizedEventArgs a, bool vertical)
+		/// <returns></returns>n
+		private int GetDimAsInt (Dim dim, bool vertical)
 		{
 		{
 			if (dim is Dim.DimAbsolute)
 			if (dim is Dim.DimAbsolute)
 				return dim.Anchor (0);
 				return dim.Anchor (0);
-			else
-				return vertical ? dim.Anchor (a.Rows) : dim.Anchor (a.Cols);
+			else { // Dim.Fill Dim.Factor
+				if(autoHide)
+					return vertical ? dim.Anchor (SuperView.Bounds.Height) : dim.Anchor (SuperView.Bounds.Width);
+				else 
+					return vertical ? dim.Anchor (Bounds.Height) : dim.Anchor (Bounds.Width);
+			}
 		}
 		}
 	}
 	}
 }
 }