diff --git a/LemonUI/Menus/NativeListItem{T}.cs b/LemonUI/Menus/NativeListItem{T}.cs
index 7c5d3b7..00853ea 100644
--- a/LemonUI/Menus/NativeListItem{T}.cs
+++ b/LemonUI/Menus/NativeListItem{T}.cs
@@ -26,7 +26,7 @@ public int SelectedIndex
{
get
{
- if (Items.Count == 0)
+ if (items.Count == 0)
{
return -1;
}
@@ -34,7 +34,7 @@ public int SelectedIndex
}
set
{
- if (Items.Count == 0)
+ if (items.Count == 0)
{
throw new InvalidOperationException("There are no available items.");
}
@@ -62,12 +62,7 @@ public T SelectedItem
{
get
{
- if (Items.Count == 0)
- {
- return default;
- }
-
- return Items[SelectedIndex];
+ return Items.Count == 0 ? default : Items[index];
}
set
{
@@ -86,6 +81,7 @@ public T SelectedItem
SelectedIndex = newIndex;
}
}
+
///
/// The objects used by this item.
///
@@ -146,7 +142,12 @@ private void TriggerEvent(int index, Direction direction)
}
private void FixIndexIfRequired()
{
- if (index >= items.Count)
+ if (items.Count == 0)
+ {
+ index = 0;
+ UpdateIndex();
+ }
+ else if (index >= items.Count)
{
index = items.Count - 1;
UpdateIndex();
@@ -175,25 +176,7 @@ private void UpdateIndex()
/// Adds a into this item.
///
/// The to add.
- public void Add(T item)
- {
- if (item == null)
- {
- throw new ArgumentNullException(nameof(item));
- }
-
- if (items.Contains(item))
- {
- throw new InvalidOperationException("Item is already part of this NativeListItem.");
- }
-
- items.Add(item);
-
- if (items.Count == 1)
- {
- UpdateIndex();
- }
- }
+ public void Add(T item) => Add(items.Count, item);
///
/// Adds a in a specific location.
///
@@ -211,9 +194,14 @@ public void Add(int position, T item)
throw new ArgumentOutOfRangeException(nameof(position), "The position is out of the range of items.");
}
- Items.Insert(position, item);
+ items.Insert(position, item);
FixIndexIfRequired();
+
+ if (items.Count == 1)
+ {
+ UpdateIndex();
+ }
}
///
/// Removes a specific .
@@ -239,6 +227,7 @@ public void RemoveAt(int position)
items.RemoveAt(position);
FixIndexIfRequired();
+ UpdateIndex();
}
///
/// Removes all of the items that match the .