juce_ConcertinaPanel.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. namespace juce
  20. {
  21. //==============================================================================
  22. /**
  23. A panel which holds a vertical stack of components which can be expanded
  24. and contracted.
  25. Each section has its own header bar which can be dragged up and down
  26. to resize it, or double-clicked to fully expand that section.
  27. @tags{GUI}
  28. */
  29. class JUCE_API ConcertinaPanel : public Component
  30. {
  31. public:
  32. /** Creates an empty concertina panel.
  33. You can call addPanel() to add some components to it.
  34. */
  35. ConcertinaPanel();
  36. /** Destructor. */
  37. ~ConcertinaPanel() override;
  38. /** Adds a component to the panel.
  39. @param insertIndex the index at which this component will be inserted, or
  40. -1 to append it to the end of the list.
  41. @param component the component that will be shown
  42. @param takeOwnership if true, then the ConcertinaPanel will take ownership
  43. of the content component, and will delete it later when
  44. it's no longer needed. If false, it won't delete it, and
  45. you must make sure it doesn't get deleted while in use.
  46. */
  47. void addPanel (int insertIndex, Component* component, bool takeOwnership);
  48. /** Removes one of the panels.
  49. If the takeOwnership flag was set when the panel was added, then
  50. this will also delete the component.
  51. */
  52. void removePanel (Component* panelComponent);
  53. /** Returns the number of panels.
  54. @see getPanel
  55. */
  56. int getNumPanels() const noexcept;
  57. /** Returns one of the panels.
  58. @see getNumPanels()
  59. */
  60. Component* getPanel (int index) const noexcept;
  61. /** Resizes one of the panels.
  62. The panelComponent must point to a valid panel component.
  63. If animate is true, the panels will be animated into their new positions;
  64. if false, they will just be immediately resized.
  65. */
  66. bool setPanelSize (Component* panelComponent, int newHeight, bool animate);
  67. /** Attempts to make one of the panels full-height.
  68. The panelComponent must point to a valid panel component.
  69. If this component has had a maximum size set, then it will be
  70. expanded to that size. Otherwise, it'll fill as much of the total
  71. space as possible.
  72. */
  73. bool expandPanelFully (Component* panelComponent, bool animate);
  74. /** Sets a maximum size for one of the panels. */
  75. void setMaximumPanelSize (Component* panelComponent, int maximumSize);
  76. /** Sets the height of the header section for one of the panels. */
  77. void setPanelHeaderSize (Component* panelComponent, int headerSize);
  78. /** Sets a custom header Component for one of the panels.
  79. @param panelComponent the panel component to add the custom header to.
  80. @param customHeaderComponent the custom component to use for the panel header.
  81. This can be nullptr to clear the custom header component
  82. and just use the standard LookAndFeel panel.
  83. @param takeOwnership if true, then the PanelHolder will take ownership
  84. of the custom header component, and will delete it later when
  85. it's no longer needed. If false, it won't delete it, and
  86. you must make sure it doesn't get deleted while in use.
  87. */
  88. void setCustomPanelHeader (Component* panelComponent, Component* customHeaderComponent, bool takeOwnership);
  89. //==============================================================================
  90. /** This abstract base class is implemented by LookAndFeel classes. */
  91. struct JUCE_API LookAndFeelMethods
  92. {
  93. virtual ~LookAndFeelMethods() = default;
  94. virtual void drawConcertinaPanelHeader (Graphics&, const Rectangle<int>& area,
  95. bool isMouseOver, bool isMouseDown,
  96. ConcertinaPanel&, Component&) = 0;
  97. };
  98. private:
  99. void resized() override;
  100. class PanelHolder;
  101. struct PanelSizes;
  102. std::unique_ptr<PanelSizes> currentSizes;
  103. OwnedArray<PanelHolder> holders;
  104. ComponentAnimator animator;
  105. int headerHeight;
  106. int indexOfComp (Component*) const noexcept;
  107. PanelSizes getFittedSizes() const;
  108. void applyLayout (const PanelSizes&, bool animate);
  109. void setLayout (const PanelSizes&, bool animate);
  110. void panelHeaderDoubleClicked (Component*);
  111. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConcertinaPanel)
  112. };
  113. } // namespace juce