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_Toolbar.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
29const char* const Toolbar::toolbarDragDescriptor = "_toolbarItem_";
30
31//==============================================================================
33{
34public:
35 Spacer (int itemID, float sizeToUse, bool shouldDrawBar)
36 : ToolbarItemComponent (itemID, {}, false),
37 fixedSize (sizeToUse),
38 drawBar (shouldDrawBar)
39 {
41 }
42
43 bool getToolbarItemSizes (int toolbarThickness, bool /*isToolbarVertical*/,
44 int& preferredSize, int& minSize, int& maxSize) override
45 {
46 if (fixedSize <= 0)
47 {
48 preferredSize = toolbarThickness * 2;
49 minSize = 4;
50 maxSize = 32768;
51 }
52 else
53 {
54 maxSize = roundToInt ((float) toolbarThickness * fixedSize);
55 minSize = drawBar ? maxSize : jmin (4, maxSize);
56 preferredSize = maxSize;
57
59 preferredSize = maxSize = toolbarThickness / (drawBar ? 3 : 2);
60 }
61
62 return true;
63 }
64
65 void paintButtonArea (Graphics&, int, int, bool, bool) override
66 {
67 }
68
69 void contentAreaChanged (const Rectangle<int>&) override
70 {
71 }
72
73 int getResizeOrder() const noexcept
74 {
75 return fixedSize <= 0 ? 0 : 1;
76 }
77
78 void paint (Graphics& g) override
79 {
80 auto w = getWidth();
81 auto h = getHeight();
82
83 if (drawBar)
84 {
86
87 auto thickness = 0.2f;
88
90 g.fillRect ((float) w * 0.1f, (float) h * (0.5f - thickness * 0.5f), (float) w * 0.8f, (float) h * thickness);
91 else
92 g.fillRect ((float) w * (0.5f - thickness * 0.5f), (float) h * 0.1f, (float) w * thickness, (float) h * 0.8f);
93 }
94
95 if (getEditingMode() != normalMode && ! drawBar)
96 {
98
99 auto indentX = jmin (2, (w - 3) / 2);
100 auto indentY = jmin (2, (h - 3) / 2);
101 g.drawRect (indentX, indentY, w - indentX * 2, h - indentY * 2, 1);
102
103 if (fixedSize <= 0)
104 {
105 float x1, y1, x2, y2, x3, y3, x4, y4, hw, hl;
106
107 if (isToolbarVertical())
108 {
109 x1 = (float) w * 0.5f;
110 y1 = (float) h * 0.4f;
111 x2 = x1;
112 y2 = (float) indentX * 2.0f;
113
114 x3 = x1;
115 y3 = (float) h * 0.6f;
116 x4 = x1;
117 y4 = (float) h - y2;
118
119 hw = (float) w * 0.15f;
120 hl = (float) w * 0.2f;
121 }
122 else
123 {
124 x1 = (float) w * 0.4f;
125 y1 = (float) h * 0.5f;
126 x2 = (float) indentX * 2.0f;
127 y2 = y1;
128
129 x3 = (float) w * 0.6f;
130 y3 = y1;
131 x4 = (float) w - x2;
132 y4 = y1;
133
134 hw = (float) h * 0.15f;
135 hl = (float) h * 0.2f;
136 }
137
138 Path p;
139 p.addArrow ({ x1, y1, x2, y2 }, 1.5f, hw, hl);
140 p.addArrow ({ x3, y3, x4, y4 }, 1.5f, hw, hl);
141 g.fillPath (p);
142 }
143 }
144 }
145
146private:
147 const float fixedSize;
148 const bool drawBar;
149
151};
152
153//==============================================================================
155{
156public:
159 owner (&bar),
160 height (h)
161 {
162 for (int i = bar.items.size(); --i >= 0;)
163 {
164 auto* tc = bar.items.getUnchecked (i);
165
166 if (tc != nullptr && dynamic_cast<Spacer*> (tc) == nullptr && ! tc->isVisible())
167 {
168 oldIndexes.insert (0, i);
170 }
171 }
172
173 layout (400);
174 }
175
176 ~MissingItemsComponent() override
177 {
178 if (owner != nullptr)
179 {
180 for (int i = 0; i < getNumChildComponents(); ++i)
181 {
182 if (auto* tc = dynamic_cast<ToolbarItemComponent*> (getChildComponent (i)))
183 {
184 tc->setVisible (false);
185 auto index = oldIndexes.removeAndReturn (i);
186 owner->addChildComponent (tc, index);
187 --i;
188 }
189 }
190
191 owner->resized();
192 }
193 }
194
195 void layout (const int preferredWidth)
196 {
197 const int indent = 8;
198 auto x = indent;
199 auto y = indent;
200 int maxX = 0;
201
202 for (auto* c : getChildren())
203 {
204 if (auto* tc = dynamic_cast<ToolbarItemComponent*> (c))
205 {
206 int preferredSize = 1, minSize = 1, maxSize = 1;
207
208 if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
209 {
210 if (x + preferredSize > preferredWidth && x > indent)
211 {
212 x = indent;
213 y += height;
214 }
215
216 tc->setBounds (x, y, preferredSize, height);
217
218 x += preferredSize;
219 maxX = jmax (maxX, x);
220 }
221 }
222 }
223
224 setSize (maxX + 8, y + height + 8);
225 }
226
227 void getIdealSize (int& idealWidth, int& idealHeight) override
228 {
231 }
232
233private:
235 const int height;
236 Array<int> oldIndexes;
237
239};
240
241
242//==============================================================================
244{
246 initMissingItemButton();
247}
248
250{
251 items.clear();
252}
253
255{
256 if (vertical != shouldBeVertical)
257 {
258 vertical = shouldBeVertical;
259 resized();
260 }
261}
262
264{
265 items.clear();
266 resized();
267}
268
269ToolbarItemComponent* Toolbar::createItem (ToolbarItemFactory& factory, const int itemId)
270{
271 if (itemId == ToolbarItemFactory::separatorBarId) return new Spacer (itemId, 0.1f, true);
272 if (itemId == ToolbarItemFactory::spacerId) return new Spacer (itemId, 0.5f, false);
273 if (itemId == ToolbarItemFactory::flexibleSpacerId) return new Spacer (itemId, 0.0f, false);
274
275 return factory.createItem (itemId);
276}
277
278void Toolbar::addItemInternal (ToolbarItemFactory& factory,
279 const int itemId,
280 const int insertIndex)
281{
282 // An ID can't be zero - this might indicate a mistake somewhere?
283 jassert (itemId != 0);
284
285 if (auto* tc = createItem (factory, itemId))
286 {
287 #if JUCE_DEBUG
288 Array<int> allowedIds;
289 factory.getAllToolbarItemIds (allowedIds);
290
291 // If your factory can create an item for a given ID, it must also return
292 // that ID from its getAllToolbarItemIds() method!
293 jassert (allowedIds.contains (itemId));
294 #endif
295
296 items.insert (insertIndex, tc);
297 addAndMakeVisible (tc, insertIndex);
298 }
299}
300
301void Toolbar::addItem (ToolbarItemFactory& factory, int itemId, int insertIndex)
302{
303 addItemInternal (factory, itemId, insertIndex);
304 resized();
305}
306
308{
310 factoryToUse.getDefaultItemSet (ids);
311
312 clear();
313
314 for (auto i : ids)
315 addItemInternal (factoryToUse, i, -1);
316
317 resized();
318}
319
320void Toolbar::removeToolbarItem (const int itemIndex)
321{
322 items.remove (itemIndex);
323 resized();
324}
325
327{
328 if (auto* tc = items.removeAndReturn (itemIndex))
329 {
331 resized();
332 return tc;
333 }
334
335 return nullptr;
336}
337
339{
340 return items.size();
341}
342
343int Toolbar::getItemId (const int itemIndex) const noexcept
344{
345 if (auto* tc = getItemComponent (itemIndex))
346 return tc->getItemId();
347
348 return 0;
349}
350
351ToolbarItemComponent* Toolbar::getItemComponent (const int itemIndex) const noexcept
352{
353 return items[itemIndex];
354}
355
356ToolbarItemComponent* Toolbar::getNextActiveComponent (int index, const int delta) const
357{
358 for (;;)
359 {
360 index += delta;
361
362 if (auto* tc = getItemComponent (index))
363 {
364 if (tc->isActive)
365 return tc;
366 }
367 else
368 {
369 return nullptr;
370 }
371 }
372}
373
375{
376 if (toolbarStyle != newStyle)
377 {
378 toolbarStyle = newStyle;
379 updateAllItemPositions (false);
380 }
381}
382
384{
385 String s ("TB:");
386
387 for (int i = 0; i < getNumItems(); ++i)
388 s << getItemId (i) << ' ';
389
390 return s.trimEnd();
391}
392
394 const String& savedVersion)
395{
396 if (! savedVersion.startsWith ("TB:"))
397 return false;
398
399 StringArray tokens;
400 tokens.addTokens (savedVersion.substring (3), false);
401
402 clear();
403
404 for (auto& t : tokens)
405 addItemInternal (factoryToUse, t.getIntValue(), -1);
406
407 resized();
408 return true;
409}
410
412{
413 getLookAndFeel().paintToolbarBackground (g, getWidth(), getHeight(), *this);
414}
415
417{
418 return vertical ? getWidth() : getHeight();
419}
420
422{
423 return vertical ? getHeight() : getWidth();
424}
425
426void Toolbar::setEditingActive (const bool active)
427{
428 if (isEditingActive != active)
429 {
430 isEditingActive = active;
431 updateAllItemPositions (false);
432 }
433}
434
435//==============================================================================
437{
438 updateAllItemPositions (false);
439}
440
441void Toolbar::updateAllItemPositions (bool animate)
442{
443 if (getWidth() > 0 && getHeight() > 0)
444 {
446
447 for (auto* tc : items)
448 {
449 tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar
450 : ToolbarItemComponent::normalMode);
451
452 tc->setStyle (toolbarStyle);
453
454 auto* spacer = dynamic_cast<Spacer*> (tc);
455
456 int preferredSize = 1, minSize = 1, maxSize = 1;
457
458 if (tc->getToolbarItemSizes (getThickness(), isVertical(),
459 preferredSize, minSize, maxSize))
460 {
461 tc->isActive = true;
462 resizer.addItem (preferredSize, minSize, maxSize,
463 spacer != nullptr ? spacer->getResizeOrder() : 2);
464 }
465 else
466 {
467 tc->isActive = false;
468 tc->setVisible (false);
469 }
470 }
471
472 resizer.resizeToFit (getLength());
473
474 int totalLength = 0;
475
476 for (int i = 0; i < resizer.getNumItems(); ++i)
477 totalLength += (int) resizer.getItemSize (i);
478
479 const bool itemsOffTheEnd = totalLength > getLength();
480
481 auto extrasButtonSize = getThickness() / 2;
482 missingItemsButton->setSize (extrasButtonSize, extrasButtonSize);
483 missingItemsButton->setVisible (itemsOffTheEnd);
484 missingItemsButton->setEnabled (! isEditingActive);
485
486 if (vertical)
487 missingItemsButton->setCentrePosition (getWidth() / 2,
488 getHeight() - 4 - extrasButtonSize / 2);
489 else
490 missingItemsButton->setCentrePosition (getWidth() - 4 - extrasButtonSize / 2,
491 getHeight() / 2);
492
493 auto maxLength = itemsOffTheEnd ? (vertical ? missingItemsButton->getY()
494 : missingItemsButton->getX()) - 4
495 : getLength();
496
497 int pos = 0, activeIndex = 0;
498
499 for (auto* tc : items)
500 {
501 if (tc->isActive)
502 {
503 auto size = (int) resizer.getItemSize (activeIndex++);
504
505 Rectangle<int> newBounds;
506
507 if (vertical)
508 newBounds.setBounds (0, pos, getWidth(), size);
509 else
510 newBounds.setBounds (pos, 0, size, getHeight());
511
512 auto& animator = Desktop::getInstance().getAnimator();
513
514 if (animate)
515 {
516 animator.animateComponent (tc, newBounds, 1.0f, 200, false, 3.0, 0.0);
517 }
518 else
519 {
520 animator.cancelAnimation (tc, false);
521 tc->setBounds (newBounds);
522 }
523
524 pos += size;
525 tc->setVisible (pos <= maxLength
526 && ((! tc->isBeingDragged)
527 || tc->getEditingMode() == ToolbarItemComponent::editableOnPalette));
528 }
529 }
530 }
531}
532
533//==============================================================================
534void Toolbar::initMissingItemButton()
535{
536 if (missingItemsButton == nullptr)
537 return;
538
539 addChildComponent (*missingItemsButton);
540 missingItemsButton->setAlwaysOnTop (true);
541 missingItemsButton->onClick = [this] { showMissingItems(); };
542}
543
544void Toolbar::showMissingItems()
545{
546 jassert (missingItemsButton->isShowing());
547
548 if (missingItemsButton->isShowing())
549 {
550 PopupMenu m;
551 auto comp = std::make_unique<MissingItemsComponent> (*this, getThickness());
552 m.addCustomItem (1, std::move (comp), nullptr, TRANS ("Additional Items"));
553 m.showMenuAsync (PopupMenu::Options().withTargetComponent (missingItemsButton.get()));
554 }
555}
556
557//==============================================================================
559{
560 return dragSourceDetails.description == toolbarDragDescriptor && isEditingActive;
561}
562
564{
565 if (auto* tc = dynamic_cast<ToolbarItemComponent*> (dragSourceDetails.sourceComponent.get()))
566 {
567 if (! items.contains (tc))
568 {
569 if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
570 {
571 if (auto* palette = tc->findParentComponentOfClass<ToolbarItemPalette>())
572 palette->replaceComponent (*tc);
573 }
574 else
575 {
577 }
578
579 items.add (tc);
581 updateAllItemPositions (true);
582 }
583
584 auto& animator = Desktop::getInstance().getAnimator();
585
586 for (int i = getNumItems(); --i >= 0;)
587 {
588 auto currentIndex = items.indexOf (tc);
589 auto newIndex = currentIndex;
590
591 auto dragObjectLeft = vertical ? (dragSourceDetails.localPosition.getY() - tc->dragOffsetY)
592 : (dragSourceDetails.localPosition.getX() - tc->dragOffsetX);
593 auto dragObjectRight = dragObjectLeft + (vertical ? tc->getHeight() : tc->getWidth());
594
595 auto current = animator.getComponentDestination (getChildComponent (newIndex));
596
597 if (auto* prev = getNextActiveComponent (newIndex, -1))
598 {
599 auto previousPos = animator.getComponentDestination (prev);
600
601 if (std::abs (dragObjectLeft - (vertical ? previousPos.getY() : previousPos.getX()))
602 < std::abs (dragObjectRight - (vertical ? current.getBottom() : current.getRight())))
603 {
605 }
606 }
607
608 if (auto* next = getNextActiveComponent (newIndex, 1))
609 {
610 auto nextPos = animator.getComponentDestination (next);
611
612 if (std::abs (dragObjectLeft - (vertical ? current.getY() : current.getX()))
613 > std::abs (dragObjectRight - (vertical ? nextPos.getBottom() : nextPos.getRight())))
614 {
616 }
617 }
618
619 if (newIndex == currentIndex)
620 break;
621
622 items.removeObject (tc, false);
625 items.insert (newIndex, tc);
626 updateAllItemPositions (true);
627 }
628 }
629}
630
632{
633 if (auto* tc = dynamic_cast<ToolbarItemComponent*> (dragSourceDetails.sourceComponent.get()))
634 {
635 if (isParentOf (tc))
636 {
637 items.removeObject (tc, false);
639 updateAllItemPositions (true);
640 }
641 }
642}
643
645{
646 if (auto* tc = dynamic_cast<ToolbarItemComponent*> (dragSourceDetails.sourceComponent.get()))
647 tc->setState (Button::buttonNormal);
648}
649
651{
652 missingItemsButton.reset (getLookAndFeel().createToolbarMissingItemsButton (*this));
653 initMissingItemButton();
654}
655
657
658//==============================================================================
660{
661public:
663 : DialogWindow (TRANS ("Add/remove items from toolbar"),
665 true,
666 true),
667 toolbar (bar)
668 {
669 setContentOwned (new CustomiserPanel (factory, toolbar, optionFlags), true);
670 setResizable (true, true);
671 setResizeLimits (400, 300, 1500, 1000);
672 positionNearBar();
673 }
674
675 ~CustomisationDialog() override
676 {
677 toolbar.setEditingActive (false);
678 }
679
680 void closeButtonPressed() override
681 {
682 setVisible (false);
683 }
684
685 bool canModalEventBeSentToComponent (const Component* comp) override
686 {
687 return toolbar.isParentOf (comp)
688 || dynamic_cast<const detail::ToolbarItemDragAndDropOverlayComponent*> (comp) != nullptr;
689 }
690
691 void positionNearBar()
692 {
693 auto screenSize = toolbar.getParentMonitorArea();
694 auto pos = toolbar.getScreenPosition();
695 const int gap = 8;
696
697 if (toolbar.isVertical())
698 {
699 if (pos.x > screenSize.getCentreX())
700 pos.x -= getWidth() - gap;
701 else
702 pos.x += toolbar.getWidth() + gap;
703 }
704 else
705 {
706 pos.x += (toolbar.getWidth() - getWidth()) / 2;
707
708 if (pos.y > screenSize.getCentreY())
709 pos.y -= getHeight() - gap;
710 else
711 pos.y += toolbar.getHeight() + gap;
712 }
713
714 setTopLeftPosition (pos);
715 }
716
717private:
718 Toolbar& toolbar;
719
720 class CustomiserPanel : public Component
721 {
722 public:
723 CustomiserPanel (ToolbarItemFactory& tbf, Toolbar& bar, int optionFlags)
724 : factory (tbf), toolbar (bar), palette (tbf, bar),
725 instructions ({}, TRANS ("You can drag the items above and drop them onto a toolbar to add them.")
726 + "\n\n"
727 + TRANS ("Items on the toolbar can also be dragged around to change their order, or dragged off the edge to delete them.")),
728 defaultButton (TRANS ("Restore to default set of items"))
729 {
730 addAndMakeVisible (palette);
731
735 {
736 addAndMakeVisible (styleBox);
737 styleBox.setEditableText (false);
738
739 if ((optionFlags & Toolbar::allowIconsOnlyChoice) != 0) styleBox.addItem (TRANS ("Show icons only"), 1);
740 if ((optionFlags & Toolbar::allowIconsWithTextChoice) != 0) styleBox.addItem (TRANS ("Show icons and descriptions"), 2);
741 if ((optionFlags & Toolbar::allowTextOnlyChoice) != 0) styleBox.addItem (TRANS ("Show descriptions only"), 3);
742
743 int selectedStyle = 0;
744 switch (bar.getStyle())
745 {
746 case Toolbar::iconsOnly: selectedStyle = 1; break;
747 case Toolbar::iconsWithText: selectedStyle = 2; break;
748 case Toolbar::textOnly: selectedStyle = 3; break;
749 default: break;
750 }
751
752 styleBox.setSelectedId (selectedStyle);
753
754 styleBox.onChange = [this] { updateStyle(); };
755 }
756
758 {
759 addAndMakeVisible (defaultButton);
760 defaultButton.onClick = [this] { toolbar.addDefaultItems (factory); };
761 }
762
763 addAndMakeVisible (instructions);
764 instructions.setFont (Font (13.0f));
765
766 setSize (500, 300);
767 }
768
769 void updateStyle()
770 {
771 switch (styleBox.getSelectedId())
772 {
773 case 1: toolbar.setStyle (Toolbar::iconsOnly); break;
774 case 2: toolbar.setStyle (Toolbar::iconsWithText); break;
775 case 3: toolbar.setStyle (Toolbar::textOnly); break;
776 default: break;
777 }
778
779 palette.resized(); // to make it update the styles
780 }
781
782 void paint (Graphics& g) override
783 {
784 Colour background;
785
787 background = dw->getBackgroundColour();
788
789 g.setColour (background.contrasting().withAlpha (0.3f));
790 g.fillRect (palette.getX(), palette.getBottom() - 1, palette.getWidth(), 1);
791 }
792
793 void resized() override
794 {
795 palette.setBounds (0, 0, getWidth(), getHeight() - 120);
796 styleBox.setBounds (10, getHeight() - 110, 200, 22);
797
798 defaultButton.changeWidthToFitText (22);
799 defaultButton.setTopLeftPosition (240, getHeight() - 110);
800
801 instructions.setBounds (10, getHeight() - 80, getWidth() - 20, 80);
802 }
803
804 private:
805 ToolbarItemFactory& factory;
806 Toolbar& toolbar;
807
808 ToolbarItemPalette palette;
809 Label instructions;
810 ComboBox styleBox;
811 TextButton defaultButton;
812 };
813};
814
816{
817 setEditingActive (true);
818
819 (new CustomisationDialog (factory, *this, optionFlags))
820 ->enterModalState (true, nullptr, true);
821}
822
823//==============================================================================
825{
826 return std::make_unique<AccessibilityHandler> (*this, AccessibilityRole::group);
827}
828
829} // namespace juce
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:56
void insert(int indexToInsertAt, ParameterType newElement)
Inserts a new element into the array at a given position.
Definition juce_Array.h:462
ElementType removeAndReturn(int indexToRemove)
Removes an element from the array.
Definition juce_Array.h:760
void animateComponent(Component *component, const Rectangle< int > &finalBounds, float finalAlpha, int animationDurationMilliseconds, bool useProxyComponent, double startSpeed, double endSpeed)
Starts a component moving from its current position to a specified position.
Holds a pointer to some type of Component, which automatically becomes null if the component is delet...
The base class for all JUCE user-interface objects.
bool isVisible() const noexcept
Tests whether the component is visible or not.
int getNumChildComponents() const noexcept
Returns the number of child components that this component contains.
int getIndexOfChildComponent(const Component *child) const noexcept
Returns the index of this component in the list of child components.
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.
Component() noexcept
Creates a component.
void removeChildComponent(Component *childToRemove)
Removes one of this component's child-components.
Component * getChildComponent(int index) const noexcept
Returns one of this component's child components, by it index.
bool isParentOf(const Component *possibleChild) const noexcept
Checks whether a component is anywhere inside this component or its children.
void setSize(int newWidth, int newHeight)
Changes the size of the component.
void enterModalState(bool takeKeyboardFocus=true, ModalComponentManager::Callback *callback=nullptr, bool deleteWhenDismissed=false)
Puts the component into a modal state.
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.
Rectangle< int > getParentMonitorArea() const
Returns the screen coordinates of the monitor that contains this component.
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.
Point< int > getScreenPosition() const
Returns the position of this component's top-left corner relative to the screen's top-left.
void setTopLeftPosition(int x, int y)
Moves the component to a new position.
void addChildComponent(Component *child, int zOrder=-1)
Adds a child component to this one.
const Array< Component * > & getChildren() const noexcept
Provides access to the underlying array of child components.
virtual void setVisible(bool shouldBeVisible)
Makes the component visible or invisible.
ComponentAnimator & getAnimator() noexcept
The Desktop object has a ComponentAnimator instance which can be used for performing your animations.
static Desktop &JUCE_CALLTYPE getInstance()
There's only one desktop object, and this method will return it.
A dialog-box style window.
Contains details about the source of a drag-and-drop operation.
A graphics context, used for drawing a component or image.
void drawRect(int x, int y, int width, int height, int lineThickness=1) const
Draws a rectangular outline, using the current colour or brush.
void fillRect(Rectangle< int > rectangle) const
Fills a rectangle with the current colour or brush.
void fillPath(const Path &path) const
Fills a path using the currently selected colour or brush.
void setColour(Colour newColour)
Changes the current drawing colour.
Contains position and status information about a mouse event.
A path is a sequence of lines and curves that may either form a closed shape or be open-ended.
Definition juce_Path.h:65
void addArrow(Line< float > line, float lineThickness, float arrowheadWidth, float arrowheadLength)
Adds a line with an arrowhead on the end.
ValueType x
The point's X coordinate.
Definition juce_Point.h:251
A user-defined component that can be used as an item in a popup menu.
Manages a rectangle and allows geometric operations to be performed on it.
void setResizable(bool shouldBeResizable, bool useBottomRightCornerResizer)
Make the window resizable or fixed.
void setResizeLimits(int newMinimumWidth, int newMinimumHeight, int newMaximumWidth, int newMaximumHeight) noexcept
This sets the maximum and minimum sizes for the window.
void setContentOwned(Component *newContentComponent, bool resizeToFitWhenContentChangesSize)
Changes the current content component.
A utility class for fitting a set of objects whose sizes can vary between a minimum and maximum size,...
void addItem(double currentSize, double minSize, double maxSize, int order=0)
Adds an item to the list.
A special array for holding a list of strings.
int addTokens(StringRef stringToTokenise, bool preserveQuotedStrings)
Breaks up a string into tokens and adds them to this array.
The JUCE String class!
Definition juce_String.h:53
String trimEnd() const
Returns a copy of this string with any whitespace characters removed from the end.
A component that can be used as one of the items in a Toolbar.
@ editableOnToolbar
Means that the component is on a toolbar, but the toolbar is in customisation mode,...
@ normalMode
Means that the component is active, inside a toolbar.
@ editableOnPalette
Means that the component is on an new-item palette, so it can be dragged onto a toolbar to add it to ...
ToolbarEditingMode getEditingMode() const noexcept
Returns the current editing mode of this component.
bool isToolbarVertical() const
Returns true if this component is currently inside a toolbar which is vertical.
A factory object which can create ToolbarItemComponent objects.
@ flexibleSpacerId
The item ID for a gap that pushes outwards against the things on either side of it,...
@ separatorBarId
The item ID for a vertical (or horizontal) separator bar that can be placed between sets of items to ...
@ spacerId
The item ID for a fixed-width space that can be placed between items.
virtual ToolbarItemComponent * createItem(int itemId)=0
Must create an instance of one of the items that the factory lists in its getAllToolbarItemIds() meth...
A component containing a list of toolbar items, which the user can drag onto a toolbar to add them.
void closeButtonPressed() override
This method is called when the user tries to close the window.
bool canModalEventBeSentToComponent(const Component *comp) override
When a component is modal, this callback allows it to choose which other components can still receive...
void getIdealSize(int &idealWidth, int &idealHeight) override
Returns a rectangle with the size that this component would like to have.
void paint(Graphics &g) override
Components can override this method to draw their content.
bool getToolbarItemSizes(int toolbarThickness, bool, int &preferredSize, int &minSize, int &maxSize) override
This method must return the size criteria for this item, based on a given toolbar size and orientatio...
void contentAreaChanged(const Rectangle< int > &) override
Callback to indicate that the content area of this item has changed.
void paintButtonArea(Graphics &, int, int, bool, bool) override
Your subclass should use this method to draw its content area.
A toolbar component.
@ customisationDialogBackgroundColourId
A colour used to paint the background of the CustomisationDialog.
@ separatorColourId
A colour to use to draw the separator lines.
void lookAndFeelChanged() override
Called to let the component react to a change in the look-and-feel setting.
void clear()
Deletes all items from the bar.
Toolbar()
Creates an empty toolbar component.
int getNumItems() const noexcept
Returns the number of items currently on the toolbar.
bool isInterestedInDragSource(const SourceDetails &) override
Callback to check whether this target is interested in the type of object being dragged.
void setEditingActive(bool editingEnabled)
Turns on or off the toolbar's editing mode, in which its items can be rearranged by the user.
String toString() const
Returns a string that represents the toolbar's current set of items.
void addItem(ToolbarItemFactory &factory, int itemId, int insertIndex=-1)
Adds an item to the toolbar.
void removeToolbarItem(int itemIndex)
Deletes one of the items from the bar.
void addDefaultItems(ToolbarItemFactory &factoryToUse)
Clears this toolbar and adds to it the default set of items that the specified factory creates.
ToolbarItemStyle
Options for the way items should be displayed.
@ textOnly
Means that the toolbar only display text labels for each item.
@ iconsWithText
Means that the toolbar should have text labels under each icon.
@ iconsOnly
Means that the toolbar should just contain icons.
int getThickness() const noexcept
Returns the depth of the bar.
~Toolbar() override
Destructor.
void itemDragExit(const SourceDetails &) override
Callback to indicate that something has been dragged off the edge of this component.
void itemDropped(const SourceDetails &) override
Callback to indicate that the user has dropped something onto this component.
void setVertical(bool shouldBeVertical)
Changes the bar's orientation.
std::unique_ptr< AccessibilityHandler > createAccessibilityHandler() override
Override this method to return a custom AccessibilityHandler for this component.
void setStyle(const ToolbarItemStyle &newStyle)
Changes the toolbar's current style.
int getLength() const noexcept
Returns the length of the bar.
ToolbarItemComponent * getItemComponent(int itemIndex) const noexcept
Returns the component being used for the item with the given index.
void showCustomisationDialog(ToolbarItemFactory &factory, int optionFlags=allCustomisationOptionsEnabled)
Pops up a modal dialog box that allows this toolbar to be customised by the user.
bool restoreFromString(ToolbarItemFactory &factoryToUse, const String &savedVersion)
Restores a set of items that was previously stored in a string by the toString() method.
int getItemId(int itemIndex) const noexcept
Returns the ID of the item with the given index.
void resized() override
Called when this component's size has been changed.
@ allowIconsWithTextChoice
If this flag is specified, the customisation dialog can show the "icons with text" option on its choi...
@ allowIconsOnlyChoice
If this flag is specified, the customisation dialog can show the "icons only" option on its choice of...
@ allowTextOnlyChoice
If this flag is specified, the customisation dialog can show the "text only" option on its choice of ...
@ showResetToDefaultsButton
If this flag is specified, the customisation dialog can show a button to reset the toolbar to its def...
void mouseDown(const MouseEvent &) override
Called when a mouse button is pressed.
void paint(Graphics &) override
Components can override this method to draw their content.
bool isVertical() const noexcept
Returns true if the bar is set to be vertical, or false if it's horizontal.
void itemDragMove(const SourceDetails &) override
Callback to indicate that the user is dragging something over this component.
ToolbarItemComponent * removeAndReturnItem(int itemIndex)
Removes an item from the bar and returns it.
#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 ...
typedef int
typedef float
JUCE Namespace.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
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
int roundToInt(const FloatType value) noexcept
Fast floating-point-to-integer conversion.
T size(T... args)
y1