PopupMenu doesn't seem to respect shouldPopupMenuScaleWithTargetComponent()

I’ve got a GUI that is being scaled overall with an AffineTransform. All components seem to respect this including ComboBoxes and their popupMenus. JUCE 6.0.7.

However, I have some standalone PopupMenus that are created on the fly (in lambdas) and they do not get scaled, even though they are child components of the mainComponent that has the transform, and even though they have a LookAndFeel assigned that is overriding shouldPopupMenuScaleWithTargetComponent() and returning true.

I’ve debugged into the shouldPopupMenuScaleWithTargetComponent() and it is getting called when the popupMenu is shown. But no scaling. Code looks like this:

    addAndMakeVisible(menuButton);
    menuButton.setTooltip("Layer Operations Menu");
    menuButton.onClick = [this] {
        PopupMenu menu;
        menu.setLookAndFeel (&getLookAndFeel());
        menu.addItem(1, "Duplicate Layer");
        menu.addItem(2, "Delete Layer");
        int sel = menu.show();
        if (sel)
        {
            switch (sel)
            {
               [...]
            }
        }
    };

Override is simply:

bool MainLookAndFeel::shouldPopupMenuScaleWithTargetComponent(const PopupMenu::Options& options)
{
    return true;
}

Am I approaching this incorrectly? Thanks!

use showAt

int sel = menu.showAt(&menuButton)
or
use the Options version where you precise which component is the target one

1 Like

Thank you for that! I was missing the concept of the target component. Works now. :partying_face: