Fix editing LinearCurve<Color> in properties window (color picker window closed keyframe editing popup)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using FlaxEngine;
|
||||
using FlaxEngine.Assertions;
|
||||
using FlaxEngine.GUI;
|
||||
@@ -88,6 +89,11 @@ namespace FlaxEditor.GUI.ContextMenu
|
||||
/// </summary>
|
||||
public bool IsSubMenu => _isSubMenu;
|
||||
|
||||
/// <summary>
|
||||
/// External dialog popups opened within the context window (eg. color picker) that should preserve context menu visibility (prevent from closing context menu).
|
||||
/// </summary>
|
||||
public List<Window> ExternalPopups = new List<Window>();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ContextMenuBase"/> class.
|
||||
/// </summary>
|
||||
@@ -311,6 +317,34 @@ namespace FlaxEditor.GUI.ContextMenu
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if context menu is in foreground (eg. context window or any child window has user focus or user opened additional popup within this context).
|
||||
/// </summary>
|
||||
protected virtual bool IsForeground
|
||||
{
|
||||
get
|
||||
{
|
||||
// Any external popup is focused
|
||||
foreach (var externalPopup in ExternalPopups)
|
||||
{
|
||||
if (externalPopup && externalPopup.IsForegroundWindow)
|
||||
return true;
|
||||
}
|
||||
|
||||
// Any context menu window is focused
|
||||
var anyForeground = false;
|
||||
var c = this;
|
||||
while (!anyForeground && c != null)
|
||||
{
|
||||
if (c._window != null && c._window.IsForegroundWindow)
|
||||
anyForeground = true;
|
||||
c = c._childCM;
|
||||
}
|
||||
|
||||
return anyForeground;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnWindowLostFocus()
|
||||
{
|
||||
// Skip for parent menus (child should handle lost of focus)
|
||||
@@ -354,20 +388,9 @@ namespace FlaxEditor.GUI.ContextMenu
|
||||
base.Update(deltaTime);
|
||||
|
||||
// Let root context menu to check if none of the popup windows
|
||||
if (_parentCM == null)
|
||||
if (_parentCM == null && !IsForeground)
|
||||
{
|
||||
var anyForeground = false;
|
||||
var c = this;
|
||||
while (!anyForeground && c != null)
|
||||
{
|
||||
if (c._window != null && c._window.IsForegroundWindow)
|
||||
anyForeground = true;
|
||||
c = c._childCM;
|
||||
}
|
||||
if (!anyForeground)
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -398,9 +398,9 @@ namespace FlaxEditor.Modules
|
||||
var dialog = new ColorPickerDialog(initialValue, colorChanged, pickerClosed, useDynamicEditing);
|
||||
dialog.Show(targetControl);
|
||||
|
||||
// Place dialog nearby the target control
|
||||
if (targetControl != null)
|
||||
{
|
||||
// Place dialog nearby the target control
|
||||
var targetControlDesktopCenter = targetControl.PointToScreen(targetControl.Size * 0.5f);
|
||||
var desktopSize = Platform.GetMonitorBounds(targetControlDesktopCenter);
|
||||
var pos = targetControlDesktopCenter + new Float2(10.0f, -dialog.Height * 0.5f);
|
||||
@@ -411,6 +411,18 @@ namespace FlaxEditor.Modules
|
||||
var desktopBounds = Platform.VirtualDesktopBounds;
|
||||
pos = Float2.Clamp(pos, desktopBounds.UpperLeft, desktopBounds.BottomRight - dialog.Size);
|
||||
dialog.RootWindow.Window.Position = pos;
|
||||
|
||||
// Register for context menu (prevent auto-closing context menu when selecting color)
|
||||
var c = targetControl;
|
||||
while (c != null)
|
||||
{
|
||||
if (c is ContextMenuBase cm)
|
||||
{
|
||||
cm.ExternalPopups.Add(dialog.RootWindow?.Window);
|
||||
break;
|
||||
}
|
||||
c = c.Parent;
|
||||
}
|
||||
}
|
||||
|
||||
return dialog;
|
||||
|
||||
Reference in New Issue
Block a user