diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index 71657731c..627ec6fc7 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/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); } + /// public override bool OnEnter () { if (!search.HasFocus) @@ -92,6 +97,7 @@ namespace Terminal.Gui { return true; } + /// 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 () : 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); } + + /// + /// Internal width + /// + /// + private int CalculateWidth() + { + return autoHide? Math.Max (1, width - 1) : width; + } } } diff --git a/UICatalog/Scenarios/ListsAndCombos.cs b/UICatalog/Scenarios/ListsAndCombos.cs index 31daec9c3..f5633e47b 100644 --- a/UICatalog/Scenarios/ListsAndCombos.cs +++ b/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 };