diff --git a/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs b/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs index 7cb6fe03ca..a679a5c4ed 100644 --- a/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs +++ b/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs @@ -94,6 +94,10 @@ namespace OpenRA.Mods.Common.Widgets oldBounds.Width, oldBounds.Height); panelRoot.AddChild(panel); + + var scrollPanel = panel as ScrollPanelWidget; + if (scrollPanel != null) + scrollPanel.ScrollToSelectedItem(); } public void ShowDropDown(string panelTemplate, int maxHeight, IEnumerable options, Func setupItem) diff --git a/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs b/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs index 02ef449ff7..9658a736b9 100644 --- a/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs @@ -214,17 +214,8 @@ namespace OpenRA.Mods.Common.Widgets 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 float? newOffset = null; if (item.Bounds.Top + currentListOffset < 0) @@ -237,6 +228,30 @@ namespace OpenRA.Mods.Common.Widgets 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() { if (upPressed)