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.

178 lines
6.6KB

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