Audio plugin host https://kx.studio/carla
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.

226 lines
8.7KB

  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 component with a TabbedButtonBar along one of its sides.
  23. This makes it easy to create a set of tabbed pages, just add a bunch of tabs
  24. with addTab(), and this will take care of showing the pages for you when the
  25. user clicks on a different tab.
  26. @see TabbedButtonBar
  27. @tags{GUI}
  28. */
  29. class JUCE_API TabbedComponent : public Component
  30. {
  31. public:
  32. //==============================================================================
  33. /** Creates a TabbedComponent, specifying where the tabs should be placed.
  34. Once created, add some tabs with the addTab() method.
  35. */
  36. explicit TabbedComponent (TabbedButtonBar::Orientation orientation);
  37. /** Destructor. */
  38. ~TabbedComponent() override;
  39. //==============================================================================
  40. /** Changes the placement of the tabs.
  41. This will rearrange the layout to place the tabs along the appropriate
  42. side of this component, and will shift the content component accordingly.
  43. @see TabbedButtonBar::setOrientation
  44. */
  45. void setOrientation (TabbedButtonBar::Orientation orientation);
  46. /** Returns the current tab placement.
  47. @see setOrientation, TabbedButtonBar::getOrientation
  48. */
  49. TabbedButtonBar::Orientation getOrientation() const noexcept;
  50. /** Specifies how many pixels wide or high the tab-bar should be.
  51. If the tabs are placed along the top or bottom, this specified the height
  52. of the bar; if they're along the left or right edges, it'll be the width
  53. of the bar.
  54. */
  55. void setTabBarDepth (int newDepth);
  56. /** Returns the current thickness of the tab bar.
  57. @see setTabBarDepth
  58. */
  59. int getTabBarDepth() const noexcept { return tabDepth; }
  60. /** Specifies the thickness of an outline that should be drawn around the content component.
  61. If this thickness is > 0, a line will be drawn around the three sides of the content
  62. component which don't touch the tab-bar, and the content component will be inset by this amount.
  63. To set the colour of the line, use setColour (outlineColourId, ...).
  64. */
  65. void setOutline (int newThickness);
  66. /** Specifies a gap to leave around the edge of the content component.
  67. Each edge of the content component will be indented by the given number of pixels.
  68. */
  69. void setIndent (int indentThickness);
  70. //==============================================================================
  71. /** Removes all the tabs from the bar.
  72. @see TabbedButtonBar::clearTabs
  73. */
  74. void clearTabs();
  75. /** Adds a tab to the tab-bar.
  76. The component passed in will be shown for the tab. If deleteComponentWhenNotNeeded
  77. is true, then the TabbedComponent will take ownership of the component and will delete
  78. it when the tab is removed or when this object is deleted.
  79. @see TabbedButtonBar::addTab
  80. */
  81. void addTab (const String& tabName,
  82. Colour tabBackgroundColour,
  83. Component* contentComponent,
  84. bool deleteComponentWhenNotNeeded,
  85. int insertIndex = -1);
  86. /** Changes the name of one of the tabs. */
  87. void setTabName (int tabIndex, const String& newName);
  88. /** Gets rid of one of the tabs. */
  89. void removeTab (int tabIndex);
  90. /** Moves a tab to a new index in the list.
  91. Pass -1 as the index to move it to the end of the list.
  92. */
  93. void moveTab (int currentIndex, int newIndex, bool animate = false);
  94. /** Returns the number of tabs in the bar. */
  95. int getNumTabs() const;
  96. /** Returns a list of all the tab names in the bar. */
  97. StringArray getTabNames() const;
  98. /** Returns the content component that was added for the given index.
  99. Be careful not to reposition or delete the components that are returned, as
  100. this will interfere with the TabbedComponent's behaviour.
  101. */
  102. Component* getTabContentComponent (int tabIndex) const noexcept;
  103. /** Returns the colour of one of the tabs. */
  104. Colour getTabBackgroundColour (int tabIndex) const noexcept;
  105. /** Changes the background colour of one of the tabs. */
  106. void setTabBackgroundColour (int tabIndex, Colour newColour);
  107. //==============================================================================
  108. /** Changes the currently-selected tab.
  109. To deselect all the tabs, pass -1 as the index.
  110. @see TabbedButtonBar::setCurrentTabIndex
  111. */
  112. void setCurrentTabIndex (int newTabIndex, bool sendChangeMessage = true);
  113. /** Returns the index of the currently selected tab.
  114. @see addTab, TabbedButtonBar::getCurrentTabIndex()
  115. */
  116. int getCurrentTabIndex() const;
  117. /** Returns the name of the currently selected tab.
  118. @see addTab, TabbedButtonBar::getCurrentTabName()
  119. */
  120. String getCurrentTabName() const;
  121. /** Returns the current component that's filling the panel.
  122. This will return nullptr if there isn't one.
  123. */
  124. Component* getCurrentContentComponent() const noexcept { return panelComponent.get(); }
  125. //==============================================================================
  126. /** Callback method to indicate the selected tab has been changed.
  127. @see setCurrentTabIndex
  128. */
  129. virtual void currentTabChanged (int newCurrentTabIndex, const String& newCurrentTabName);
  130. /** Callback method to indicate that the user has right-clicked on a tab. */
  131. virtual void popupMenuClickOnTab (int tabIndex, const String& tabName);
  132. /** Returns the tab button bar component that is being used. */
  133. TabbedButtonBar& getTabbedButtonBar() const noexcept { return *tabs; }
  134. //==============================================================================
  135. /** A set of colour IDs to use to change the colour of various aspects of the component.
  136. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  137. methods.
  138. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  139. */
  140. enum ColourIds
  141. {
  142. backgroundColourId = 0x1005800, /**< The colour to fill the background behind the tabs. */
  143. outlineColourId = 0x1005801, /**< The colour to use to draw an outline around the content.
  144. (See setOutline) */
  145. };
  146. //==============================================================================
  147. /** @internal */
  148. void paint (Graphics&) override;
  149. /** @internal */
  150. void resized() override;
  151. /** @internal */
  152. void lookAndFeelChanged() override;
  153. protected:
  154. //==============================================================================
  155. /** This creates one of the tab buttons.
  156. If you need to use custom tab components, you can override this method and
  157. return your own class instead of the default.
  158. */
  159. virtual TabBarButton* createTabButton (const String& tabName, int tabIndex);
  160. /** @internal */
  161. std::unique_ptr<TabbedButtonBar> tabs;
  162. private:
  163. //==============================================================================
  164. Array<WeakReference<Component>> contentComponents;
  165. WeakReference<Component> panelComponent;
  166. int tabDepth = 30, outlineThickness = 1, edgeIndent = 0;
  167. struct ButtonBar;
  168. void changeCallback (int newCurrentTabIndex, const String& newTabName);
  169. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TabbedComponent)
  170. };
  171. } // namespace juce