Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updating popmenu #1312

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion modules/juce_core/maths/juce_NormalisableRange.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class NormalisableRange

// If you hit this assertion then either your normalisation function is not working
// correctly or your input is out of the expected bounds.
jassert (exactlyEqual (clampedValue, value));
//jassert (clampedValue == value);

return clampedValue;
}
Expand Down
4 changes: 2 additions & 2 deletions modules/juce_data_structures/values/juce_Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ Value& Value::operator= (const var& newValue)
return *this;
}

void Value::referTo (const Value& valueToReferTo)
void Value::referTo (const Value& valueToReferTo, bool notifyListeners)
{
if (valueToReferTo.value != value)
{
Expand All @@ -185,7 +185,7 @@ void Value::referTo (const Value& valueToReferTo)
}

value = valueToReferTo.value;
callListeners();
if(notifyListeners) callListeners();
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/juce_data_structures/values/juce_Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class JUCE_API Value final
Existing listeners will still be registered after you call this method, and
they'll continue to receive messages when the new value changes.
*/
void referTo (const Value& valueToReferTo);
void referTo (const Value& valueToReferTo, bool notifyListeners = true);

/** Returns true if this object and the other one use the same underlying
ValueSource object.
Expand Down
8 changes: 4 additions & 4 deletions modules/juce_gui_basics/components/juce_Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2978,10 +2978,10 @@ AccessibilityHandler* Component::getAccessibilityHandler()
// By assigning the accessibility handler before notifying the system that an element was
// created, the if() predicate above should evaluate to false on recursive calls,
// terminating the recursion.
if (accessibilityHandler != nullptr)
detail::AccessibilityHelpers::notifyAccessibilityEvent (*accessibilityHandler, detail::AccessibilityHelpers::Event::elementCreated);
else
jassertfalse; // createAccessibilityHandler must return non-null
// if (accessibilityHandler != nullptr)
// notifyAccessibilityEventInternal (*accessibilityHandler, InternalAccessibilityEvent::elementCreated);
// else
// jassertfalse; // createAccessibilityHandler must return non-null
}

return accessibilityHandler.get();
Expand Down
11 changes: 11 additions & 0 deletions modules/juce_gui_basics/menus/juce_PopupMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1970,6 +1970,17 @@ static PopupMenu::Options with (PopupMenu::Options options, Member&& member, Ite
return options;
}

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::Options PopupMenu::Options::withTargetComponent (Component* comp) const
{
auto o = with (with (*this, &Options::targetComponent, comp), &Options::topLevelTarget, comp);
Expand Down
31 changes: 31 additions & 0 deletions modules/juce_gui_basics/menus/juce_PopupMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,35 @@ class JUCE_API PopupMenu
*/
[[nodiscard]] Options forSubmenu() 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;

//==============================================================================
/** Gets the parent component. This may be nullptr if the Component has been deleted.

Expand Down Expand Up @@ -651,6 +680,8 @@ class JUCE_API PopupMenu
int visibleItemID = 0, minWidth = 0, minColumns = 1, maxColumns = 0, standardHeight = 0, initiallySelectedItemId = 0;
bool isWatchingForDeletion = false;
PopupDirection preferredPopupDirection = PopupDirection::downwards;
int selectableAreaLeftInset = 0;
int selectableAreaRightInset = 0;
};

//==============================================================================
Expand Down
5 changes: 4 additions & 1 deletion modules/juce_gui_basics/widgets/juce_ComboBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,9 @@ class JUCE_API ComboBox : public Component,
[[deprecated]] void setSelectedItemIndex (int, bool);
[[deprecated]] void setText (const String&, bool);
#endif

//GB 31/1/24 Changed to public
PopupMenu::Item* getItemForId (int) const noexcept;

private:
//==============================================================================
Expand All @@ -450,7 +453,7 @@ class JUCE_API ComboBox : public Component,
String textWhenNothingSelected, noChoicesMessage;
EditableState labelEditableState = editableUnknown;

PopupMenu::Item* getItemForId (int) const noexcept;
// std::unique_ptr<AccessibilityHandler> createAccessibilityHandler() override;
PopupMenu::Item* getItemForIndex (int) const noexcept;
bool selectIfEnabled (int index);
bool nudgeSelectedItem (int delta);
Expand Down
Loading