36 isOpen (sectionIsOpen),
37 padding (extraPadding)
41 propertyComps.addArray (newProperties);
43 for (
auto* propertyComponent : propertyComps)
46 propertyComponent->refresh();
52 propertyComps.clear();
65 for (
auto* propertyComponent : propertyComps)
67 propertyComponent->setBounds (1, y,
getWidth() - 2, propertyComponent->getPreferredHeight());
68 y = propertyComponent->getBottom() + padding;
79 int getPreferredHeight()
const
83 auto numComponents = propertyComps.size();
85 if (numComponents > 0 && isOpen)
87 for (
auto* propertyComponent : propertyComps)
88 y += propertyComponent->getPreferredHeight();
90 y += (numComponents - 1) * padding;
96 void setOpen (
bool open)
102 for (
auto* propertyComponent : propertyComps)
105 if (
auto* propertyPanel = findParentComponentOfClass<PropertyPanel>())
106 propertyPanel->resized();
110 void refreshAll()
const
112 for (
auto* propertyComponent : propertyComps)
113 propertyComponent->refresh();
126 if (e.
y < titleHeight)
145 void updateLayout (
int width)
149 for (
auto* section : sections)
151 section->setBounds (0, y, width, section->getPreferredHeight());
152 y = section->getBottom();
159 void refreshAll()
const
161 for (
auto* section : sections)
162 section->refreshAll();
165 void insertSection (
int indexToInsertAt, SectionComponent* newSection)
167 sections.insert (indexToInsertAt, newSection);
171 SectionComponent* getSectionWithNonEmptyName (
int targetIndex)
const noexcept
174 for (
auto* section : sections)
176 if (section->getName().isNotEmpty())
177 if (index++ == targetIndex)
184 OwnedArray<SectionComponent> sections;
201void PropertyPanel::init()
203 messageWhenEmpty =
TRANS (
"(nothing selected)");
206 viewport.
setViewedComponent (propertyHolderComponent =
new PropertyHolderComponent());
220 g.
setColour (Colours::black.withAlpha (0.5f));
230 updatePropHolderLayout();
238 propertyHolderComponent->sections.clear();
239 updatePropHolderLayout();
245 return propertyHolderComponent->sections.size() == 0;
250 return propertyHolderComponent->
getHeight();
254 int extraPaddingBetweenComponents)
259 propertyHolderComponent->insertSection (-1,
new SectionComponent ({}, newProperties,
true, extraPaddingBetweenComponents));
260 updatePropHolderLayout();
267 int extraPaddingBetweenComponents)
274 propertyHolderComponent->insertSection (indexToInsertAt,
new SectionComponent (sectionTitle,
277 extraPaddingBetweenComponents));
279 updatePropHolderLayout();
282void PropertyPanel::updatePropHolderLayout()
const
285 propertyHolderComponent->updateLayout (maxWidth);
288 if (maxWidth != newMaxWidth)
291 propertyHolderComponent->updateLayout (newMaxWidth);
297 propertyHolderComponent->refreshAll();
305 for (
auto* section : propertyHolderComponent->sections)
307 if (section->getName().isNotEmpty())
308 s.
add (section->getName());
316 if (
auto* s = propertyHolderComponent->getSectionWithNonEmptyName (sectionIndex))
324 if (
auto* s = propertyHolderComponent->getSectionWithNonEmptyName (sectionIndex))
325 s->setOpen (shouldBeOpen);
330 if (
auto* s = propertyHolderComponent->getSectionWithNonEmptyName (sectionIndex))
331 s->setEnabled (shouldBeEnabled);
336 if (
auto* s = propertyHolderComponent->getSectionWithNonEmptyName (sectionIndex))
338 propertyHolderComponent->sections.removeObject (s);
339 updatePropHolderLayout();
351 for (
auto s : sections)
355 auto* e = xml->createNewChildElement (
"SECTION");
356 e->setAttribute (
"name", s);
357 e->setAttribute (
"open",
isSectionOpen (sections.indexOf (s)) ? 1 : 0);
372 setSectionOpen (sections.indexOf (e->getStringAttribute (
"name")),
373 e->getBoolAttribute (
"open"));
384 if (messageWhenEmpty != newMessage)
386 messageWhenEmpty = newMessage;
393 return messageWhenEmpty;
Holds a resizable array of primitive or copy-by-value objects.
The base class for all JUCE user-interface objects.
void setFocusContainerType(FocusContainerType containerType) noexcept
Sets whether this component is a container for components that can have their focus traversed,...
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.
void repaint()
Marks the whole component as needing to be redrawn.
Component() noexcept
Creates a component.
@ keyboardFocusContainer
The component will act as a top-level component within which keyboard focus is passed around.
void setBounds(int x, int y, int width, int height)
Changes the component's position and size.
void setSize(int newWidth, int newHeight)
Changes the size of the 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.
Rectangle< int > getLocalBounds() const noexcept
Returns the component's bounds, relative to its own origin.
virtual void setVisible(bool shouldBeVisible)
Makes the component visible or invisible.
String getName() const noexcept
Returns the name of this component.
A graphics context, used for drawing a component or image.
void drawText(const String &text, int x, int y, int width, int height, Justification justificationType, bool useEllipsesIfTooBig=true) const
Draws a line of text within a specified rectangle.
void setFont(const Font &newFont)
Changes the font to use for subsequent text-drawing functions.
void setColour(Colour newColour)
Changes the current drawing colour.
@ centred
Indicates that the item should be centred vertically and horizontally.
Contains position and status information about a mouse event.
int getMouseDownX() const noexcept
Returns the x coordinate of the last place that a mouse was pressed.
const int x
The x-position of the mouse when the event occurred.
const int y
The y-position of the mouse when the event occurred.
int getNumberOfClicks() const noexcept
For a click event, the number of times the mouse was clicked in succession.
An array designed for holding objects.
void paint(Graphics &) override
Components can override this method to draw their content.
StringArray getSectionNames() const
Returns a list of all the names of sections in the panel.
void setSectionEnabled(int sectionIndex, bool shouldBeEnabled)
Enables or disables one of the sections.
bool isEmpty() const
Returns true if the panel contains no properties.
std::unique_ptr< XmlElement > getOpennessState() const
Saves the current state of open/closed sections so it can be restored later.
int getTotalContentHeight() const
Returns the height that the panel needs in order to display all of its content without scrolling.
bool isSectionOpen(int sectionIndex) const
Returns true if the section at this index is currently open.
void setSectionOpen(int sectionIndex, bool shouldBeOpen)
Opens or closes one of the sections.
void removeSection(int sectionIndex)
Remove one of the sections using the section index.
void resized() override
Called when this component's size has been changed.
void addSection(const String §ionTitle, const Array< PropertyComponent * > &newPropertyComponents, bool shouldSectionInitiallyBeOpen=true, int indexToInsertAt=-1, int extraPaddingBetweenComponents=0)
Adds a set of properties to the panel.
PropertyPanel()
Creates an empty property panel.
const String & getMessageWhenEmpty() const noexcept
Returns the message that is displayed when there are no properties.
~PropertyPanel() override
Destructor.
void setMessageWhenEmpty(const String &newMessage)
Sets a message to be displayed when there are no properties in the panel.
void clear()
Deletes all property components from the panel.
void refreshAll() const
Calls the refresh() method of all PropertyComponents in the panel.
void addProperties(const Array< PropertyComponent * > &newPropertyComponents, int extraPaddingBetweenComponents=0)
Adds a set of properties to the panel.
void restoreOpennessState(const XmlElement &newState)
Restores a previously saved arrangement of open/closed sections.
A special array for holding a list of strings.
void add(String stringToAdd)
Appends a string at the end of the array.
bool isNotEmpty() const noexcept
Returns true if the string contains at least one character.
int getViewPositionX() const noexcept
Returns the position within the child component of the top-left of its visible area.
void setViewPosition(int xPixelsOffset, int yPixelsOffset)
Changes the position of the viewed component.
int getViewPositionY() const noexcept
Returns the position within the child component of the top-left of its visible area.
int getMaximumVisibleWidth() const
Returns the width available within this component for the contents.
void setViewedComponent(Component *newViewedComponent, bool deleteComponentWhenNoLongerNeeded=true)
Sets the component that this viewport will contain and scroll around.
Used to build a tree of elements representing an XML document.
Iterator< GetNextElementWithTagName > getChildWithTagNameIterator(StringRef name) const
Allows iterating children of an XmlElement with a specific tag using range-for syntax.
bool hasTagName(StringRef possibleTagName) const noexcept
Tests whether this element has a particular tag name.
int getIntAttribute(StringRef attributeName, int defaultReturnValue=0) const
Returns the value of a named attribute as an integer.
#define TRANS(stringLiteral)
Uses the LocalisedStrings class to translate the given string literal.
void paint(Graphics &) override
Components can override this method to draw their content.
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.
void mouseDoubleClick(const MouseEvent &e) override
Called when a mouse button has been double-clicked on a component.
void mouseUp(const MouseEvent &e) override
Called when a mouse button is released.
void paint(Graphics &g) override
Components can override this method to draw their content.