Updated DropDown and Autocomplete controls based on feedback in #204

Resolves #204
pull/413/head
Simon (darkside) Jackson 2020-08-27 18:20:49 +01:00
parent b9ad53470f
commit 3429d37f14
2 changed files with 69 additions and 25 deletions

View File

@ -213,6 +213,43 @@ namespace UnityEngine.UI.Extensions
} }
*/ */
public void AddItem(string item)
{
AvailableOptions.Add(item);
RebuildPanel();
}
public void RemoveItem(string item)
{
AvailableOptions.Remove(item);
RebuildPanel();
}
public void SetAvailableOptions(List<string> newOptions)
{
AvailableOptions.Clear();
AvailableOptions = newOptions;
RebuildPanel();
}
public void SetAvailableOptions(string[] newOptions)
{
AvailableOptions.Clear();
for (int i = 0; i < newOptions.Length; i++)
{
AvailableOptions.Add(newOptions[i]);
}
RebuildPanel();
}
public void ResetItems()
{
AvailableOptions.Clear();
RebuildPanel();
}
/// <summary> /// <summary>
/// Rebuilds the contents of the panel in response to items being added. /// Rebuilds the contents of the panel in response to items being added.
/// </summary> /// </summary>

View File

@ -131,34 +131,41 @@ namespace UnityEngine.UI.Extensions
return success; return success;
} }
/* currently just using items in the list instead of being able to add to it. public void AddItem(string item)
public void AddItems(params object[] list)
{ {
List<DropDownListItem> ddItems = new List<DropDownListItem>(); AvailableOptions.Add(item);
foreach (var obj in list) RebuildPanel();
{ }
if (obj is DropDownListItem)
{ public void RemoveItem(string item)
ddItems.Add((DropDownListItem)obj); {
} AvailableOptions.Remove(item);
else if (obj is string) RebuildPanel();
{ }
ddItems.Add(new DropDownListItem(caption: (string)obj));
} public void SetAvailableOptions(List<string> newOptions)
else if (obj is Sprite) {
{ AvailableOptions.Clear();
ddItems.Add(new DropDownListItem(image: (Sprite)obj)); AvailableOptions = newOptions;
} RebuildPanel();
else }
{
throw new System.Exception("Only ComboBoxItems, Strings, and Sprite types are allowed"); public void SetAvailableOptions(string[] newOptions)
} {
} AvailableOptions.Clear();
Items.AddRange(ddItems);
Items = Items.Distinct().ToList();//remove any duplicates for (int i = 0; i < newOptions.Length; i++)
{
AvailableOptions.Add(newOptions[i]);
}
RebuildPanel();
}
public void ResetItems()
{
AvailableOptions.Clear();
RebuildPanel(); RebuildPanel();
} }
*/
/// <summary> /// <summary>
/// Rebuilds the contents of the panel in response to items being added. /// Rebuilds the contents of the panel in response to items being added.