mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Added method PopupMenu::CustomComponent::getItem() to give them access to item details
This commit is contained in:
parent
2d0eb9e033
commit
635e070cba
2 changed files with 24 additions and 0 deletions
|
|
@ -80,7 +80,10 @@ struct ItemComponent : public Component
|
|||
customComp = *new HeaderItemComponent (item.text);
|
||||
|
||||
if (customComp != nullptr)
|
||||
{
|
||||
setItem (*customComp, &item);
|
||||
addAndMakeVisible (*customComp);
|
||||
}
|
||||
|
||||
parent.addAndMakeVisible (this);
|
||||
|
||||
|
|
@ -96,6 +99,9 @@ struct ItemComponent : public Component
|
|||
|
||||
~ItemComponent() override
|
||||
{
|
||||
if (customComp != nullptr)
|
||||
setItem (*customComp, nullptr);
|
||||
|
||||
removeChildComponent (customComp.get());
|
||||
}
|
||||
|
||||
|
|
@ -1893,6 +1899,12 @@ void PopupMenu::setLookAndFeel (LookAndFeel* const newLookAndFeel)
|
|||
lookAndFeel = newLookAndFeel;
|
||||
}
|
||||
|
||||
void PopupMenu::setItem (CustomComponent& c, const Item* itemToUse)
|
||||
{
|
||||
c.item = itemToUse;
|
||||
c.repaint();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
PopupMenu::CustomComponent::CustomComponent (bool autoTrigger)
|
||||
: triggeredAutomatically (autoTrigger)
|
||||
|
|
|
|||
|
|
@ -699,6 +699,13 @@ public:
|
|||
*/
|
||||
bool isItemHighlighted() const noexcept { return isHighlighted; }
|
||||
|
||||
/** Returns a pointer to the Item that holds this custom component, if this
|
||||
component is currently held by an Item.
|
||||
You can query the Item for information that you might want to use
|
||||
in your paint() method, such as the item's enabled and ticked states.
|
||||
*/
|
||||
const PopupMenu::Item* getItem() const noexcept { return item; }
|
||||
|
||||
/** @internal */
|
||||
bool isTriggeredAutomatically() const noexcept { return triggeredAutomatically; }
|
||||
/** @internal */
|
||||
|
|
@ -707,6 +714,9 @@ public:
|
|||
private:
|
||||
//==============================================================================
|
||||
bool isHighlighted = false, triggeredAutomatically;
|
||||
const PopupMenu::Item* item = nullptr;
|
||||
|
||||
friend PopupMenu;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CustomComponent)
|
||||
};
|
||||
|
|
@ -812,6 +822,8 @@ private:
|
|||
Component* createWindow (const Options&, ApplicationCommandManager**) const;
|
||||
int showWithOptionalCallback (const Options&, ModalComponentManager::Callback*, bool);
|
||||
|
||||
static void setItem (CustomComponent&, const Item*);
|
||||
|
||||
#if JUCE_CATCH_DEPRECATED_CODE_MISUSE
|
||||
// These methods have new implementations now - see its new definition
|
||||
int drawPopupMenuItem (Graphics&, int, int, bool, bool, bool, bool, bool, const String&, const String&, Image*, const Colour*) { return 0; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue