Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accelerate the update speed #190

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading