List narrower than the edit when in Window

Add XML comments
This commit is contained in:
Ross Ferguson
2020-05-23 09:07:08 +01:00
parent e84eb78150
commit bc51486236
2 changed files with 19 additions and 6 deletions

View File

@@ -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;
}
}
}

View File

@@ -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
};