From 4725a834062c42799ee1f93ec728c391b8fee6e1 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sun, 12 Feb 2023 21:29:58 -0600 Subject: [PATCH] Move the child menu arrow image to accommodatefor the scroll bar showing when the amunt of items exceeds the maximum. --- Source/Editor/GUI/ContextMenu/ContextMenu.cs | 17 +++++++++++++++++ .../GUI/ContextMenu/ContextMenuChildMenu.cs | 7 ++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Source/Editor/GUI/ContextMenu/ContextMenu.cs b/Source/Editor/GUI/ContextMenu/ContextMenu.cs index e652bc98d..f2e5d30e3 100644 --- a/Source/Editor/GUI/ContextMenu/ContextMenu.cs +++ b/Source/Editor/GUI/ContextMenu/ContextMenu.cs @@ -365,6 +365,7 @@ namespace FlaxEditor.GUI.ContextMenu float maxWidth = 0; float height = _itemsAreaMargin.Height; int itemsLeft = MaximumItemsInViewCount; + int overflowItemCount = 0; for (int i = 0; i < _panel.Children.Count; i++) { if (_panel.Children[i] is ContextMenuItem item && item.Visible) @@ -374,11 +375,27 @@ namespace FlaxEditor.GUI.ContextMenu height += item.Height + _itemsMargin.Height; itemsLeft--; } + else + { + overflowItemCount++; + } maxWidth = Mathf.Max(maxWidth, item.MinimumWidth); } } maxWidth = Mathf.Max(maxWidth + 20, MinimumWidth); + // Move child arrows to accommodate scroll bar showing + if (overflowItemCount > 0) + { + foreach (var child in _panel.Children) + { + if (child is ContextMenuChildMenu item && item.Visible) + { + item.AdjustArrowAmount = -_panel.VScrollBar.Width; + } + } + } + // Resize container Size = new Float2(Mathf.Ceil(maxWidth), Mathf.Ceil(height)); diff --git a/Source/Editor/GUI/ContextMenu/ContextMenuChildMenu.cs b/Source/Editor/GUI/ContextMenu/ContextMenuChildMenu.cs index ebf0a3b4a..0256d2bee 100644 --- a/Source/Editor/GUI/ContextMenu/ContextMenuChildMenu.cs +++ b/Source/Editor/GUI/ContextMenu/ContextMenuChildMenu.cs @@ -17,6 +17,11 @@ 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. /// @@ -44,7 +49,7 @@ namespace FlaxEditor.GUI.ContextMenu // Draw arrow if (ContextMenu.HasChildren) - Render2D.DrawSprite(style.ArrowRight, new Rectangle(Width - 15, (Height - 12) / 2, 12, 12), Enabled ? isCMopened ? style.BackgroundSelected : style.Foreground : style.ForegroundDisabled); + Render2D.DrawSprite(style.ArrowRight, new Rectangle(Width - 15 + AdjustArrowAmount, (Height - 12) / 2, 12, 12), Enabled ? isCMopened ? style.BackgroundSelected : style.Foreground : style.ForegroundDisabled); } ///