JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_ComboBox.cpp
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
30 : Component (name),
31 noChoicesMessage (TRANS ("(no choices)"))
32{
35 currentId.addListener (this);
36}
37
39{
40 currentId.removeListener (this);
41 hidePopup();
42 label.reset();
43}
44
45//==============================================================================
46void ComboBox::setEditableText (const bool isEditable)
47{
48 if (label->isEditableOnSingleClick() != isEditable || label->isEditableOnDoubleClick() != isEditable)
49 {
50 label->setEditable (isEditable, isEditable, false);
51 labelEditableState = (isEditable ? labelIsEditable : labelIsNotEditable);
52
53 const auto isLabelEditable = (labelEditableState == labelIsEditable);
54
56 label->setAccessible (isLabelEditable);
57
58 resized();
59 }
60}
61
63{
64 return label->isEditable();
65}
66
68{
69 label->setJustificationType (justification);
70}
71
73{
74 return label->getJustificationType();
75}
76
82
83//==============================================================================
85{
86 // you can't add empty strings to the list..
87 jassert (newItemText.isNotEmpty());
88
89 // IDs must be non-zero, as zero is used to indicate a lack of selection.
90 jassert (newItemId != 0);
91
92 // you shouldn't use duplicate item IDs!
93 jassert (getItemForId (newItemId) == nullptr);
94
95 if (newItemText.isNotEmpty() && newItemId != 0)
96 currentMenu.addItem (newItemId, newItemText, true, false);
97}
98
100{
101 for (auto& i : itemsToAdd)
102 currentMenu.addItem (firstItemID++, i);
103}
104
106{
107 currentMenu.addSeparator();
108}
109
111{
112 // you can't add empty strings to the list..
113 jassert (headingName.isNotEmpty());
114
115 if (headingName.isNotEmpty())
116 currentMenu.addSectionHeader (headingName);
117}
118
120{
121 if (auto* item = getItemForId (itemId))
122 item->isEnabled = shouldBeEnabled;
123}
124
125bool ComboBox::isItemEnabled (int itemId) const noexcept
126{
127 if (auto* item = getItemForId (itemId))
128 return item->isEnabled;
129
130 return false;
131}
132
133void ComboBox::changeItemText (int itemId, const String& newText)
134{
135 if (auto* item = getItemForId (itemId))
136 item->text = newText;
137 else
139}
140
142{
143 currentMenu.clear();
144
145 if (! label->isEditable())
147}
148
149//==============================================================================
150PopupMenu::Item* ComboBox::getItemForId (int itemId) const noexcept
151{
152 if (itemId != 0)
153 {
154 for (PopupMenu::MenuItemIterator iterator (currentMenu, true); iterator.next();)
155 {
156 auto& item = iterator.getItem();
157
158 if (item.itemID == itemId)
159 return &item;
160 }
161 }
162
163 return nullptr;
164}
165
166PopupMenu::Item* ComboBox::getItemForIndex (const int index) const noexcept
167{
168 int n = 0;
169
170 for (PopupMenu::MenuItemIterator iterator (currentMenu, true); iterator.next();)
171 {
172 auto& item = iterator.getItem();
173
174 if (item.itemID != 0)
175 if (n++ == index)
176 return &item;
177 }
178
179 return nullptr;
180}
181
183{
184 int n = 0;
185
186 for (PopupMenu::MenuItemIterator iterator (currentMenu, true); iterator.next();)
187 {
188 auto& item = iterator.getItem();
189
190 if (item.itemID != 0)
191 n++;
192 }
193
194 return n;
195}
196
197String ComboBox::getItemText (const int index) const
198{
199 if (auto* item = getItemForIndex (index))
200 return item->text;
201
202 return {};
203}
204
205int ComboBox::getItemId (const int index) const noexcept
206{
207 if (auto* item = getItemForIndex (index))
208 return item->itemID;
209
210 return 0;
211}
212
213int ComboBox::indexOfItemId (const int itemId) const noexcept
214{
215 if (itemId != 0)
216 {
217 int n = 0;
218
219 for (PopupMenu::MenuItemIterator iterator (currentMenu, true); iterator.next();)
220 {
221 auto& item = iterator.getItem();
222
223 if (item.itemID == itemId)
224 return n;
225
226 else if (item.itemID != 0)
227 n++;
228 }
229 }
230
231 return -1;
232}
233
234//==============================================================================
236{
237 auto index = indexOfItemId (currentId.getValue());
238
239 if (getText() != getItemText (index))
240 index = -1;
241
242 return index;
243}
244
249
251{
252 if (auto* item = getItemForId (currentId.getValue()))
253 if (getText() == item->text)
254 return item->itemID;
255
256 return 0;
257}
258
260{
261 auto* item = getItemForId (newItemId);
262 auto newItemText = item != nullptr ? item->text : String();
263
264 if (lastCurrentId != newItemId || label->getText() != newItemText)
265 {
266 label->setText (newItemText, dontSendNotification);
267 lastCurrentId = newItemId;
268 currentId = newItemId;
269
270 repaint(); // for the benefit of the 'none selected' text
271
272 sendChange (notification);
273 }
274}
275
276bool ComboBox::selectIfEnabled (const int index)
277{
278 if (auto* item = getItemForIndex (index))
279 {
280 if (item->isEnabled)
281 {
282 setSelectedItemIndex (index);
283 return true;
284 }
285 }
286
287 return false;
288}
289
290bool ComboBox::nudgeSelectedItem (int delta)
291{
292 for (int i = getSelectedItemIndex() + delta; isPositiveAndBelow (i, getNumItems()); i += delta)
293 if (selectIfEnabled (i))
294 return true;
295
296 return false;
297}
298
300{
301 if (lastCurrentId != (int) currentId.getValue())
302 setSelectedId (currentId.getValue());
303}
304
305//==============================================================================
307{
308 return label->getText();
309}
310
312{
313 for (PopupMenu::MenuItemIterator iterator (currentMenu, true); iterator.next();)
314 {
315 auto& item = iterator.getItem();
316
317 if (item.itemID != 0
318 && item.text == newText)
319 {
320 setSelectedId (item.itemID, notification);
321 return;
322 }
323 }
324
325 lastCurrentId = 0;
326 currentId = 0;
327 repaint();
328
329 if (label->getText() != newText)
330 {
331 label->setText (newText, dontSendNotification);
332 sendChange (notification);
333 }
334}
335
337{
338 jassert (isTextEditable()); // you probably shouldn't do this to a non-editable combo box?
339
340 label->showEditor();
341}
342
343//==============================================================================
345{
346 if (textWhenNothingSelected != newMessage)
347 {
348 textWhenNothingSelected = newMessage;
349 repaint();
350 }
351}
352
354{
355 return textWhenNothingSelected;
356}
357
359{
360 noChoicesMessage = newMessage;
361}
362
364{
365 return noChoicesMessage;
366}
367
368//==============================================================================
370{
371 getLookAndFeel().drawComboBox (g, getWidth(), getHeight(), isButtonDown,
372 label->getRight(), 0, getWidth() - label->getRight(), getHeight(),
373 *this);
374
375 if (textWhenNothingSelected.isNotEmpty() && label->getText().isEmpty() && ! label->isBeingEdited())
376 getLookAndFeel().drawComboBoxTextWhenNothingSelected (g, *this, *label);
377}
378
380{
381 if (getHeight() > 0 && getWidth() > 0)
382 getLookAndFeel().positionComboBoxText (*this, *label);
383}
384
386{
387 if (! isEnabled())
388 hidePopup();
389
390 repaint();
391}
392
394{
395 label->setColour (Label::backgroundColourId, Colours::transparentBlack);
397
399 label->setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
401 label->setColour (TextEditor::outlineColourId, Colours::transparentBlack);
402 repaint();
403}
404
409
411{
412 {
413 std::unique_ptr<Label> newLabel (getLookAndFeel().createComboBoxTextBox (*this));
414 jassert (newLabel != nullptr);
415
416 if (label != nullptr)
417 {
418 newLabel->setEditable (label->isEditable());
419 newLabel->setJustificationType (label->getJustificationType());
420 newLabel->setTooltip (label->getTooltip());
421 newLabel->setText (label->getText(), dontSendNotification);
422 }
423
424 std::swap (label, newLabel);
425 }
426
427 addAndMakeVisible (label.get());
428
429 EditableState newEditableState = (label->isEditable() ? labelIsEditable : labelIsNotEditable);
430
431 if (newEditableState != labelEditableState)
432 {
433 labelEditableState = newEditableState;
434 setWantsKeyboardFocus (labelEditableState == labelIsNotEditable);
435 }
436
437 label->onTextChange = [this] { triggerAsyncUpdate(); };
438 label->addMouseListener (this, false);
439 label->setAccessible (labelEditableState == labelIsEditable);
440
442 resized();
443}
444
445//==============================================================================
447{
448 if (key == KeyPress::upKey || key == KeyPress::leftKey)
449 {
450 nudgeSelectedItem (-1);
451 return true;
452 }
453
454 if (key == KeyPress::downKey || key == KeyPress::rightKey)
455 {
456 nudgeSelectedItem (1);
457 return true;
458 }
459
460 if (key == KeyPress::returnKey)
461 {
462 showPopupIfNotActive();
463 return true;
464 }
465
466 return false;
467}
468
469bool ComboBox::keyStateChanged (const bool isKeyDown)
470{
471 // only forward key events that aren't used by this component
472 return isKeyDown
477}
478
479//==============================================================================
482
483//==============================================================================
484void ComboBox::showPopupIfNotActive()
485{
486 if (! menuActive)
487 {
488 menuActive = true;
489
490 // as this method was triggered by a mouse event, the same mouse event may have
491 // exited the modal state of other popups currently on the screen. By calling
492 // showPopup asynchronously, we are giving the other popups a chance to properly
493 // close themselves
494 MessageManager::callAsync ([safePointer = SafePointer<ComboBox> { this }]() mutable { if (safePointer != nullptr) safePointer->showPopup(); });
495 repaint();
496 }
497}
498
500{
501 if (menuActive)
502 {
503 menuActive = false;
505 repaint();
506 }
507}
508
509static void comboBoxPopupMenuFinishedCallback (int result, ComboBox* combo)
510{
511 if (combo != nullptr)
512 {
513 combo->hidePopup();
514
515 if (result != 0)
516 combo->setSelectedId (result);
517 }
518}
519
521{
522 if (! menuActive)
523 menuActive = true;
524
525 auto menu = currentMenu;
526
527 if (menu.getNumItems() > 0)
528 {
529 auto selectedId = getSelectedId();
530
531 for (PopupMenu::MenuItemIterator iterator (menu, true); iterator.next();)
532 {
533 auto& item = iterator.getItem();
534
535 if (item.itemID != 0)
536 item.isTicked = (item.itemID == selectedId);
537 }
538 }
539 else
540 {
541 menu.addItem (1, noChoicesMessage, false, false);
542 }
543
544 auto& lf = getLookAndFeel();
545
546 menu.setLookAndFeel (&lf);
547 menu.showMenuAsync (lf.getOptionsForComboBoxPopupMenu (*this, *label),
548 ModalCallbackFunction::forComponent (comboBoxPopupMenuFinishedCallback, this));
549}
550
551//==============================================================================
553{
555
556 isButtonDown = isEnabled() && ! e.mods.isPopupMenu();
557
558 if (isButtonDown && (e.eventComponent == this || ! label->isEditable()))
559 showPopupIfNotActive();
560}
561
563{
565
566 if (isButtonDown && e.mouseWasDraggedSinceMouseDown())
567 showPopupIfNotActive();
568}
569
571{
572 if (isButtonDown)
573 {
574 isButtonDown = false;
575 repaint();
576
577 auto e = e2.getEventRelativeTo (this);
578
579 if (reallyContains (e.getPosition(), true)
580 && (e2.eventComponent == this || ! label->isEditable()))
581 {
582 showPopupIfNotActive();
583 }
584 }
585}
586
588{
589 if (! menuActive && scrollWheelEnabled && e.eventComponent == this && ! approximatelyEqual (wheel.deltaY, 0.0f))
590 {
591 mouseWheelAccumulator += wheel.deltaY * 5.0f;
592
593 while (mouseWheelAccumulator > 1.0f)
594 {
595 mouseWheelAccumulator -= 1.0f;
596 nudgeSelectedItem (-1);
597 }
598
599 while (mouseWheelAccumulator < -1.0f)
600 {
601 mouseWheelAccumulator += 1.0f;
602 nudgeSelectedItem (1);
603 }
604 }
605 else
606 {
608 }
609}
610
611void ComboBox::setScrollWheelEnabled (bool enabled) noexcept
612{
613 scrollWheelEnabled = enabled;
614}
615
616//==============================================================================
617void ComboBox::addListener (ComboBox::Listener* l) { listeners.add (l); }
618void ComboBox::removeListener (ComboBox::Listener* l) { listeners.remove (l); }
619
621{
623 listeners.callChecked (checker, [this] (Listener& l) { l.comboBoxChanged (this); });
624
625 if (checker.shouldBailOut())
626 return;
627
628 NullCheckedInvocation::invoke (onChange);
629
630 if (checker.shouldBailOut())
631 return;
632
633 if (auto* handler = getAccessibilityHandler())
634 handler->notifyAccessibilityEvent (AccessibilityEvent::valueChanged);
635}
636
637void ComboBox::sendChange (const NotificationType notification)
638{
641
644}
645
646// Old deprecated methods - remove eventually...
651
652//==============================================================================
654{
655public:
658 AccessibilityRole::comboBox,
659 getAccessibilityActions (comboBoxToWrap),
660 { std::make_unique<ComboBoxValueInterface> (comboBoxToWrap) }),
661 comboBox (comboBoxToWrap)
662 {
663 }
664
666 {
668
669 return comboBox.isPopupActive() ? state.withExpanded() : state.withCollapsed();
670 }
671
672 String getTitle() const override { return comboBox.getText(); }
673 String getHelp() const override { return comboBox.getTooltip(); }
674
675private:
676 class ComboBoxValueInterface final : public AccessibilityTextValueInterface
677 {
678 public:
679 explicit ComboBoxValueInterface (ComboBox& comboBoxToWrap)
680 : comboBox (comboBoxToWrap)
681 {
682 }
683
684 bool isReadOnly() const override { return true; }
685 String getCurrentValueAsString() const override { return comboBox.getText(); }
686 void setValueAsString (const String&) override {}
687
688 private:
689 ComboBox& comboBox;
690
691 //==============================================================================
692 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ComboBoxValueInterface)
693 };
694
695 static AccessibilityActions getAccessibilityActions (ComboBox& comboBox)
696 {
697 return AccessibilityActions().addAction (AccessibilityActionType::press, [&comboBox] { comboBox.showPopup(); })
698 .addAction (AccessibilityActionType::showMenu, [&comboBox] { comboBox.showPopup(); });
699 }
700
701 ComboBox& comboBox;
702
703 //==============================================================================
704 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ComboBoxAccessibilityHandler)
705};
706
708{
709 return std::make_unique<ComboBoxAccessibilityHandler> (*this);
710}
711
712} // namespace juce
Base class for accessible Components.
virtual AccessibleState getCurrentState() const
Returns the current state of the UI element.
A value interface that represents a text value.
Represents the state of an accessible UI element.
AccessibleState withExpandable() const noexcept
Sets the expandable flag and returns the new state.
void handleUpdateNowIfNeeded()
If an update has been triggered and is pending, this will invoke it synchronously.
void triggerAsyncUpdate()
Causes the callback to be triggered at a later time.
String getHelp() const override
Some help text for the UI element (if required).
String getTitle() const override
The title of the UI element.
AccessibleState getCurrentState() const override
Returns the current state of the UI element.
A class for receiving events from a ComboBox.
A component that lets the user choose from a drop-down list of choices.
void handleAsyncUpdate() override
Called back to do whatever your class needs to do.
@ textColourId
The colour for the text in the box.
void showEditor()
Programmatically opens the text editor to allow the user to edit the current item.
bool isPopupActive() const noexcept
Returns true if the popup menu is currently being shown.
void valueChanged(Value &) override
Called when a Value object is changed.
void colourChanged() override
This method is called when a colour is changed by the setColour() method, or when the look-and-feel i...
void setText(const String &newText, NotificationType notification=sendNotificationAsync)
Sets the contents of the combo-box's text field.
void addItemList(const StringArray &items, int firstItemIdOffset)
Adds an array of items to the drop-down list.
void setJustificationType(Justification justification)
Sets the style of justification to be used for positioning the text.
void clear(NotificationType notification=sendNotificationAsync)
Removes all the items from the drop-down list.
void resized() override
Called when this component's size has been changed.
void lookAndFeelChanged() override
Called to let the component react to a change in the look-and-feel setting.
bool isItemEnabled(int itemId) const noexcept
Returns true if the given item is enabled.
void addSectionHeading(const String &headingName)
Adds a heading to the drop-down list, so that you can group the items into different sections.
void mouseDrag(const MouseEvent &) override
Called when the mouse is moved while a button is held down.
void focusGained(Component::FocusChangeType) override
Called to indicate that this component has just acquired the keyboard focus.
void hidePopup()
Hides the combo box's popup list, if it's currently visible.
virtual void showPopup()
Pops up the combo box's list.
void setItemEnabled(int itemId, bool shouldBeEnabled)
This allows items in the drop-down list to be selectively disabled.
void setSelectedItemIndex(int newItemIndex, NotificationType notification=sendNotificationAsync)
Sets one of the items to be the current selection.
void mouseUp(const MouseEvent &) override
Called when a mouse button is released.
void addListener(Listener *listener)
Registers a listener that will be called when the box's content changes.
void paint(Graphics &) override
Components can override this method to draw their content.
void setSelectedId(int newItemId, NotificationType notification=sendNotificationAsync)
Sets one of the items to be the current selection.
void parentHierarchyChanged() override
Called to indicate that the component's parents have changed.
bool keyStateChanged(bool) override
Called when a key is pressed or released.
void setScrollWheelEnabled(bool enabled) noexcept
This can be used to allow the scroll-wheel to nudge the chosen item.
void mouseDown(const MouseEvent &) override
Called when a mouse button is pressed.
Justification getJustificationType() const noexcept
Returns the current justification for the text box.
void mouseWheelMove(const MouseEvent &, const MouseWheelDetails &) override
Called when the mouse-wheel is moved.
std::function< void()> onChange
You can assign a lambda to this callback object to have it called when the selected ID is changed.
std::unique_ptr< AccessibilityHandler > createAccessibilityHandler() override
Override this method to return a custom AccessibilityHandler for this component.
void setTextWhenNothingSelected(const String &newMessage)
Sets a message to display when there is no item currently selected.
String getItemText(int index) const
Returns the text for one of the items in the list.
void setTooltip(const String &newTooltip) override
Gives the ComboBox a tooltip.
String getTooltip() override
Returns the string that this object wants to show as its tooltip.
bool isTextEditable() const noexcept
Returns true if the text is directly editable.
void setEditableText(bool isEditable)
Sets whether the text in the combo-box is editable.
int indexOfItemId(int itemId) const noexcept
Returns the index in the list of a particular item ID.
int getItemId(int index) const noexcept
Returns the ID for one of the items in the list.
void addSeparator()
Adds a separator line to the drop-down list.
ComboBox(const String &componentName={})
Creates a combo-box.
String getTextWhenNoChoicesAvailable() const
Returns the text shown when no items have been added to the list.
void changeItemText(int itemId, const String &newText)
Changes the text for an existing item.
void focusLost(Component::FocusChangeType) override
Called to indicate that this component has just lost the keyboard focus.
int getSelectedId() const noexcept
Returns the ID of the item that's currently shown in the box.
String getText() const
Returns the text that is currently shown in the combo-box's text field.
void addItem(const String &newItemText, int newItemId)
Adds an item to be shown in the drop-down list.
int getNumItems() const noexcept
Returns the number of items that have been added to the list.
String getTextWhenNothingSelected() const
Returns the text that is shown when no item is selected.
bool keyPressed(const KeyPress &) override
Called when a key is pressed.
~ComboBox() override
Destructor.
void enablementChanged() override
Callback to indicate that this component has been enabled or disabled.
int getSelectedItemIndex() const
Returns the index of the item that's currently shown in the box.
void removeListener(Listener *listener)
Deregisters a previously-registered listener.
void setTextWhenNoChoicesAvailable(const String &newMessage)
Sets the message to show when there are no items in the list, and the user clicks on the drop-down bo...
A class to keep an eye on a component and check for it being deleted.
The base class for all JUCE user-interface objects.
void setRepaintsOnMouseActivity(bool shouldRepaint) noexcept
Causes automatic repaints when the mouse enters or exits this component.
bool reallyContains(Point< int > localPoint, bool returnTrueIfWithinAChild)
Returns true if a given point lies in this component, taking any overlapping siblings into account.
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.
FocusChangeType
Enumeration used by the focusGained() and focusLost() methods.
AccessibilityHandler * getAccessibilityHandler()
Returns the accessibility handler for this component, or nullptr if this component is not accessible.
void repaint()
Marks the whole component as needing to be redrawn.
void setWantsKeyboardFocus(bool wantsFocus) noexcept
Sets a flag to indicate whether this component wants keyboard focus or not.
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.
void mouseWheelMove(const MouseEvent &event, const MouseWheelDetails &wheel) override
Called when the mouse-wheel is moved.
static void JUCE_CALLTYPE beginDragAutoRepeat(int millisecondsBetweenCallbacks)
Ensures that a non-stop stream of mouse-drag events will be sent during the current mouse-drag operat...
bool isEnabled() const noexcept
Returns true if the component (and all its parents) are enabled.
LookAndFeel & getLookAndFeel() const noexcept
Finds the appropriate look-and-feel to use for this component.
A graphics context, used for drawing a component or image.
Represents a type of justification to be used when positioning graphical items.
Represents a key press, including any modifier keys that are needed.
static const int upKey
key-code for the cursor-up key
static bool isKeyCurrentlyDown(int keyCode)
Checks whether a particular key is held down, irrespective of modifiers.
static const int rightKey
key-code for the cursor-right key
static const int downKey
key-code for the cursor-down key
static const int returnKey
key-code for the return key
static const int leftKey
key-code for the cursor-left key
@ backgroundColourId
The background colour to fill the label with.
Definition juce_Label.h:106
@ textColourId
The colour for the text.
Definition juce_Label.h:107
static bool callAsync(std::function< void()> functionToCall)
Asynchronously invokes a function or C++11 lambda on the message thread.
static ModalComponentManager::Callback * forComponent(void(*functionToCall)(int, ComponentType *), ComponentType *component)
This is a utility function to create a ModalComponentManager::Callback that will call a static functi...
bool isPopupMenu() const noexcept
Checks whether the user is trying to launch a pop-up menu.
Contains position and status information about a mouse event.
const ModifierKeys mods
The key modifiers associated with the event.
bool mouseWasDraggedSinceMouseDown() const noexcept
Returns true if the user seems to be performing a drag gesture.
Component *const eventComponent
The component that this event applies to.
Allows you to iterate through the items in a pop-up menu, and examine their properties.
bool next()
Returns true if there is another item, and sets up all this object's member variables to reflect that...
void addSeparator()
Appends a separator to the menu, to help break it up into sections.
void addSectionHeader(String title)
Adds a non-clickable text item to the menu.
void clear()
Resets the menu, removing all its items.
void addItem(Item newItem)
Adds an item to the menu.
static bool JUCE_CALLTYPE dismissAllActiveMenus()
Closes any menus that are currently open.
virtual void setTooltip(const String &newTooltip)
Assigns a new tooltip to this object.
A special array for holding a list of strings.
The JUCE String class!
Definition juce_String.h:53
bool isNotEmpty() const noexcept
Returns true if the string contains at least one character.
@ backgroundColourId
The colour to use for the text component's background - this can be transparent if necessary.
@ highlightColourId
The colour with which to fill the background of highlighted sections of the text - this can be transp...
@ textColourId
The colour that will be used when text is added to the editor.
@ outlineColourId
If this is non-transparent, it will be used to draw a box around the edge of the component.
Represents a shared variant value.
Definition juce_Value.h:51
void addListener(Listener *listener)
Adds a listener to receive callbacks when the value changes.
void removeListener(Listener *listener)
Removes a listener that was previously added with addListener().
var getValue() const
Returns the current value.
#define TRANS(stringLiteral)
Uses the LocalisedStrings class to translate the given string literal.
#define jassert(expression)
Platform-independent assertion macro.
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and JUCE_LEAK_DETECTOR macro for ...
#define jassertfalse
This will always cause an assertion failure.
JUCE Namespace.
constexpr bool approximatelyEqual(Type a, Type b, Tolerance< Type > tolerance=Tolerance< Type >{} .withAbsolute(std::numeric_limits< Type >::min()) .withRelative(std::numeric_limits< Type >::epsilon()))
Returns true if the two floating-point numbers are approximately equal.
@ valueChanged
Indicates that the UI element's value has changed.
NotificationType
These enums are used in various classes to indicate whether a notification event should be sent out.
@ sendNotification
Requests a notification message, either synchronous or not.
@ sendNotificationSync
Requests a synchronous notification.
@ dontSendNotification
No notification message should be sent.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
@ showMenu
Represents the user showing a contextual menu for a UI element.
@ press
Represents a "press" action.
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
Returns true if a value is at least zero, and also below a specified upper limit.
Contains status information about a mouse wheel event.
Describes a popup menu item.
T swap(T... args)