Skip to content

Commit

Permalink
Merge pull request #190 from toolgood/develop
Browse files Browse the repository at this point in the history
Accelerate the update speed
  • Loading branch information
Taiizor authored Nov 29, 2024
2 parents a834456 + e7a8519 commit 2150c46
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/ReaLTaiizor/Controls/ListBox/MaterialListBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -537,10 +537,12 @@ public void AddItem(string newItem)
public void AddItems(MaterialListBoxItem[] newItems)
{
_updating = true;
_scrollBar.BeginUpdate();
foreach (MaterialListBoxItem str in newItems)
{
AddItem(str);
}
_scrollBar.EndUpdate();
_updating = false;

InvalidateScroll(this, null);
Expand All @@ -550,10 +552,12 @@ public void AddItems(MaterialListBoxItem[] newItems)
public void AddItems(string[] newItems)
{
_updating = true;
_scrollBar.BeginUpdate();
foreach (string str in newItems)
{
AddItem(str);
}
_scrollBar.EndUpdate();
_updating = false;

InvalidateScroll(this, null);
Expand Down Expand Up @@ -592,6 +596,7 @@ public int IndexOf(MaterialListBoxItem value)
public void RemoveItems(MaterialListBoxItem[] itemsToRemove)
{
_updating = true;
_scrollBar.BeginUpdate();
foreach (MaterialListBoxItem item in itemsToRemove)
{
if (Items.IndexOf(item) <= _selectedIndex)
Expand All @@ -601,6 +606,7 @@ public void RemoveItems(MaterialListBoxItem[] itemsToRemove)
}
Items.Remove(item);
}
_scrollBar.EndUpdate();
_updating = false;

InvalidateScroll(this, null);
Expand All @@ -609,7 +615,7 @@ public void RemoveItems(MaterialListBoxItem[] itemsToRemove)

private void update_selection()
{
if (_selectedIndex >= 0)
if (_selectedIndex >= 0 && _selectedIndex < Items.Count)
{
_selectedItem = Items[_selectedIndex];
SelectedValue = Items[_selectedIndex];
Expand All @@ -626,10 +632,12 @@ private void update_selection()
public void Clear()
{
_updating = true;
_scrollBar.BeginUpdate();
for (int i = Items.Count - 1; i >= 0; i += -1)
{
Items.RemoveAt(i);
}
_scrollBar.EndUpdate();
_updating = false;
_selectedIndex = -1;
update_selection();
Expand All @@ -641,11 +649,13 @@ public void Clear()
public void BeginUpdate()
{
_updating = true;
_scrollBar.BeginUpdate();
}

public void EndUpdate()
{
_updating = false;
_scrollBar.EndUpdate();
}

#endregion Methods
Expand Down

0 comments on commit 2150c46

Please sign in to comment.