Skip to content

Commit be345c5

Browse files
committed
fix popup menu and tooltip scaling when loaded as a plugin
1 parent 9596e3a commit be345c5

8 files changed

Lines changed: 32 additions & 25 deletions

File tree

Source/Components/ArrowPopupMenu.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ class ArrowPopupMenu final : public Component
4949
menuToAttachTo->setBounds(menuToAttachTo->getBounds().translated(-15, menuMargin - 3));
5050
} else {
5151
// adjust the popupMenu to be in the correct y position
52-
auto const menuBounds = menuToAttachTo->getScreenBounds().reduced(menuMargin + 5);
53-
auto const targetBounds = targetComponent->getScreenBounds();
52+
auto const menuBounds = menuToAttachTo->getBounds().reduced(menuMargin + 5);
53+
auto const targetBounds = targetComponent->getBounds();
5454

55-
auto const yOffset = targetBounds.getBottom() - menuBounds.getBottom();
55+
// TODO: this was totally broken as is for some reason so for now it's hard coded
56+
int const yOffset = static_cast<int>(static_cast<float>(targetBounds.getBottom() - menuBounds.getBottom()) / getApproximateScaleFactorForComponent(menuToAttachTo));
5657

57-
menuToAttachTo->setBounds(menuToAttachTo->getBounds().translated(20, yOffset));
58+
menuToAttachTo->setBounds(menuToAttachTo->getBounds().translated(30, -40));
5859
}
5960
}
6061

Source/Components/CheckedTooltip.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ class CheckedTooltip final : public TooltipWindow {
1919
{
2020
}
2121

22-
float getDesktopScaleFactor() const override
23-
{
24-
return Component::getDesktopScaleFactor();
25-
}
26-
2722
void setVisible(bool const shouldBeVisible) override
2823
{
2924
if (shouldBeVisible && !isVisible()) {

Source/PluginEditor.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class CalloutArea final : public Component
6161

6262
void timerCallback() override
6363
{
64-
setBounds(target->getScreenBounds());
64+
setBounds(target->getScreenBounds() / getDesktopScaleFactor());
6565
}
6666

6767
void paint(Graphics& g) override
@@ -71,6 +71,12 @@ class CalloutArea final : public Component
7171
}
7272
}
7373

74+
75+
float getDesktopScaleFactor() const override
76+
{
77+
return getApproximateScaleFactorForComponent(target);
78+
};
79+
7480
private:
7581
WeakReference<Component> target;
7682
TooltipWindow tooltipWindow;

Source/Sidebar/Console.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class Console final : public Component
211211
auto* editor = findParentComponentOfClass<PluginEditor>();
212212
editor->highlightSearchTarget(target, true);
213213
});
214-
menu.showMenuAsync(PopupMenu::Options());
214+
menu.showMenuAsync(PopupMenu::Options().withTargetComponent(this));
215215
}
216216

217217
if (e.mods.isShiftDown()) {
@@ -473,7 +473,8 @@ class Console final : public Component
473473
settingsCalloutButton->onClick = [this, settingsCalloutButton] {
474474
auto consoleSettings = std::make_unique<ConsoleSettings>(settingsValues);
475475
auto const bounds = settingsCalloutButton->getScreenBounds();
476-
CallOutBox::launchAsynchronously(std::move(consoleSettings), bounds, nullptr);
476+
auto* pluginEditor = findParentComponentOfClass<PluginEditor>();
477+
pluginEditor->showCalloutBox(std::move(consoleSettings), bounds);
477478
};
478479

479480
return std::unique_ptr<TextButton>(settingsCalloutButton);

Source/Sidebar/DocumentationBrowser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ class DocumentationBrowser final : public Component
457457
};
458458

459459
auto docsSettings = std::make_unique<DocumentBrowserSettings>(openFolderCallback, resetFolderCallback);
460-
CallOutBox::launchAsynchronously(std::move(docsSettings), bounds, nullptr);
460+
editor->showCalloutBox(std::move(docsSettings), bounds);
461461
};
462462

463463
return std::unique_ptr<TextButton>(settingsCalloutButton);

Source/Sidebar/Palettes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ class PaletteSelector final : public TextButton {
376376
PopupMenu menu;
377377
menu.addItem("Export palette", exportClicked);
378378
menu.addItem("Delete palette", deleteClicked);
379-
menu.showMenuAsync(PopupMenu::Options());
379+
auto const position = e.getScreenPosition();
380+
menu.showMenuAsync(PopupMenu::Options().withTargetComponent(this).withTargetScreenArea(Rectangle<int>(position, position.translated(1, 1))));
380381
}
381382

