Remove a pile of unnecessary state management from Scrollpanels.

This commit is contained in:
Paul Chote
2011-01-01 16:47:52 +13:00
parent e2b739cd3e
commit d90dec9c8e
22 changed files with 57 additions and 115 deletions

View File

@@ -40,11 +40,9 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
var template = widget.GetWidget<LabelWidget>("REPLAY_TEMPLATE");
CurrentReplay = null;
rl.Children.Clear();
rl.ContentHeight = 0;
var offset = template.Bounds.Y;
rl.ClearChildren();
foreach (var replayFile in Directory.GetFiles(replayDir, "*.rep").Reverse())
AddReplay(rl, replayFile, template, ref offset);
AddReplay(rl, replayFile, template);
widget.GetWidget("WATCH_BUTTON").OnMouseUp = mi =>
{
@@ -100,27 +98,15 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
}
}
void AddReplay(ScrollPanelWidget list, string filename, LabelWidget template, ref int offset)
void AddReplay(ScrollPanelWidget list, string filename, LabelWidget template)
{
var entry = template.Clone() as LabelWidget;
entry.Id = "REPLAY_";
entry.GetText = () => " {0}".F(Path.GetFileName(filename));
entry.GetBackground = () => (CurrentReplay == filename) ? "dialog2" : null;
entry.OnMouseDown = mi => { CurrentReplay = filename; return true; };
entry.Parent = list;
entry.Bounds = new Rectangle(entry.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height);
entry.IsVisible = () => true;
list.AddChild(entry);
if (offset == template.Bounds.Y)
CurrentReplay = filename;
offset += template.Bounds.Height;
// Padding hack
if (list.ContentHeight == 0)
list.ContentHeight += 2*template.Bounds.Y;
list.ContentHeight += template.Bounds.Height;
}
}