diff --git a/Studio/CelesteStudio/Editing/Editor.cs b/Studio/CelesteStudio/Editing/Editor.cs index 8335ca9a..d0d99b57 100644 --- a/Studio/CelesteStudio/Editing/Editor.cs +++ b/Studio/CelesteStudio/Editing/Editor.cs @@ -616,24 +616,26 @@ private void Recalc() { // Update popup-menu position if (ActivePopupMenu != null) { - const float menuXOffset = 8.0f; - const float menuYOffset = 7.0f; + const int menuXOffset = 8; + const int menuYOffset = 7; + const int menuLPadding = 7; + const int menuRPadding = 20; - float availableWidth = scrollablePosition.X + scrollableSize.Width - Font.CharWidth(); float carX = Font.CharWidth() * Document.Caret.Col; float carY = Font.LineHeight() * (actualToVisualRows[Document.Caret.Row] + 1); int menuX = (int)(carX + scrollablePosition.X + textOffsetX + menuXOffset); int menuYBelow = (int)(carY + menuYOffset); int menuYAbove = (int)Math.Max(carY - Font.LineHeight() - menuYOffset - ActivePopupMenu.ContentHeight, scrollablePosition.Y + menuYOffset); - int menuMaxW = (int)(availableWidth - menuX); + int menuMaxRight = scrollablePosition.X + scrollableSize.Width - menuRPadding; + int menuMaxW = menuMaxRight - menuX; int menuMaxHBelow = (int)(scrollablePosition.Y + scrollableSize.Height - Font.LineHeight() - menuYBelow); int menuMaxHAbove = (int)(scrollablePosition.Y + carY - Font.LineHeight() - menuYOffset - menuYAbove); // Try moving the menu to the left when there isn't enough space, before having to shrink it if (menuMaxW < ActivePopupMenu.ContentWidth) { - menuX = (int)Math.Max(availableWidth - ActivePopupMenu.ContentWidth, scrollablePosition.X + textOffsetX); - menuMaxW = (int)(availableWidth - menuX); + menuX = (int)Math.Max(menuMaxRight - ActivePopupMenu.ContentWidth, scrollablePosition.X + textOffsetX + menuLPadding); + menuMaxW = menuMaxRight - menuX; } // Chose above / below caret depending on which provides more height. Default to below @@ -649,6 +651,7 @@ private void Recalc() { // Set height first, to account for a potential scroll bar ActivePopupMenu.ContentHeight = Math.Min(ActivePopupMenu.ContentHeight, menuMaxH); ActivePopupMenu.ContentWidth = Math.Min(ActivePopupMenu.ContentWidth, menuMaxW); + ActivePopupMenu.Recalc(); pixelLayout.Move(ActivePopupMenu, menuX, menuY); } @@ -1338,6 +1341,7 @@ private void UpdateAutoComplete(bool open = true) { await Application.Instance.InvokeAsync(() => { autoCompleteMenu.Entries.Clear(); autoCompleteMenu.Entries.Add(loadingEntry); + autoCompleteMenu.Recalc(); Recalc(); }).ConfigureAwait(false); @@ -1426,6 +1430,7 @@ await Application.Instance.InvokeAsync(() => { if (!done) { autoCompleteMenu.Entries.Add(loadingEntry); } + autoCompleteMenu.Recalc(); Recalc(); }).ConfigureAwait(false); @@ -1442,6 +1447,7 @@ await Application.Instance.InvokeAsync(() => { } else { autoCompleteMenu.Entries.Clear(); autoCompleteMenu.Recalc(); + Recalc(); } if (GetSelectedQuickEdit() is { } quickEdit && commandLine.Value.Arguments[^1] == quickEdit.DefaultText) { diff --git a/Studio/CelesteStudio/Editing/PopupMenu.cs b/Studio/CelesteStudio/Editing/PopupMenu.cs index 4731bc7d..88641397 100644 --- a/Studio/CelesteStudio/Editing/PopupMenu.cs +++ b/Studio/CelesteStudio/Editing/PopupMenu.cs @@ -62,9 +62,8 @@ public ContentDrawable(PopupMenu menu) { } protected override void OnPaint(PaintEventArgs e) { - e.Graphics.FillPath( - Settings.Instance.Theme.PopupMenuBg, - GraphicsPath.GetRoundRect(new RectangleF(menu.ScrollPosition.X, menu.ScrollPosition.Y, menu.Width, menu.Height), Settings.Instance.Theme.PopupMenuBorderRounding)); + e.Graphics.SetClip(GraphicsPath.GetRoundRect(new RectangleF(menu.ScrollPosition.X, menu.ScrollPosition.Y, menu.Width, menu.Height), Settings.Instance.Theme.PopupMenuBorderRounding)); + e.Graphics.FillRectangle(Settings.Instance.Theme.PopupMenuBg, menu.ScrollPosition.X, menu.ScrollPosition.Y, menu.Width, menu.Height); if (menu.shownEntries.Length == 0) { return; @@ -194,7 +193,7 @@ public int SelectedEntry { } public int ContentWidth { - set => Width = Math.Max(0, value + ScrollBarWidth); + set => Width = Math.Max(0, value); get { if (shownEntries.Length == 0) { return 0; @@ -204,7 +203,7 @@ public int ContentWidth { int maxDisplayLen = shownEntries.Select(entry => entry.DisplayText.Length).Aggregate(Math.Max); int maxExtraLen = shownEntries.Select(entry => entry.ExtraText.Length).Aggregate(Math.Max); - return (int)(font.CharWidth() * (maxDisplayLen + DisplayExtraPadding + maxExtraLen) + Settings.Instance.Theme.PopupMenuEntryHorizontalPadding * 2.0f + Settings.Instance.Theme.PopupMenuBorderPadding * 2); + return (int)(font.CharWidth() * (maxDisplayLen + DisplayExtraPadding + maxExtraLen) + Settings.Instance.Theme.PopupMenuEntryHorizontalPadding * 2.0f + Settings.Instance.Theme.PopupMenuBorderPadding * 2 + ScrollBarWidth); } } public int ContentHeight {