Add ScrollPanel.ScrollToItem().
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user