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.

juce_PreferencesPanel.h 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - 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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-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 set of buttons at the top for changing between pages of
  23. preferences.
  24. This is just a handy way of writing a Mac-style preferences panel where you
  25. have a row of buttons along the top for the different preference categories,
  26. each button having an icon above its name. Clicking these will show an
  27. appropriate prefs page below it.
  28. You can either put one of these inside your own component, or just use the
  29. showInDialogBox() method to show it in a window and run it modally.
  30. To use it, just add a set of named pages with the addSettingsPage() method,
  31. and implement the createComponentForPage() method to create suitable components
  32. for each of these pages.
  33. @tags{GUI}
  34. */
  35. class JUCE_API PreferencesPanel : public Component
  36. {
  37. public:
  38. //==============================================================================
  39. /** Creates an empty panel.
  40. Use addSettingsPage() to add some pages to it in your constructor.
  41. */
  42. PreferencesPanel();
  43. /** Destructor. */
  44. ~PreferencesPanel() override;
  45. //==============================================================================
  46. /** Creates a page using a set of drawables to define the page's icon.
  47. Note that the other version of this method is much easier if you're using
  48. an image instead of a custom drawable.
  49. @param pageTitle the name of this preferences page - you'll need to
  50. make sure your createComponentForPage() method creates
  51. a suitable component when it is passed this name
  52. @param normalIcon the drawable to display in the page's button normally
  53. @param overIcon the drawable to display in the page's button when the mouse is over
  54. @param downIcon the drawable to display in the page's button when the button is down
  55. @see DrawableButton
  56. */
  57. void addSettingsPage (const String& pageTitle,
  58. const Drawable* normalIcon,
  59. const Drawable* overIcon,
  60. const Drawable* downIcon);
  61. /** Creates a page using a set of drawables to define the page's icon.
  62. The other version of this method gives you more control over the icon, but this
  63. one is much easier if you're just loading it from a file.
  64. @param pageTitle the name of this preferences page - you'll need to
  65. make sure your createComponentForPage() method creates
  66. a suitable component when it is passed this name
  67. @param imageData a block of data containing an image file, e.g. a jpeg, png or gif.
  68. For this to look good, you'll probably want to use a nice
  69. transparent png file.
  70. @param imageDataSize the size of the image data, in bytes
  71. */
  72. void addSettingsPage (const String& pageTitle,
  73. const void* imageData,
  74. int imageDataSize);
  75. /** Utility method to display this panel in a DialogWindow.
  76. Calling this will create a DialogWindow containing this panel with the
  77. given size and title, and will run it modally, returning when the user
  78. closes the dialog box.
  79. */
  80. void showInDialogBox (const String& dialogTitle,
  81. int dialogWidth,
  82. int dialogHeight,
  83. Colour backgroundColour = Colours::white);
  84. //==============================================================================
  85. /** Subclasses must override this to return a component for each preferences page.
  86. The subclass should return a pointer to a new component representing the named
  87. page, which the panel will then display.
  88. The panel will delete the component later when the user goes to another page
  89. or deletes the panel.
  90. */
  91. virtual Component* createComponentForPage (const String& pageName) = 0;
  92. //==============================================================================
  93. /** Changes the current page being displayed. */
  94. void setCurrentPage (const String& pageName);
  95. /** Returns the size of the buttons shown along the top. */
  96. int getButtonSize() const noexcept;
  97. /** Changes the size of the buttons shown along the top. */
  98. void setButtonSize (int newSize);
  99. //==============================================================================
  100. /** @internal */
  101. void resized() override;
  102. /** @internal */
  103. void paint (Graphics&) override;
  104. private:
  105. //==============================================================================
  106. String currentPageName;
  107. std::unique_ptr<Component> currentPage;
  108. OwnedArray<DrawableButton> buttons;
  109. int buttonSize;
  110. void clickedPage();
  111. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PreferencesPanel)
  112. };
  113. } // namespace juce