The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

176 lines
6.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #pragma once
  20. //==============================================================================
  21. /**
  22. A panel that holds a list of PropertyComponent objects.
  23. This panel displays a list of PropertyComponents, and allows them to be organised
  24. into collapsible sections.
  25. To use, simply create one of these and add your properties to it with addProperties()
  26. or addSection().
  27. @see PropertyComponent
  28. */
  29. class JUCE_API PropertyPanel : public Component
  30. {
  31. public:
  32. //==============================================================================
  33. /** Creates an empty property panel. */
  34. PropertyPanel();
  35. /** Creates an empty property panel. */
  36. PropertyPanel (const String& name);
  37. /** Destructor. */
  38. ~PropertyPanel();
  39. //==============================================================================
  40. /** Deletes all property components from the panel. */
  41. void clear();
  42. /** Adds a set of properties to the panel.
  43. The components in the list will be owned by this object and will be automatically
  44. deleted later on when no longer needed.
  45. These properties are added without them being inside a named section. If you
  46. want them to be kept together in a collapsible section, use addSection() instead.
  47. */
  48. void addProperties (const Array<PropertyComponent*>& newPropertyComponents);
  49. /** Adds a set of properties to the panel.
  50. These properties are added under a section heading with a plus/minus button that
  51. allows it to be opened and closed. If indexToInsertAt is < 0 then it will be added
  52. at the end of the list, or before the given index if the index is non-zero.
  53. The components in the list will be owned by this object and will be automatically
  54. deleted later on when no longer needed.
  55. To add properies without them being in a section, use addProperties().
  56. */
  57. void addSection (const String& sectionTitle,
  58. const Array<PropertyComponent*>& newPropertyComponents,
  59. bool shouldSectionInitiallyBeOpen = true,
  60. int indexToInsertAt = -1);
  61. /** Calls the refresh() method of all PropertyComponents in the panel */
  62. void refreshAll() const;
  63. /** Returns true if the panel contains no properties. */
  64. bool isEmpty() const;
  65. /** Returns the height that the panel needs in order to display all of its content
  66. without scrolling.
  67. */
  68. int getTotalContentHeight() const;
  69. //==============================================================================
  70. /** Returns a list of all the names of sections in the panel.
  71. These are the sections that have been added with addSection().
  72. */
  73. StringArray getSectionNames() const;
  74. /** Returns true if the section at this index is currently open.
  75. The index is from 0 up to the number of items returned by getSectionNames().
  76. */
  77. bool isSectionOpen (int sectionIndex) const;
  78. /** Opens or closes one of the sections.
  79. The index is from 0 up to the number of items returned by getSectionNames().
  80. */
  81. void setSectionOpen (int sectionIndex, bool shouldBeOpen);
  82. /** Enables or disables one of the sections.
  83. The index is from 0 up to the number of items returned by getSectionNames().
  84. */
  85. void setSectionEnabled (int sectionIndex, bool shouldBeEnabled);
  86. /** Remove one of the sections using the section index.
  87. The index is from 0 up to the number of items returned by getSectionNames().
  88. */
  89. void removeSection (int sectionIndex);
  90. //==============================================================================
  91. /** Saves the current state of open/closed sections so it can be restored later.
  92. The caller is responsible for deleting the object that is returned.
  93. To restore this state, use restoreOpennessState().
  94. @see restoreOpennessState
  95. */
  96. XmlElement* getOpennessState() const;
  97. /** Restores a previously saved arrangement of open/closed sections.
  98. This will try to restore a snapshot of the panel's state that was created by
  99. the getOpennessState() method. If any of the sections named in the original
  100. XML aren't present, they will be ignored.
  101. @see getOpennessState
  102. */
  103. void restoreOpennessState (const XmlElement& newState);
  104. //==============================================================================
  105. /** Sets a message to be displayed when there are no properties in the panel.
  106. The default message is "nothing selected".
  107. */
  108. void setMessageWhenEmpty (const String& newMessage);
  109. /** Returns the message that is displayed when there are no properties.
  110. @see setMessageWhenEmpty
  111. */
  112. const String& getMessageWhenEmpty() const noexcept;
  113. //==============================================================================
  114. /** Returns the PropertyPanel's internal Viewport. */
  115. Viewport& getViewport() noexcept { return viewport; }
  116. //==============================================================================
  117. /** @internal */
  118. void paint (Graphics&) override;
  119. /** @internal */
  120. void resized() override;
  121. private:
  122. Viewport viewport;
  123. struct SectionComponent;
  124. struct PropertyHolderComponent;
  125. PropertyHolderComponent* propertyHolderComponent;
  126. String messageWhenEmpty;
  127. void init();
  128. void updatePropHolderLayout() const;
  129. void updatePropHolderLayout (int width) const;
  130. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PropertyPanel)
  131. };