Makes dropdown menus auto-scroll to selected item.
This commit is contained in:
@@ -94,6 +94,10 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
oldBounds.Width,
|
oldBounds.Width,
|
||||||
oldBounds.Height);
|
oldBounds.Height);
|
||||||
panelRoot.AddChild(panel);
|
panelRoot.AddChild(panel);
|
||||||
|
|
||||||
|
var scrollPanel = panel as ScrollPanelWidget;
|
||||||
|
if (scrollPanel != null)
|
||||||
|
scrollPanel.ScrollToSelectedItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowDropDown<T>(string panelTemplate, int maxHeight, IEnumerable<T> options, Func<T, ScrollItemWidget, ScrollItemWidget> setupItem)
|
public void ShowDropDown<T>(string panelTemplate, int maxHeight, IEnumerable<T> options, Func<T, ScrollItemWidget, ScrollItemWidget> setupItem)
|
||||||
|
|||||||
@@ -214,17 +214,8 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
get { return targetListOffset == Math.Min(0, Bounds.Height - ContentHeight) || ContentHeight <= Bounds.Height; }
|
get { return targetListOffset == Math.Min(0, Bounds.Height - ContentHeight) || ContentHeight <= Bounds.Height; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ScrollToItem(string itemKey, bool smooth = false)
|
void ScrollToItem(Widget item, bool smooth = false)
|
||||||
{
|
{
|
||||||
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
|
// Scroll the item to be visible
|
||||||
float? newOffset = null;
|
float? newOffset = null;
|
||||||
if (item.Bounds.Top + currentListOffset < 0)
|
if (item.Bounds.Top + currentListOffset < 0)
|
||||||
@@ -237,6 +228,30 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
SetListOffset(newOffset.Value, smooth);
|
SetListOffset(newOffset.Value, smooth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ScrollToItem(string itemKey, bool smooth = false)
|
||||||
|
{
|
||||||
|
var item = Children.FirstOrDefault(c =>
|
||||||
|
{
|
||||||
|
var si = c as ScrollItemWidget;
|
||||||
|
return si != null && si.ItemKey == itemKey;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (item != null)
|
||||||
|
ScrollToItem(item, smooth);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ScrollToSelectedItem()
|
||||||
|
{
|
||||||
|
var item = Children.FirstOrDefault(c =>
|
||||||
|
{
|
||||||
|
var si = c as ScrollItemWidget;
|
||||||
|
return si != null && si.IsSelected();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (item != null)
|
||||||
|
ScrollToItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
public override void Tick()
|
public override void Tick()
|
||||||
{
|
{
|
||||||
if (upPressed)
|
if (upPressed)
|
||||||
|
|||||||
Reference in New Issue
Block a user