Reuse code

#3354
This commit is contained in:
Wojtek Figat
2025-04-08 17:05:15 +02:00
parent 58813d09c3
commit 3de6ac2658

View File

@@ -325,7 +325,7 @@ namespace FlaxEditor.Windows
}
var text = (attribute == null) ? actorType.Name : string.IsNullOrEmpty(attribute.Name) ? actorType.Name : attribute.Name;
// Display all actors on no search
if (string.IsNullOrEmpty(filterText))
_groupSearch.AddChild(CreateActorItem(Utilities.Utils.GetPropertyNameUI(text), actorType));
@@ -333,19 +333,8 @@ namespace FlaxEditor.Windows
if (!QueryFilterHelper.Match(filterText, text, out QueryFilterHelper.Range[] ranges))
continue;
var item = _groupSearch.AddChild(CreateActorItem(Utilities.Utils.GetPropertyNameUI(text), actorType));
var highlights = new List<Rectangle>(ranges.Length);
var style = Style.Current;
var font = style.FontSmall;
var textRect = item.TextRect;
for (int i = 0; i < ranges.Length; i++)
{
var start = font.GetCharPosition(text, ranges[i].StartIndex);
var end = font.GetCharPosition(text, ranges[i].EndIndex);
highlights.Add(new Rectangle(start.X + textRect.X, textRect.Y, end.X - start.X, textRect.Height));
}
item.SetHighlights(highlights);
var item = CreateActorItem(Utilities.Utils.GetPropertyNameUI(text), actorType);
SearchFilterHighlights(item, text, ranges);
}
// Hack primitive models into the search results
@@ -353,26 +342,16 @@ namespace FlaxEditor.Windows
{
if (child is Item primitiveAssetItem)
{
String text = primitiveAssetItem.Text;
var text = primitiveAssetItem.Text;
if (!QueryFilterHelper.Match(filterText, text, out QueryFilterHelper.Range[] ranges))
continue;
// Rebuild the path based on item name (it would be better to convert the drag data back to a string somehow)
string path = $"Primitives/{text}.flax";
var item = _groupSearch.AddChild(CreateEditorAssetItem(text, path));
var highlights = new List<Rectangle>(ranges.Length);
var style = Style.Current;
var font = style.FontSmall;
var textRect = item.TextRect;
for (int i = 0; i < ranges.Length; i++)
{
var start = font.GetCharPosition(text, ranges[i].StartIndex);
var end = font.GetCharPosition(text, ranges[i].EndIndex);
highlights.Add(new Rectangle(start.X + textRect.X, textRect.Y, end.X - start.X, textRect.Height));
}
item.SetHighlights(highlights);
var item = CreateEditorAssetItem(text, path);
SearchFilterHighlights(item, text, ranges);
}
}
@@ -384,6 +363,21 @@ namespace FlaxEditor.Windows
PerformLayout();
}
private void SearchFilterHighlights(Item item, string text, QueryFilterHelper.Range[] ranges)
{
_groupSearch.AddChild(item);
var highlights = new List<Rectangle>(ranges.Length);
var font = Style.Current.FontSmall;
var textRect = item.TextRect;
for (int i = 0; i < ranges.Length; i++)
{
var start = font.GetCharPosition(text, ranges[i].StartIndex);
var end = font.GetCharPosition(text, ranges[i].EndIndex);
highlights.Add(new Rectangle(start.X + textRect.X, textRect.Y, end.X - start.X, textRect.Height));
}
item.SetHighlights(highlights);
}
private Item CreateEditorAssetItem(string name, string path)
{
string globalPath = StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor", path);