// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. using System; using System.Collections.Generic; namespace FlaxEngine.GUI { /// /// Dropdown menu control allows to choose one item from the provided collection of options. /// /// public class Dropdown : ContainerControl { /// /// The root control used by the to show the items collections and track item selecting event. /// /// [HideInEditor] protected class DropdownRoot : Panel { /// /// Occurs when popup lost focus. /// public Action LostFocus; /// public override void OnEndContainsFocus() { base.OnEndContainsFocus(); // Call event after this 'focus contains flag' propagation ends to prevent focus issues if (LostFocus != null) Scripting.RunOnUpdate(LostFocus); } private static DropdownLabel FindItem(Control control) { if (control is DropdownLabel item) return item; if (control is ContainerControl containerControl) { foreach (var child in containerControl.Children) { item = FindItem(child); if (item != null) return item; } } return null; } /// public override Control OnNavigate(NavDirection direction, Float2 location, Control caller, List visited) { if (IsFocused) { // Dropdown root is focused if (direction == NavDirection.Down) { // Pick the first item return FindItem(this); } // Close popup Defocus(); return null; } return base.OnNavigate(direction, location, caller, visited); } /// public override void OnSubmit() { Defocus(); base.OnSubmit(); } /// public override void OnDestroy() { LostFocus = null; base.OnDestroy(); } } [HideInEditor] private class DropdownLabel : Label { public Action