From afb5edb82451fe1525b40b86cc0b8059b2e6a8c5 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Mon, 8 Jan 2024 19:45:54 -0600 Subject: [PATCH 1/2] Adjust `ContextMenu` ShortKeys as needed to accommodate for scrollbar when visible. --- Source/Editor/GUI/ContextMenu/ContextMenu.cs | 4 ++-- Source/Editor/GUI/ContextMenu/ContextMenuButton.cs | 7 ++++++- Source/Editor/GUI/ContextMenu/ContextMenuChildMenu.cs | 7 +------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/Editor/GUI/ContextMenu/ContextMenu.cs b/Source/Editor/GUI/ContextMenu/ContextMenu.cs index 25f45a1f8..072b01678 100644 --- a/Source/Editor/GUI/ContextMenu/ContextMenu.cs +++ b/Source/Editor/GUI/ContextMenu/ContextMenu.cs @@ -408,9 +408,9 @@ namespace FlaxEditor.GUI.ContextMenu { foreach (var child in _panel.Children) { - if (child is ContextMenuChildMenu item && item.Visible) + if (child is ContextMenuButton item && item.Visible) { - item.AdjustArrowAmount = -_panel.VScrollBar.Width; + item.ExtraAdjustmentAmount = -_panel.VScrollBar.Width; } } } diff --git a/Source/Editor/GUI/ContextMenu/ContextMenuButton.cs b/Source/Editor/GUI/ContextMenu/ContextMenuButton.cs index e371f7c4b..e79d75e46 100644 --- a/Source/Editor/GUI/ContextMenu/ContextMenuButton.cs +++ b/Source/Editor/GUI/ContextMenu/ContextMenuButton.cs @@ -14,6 +14,11 @@ namespace FlaxEditor.GUI.ContextMenu public class ContextMenuButton : ContextMenuItem { private bool _isMouseDown; + + /// + /// The amount to adjust the short keys and arrow image by in x coordinates. + /// + public float ExtraAdjustmentAmount = 0; /// /// Event fired when user clicks on the button. @@ -133,7 +138,7 @@ namespace FlaxEditor.GUI.ContextMenu if (!string.IsNullOrEmpty(ShortKeys)) { // Draw short keys - Render2D.DrawText(style.FontMedium, ShortKeys, textRect, textColor, TextAlignment.Far, TextAlignment.Center); + Render2D.DrawText(style.FontMedium, ShortKeys, new Rectangle(ExtraAdjustmentAmount, textRect.Y, textRect.Width, textRect.Height), textColor, TextAlignment.Far, TextAlignment.Center); } // Draw icon diff --git a/Source/Editor/GUI/ContextMenu/ContextMenuChildMenu.cs b/Source/Editor/GUI/ContextMenu/ContextMenuChildMenu.cs index 49a60a04e..d71166196 100644 --- a/Source/Editor/GUI/ContextMenu/ContextMenuChildMenu.cs +++ b/Source/Editor/GUI/ContextMenu/ContextMenuChildMenu.cs @@ -17,11 +17,6 @@ namespace FlaxEditor.GUI.ContextMenu /// public readonly ContextMenu ContextMenu = new ContextMenu(); - /// - /// The amount to adjust the arrow image by in x coordinates. - /// - public float AdjustArrowAmount = 0; - /// /// Initializes a new instance of the class. /// @@ -49,7 +44,7 @@ namespace FlaxEditor.GUI.ContextMenu // Draw arrow if (ContextMenu.HasChildren) - Render2D.DrawSprite(style.ArrowRight, new Rectangle(Width - 15 + AdjustArrowAmount, (Height - 12) / 2, 12, 12), Enabled ? isCMopened ? style.BackgroundSelected : style.Foreground : style.ForegroundDisabled); + Render2D.DrawSprite(style.ArrowRight, new Rectangle(Width - 15 + ExtraAdjustmentAmount, (Height - 12) / 2, 12, 12), Enabled ? isCMopened ? style.BackgroundSelected : style.Foreground : style.ForegroundDisabled); } /// From 1e061b77afc18d7dc1c2559ad9e062961c35b8aa Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Mon, 8 Jan 2024 19:48:12 -0600 Subject: [PATCH 2/2] Add back in checking for textRect x location. --- Source/Editor/GUI/ContextMenu/ContextMenuButton.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Editor/GUI/ContextMenu/ContextMenuButton.cs b/Source/Editor/GUI/ContextMenu/ContextMenuButton.cs index e79d75e46..485cde1a7 100644 --- a/Source/Editor/GUI/ContextMenu/ContextMenuButton.cs +++ b/Source/Editor/GUI/ContextMenu/ContextMenuButton.cs @@ -138,7 +138,7 @@ namespace FlaxEditor.GUI.ContextMenu if (!string.IsNullOrEmpty(ShortKeys)) { // Draw short keys - Render2D.DrawText(style.FontMedium, ShortKeys, new Rectangle(ExtraAdjustmentAmount, textRect.Y, textRect.Width, textRect.Height), textColor, TextAlignment.Far, TextAlignment.Center); + Render2D.DrawText(style.FontMedium, ShortKeys, new Rectangle(textRect.X + ExtraAdjustmentAmount, textRect.Y, textRect.Width, textRect.Height), textColor, TextAlignment.Far, TextAlignment.Center); } // Draw icon