Fix frame end task race condition in ScrollPanelWidget
This commit is contained in:
@@ -374,9 +374,15 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
});
|
||||
}
|
||||
|
||||
void BindingAdd(object item)
|
||||
void BindingAdd(IObservableCollection col, object item)
|
||||
{
|
||||
Game.RunAfterTick(() => BindingAddImpl(item));
|
||||
Game.RunAfterTick(() =>
|
||||
{
|
||||
if (collection != col)
|
||||
return;
|
||||
|
||||
BindingAddImpl(item);
|
||||
});
|
||||
}
|
||||
|
||||
void BindingAddImpl(object item)
|
||||
@@ -393,30 +399,40 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
ScrollToBottom();
|
||||
}
|
||||
|
||||
void BindingRemove(object item)
|
||||
void BindingRemove(IObservableCollection col, object item)
|
||||
{
|
||||
Game.RunAfterTick(() =>
|
||||
{
|
||||
if (collection != col)
|
||||
return;
|
||||
|
||||
var widget = Children.FirstOrDefault(w => widgetItemEquals(w, item));
|
||||
if (widget != null)
|
||||
RemoveChild(widget);
|
||||
});
|
||||
}
|
||||
|
||||
void BindingRemoveAt(int index)
|
||||
void BindingRemoveAt(IObservableCollection col, int index)
|
||||
{
|
||||
Game.RunAfterTick(() =>
|
||||
{
|
||||
if (collection != col)
|
||||
return;
|
||||
|
||||
if (index < 0 || index >= Children.Count)
|
||||
return;
|
||||
|
||||
RemoveChild(Children[index]);
|
||||
});
|
||||
}
|
||||
|
||||
void BindingSet(object oldItem, object newItem)
|
||||
void BindingSet(IObservableCollection col, object oldItem, object newItem)
|
||||
{
|
||||
Game.RunAfterTick(() =>
|
||||
{
|
||||
if (collection != col)
|
||||
return;
|
||||
|
||||
var newWidget = makeWidget(newItem);
|
||||
newWidget.Parent = this;
|
||||
|
||||
@@ -433,10 +449,13 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
});
|
||||
}
|
||||
|
||||
void BindingRefresh()
|
||||
void BindingRefresh(IObservableCollection col)
|
||||
{
|
||||
Game.RunAfterTick(() =>
|
||||
{
|
||||
if (collection != col)
|
||||
return;
|
||||
|
||||
RemoveChildren();
|
||||
foreach (var item in collection.ObservedItems)
|
||||
BindingAddImpl(item);
|
||||
|
||||
Reference in New Issue
Block a user