LMMS
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();
33 viewport.setViewedComponent (itemHolder);
34
35 Array<int> allIds;
36 factory.getAllToolbarItemIds (allIds);
37
38 for (auto& i : allIds)
39 addComponent (i, -1);
40
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);
55 tc->setEditingMode (ToolbarItemComponent::editableOnPalette);
56 }
57 else
58 {
60 }
61}
62
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//==============================================================================
111std::unique_ptr<AccessibilityHandler> ToolbarItemPalette::createAccessibilityHandler()
112{
113 return std::make_unique<AccessibilityHandler> (*this, AccessibilityRole::group);
114}
115
116} // namespace juce
Type jmax(const Type a, const Type b)
Definition MathsFunctions.h:48
Definition juce_Array.h:56
Definition juce_BorderSize.h:42
void addAndMakeVisible(Component *child, int zOrder=-1)
Definition juce_Component.cpp:1554
Component() noexcept
Definition juce_Component.cpp:517
static ToolbarItemComponent * createItem(ToolbarItemFactory &, int itemId)
Definition juce_Toolbar.cpp:269
Definition juce_ToolbarItemComponent.h:50
@ editableOnPalette
Definition juce_ToolbarItemComponent.h:166
Definition juce_ToolbarItemFactory.h:45
void replaceComponent(ToolbarItemComponent &)
Definition juce_ToolbarItemPalette.cpp:63
~ToolbarItemPalette() override
Definition juce_ToolbarItemPalette.cpp:44
void addComponent(int itemId, int index)
Definition juce_ToolbarItemPalette.cpp:49
std::unique_ptr< AccessibilityHandler > createAccessibilityHandler() override
Definition juce_ToolbarItemPalette.cpp:111
Viewport viewport
Definition juce_ToolbarItemPalette.h:67
void resized() override
Definition juce_ToolbarItemPalette.cpp:73
friend class Toolbar
Definition juce_ToolbarItemPalette.h:70
Toolbar & toolbar
Definition juce_ToolbarItemPalette.h:66
ToolbarItemFactory & factory
Definition juce_ToolbarItemPalette.h:65
OwnedArray< ToolbarItemComponent > items
Definition juce_ToolbarItemPalette.h:68
ToolbarItemPalette(ToolbarItemFactory &factory, Toolbar &toolbar)
Definition juce_ToolbarItemPalette.cpp:29
int y
Definition inflate.c:1588
register unsigned i
Definition inflate.c:1575
unsigned x[BMAX+1]
Definition inflate.c:1586
static int int height
Definition pugl.h:1594
static int int int maxX
Definition pugl.h:1628
#define jassert(expression)
#define jassertfalse
static int JUCE_CDECL comp(const void *a, const void *b)
Definition lsp.c:298
Definition carla_juce.cpp:31
@ group
Definition juce_AccessibilityRole.h:61