35 update (customComponent);
40 jassert (newComponent !=
nullptr);
42 if (newComponent != custom)
44 if (custom !=
nullptr)
47 custom = newComponent;
81 if (newModel != model)
101void BurgerMenuComponent::refresh()
103 lastRowClicked = inputSourceIndexOfLastClick = -1;
107 if (model !=
nullptr)
111 for (
auto menuIdx = 0; menuIdx < menuBarNames.size(); ++menuIdx)
114 menuItem.text = menuBarNames[menuIdx];
119 rows.
add (Row {
true, menuIdx, menuItem });
120 addMenuBarItemsForMenu (menu, menuIdx);
125void BurgerMenuComponent::addMenuBarItemsForMenu (PopupMenu& menu,
int menuIdx)
127 for (PopupMenu::MenuItemIterator it (menu); it.next();)
129 auto& item = it.getItem();
131 if (item.isSeparator)
134 if (hasSubMenu (item))
135 addMenuBarItemsForMenu (*item.subMenu, menuIdx);
137 rows.
add (Row {
false, menuIdx, it.getItem()});
141int BurgerMenuComponent::getNumRows()
146void BurgerMenuComponent::paint (Graphics& g)
151void BurgerMenuComponent::paintListBoxItem (
int rowIndex, Graphics& g,
int w,
int h,
bool highlight)
154 Rectangle<int> r (w, h);
157 : Row {
true, 0, {} });
161 if (row.isMenuHeader)
163 lf.drawPopupMenuSectionHeader (g, r.reduced (20, 0), row.item.text);
164 g.setColour (Colours::grey);
165 g.fillRect (r.withHeight (1));
169 auto& item = row.item;
170 auto* colour = item.colour != Colour() ? &item.colour :
nullptr;
172 if (item.customComponent ==
nullptr)
173 lf.drawPopupMenuItem (g, r.reduced (20, 0),
180 item.shortcutKeyDescription,
186bool BurgerMenuComponent::hasSubMenu (
const PopupMenu::Item& item)
188 return item.subMenu !=
nullptr && (item.itemID == 0 || item.subMenu->getNumItems() > 0);
191void BurgerMenuComponent::listBoxItemClicked (
int rowIndex,
const MouseEvent& e)
194 : Row {
true, 0, {} };
196 if (! row.isMenuHeader)
198 lastRowClicked = rowIndex;
199 inputSourceIndexOfLastClick = e.source.getIndex();
203Component* BurgerMenuComponent::refreshComponentForRow (
int rowIndex,
bool isRowSelected, Component* existing)
206 : Row {
true, 0, {} };
208 auto hasCustomComponent = (row.item.customComponent !=
nullptr);
210 if (existing ==
nullptr && hasCustomComponent)
211 return new CustomMenuBarItemHolder (row.item.customComponent);
213 if (existing !=
nullptr)
215 auto* componentToUpdate =
dynamic_cast<CustomMenuBarItemHolder*
> (existing);
216 jassert (componentToUpdate !=
nullptr);
218 if (hasCustomComponent && componentToUpdate !=
nullptr)
220 row.item.customComponent->setHighlighted (isRowSelected);
221 componentToUpdate->update (row.item.customComponent);
233void BurgerMenuComponent::resized()
238void BurgerMenuComponent::menuBarItemsChanged (MenuBarModel* menuBarModel)
243void BurgerMenuComponent::menuCommandInvoked (MenuBarModel*,
const ApplicationCommandTarget::InvocationInfo&)
247void BurgerMenuComponent::mouseUp (
const MouseEvent& event)
251 if (rowIndex == lastRowClicked && rowIndex < rows.
size()
252 && event.source.getIndex() == inputSourceIndexOfLastClick)
256 if (! row.isMenuHeader)
261 inputSourceIndexOfLastClick = -1;
263 topLevelIndexClicked = row.topLevelMenuIndex;
264 auto& item = row.item;
266 if (
auto* managerOfChosenCommand = item.commandManager)
268 ApplicationCommandTarget::InvocationInfo info (item.itemID);
271 managerOfChosenCommand->invoke (info,
true);
279void BurgerMenuComponent::handleCommandMessage (
int commandID)
281 if (model !=
nullptr)
284 topLevelIndexClicked = -1;
int size() const noexcept
Returns the current number of elements in the array.
void add(const ElementType &newElement)
Appends a new element at the end of the array.
void clear()
Removes all elements from the array.
ElementType & getReference(int index) noexcept
Returns a direct reference to one of the elements in the array, without checking the index passed in.
The base class for all JUCE user-interface objects.
void setInterceptsMouseClicks(bool allowClicksOnThisComponent, bool allowClicksOnChildComponents) noexcept
Changes the default return value for the hitTest() method.
int getHeight() const noexcept
Returns the component's height in pixels.
void addAndMakeVisible(Component *child, int zOrder=-1)
Adds a child component to this one, and also makes the child visible if it isn't already.
void addMouseListener(MouseListener *newListener, bool wantsEventsForAllNestedChildComponents)
Registers a listener to be told when mouse events occur in this component.
void postCommandMessage(int commandId)
Dispatches a numbered message to this component.
void removeChildComponent(Component *childToRemove)
Removes one of this component's child-components.
void setBounds(int x, int y, int width, int height)
Changes the component's position and size.
Colour findColour(int colourID, bool inheritFromParent=false) const
Looks for a colour that has been registered with the given colour ID number.
int getWidth() const noexcept
Returns the component's width in pixels.
LookAndFeel & getLookAndFeel() const noexcept
Finds the appropriate look-and-feel to use for this component.
Rectangle< int > getLocalBounds() const noexcept
Returns the component's bounds, relative to its own origin.
void setRowHeight(int newHeight)
Sets the height of each row in the list.
int getSelectedRow(int index=0) const
Returns the row number of a selected row.
void updateContent()
Causes the list to refresh its content.
void selectRow(int rowNumber, bool dontScrollToShowThisRow=false, bool deselectOthersFirst=true)
Selects a row.
A smart-pointer class which points to a reference-counted object.
int roundToInt(const FloatType value) noexcept
Fast floating-point-to-integer conversion.
@ fromMenu
The command is being invoked by a menu selection.
virtual void drawPopupMenuBackground(Graphics &, int width, int height)
Fills the background of a popup menu component.