Add CreateSearchPopup to editor utils

This commit is contained in:
Wojtek Figat
2021-04-26 15:14:46 +02:00
parent d36a36d439
commit c519c00678
2 changed files with 40 additions and 26 deletions

View File

@@ -113,32 +113,8 @@ namespace FlaxEditor.CustomEditors.Editors
internal static ContextMenuBase CreatePicker(CultureInfo value, Action<CultureInfo> changed)
{
var menu = new ContextMenuBase
{
Size = new Vector2(320, 220),
};
var searchBox = new TextBox(false, 1, 1)
{
Width = menu.Width - 3,
WatermarkText = "Search...",
Parent = menu
};
var panel1 = new Panel(ScrollBars.Vertical)
{
Bounds = new Rectangle(0, searchBox.Bottom + 1, menu.Width, menu.Height - searchBox.Bottom - 2),
Parent = menu
};
var panel2 = new VerticalPanel
{
Parent = panel1,
AnchorPreset = AnchorPresets.HorizontalStretchTop,
IsScrollable = true,
};
var tree = new Tree(false)
{
Parent = panel2,
Margin = new Margin(-16.0f, 0.0f, -16.0f, -0.0f), // Hide root node
};
var menu = Utilities.Utils.CreateSearchPopup(out var searchBox, out var tree);
tree.Margin = new Margin(-16.0f, 0.0f, -16.0f, -0.0f); // Hide root node
var root = tree.AddChild<TreeNode>();
var cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
Array.Sort(cultures, 1, cultures.Length - 2, new CultureInfoComparer()); // at 0 there is Invariant Culture

View File

@@ -6,6 +6,8 @@ using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using FlaxEditor.GUI.ContextMenu;
using FlaxEditor.GUI.Tree;
using FlaxEditor.SceneGraph;
using FlaxEditor.Scripting;
using FlaxEngine;
@@ -1880,5 +1882,41 @@ namespace FlaxEditor.Utilities
}
}
}
/// <summary>
/// Creates the search popup with a tree.
/// </summary>
/// <param name="searchBox">The search box.</param>
/// <param name="tree">The tree control.</param>
/// <returns>The created menu to setup and show.</returns>
public static ContextMenuBase CreateSearchPopup(out TextBox searchBox, out Tree tree)
{
var menu = new ContextMenuBase
{
Size = new Vector2(320, 220),
};
searchBox = new TextBox(false, 1, 1)
{
Width = menu.Width - 3,
WatermarkText = "Search...",
Parent = menu,
};
var panel1 = new Panel(ScrollBars.Vertical)
{
Bounds = new Rectangle(0, searchBox.Bottom + 1, menu.Width, menu.Height - searchBox.Bottom - 2),
Parent = menu
};
var panel2 = new VerticalPanel
{
Parent = panel1,
AnchorPreset = AnchorPresets.HorizontalStretchTop,
IsScrollable = true,
};
tree = new Tree(false)
{
Parent = panel2,
};
return menu;
}
}
}