Add ScrollPanel.ScrollToItem().

This commit is contained in:
Paul Chote
2013-04-05 23:14:08 +13:00
parent 4907ea1f0c
commit 01248de66b
2 changed files with 30 additions and 0 deletions

View File

@@ -10,6 +10,7 @@
using System;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
namespace OpenRA.Widgets
@@ -143,6 +144,25 @@ namespace OpenRA.Widgets
ListOffset = 0;
}
public void ScrollToItem(string itemKey)
{
var item = Children.FirstOrDefault(c =>
{
var si = c as ScrollItemWidget;
return si != null && si.ItemKey == itemKey;
});
if (item == null)
return;
// Scroll the item to be visible
if (item.Bounds.Top + ListOffset < 0)
ListOffset = ItemSpacing - item.Bounds.Top;
if (item.Bounds.Bottom + ListOffset > RenderBounds.Height)
ListOffset = RenderBounds.Height - item.Bounds.Bottom - ItemSpacing;
}
public override void Tick ()
{
if (UpPressed) Scroll(1);