Krotos Modules 3
Loading...
Searching...
No Matches
CustomLayout.h
Go to the documentation of this file.
1#pragma once
2
4
5namespace krotos
6{
13 class CustomLayout : public Component, public ValueTree::Listener, public ComponentListener
14 {
15 public:
16 //==============================================================================
17 // LayoutTree Identifiers..
18 struct Tag
19 {
20 static const Identifier layout;
21 static const Identifier slot;
22 };
23
24 struct Property
25 {
26 static const Identifier name;
27 static const Identifier index;
28 static const Identifier bounds;
29 };
30
31 static const String FileExtension;
32 static const Rectangle<int> DefaultSize;
33
34 //==============================================================================
38
41
42 void resized() override;
43 void paint(Graphics&) override{};
44
52 void setLayoutTree(const ValueTree& layoutTree) { m_layoutTree = layoutTree; };
53
63 void resetLayoutTree(const ValueTree& layoutTree);
64
68 ValueTree& getLayoutTree();
69
78 void addComponent(Component& component, Rectangle<int> bounds = CustomLayout::DefaultSize);
79
96 void addComponent(Component& component, ValueTree slot);
97
98 // TODO: Implement remove component by ID
104 void removeComponent(int index);
105
108
111 bool isEditModeActive() { return m_editable; };
112
119 void setAutoLayout(bool isEnabled) { m_autoLayout = isEnabled; };
120
126
127 /* Specify the flexbox settings for autolayout */
128 void configureAutoLayout(FlexBox flexboxSettings, FlexItem::Margin margin);
129
134 std::function<Rectangle<int>(String componentType, Rectangle<int> currentBounds)> getAutoLayoutBoundsFromType;
135
138 std::function<void()> treeRedirected;
139
140 private:
141 OwnedArray<Component> m_components;
142 ValueTree m_layoutTree;
143
144 bool m_editable{false};
145
146 bool m_autoLayout{false};
148 FlexItem::Margin m_flexMargin{0.0f};
149
158 void addSlot(const String& name, const Rectangle<int>& bounds);
159
165 Component* createAndAddResizableComponent(String name, Rectangle<int> bounds);
166
171 void saveLayout();
172
173 //==============================================================================
174 // ValueTree::Listener callbacks..
175
176 void valueTreeChildAdded(ValueTree& parentTree, ValueTree& childWhichHasBeenAdded) override;
177
178 void valueTreeChildRemoved(ValueTree& parentTree, ValueTree& childWhichHasBeenRemoved,
179 int indexFromWhichChildWasRemoved) override;
180
181 void valueTreePropertyChanged(ValueTree& treeWhosePropertyHasChanged, const Identifier& property) override;
182
183 void valueTreeRedirected(ValueTree& treeWhichHasBeenChanged);
184
185 //==============================================================================
186 // ComponentListener callbacks..
187
189 void componentMovedOrResized(Component& component, bool wasMoved, bool wasResized) override;
190
191 //==============================================================================
192 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CustomLayout)
193 };
194} // namespace krotos
Definition CustomLayout.h:14
void resized() override
Definition CustomLayout.cpp:23
void configureAutoLayout(FlexBox flexboxSettings, FlexItem::Margin margin)
Definition CustomLayout.cpp:227
std::function< Rectangle< int >(String componentType, Rectangle< int > currentBounds)> getAutoLayoutBoundsFromType
Used to look up what bounds should be used for a given component type when using auto layout....
Definition CustomLayout.h:134
~CustomLayout()
Definition CustomLayout.cpp:21
void paint(Graphics &) override
Definition CustomLayout.h:43
void setLayoutTree(const ValueTree &layoutTree)
Definition CustomLayout.h:52
void valueTreePropertyChanged(ValueTree &treeWhosePropertyHasChanged, const Identifier &property) override
Definition CustomLayout.cpp:199
ValueTree & getLayoutTree()
Definition CustomLayout.cpp:68
static const String FileExtension
Definition CustomLayout.h:31
FlexBox m_flexSettings
Definition CustomLayout.h:147
ValueTree m_layoutTree
Definition CustomLayout.h:142
void valueTreeRedirected(ValueTree &treeWhichHasBeenChanged)
Definition CustomLayout.cpp:204
bool m_editable
Definition CustomLayout.h:144
void valueTreeChildAdded(ValueTree &parentTree, ValueTree &childWhichHasBeenAdded) override
Definition CustomLayout.cpp:181
static const Rectangle< int > DefaultSize
Definition CustomLayout.h:32
CustomLayout()
Definition CustomLayout.cpp:15
void setAutoLayout(bool isEnabled)
Use this to enable / disable automatic laying out of slots using FlexBox. FlexBox settings must be co...
Definition CustomLayout.h:119
void addComponent(Component &component, Rectangle< int > bounds=CustomLayout::DefaultSize)
Definition CustomLayout.cpp:94
void saveLayout()
Definition CustomLayout.cpp:147
void resetLayoutTree(const ValueTree &layoutTree)
Definition CustomLayout.cpp:75
FlexItem::Margin m_flexMargin
Definition CustomLayout.h:148
bool isAutoLayoutActive()
Returns true if auto layout is active.
Definition CustomLayout.h:125
void componentMovedOrResized(Component &component, bool wasMoved, bool wasResized) override
Definition CustomLayout.cpp:212
void valueTreeChildRemoved(ValueTree &parentTree, ValueTree &childWhichHasBeenRemoved, int indexFromWhichChildWasRemoved) override
Definition CustomLayout.cpp:189
OwnedArray< Component > m_components
Definition CustomLayout.h:141
bool m_autoLayout
Definition CustomLayout.h:146
void addSlot(const String &name, const Rectangle< int > &bounds)
Definition CustomLayout.cpp:82
bool isEditModeActive()
Definition CustomLayout.h:111
void removeComponent(int index)
Definition CustomLayout.cpp:130
std::function< void()> treeRedirected
Definition CustomLayout.h:138
Component * createAndAddResizableComponent(String name, Rectangle< int > bounds)
Definition CustomLayout.cpp:161
void setEditModeActive(bool isEditModeActive)
Definition CustomLayout.cpp:137
Definition AirAbsorptionFilter.cpp:2
Definition CustomLayout.h:25
static const Identifier name
Definition CustomLayout.h:26
static const Identifier index
Definition CustomLayout.h:27
static const Identifier bounds
Definition CustomLayout.h:28
Definition CustomLayout.h:19
static const Identifier slot
Definition CustomLayout.h:21
static const Identifier layout
Definition CustomLayout.h:20