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_ToolbarItemPalette.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 : factory (tbf), toolbar (bar)
31{
32 auto* itemHolder = new Component();
34
37
38 for (auto& i : allIds)
39 addComponent (i, -1);
40
41 addAndMakeVisible (viewport);
42}
43
47
48//==============================================================================
49void ToolbarItemPalette::addComponent (const int itemId, const int index)
50{
51 if (auto* tc = Toolbar::createItem (factory, itemId))
52 {
53 items.insert (index, tc);
54 viewport.getViewedComponent()->addAndMakeVisible (tc, index);
56 }
57 else
58 {
60 }
61}
62
63void ToolbarItemPalette::replaceComponent (ToolbarItemComponent& comp)
64{
65 auto index = items.indexOf (&comp);
66 jassert (index >= 0);
67 items.removeObject (&comp, false);
68
69 addComponent (comp.getItemId(), index);
70 resized();
71}
72
74{
75 viewport.setBoundsInset (BorderSize<int> (1));
76
77 auto* itemHolder = viewport.getViewedComponent();
78
79 const int indent = 8;
80 const int preferredWidth = viewport.getWidth() - viewport.getScrollBarThickness() - indent;
81 const int height = toolbar.getThickness();
82 auto x = indent;
83 auto y = indent;
84 int maxX = 0;
85
86 for (auto* tc : items)
87 {
88 tc->setStyle (toolbar.getStyle());
89
90 int preferredSize = 1, minSize = 1, maxSize = 1;
91
92 if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
93 {
94 if (x + preferredSize > preferredWidth && x > indent)
95 {
96 x = indent;
97 y += height;
98 }
99
100 tc->setBounds (x, y, preferredSize, height);
101
102 x += preferredSize + 8;
103 maxX = jmax (maxX, x);
104 }
105 }
106
107 itemHolder->setSize (maxX, y + height + 8);
108}
109
110//==============================================================================
112{
113 return std::make_unique<AccessibilityHandler> (*this, AccessibilityRole::group);
114}
115
116} // namespace juce
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:56
Specifies a set of gaps to be left around the sides of a rectangle.
void setBoundsInset(BorderSize< int > borders)
Changes the component's position and size based on the amount of space to leave around it.
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.
int getWidth() const noexcept
Returns the component's width in pixels.
@ editableOnPalette
Means that the component is on an new-item palette, so it can be dragged onto a toolbar to add it to ...
A factory object which can create ToolbarItemComponent objects.
virtual void getAllToolbarItemIds(Array< int > &ids)=0
Must return a list of the IDs for all the item types that this factory can create.
~ToolbarItemPalette() override
Destructor.
std::unique_ptr< AccessibilityHandler > createAccessibilityHandler() override
Override this method to return a custom AccessibilityHandler for this component.
void resized() override
Called when this component's size has been changed.
ToolbarItemPalette(ToolbarItemFactory &factory, Toolbar &toolbar)
Creates a palette of items for a given factory, with the aim of adding them to the specified toolbar.
A toolbar component.
int getThickness() const noexcept
Returns the depth of the bar.
ToolbarItemStyle getStyle() const noexcept
Returns the toolbar's current style.
Component * getViewedComponent() const noexcept
Returns the component that's currently being used inside the Viewport.
int getScrollBarThickness() const
Returns the thickness of the scrollbars.
void setViewedComponent(Component *newViewedComponent, bool deleteComponentWhenNoLongerNeeded=true)
Sets the component that this viewport will contain and scroll around.
#define jassert(expression)
Platform-independent assertion macro.
#define jassertfalse
This will always cause an assertion failure.
JUCE Namespace.
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