mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-15 00:24:19 +00:00
Added a getPropertyPanelSectionHeaderHeight() method to PropertyComponent::LookAndFeelMethods
This commit is contained in:
parent
27df960a52
commit
3eaeb3795e
4 changed files with 54 additions and 54 deletions
|
|
@ -2490,6 +2490,11 @@ Rectangle<int> LookAndFeel_V2::getPropertyComponentContentPosition (PropertyComp
|
|||
return Rectangle<int> (textW, 1, component.getWidth() - textW - 1, component.getHeight() - 3);
|
||||
}
|
||||
|
||||
int LookAndFeel_V2::getPropertyPanelSectionHeaderHeight (const String& sectionTitle)
|
||||
{
|
||||
return sectionTitle.isEmpty() ? 0 : 22;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void LookAndFeel_V2::drawCallOutBoxBackground (CallOutBox& box, Graphics& g,
|
||||
const Path& path, Image& cachedImage)
|
||||
|
|
|
|||
|
|
@ -313,6 +313,7 @@ public:
|
|||
void drawPropertyComponentBackground (Graphics&, int width, int height, PropertyComponent&) override;
|
||||
void drawPropertyComponentLabel (Graphics&, int width, int height, PropertyComponent&) override;
|
||||
Rectangle<int> getPropertyComponentContentPosition (PropertyComponent&) override;
|
||||
int getPropertyPanelSectionHeaderHeight (const String& sectionTitle) override;
|
||||
|
||||
//==============================================================================
|
||||
void drawCallOutBoxBackground (CallOutBox&, Graphics&, const Path& path, Image& cachedImage) override;
|
||||
|
|
|
|||
|
|
@ -127,6 +127,7 @@ public:
|
|||
virtual void drawPropertyComponentBackground (Graphics&, int width, int height, PropertyComponent&) = 0;
|
||||
virtual void drawPropertyComponentLabel (Graphics&, int width, int height, PropertyComponent&) = 0;
|
||||
virtual Rectangle<int> getPropertyComponentContentPosition (PropertyComponent&) = 0;
|
||||
virtual int getPropertyPanelSectionHeaderHeight (const String& sectionTitle) = 0;
|
||||
};
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue