From bb9b531b20a31e5a291e5421ff2d7f73c4f35650 Mon Sep 17 00:00:00 2001 From: GavinFAW Date: Wed, 6 Dec 2023 12:52:06 +0100 Subject: [PATCH] Adding in PopMenu left and right insert --- .../juce_gui_basics/menus/juce_PopupMenu.cpp | 10 ++++++ .../juce_gui_basics/menus/juce_PopupMenu.h | 31 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/modules/juce_gui_basics/menus/juce_PopupMenu.cpp b/modules/juce_gui_basics/menus/juce_PopupMenu.cpp index 8dd135733a6c..55f435c0e98c 100644 --- a/modules/juce_gui_basics/menus/juce_PopupMenu.cpp +++ b/modules/juce_gui_basics/menus/juce_PopupMenu.cpp @@ -2357,6 +2357,16 @@ bool PopupMenu::MenuItemIterator::next() return true; } +PopupMenu::Options PopupMenu::Options::withSelectableAreaLeftInset (int xInsetAmount) const +{ + return with (*this, &Options::selectableAreaLeftInset, xInsetAmount); +} + +PopupMenu::Options PopupMenu::Options::withSelectableAreaRightInset (int xInsetAmount) const +{ + return with (*this, &Options::selectableAreaRightInset, xInsetAmount); +} + PopupMenu::Item& PopupMenu::MenuItemIterator::getItem() const { jassert (currentItem != nullptr); diff --git a/modules/juce_gui_basics/menus/juce_PopupMenu.h b/modules/juce_gui_basics/menus/juce_PopupMenu.h index 6ca8c721d72d..04c2f58f1f6d 100644 --- a/modules/juce_gui_basics/menus/juce_PopupMenu.h +++ b/modules/juce_gui_basics/menus/juce_PopupMenu.h @@ -551,6 +551,37 @@ class JUCE_API PopupMenu /** Sets the direction of the popup menu relative to the target screen area. */ [[nodiscard]] Options withPreferredPopupDirection (PopupDirection direction) const; + + + /** Provide an X value from the left edge of any PopupMenu item such + that clicks to the left of the X value will NOT select the Popup + menu item, but clicks to the right will select the Popup men item. + + This is useful for blocking off area for extra UI in a + PopupMenu::CustomComponent that you do not want to be used for + selecting a menu item. + + @note Added by Tim for FAW SampleComboBox.h so that we could prevent + the sample audio preview buttons in the SamplePopMenuItem + from selecting the item. + */ + [[nodiscard]] Options withSelectableAreaLeftInset (int xInsetAmount) const; + + + /** Provide an X value from the right edge of any PopupMenu item such + that clicks to the right of the X value will NOT select the Popup + menu item, but clicks to the left will select the Popup men item. + + This is useful for blocking off area for extra UI in a + PopupMenu::CustomComponent that you do not want to be used for + selecting a menu item. + + @note Added by Tim for FAW SampleComboBox.h so that we could prevent + the favorite buttons in the SamplePopMenuItem from selecting + the item. + */ + [[nodiscard]] Options withSelectableAreaRightInset (int xInsetAmount) const; + /** Sets an item to select in the menu.