mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-28 16:58:01 +01:00
Fixes #773. Added a default drop down height to the ComboBox.
This commit is contained in:
@@ -69,6 +69,7 @@ namespace Terminal.Gui {
|
||||
readonly TextField search;
|
||||
readonly ListView listview;
|
||||
bool autoHide = true;
|
||||
int dropDownHeight = 4;
|
||||
|
||||
/// <summary>
|
||||
/// 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 {
|
||||
/// <value>The selected item or -1 none selected.</value>
|
||||
public int SelectedItem { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the list height when is drop down. Ensures at least the SelectedItem is shown.
|
||||
/// </summary>
|
||||
public int DropDownHeight {
|
||||
get { return dropDownHeight; }
|
||||
set {
|
||||
if (value < 1) {
|
||||
dropDownHeight = 1;
|
||||
} else {
|
||||
dropDownHeight = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool isShow = false;
|
||||
|
||||
///<inheritdoc/>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<string> () { 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 + " Со_хранить"))) {
|
||||
|
||||
Reference in New Issue
Block a user