Adjust ContextMenu ShortKeys as needed to accommodate for scrollbar when visible.

This commit is contained in:
Chandler Cox
2024-01-08 19:45:54 -06:00
parent 7f4d2d8db6
commit afb5edb824
3 changed files with 9 additions and 9 deletions

View File

@@ -408,9 +408,9 @@ namespace FlaxEditor.GUI.ContextMenu
{ {
foreach (var child in _panel.Children) 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;
} }
} }
} }

View File

@@ -14,6 +14,11 @@ namespace FlaxEditor.GUI.ContextMenu
public class ContextMenuButton : ContextMenuItem public class ContextMenuButton : ContextMenuItem
{ {
private bool _isMouseDown; private bool _isMouseDown;
/// <summary>
/// The amount to adjust the short keys and arrow image by in x coordinates.
/// </summary>
public float ExtraAdjustmentAmount = 0;
/// <summary> /// <summary>
/// Event fired when user clicks on the button. /// Event fired when user clicks on the button.
@@ -133,7 +138,7 @@ namespace FlaxEditor.GUI.ContextMenu
if (!string.IsNullOrEmpty(ShortKeys)) if (!string.IsNullOrEmpty(ShortKeys))
{ {
// Draw short keys // 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 // Draw icon

View File

@@ -17,11 +17,6 @@ namespace FlaxEditor.GUI.ContextMenu
/// </summary> /// </summary>
public readonly ContextMenu ContextMenu = new ContextMenu(); public readonly ContextMenu ContextMenu = new ContextMenu();
/// <summary>
/// The amount to adjust the arrow image by in x coordinates.
/// </summary>
public float AdjustArrowAmount = 0;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ContextMenuChildMenu"/> class. /// Initializes a new instance of the <see cref="ContextMenuChildMenu"/> class.
/// </summary> /// </summary>
@@ -49,7 +44,7 @@ namespace FlaxEditor.GUI.ContextMenu
// Draw arrow // Draw arrow
if (ContextMenu.HasChildren) 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);
} }
/// <inheritdoc /> /// <inheritdoc />