예제 #1
0
 private void OnPopupClosed()
 {
     m_CurrentPopup.Destroyed -= OnPopupClosed;
     m_CurrentPopup.rootVisualElement.UnregisterCallback <KeyUpEvent>(OnKeyUp);
     m_CurrentPopup         = null;
     m_PopupClosedTimestamp = DateTime.UtcNow;
 }
예제 #2
0
        private void OnTogglePopup()
        {
            // If the user click on the arrow button while the popup is opened
            // the popup is then closed (because clicked outside) and immediately reopened
            // To prevent this behavior we allow the popup to reopen only after a very short period of time after being closed
            var deltaTime = DateTime.UtcNow - m_PopupClosedTimestamp;

            if (m_CurrentPopup == null && deltaTime.TotalMilliseconds > 500)
            {
                m_CurrentPopup           = ScriptableObject.CreateInstance <NotifyEditorWindow>();
                m_CurrentPopup.hideFlags = HideFlags.HideAndDontSave;
                if (m_PopupContent.parent != null)
                {
                    m_PopupContent.parent.Remove(m_PopupContent);
                }

                m_CurrentPopup.Destroyed += OnPopupClosed;
                m_CurrentPopup.rootVisualElement.AddStyleSheetPath("VFXToolbar");
                m_CurrentPopup.rootVisualElement.Add(m_PopupContent);
                m_CurrentPopup.rootVisualElement.AddToClassList("popup");
                m_CurrentPopup.rootVisualElement.RegisterCallback <KeyUpEvent>(OnKeyUp);

                OnOpenPopup();
                var bounds = new Rect(GetPopupPosition(), localBound.size);
                // Offset the bounds to align the popup with the real dropdown left edge
                if (m_HasLeftSeparator)
                {
                    bounds.xMin += 6;
                }

                m_CurrentPopup.ShowAsDropDown(bounds, GetPopupSize(), new[] { PopupLocation.BelowAlignLeft, PopupLocation.AboveAlignLeft });
                m_CurrentPopup.minSize = GetPopupSize();
                m_CurrentPopup.maxSize = m_CurrentPopup.minSize;
                GetNextFocusable(null, m_PopupContent.Children(), false)?.Focus();
            }
            else if (m_CurrentPopup != null)
            {
                ClosePopup();
            }
        }