From 829cd1e3d1cb9e7883efe42fadc2fa7d4d17c82b Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 11 Jul 2020 10:12:26 +0100 Subject: [PATCH 1/4] Fixes #773. Added a default drop down height to the ComboBox. --- Terminal.Gui/Views/ComboBox.cs | 21 ++++++++++++++++++++- UICatalog/Scenarios/Unicode.cs | 6 ++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index 5463117ea..b909768ee 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -69,6 +69,7 @@ namespace Terminal.Gui { readonly TextField search; readonly ListView listview; bool autoHide = true; + int dropDownHeight = 4; /// /// Public constructor @@ -110,6 +111,10 @@ namespace Terminal.Gui { private void Initialize () { + if (Bounds.Height < dropDownHeight && Height is Dim.DimAbsolute) { + Height = dropDownHeight; + } + search.TextChanged += Search_Changed; listview.Y = Pos.Bottom (search); @@ -157,6 +162,20 @@ namespace Terminal.Gui { /// The selected item or -1 none selected. public int SelectedItem { private set; get; } + /// + /// Gets or Sets the list height when is drop down. Ensures at least the SelectedItem is shown. + /// + public int DropDownHeight { + get { return dropDownHeight; } + set { + if (value < 1) { + dropDownHeight = 1; + } else { + dropDownHeight = value; + } + } + } + bool isShow = false; /// @@ -504,7 +523,7 @@ namespace Terminal.Gui { if (Bounds.Height == 0) return 0; - return Math.Min (Bounds.Height - 1, searchset?.Count > 0 ? searchset.Count : isShow ? Bounds.Height - 1 : 0); + return Math.Min (Math.Max(Bounds.Height - 1, dropDownHeight), searchset?.Count > 0 ? searchset.Count : isShow ? Math.Max (Bounds.Height - 1, dropDownHeight) : 0); } } } diff --git a/UICatalog/Scenarios/Unicode.cs b/UICatalog/Scenarios/Unicode.cs index 60fec0187..b4517ea35 100644 --- a/UICatalog/Scenarios/Unicode.cs +++ b/UICatalog/Scenarios/Unicode.cs @@ -56,20 +56,18 @@ namespace UICatalog { var checkBox = new CheckBox (gitString) { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50) }; Win.Add (checkBox); - // BUGBUG: Combobox does not deal with unicode properly. -#if false label = new Label ("ComboBox:") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 }; Win.Add (label); var comboBox = new ComboBox () { X = 20, Y = Pos.Y (label), - Width = Dim.Percent (50), + Width = Dim.Percent (50) }; comboBox.SetSource (new List () { gitString, "Со_хранить" }); Win.Add (comboBox); comboBox.Text = gitString; -#endif + label = new Label ("HexView:") { X = Pos.X (label), Y = Pos.Bottom (label) + 2 }; Win.Add (label); var hexView = new HexView (new System.IO.MemoryStream (Encoding.ASCII.GetBytes (gitString + " Со_хранить"))) { From d9e06226543a129a42d1aff5e7a3dd78816bde3e Mon Sep 17 00:00:00 2001 From: BDisp Date: Mon, 13 Jul 2020 13:07:48 +0100 Subject: [PATCH 2/4] Setting a minimum height of 2. 1 to TextField and 1 to ListView. --- Terminal.Gui/Views/ComboBox.cs | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index b909768ee..ee0a8fffb 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -69,7 +69,7 @@ namespace Terminal.Gui { readonly TextField search; readonly ListView listview; bool autoHide = true; - int dropDownHeight = 4; + int minimumHeight = 2; /// /// Public constructor @@ -111,8 +111,8 @@ namespace Terminal.Gui { private void Initialize () { - if (Bounds.Height < dropDownHeight && Height is Dim.DimAbsolute) { - Height = dropDownHeight; + if (Bounds.Height < minimumHeight && Height is Dim.DimAbsolute) { + Height = minimumHeight; } search.TextChanged += Search_Changed; @@ -162,20 +162,6 @@ namespace Terminal.Gui { /// The selected item or -1 none selected. public int SelectedItem { private set; get; } - /// - /// Gets or Sets the list height when is drop down. Ensures at least the SelectedItem is shown. - /// - public int DropDownHeight { - get { return dropDownHeight; } - set { - if (value < 1) { - dropDownHeight = 1; - } else { - dropDownHeight = value; - } - } - } - bool isShow = false; /// @@ -523,7 +509,7 @@ namespace Terminal.Gui { if (Bounds.Height == 0) return 0; - return Math.Min (Math.Max(Bounds.Height - 1, dropDownHeight), searchset?.Count > 0 ? searchset.Count : isShow ? Math.Max (Bounds.Height - 1, dropDownHeight) : 0); + return Math.Min (Math.Max(Bounds.Height - 1, minimumHeight - 1), searchset?.Count > 0 ? searchset.Count : isShow ? Math.Max (Bounds.Height - 1, minimumHeight - 1) : 0); } } } From c6b86bdc955d30f629780557f04cd8292252afdc Mon Sep 17 00:00:00 2001 From: BDisp Date: Mon, 13 Jul 2020 13:16:33 +0100 Subject: [PATCH 3/4] Preparing for the PR #779 --- Terminal.Gui/Views/ComboBox.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index ee0a8fffb..ad8e7c3cb 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -111,7 +111,7 @@ namespace Terminal.Gui { private void Initialize () { - if (Bounds.Height < minimumHeight && Height is Dim.DimAbsolute) { + if (Bounds.Height < minimumHeight && Height.GetType ().Name == "DimAbsolute") { Height = minimumHeight; } From 26d62250079dc07c3c1c65468b16427b5d8c75b6 Mon Sep 17 00:00:00 2001 From: BDisp Date: Mon, 13 Jul 2020 22:37:44 +0100 Subject: [PATCH 4/4] Revert "Preparing for the PR #779" This reverts commit c6b86bdc955d30f629780557f04cd8292252afdc. --- Terminal.Gui/Views/ComboBox.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index ad8e7c3cb..ee0a8fffb 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -111,7 +111,7 @@ namespace Terminal.Gui { private void Initialize () { - if (Bounds.Height < minimumHeight && Height.GetType ().Name == "DimAbsolute") { + if (Bounds.Height < minimumHeight && Height is Dim.DimAbsolute) { Height = minimumHeight; }