瀏覽代碼

List narrower than the edit when in Window
Add XML comments

Ross Ferguson 5 年之前
父節點
當前提交
bc51486236
共有 2 個文件被更改,包括 19 次插入6 次删除
  1. 18 5
      Terminal.Gui/Views/ComboBox.cs
  2. 1 1
      UICatalog/Scenarios/ListsAndCombos.cs

+ 18 - 5
Terminal.Gui/Views/ComboBox.cs

@@ -52,7 +52,6 @@ namespace Terminal.Gui {
 			listview = new ListView(new Rect(x, y + 1, w, 0), listsource.ToList())
 			{
 				LayoutStyle = LayoutStyle.Computed,
-				ColorScheme = Colors.Menu
 			};
 			listview.SelectedChanged += (object sender, ListViewItemEventArgs e) => {
 				if(searchset.Count > 0)
@@ -73,8 +72,13 @@ namespace Terminal.Gui {
 				// Needs to be re-applied for LayoutStyle.Computed
 				listview.X = x;
 				listview.Y = y + 1;
-				listview.Width = w;
+				listview.Width = CalculateWidth();
 				listview.Height = CalculatetHeight ();
+
+				if (autoHide)
+					listview.ColorScheme = Colors.Menu;
+				else
+					search.ColorScheme = Colors.Menu;
 			};
 
 			this.Add(listview);
@@ -82,6 +86,7 @@ namespace Terminal.Gui {
 			this.SetFocus(search);
 		}
 
+		///<inheritdoc cref="OnEnter"/>
 		public override bool OnEnter ()
 		{
 			if (!search.HasFocus)
@@ -92,6 +97,7 @@ namespace Terminal.Gui {
 			return true;
 		}
 
+		///<inheritdoc cref="ProcessKey"/>
 		public override bool ProcessKey(KeyEvent e)
 		{
 			if (e.Key == Key.Tab)
@@ -101,7 +107,6 @@ namespace Terminal.Gui {
 			}
 
 			if (e.Key == Key.Enter && listview.HasFocus) {
-
 				if (listview.Source.Count == 0 || searchset.Count == 0) {
 					text = "";
 					return true;
@@ -189,9 +194,8 @@ namespace Terminal.Gui {
 
 		private void Search_Changed (object sender, ustring text)
 		{
-			if (string.IsNullOrEmpty (search.Text.ToString())) {
+			if (string.IsNullOrEmpty (search.Text.ToString()))
 				searchset = autoHide ? new List<string> () : listsource;
-			} 
 			else
 				searchset = listsource.Where (x => x.StartsWith (search.Text.ToString (), StringComparison.CurrentCultureIgnoreCase)).ToList ();
 
@@ -210,5 +214,14 @@ namespace Terminal.Gui {
 		{
 			return Math.Min (height, searchset.Count);
 		}
+
+		/// <summary>
+		/// Internal width
+		/// </summary>
+		/// <returns></returns>
+		private int CalculateWidth()
+		{
+			return autoHide? Math.Max (1, width - 1) : width;
+		}
 	}
 }

+ 1 - 1
UICatalog/Scenarios/ListsAndCombos.cs

@@ -41,7 +41,7 @@ namespace UICatalog.Scenarios {
 			// ComboBox
 			var lbComboBox = new Label ("ComboBox") {
 				ColorScheme = Colors.TopLevel,
-				X = Pos.Right (lbListView) + 1, // <== Broken?!?
+				X = Pos.Right (lbListView) + 1,
 				Width = 30
 			};