|
|
|
@@ -31,17 +31,17 @@ struct PropertyPanel::SectionComponent : public Component |
|
|
|
{
|
|
|
|
SectionComponent (const String& sectionTitle,
|
|
|
|
const Array<PropertyComponent*>& newProperties,
|
|
|
|
const bool sectionIsOpen)
|
|
|
|
bool sectionIsOpen)
|
|
|
|
: Component (sectionTitle),
|
|
|
|
titleHeight (sectionTitle.isNotEmpty() ? 22 : 0),
|
|
|
|
titleHeight (getLookAndFeel().getPropertyPanelSectionHeaderHeight (sectionTitle)),
|
|
|
|
isOpen (sectionIsOpen)
|
|
|
|
{
|
|
|
|
propertyComps.addArray (newProperties);
|
|
|
|
|
|
|
|
for (int i = propertyComps.size(); --i >= 0;)
|
|
|
|
for (auto* propertyComponent : propertyComps)
|
|
|
|
{
|
|
|
|
addAndMakeVisible (propertyComps.getUnchecked(i));
|
|
|
|
propertyComps.getUnchecked(i)->refresh();
|
|
|
|
addAndMakeVisible (propertyComponent);
|
|
|
|
propertyComponent->refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@@ -58,45 +58,44 @@ struct PropertyPanel::SectionComponent : public Component |
|
|
|
|
|
|
|
void resized() override
|
|
|
|
{
|
|
|
|
int y = titleHeight;
|
|
|
|
auto y = titleHeight;
|
|
|
|
|
|
|
|
for (int i = 0; i < propertyComps.size(); ++i)
|
|
|
|
for (auto* propertyComponent : propertyComps)
|
|
|
|
{
|
|
|
|
PropertyComponent* const pec = propertyComps.getUnchecked (i);
|
|
|
|
pec->setBounds (1, y, getWidth() - 2, pec->getPreferredHeight());
|
|
|
|
y = pec->getBottom();
|
|
|
|
propertyComponent->setBounds (1, y, getWidth() - 2, propertyComponent->getPreferredHeight());
|
|
|
|
y = propertyComponent->getBottom();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int getPreferredHeight() const
|
|
|
|
{
|
|
|
|
int y = titleHeight;
|
|
|
|
auto y = titleHeight;
|
|
|
|
|
|
|
|
if (isOpen)
|
|
|
|
for (int i = propertyComps.size(); --i >= 0;)
|
|
|
|
y += propertyComps.getUnchecked(i)->getPreferredHeight();
|
|
|
|
for (auto* propertyComponent : propertyComps)
|
|
|
|
y += propertyComponent->getPreferredHeight();
|
|
|
|
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setOpen (const bool open)
|
|
|
|
void setOpen (bool open)
|
|
|
|
{
|
|
|
|
if (isOpen != open)
|
|
|
|
{
|
|
|
|
isOpen = open;
|
|
|
|
|
|
|
|
for (int i = propertyComps.size(); --i >= 0;)
|
|
|
|
propertyComps.getUnchecked(i)->setVisible (open);
|
|
|
|
for (auto* propertyComponent : propertyComps)
|
|
|
|
propertyComponent->setVisible (open);
|
|
|
|
|
|
|
|
if (PropertyPanel* const pp = findParentComponentOfClass<PropertyPanel>())
|
|
|
|
pp->resized();
|
|
|
|
if (auto* propertyPanel = findParentComponentOfClass<PropertyPanel>())
|
|
|
|
propertyPanel->resized();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void refreshAll() const
|
|
|
|
{
|
|
|
|
for (int i = propertyComps.size(); --i >= 0;)
|
|
|
|
propertyComps.getUnchecked (i)->refresh();
|
|
|
|
for (auto* propertyComponent : propertyComps)
|
|
|
|
propertyComponent->refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void mouseUp (const MouseEvent& e) override
|
|
|
|
@@ -114,7 +113,7 @@ struct PropertyPanel::SectionComponent : public Component |
|
|
|
}
|
|
|
|
|
|
|
|
OwnedArray<PropertyComponent> propertyComps;
|
|
|
|
const int titleHeight;
|
|
|
|
int titleHeight;
|
|
|
|
bool isOpen;
|
|
|
|
|
|
|
|
JUCE_DECLARE_NON_COPYABLE (SectionComponent)
|
|
|
|
@@ -129,12 +128,10 @@ struct PropertyPanel::PropertyHolderComponent : public Component |
|
|
|
|
|
|
|
void updateLayout (int width)
|
|
|
|
{
|
|
|
|
int y = 0;
|
|
|
|
auto y = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < sections.size(); ++i)
|
|
|
|
for (auto* section : sections)
|
|
|
|
{
|
|
|
|
SectionComponent* const section = sections.getUnchecked(i);
|
|
|
|
|
|
|
|
section->setBounds (0, y, width, section->getPreferredHeight());
|
|
|
|
y = section->getBottom();
|
|
|
|
}
|
|
|
|
@@ -145,8 +142,8 @@ struct PropertyPanel::PropertyHolderComponent : public Component |
|
|
|
|
|
|
|
void refreshAll() const
|
|
|
|
{
|
|
|
|
for (int i = 0; i < sections.size(); ++i)
|
|
|
|
sections.getUnchecked(i)->refreshAll();
|
|
|
|
for (auto* section : sections)
|
|
|
|
section->refreshAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
void insertSection (int indexToInsertAt, SectionComponent* newSection)
|
|
|
|
@@ -155,12 +152,11 @@ struct PropertyPanel::PropertyHolderComponent : public Component |
|
|
|
addAndMakeVisible (newSection, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SectionComponent* getSectionWithNonEmptyName (const int targetIndex) const noexcept
|
|
|
|
SectionComponent* getSectionWithNonEmptyName (int targetIndex) const noexcept
|
|
|
|
{
|
|
|
|
for (int index = 0, i = 0; i < sections.size(); ++i)
|
|
|
|
auto index = 0;
|
|
|
|
for (auto* section : sections)
|
|
|
|
{
|
|
|
|
SectionComponent* const section = sections.getUnchecked (i);
|
|
|
|
|
|
|
|
if (section->getName().isNotEmpty())
|
|
|
|
if (index++ == targetIndex)
|
|
|
|
return section;
|
|
|
|
@@ -249,8 +245,8 @@ void PropertyPanel::addProperties (const Array<PropertyComponent*>& newPropertie |
|
|
|
|
|
|
|
void PropertyPanel::addSection (const String& sectionTitle,
|
|
|
|
const Array<PropertyComponent*>& newProperties,
|
|
|
|
const bool shouldBeOpen,
|
|
|
|
const int indexToInsertAt)
|
|
|
|
bool shouldBeOpen,
|
|
|
|
int indexToInsertAt)
|
|
|
|
{
|
|
|
|
jassert (sectionTitle.isNotEmpty());
|
|
|
|
|
|
|
|
@@ -263,10 +259,10 @@ void PropertyPanel::addSection (const String& sectionTitle, |
|
|
|
|
|
|
|
void PropertyPanel::updatePropHolderLayout() const
|
|
|
|
{
|
|
|
|
const int maxWidth = viewport.getMaximumVisibleWidth();
|
|
|
|
auto maxWidth = viewport.getMaximumVisibleWidth();
|
|
|
|
propertyHolderComponent->updateLayout (maxWidth);
|
|
|
|
|
|
|
|
const int newMaxWidth = viewport.getMaximumVisibleWidth();
|
|
|
|
auto newMaxWidth = viewport.getMaximumVisibleWidth();
|
|
|
|
if (maxWidth != newMaxWidth)
|
|
|
|
{
|
|
|
|
// need to do this twice because of scrollbars changing the size, etc.
|
|
|
|
@@ -284,10 +280,8 @@ StringArray PropertyPanel::getSectionNames() const |
|
|
|
{
|
|
|
|
StringArray s;
|
|
|
|
|
|
|
|
for (int i = 0; i < propertyHolderComponent->sections.size(); ++i)
|
|
|
|
for (auto* section : propertyHolderComponent->sections)
|
|
|
|
{
|
|
|
|
SectionComponent* const section = propertyHolderComponent->sections.getUnchecked(i);
|
|
|
|
|
|
|
|
if (section->getName().isNotEmpty())
|
|
|
|
s.add (section->getName());
|
|
|
|
}
|
|
|
|
@@ -295,29 +289,29 @@ StringArray PropertyPanel::getSectionNames() const |
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PropertyPanel::isSectionOpen (const int sectionIndex) const
|
|
|
|
bool PropertyPanel::isSectionOpen (int sectionIndex) const
|
|
|
|
{
|
|
|
|
if (SectionComponent* s = propertyHolderComponent->getSectionWithNonEmptyName (sectionIndex))
|
|
|
|
if (auto* s = propertyHolderComponent->getSectionWithNonEmptyName (sectionIndex))
|
|
|
|
return s->isOpen;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertyPanel::setSectionOpen (const int sectionIndex, const bool shouldBeOpen)
|
|
|
|
void PropertyPanel::setSectionOpen (int sectionIndex, bool shouldBeOpen)
|
|
|
|
{
|
|
|
|
if (SectionComponent* s = propertyHolderComponent->getSectionWithNonEmptyName (sectionIndex))
|
|
|
|
if (auto* s = propertyHolderComponent->getSectionWithNonEmptyName (sectionIndex))
|
|
|
|
s->setOpen (shouldBeOpen);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertyPanel::setSectionEnabled (const int sectionIndex, const bool shouldBeEnabled)
|
|
|
|
void PropertyPanel::setSectionEnabled (int sectionIndex, bool shouldBeEnabled)
|
|
|
|
{
|
|
|
|
if (SectionComponent* s = propertyHolderComponent->getSectionWithNonEmptyName (sectionIndex))
|
|
|
|
if (auto* s = propertyHolderComponent->getSectionWithNonEmptyName (sectionIndex))
|
|
|
|
s->setEnabled (shouldBeEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertyPanel::removeSection (int sectionIndex)
|
|
|
|
{
|
|
|
|
if (SectionComponent* s = propertyHolderComponent->getSectionWithNonEmptyName (sectionIndex))
|
|
|
|
if (auto* s = propertyHolderComponent->getSectionWithNonEmptyName (sectionIndex))
|
|
|
|
{
|
|
|
|
propertyHolderComponent->sections.removeObject (s);
|
|
|
|
updatePropHolderLayout();
|
|
|
|
@@ -327,19 +321,18 @@ void PropertyPanel::removeSection (int sectionIndex) |
|
|
|
//==============================================================================
|
|
|
|
XmlElement* PropertyPanel::getOpennessState() const
|
|
|
|
{
|
|
|
|
XmlElement* const xml = new XmlElement ("PROPERTYPANELSTATE");
|
|
|
|
auto* xml = new XmlElement ("PROPERTYPANELSTATE");
|
|
|
|
|
|
|
|
xml->setAttribute ("scrollPos", viewport.getViewPositionY());
|
|
|
|
|
|
|
|
const StringArray sections (getSectionNames());
|
|
|
|
|
|
|
|
for (int i = 0; i < sections.size(); ++i)
|
|
|
|
auto sections = getSectionNames();
|
|
|
|
for (auto s : sections)
|
|
|
|
{
|
|
|
|
if (sections[i].isNotEmpty())
|
|
|
|
if (s.isNotEmpty())
|
|
|
|
{
|
|
|
|
XmlElement* const e = xml->createNewChildElement ("SECTION");
|
|
|
|
e->setAttribute ("name", sections[i]);
|
|
|
|
e->setAttribute ("open", isSectionOpen (i) ? 1 : 0);
|
|
|
|
auto* e = xml->createNewChildElement ("SECTION");
|
|
|
|
e->setAttribute ("name", s);
|
|
|
|
e->setAttribute ("open", isSectionOpen (sections.indexOf (s)) ? 1 : 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@@ -350,7 +343,7 @@ void PropertyPanel::restoreOpennessState (const XmlElement& xml) |
|
|
|
{
|
|
|
|
if (xml.hasTagName ("PROPERTYPANELSTATE"))
|
|
|
|
{
|
|
|
|
const StringArray sections (getSectionNames());
|
|
|
|
auto sections = getSectionNames();
|
|
|
|
|
|
|
|
forEachXmlChildElementWithTagName (xml, e, "SECTION")
|
|
|
|
{
|
|
|
|
|