set width of command suggestions based on longest command

This commit is contained in:
xxSeys1
2025-06-02 22:33:22 +02:00
parent fa89e710d8
commit 608839b6a5

View File

@@ -233,7 +233,10 @@ namespace FlaxEditor.Windows
else else
cm.ClearItems(); cm.ClearItems();
float longestItemWidth = 0.0f;
// Add items // Add items
var font = Style.Current.FontMedium;
ItemsListContextMenu.Item lastItem = null; ItemsListContextMenu.Item lastItem = null;
foreach (var command in commands) foreach (var command in commands)
{ {
@@ -244,7 +247,7 @@ namespace FlaxEditor.Windows
}); });
var flags = DebugCommands.GetCommandFlags(command); var flags = DebugCommands.GetCommandFlags(command);
if (flags.HasFlag(DebugCommands.CommandFlags.Exec)) if (flags.HasFlag(DebugCommands.CommandFlags.Exec))
lastItem.TintColor = new Color(0.85f, 0.85f, 1.0f, 1.0f); lastItem.TintColor = new Color(0.75f, 0.75f, 1.0f, 1.0f);
else if (flags.HasFlag(DebugCommands.CommandFlags.Read) && !flags.HasFlag(DebugCommands.CommandFlags.Write)) else if (flags.HasFlag(DebugCommands.CommandFlags.Read) && !flags.HasFlag(DebugCommands.CommandFlags.Write))
lastItem.TintColor = new Color(0.85f, 0.85f, 0.85f, 1.0f); lastItem.TintColor = new Color(0.85f, 0.85f, 0.85f, 1.0f);
lastItem.Focused += item => lastItem.Focused += item =>
@@ -252,6 +255,10 @@ namespace FlaxEditor.Windows
// Set command // Set command
Set(item.Name); Set(item.Name);
}; };
float width = font.MeasureText(command).X;
if (width > longestItemWidth)
longestItemWidth = width;
} }
cm.ItemClicked += item => cm.ItemClicked += item =>
{ {
@@ -262,6 +269,10 @@ namespace FlaxEditor.Windows
// Setup popup // Setup popup
var count = commands.Count(); var count = commands.Count();
var totalHeight = count * lastItem.Height + cm.ItemsPanel.Margin.Height + cm.ItemsPanel.Spacing * (count - 1); var totalHeight = count * lastItem.Height + cm.ItemsPanel.Margin.Height + cm.ItemsPanel.Spacing * (count - 1);
// Account for scroll bars taking up a part of the width
longestItemWidth += 25f;
cm.Width = longestItemWidth;
cm.Height = 220; cm.Height = 220;
if (cm.Height > totalHeight) if (cm.Height > totalHeight)
cm.Height = totalHeight; // Limit popup height if list is small cm.Height = totalHeight; // Limit popup height if list is small