Fix frame end task race condition in ScrollPanelWidget

This commit is contained in:
Curtis Shmyr
2016-11-13 07:09:47 +00:00
committed by Paul Chote
parent 9d7413ab3d
commit 33e1a6b2dd
5 changed files with 60 additions and 41 deletions

View File

@@ -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);