From c519c006787f0fe3ab45330c322ab23dfa891838 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 26 Apr 2021 15:14:46 +0200 Subject: [PATCH] Add `CreateSearchPopup` to editor utils --- .../Editors/CultureInfoEditor.cs | 28 +------------- Source/Editor/Utilities/Utils.cs | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/Source/Editor/CustomEditors/Editors/CultureInfoEditor.cs b/Source/Editor/CustomEditors/Editors/CultureInfoEditor.cs index e442c04cd..67533ed56 100644 --- a/Source/Editor/CustomEditors/Editors/CultureInfoEditor.cs +++ b/Source/Editor/CustomEditors/Editors/CultureInfoEditor.cs @@ -113,32 +113,8 @@ namespace FlaxEditor.CustomEditors.Editors internal static ContextMenuBase CreatePicker(CultureInfo value, Action 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(); var cultures = CultureInfo.GetCultures(CultureTypes.AllCultures); Array.Sort(cultures, 1, cultures.Length - 2, new CultureInfoComparer()); // at 0 there is Invariant Culture diff --git a/Source/Editor/Utilities/Utils.cs b/Source/Editor/Utilities/Utils.cs index 6c7aa86d7..ff97ef7cc 100644 --- a/Source/Editor/Utilities/Utils.cs +++ b/Source/Editor/Utilities/Utils.cs @@ -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 } } } + + /// + /// Creates the search popup with a tree. + /// + /// The search box. + /// The tree control. + /// The created menu to setup and show. + 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; + } } }