Merged in DropDownUpdate (pull request #90)

Updated DropDown and Autocomplete controls based on feedback in #204

Approved-by: JBKacerovsky
pull/413/head
Simon Jackson 2020-08-27 18:43:46 +00:00
commit b2798a6c5e
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>
/// Rebuilds the contents of the panel in response to items being added.
/// </summary>

View File

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