382383
TextButton::mouseDown(e);

Source/Sidebar/SearchPanel.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class OpenInspector final : public Component {
3131
buttonOpenInspector.setColour(TextButton::buttonOnColourId, backgroundColour.contrasting(0.1f));
3232
buttonOpenInspector.setColour(ComboBox::outlineColourId, Colours::transparentBlack);
3333
buttonOpenInspector.setButtonText("Open inspector");
34-
buttonOpenInspector.setTooltip("Open inspector for object");
34+
// TODO: something is probably wrong with the presentation of this popup overall, but the tooltip seems redundant
35+
// buttonOpenInspector.setTooltip("Open inspector for object");
3536

3637
addAndMakeVisible(buttonOpenInspector);
3738

@@ -185,11 +186,9 @@ class SearchPanel final : public Component
185186

186187
auto openInspector = std::make_unique<OpenInspector>();
187188
auto* rawOpenInspectorPtr = openInspector.get();
188-
auto& callOutBox = CallOutBox::launchAsynchronously(std::move(openInspector), bounds, nullptr);
189+
currentCalloutBox = &editor->showCalloutBox(std::move(openInspector), bounds);
189190

190-
SafePointer<CallOutBox> callOutBoxSafePtr(&callOutBox);
191-
192-
auto onClick = [this, ptr, callOutBoxSafePtr] {
191+
auto onClick = [this, ptr] {
193192
if (auto obj = editor->highlightSearchTarget(ptr, true)) {
194193
// FIXME: We have to wait until EVERYTHING has setup on the new canvas
195194
// So we call it on message thread, which should place this event after the previous
@@ -201,8 +200,8 @@ class SearchPanel final : public Component
201200
};
202201
MessageManager::callAsync(launchInspector);
203202
}
204-
if (callOutBoxSafePtr)
205-
callOutBoxSafePtr->dismiss();
203+
if (currentCalloutBox)
204+
currentCalloutBox->dismiss();
206205
};
207206

208207
rawOpenInspectorPtr->setButtonOnClick(onClick);
@@ -278,15 +277,16 @@ class SearchPanel final : public Component
278277
Fonts::drawIcon(g, Icons::Search, 2, 1, 32, colour, 12);
279278
}
280279

281-
static std::unique_ptr<Component> getExtraSettingsComponent()
280+
std::unique_ptr<Component> getExtraSettingsComponent()
282281
{
283282
auto* settingsCalloutButton = new SmallIconButton(Icons::More);
283+
auto* pluginEditor = findParentComponentOfClass<PluginEditor>();
284284
settingsCalloutButton->setTooltip("Show search settings");
285285
settingsCalloutButton->setConnectedEdges(12);
286-
settingsCalloutButton->onClick = [settingsCalloutButton] {
286+
settingsCalloutButton->onClick = [settingsCalloutButton, pluginEditor] {
287287
auto const bounds = settingsCalloutButton->getScreenBounds();
288288
auto docsSettings = std::make_unique<SearchPanelSettings>();
289-
CallOutBox::launchAsynchronously(std::move(docsSettings), bounds, nullptr);
289+
pluginEditor->showCalloutBox(std::move(docsSettings), bounds);
290290
};
291291

292292
return std::unique_ptr<TextButton>(settingsCalloutButton);
@@ -688,4 +688,6 @@ class SearchPanel final : public Component
688688
PluginEditor* editor;
689689
ValueTreeViewerComponent patchTree = ValueTreeViewerComponent("(Subpatch)");
690690
SearchEditor input;
691+
private:
692+
static inline SafePointer<CallOutBox> currentCalloutBox = nullptr;
691693
};

Source/TabComponent.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ class TabComponent final : public Component
269269
});
270270

271271
// Show the popup menu at the mouse position
272-
tabMenu.showMenuAsync(PopupMenu::Options().withMinimumWidth(150).withMaximumNumColumns(1));
272+
auto position = e.getScreenPosition();
273+
tabMenu.showMenuAsync(PopupMenu::Options().withMinimumWidth(150).withMaximumNumColumns(1).withTargetComponent(this).withTargetScreenArea(Rectangle<int>(position, position.translated(1, 1))));
273274
} else if (cnv && e.originalComponent == this) {
274275
toFront(false);
275276
parent->showTab(cnv, parent->tabbars[1].contains(this));

0 commit comments

Comments
 (0)