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.

139 lines
5.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. //==============================================================================
  16. /**
  17. A base class for a component that goes in a PropertyPanel and displays one of
  18. an item's properties.
  19. Subclasses of this are used to display a property in various forms, e.g. a
  20. ChoicePropertyComponent shows its value as a combo box; a SliderPropertyComponent
  21. shows its value as a slider; a TextPropertyComponent as a text box, etc.
  22. A subclass must implement the refresh() method which will be called to tell the
  23. component to update itself, and is also responsible for calling this it when the
  24. item that it refers to is changed.
  25. @see PropertyPanel, TextPropertyComponent, SliderPropertyComponent,
  26. ChoicePropertyComponent, ButtonPropertyComponent, BooleanPropertyComponent
  27. @tags{GUI}
  28. */
  29. class JUCE_API PropertyComponent : public Component,
  30. public SettableTooltipClient
  31. {
  32. public:
  33. //==============================================================================
  34. /** Creates a PropertyComponent.
  35. @param propertyName the name is stored as this component's name, and is
  36. used as the name displayed next to this component in
  37. a property panel
  38. @param preferredHeight the height that the component should be given - some
  39. items may need to be larger than a normal row height.
  40. This value can also be set if a subclass changes the
  41. preferredHeight member variable.
  42. */
  43. PropertyComponent (const String& propertyName,
  44. int preferredHeight = 25);
  45. /** Destructor. */
  46. ~PropertyComponent() override;
  47. //==============================================================================
  48. /** Returns this item's preferred height.
  49. This value is specified either in the constructor or by a subclass changing the
  50. preferredHeight member variable.
  51. */
  52. int getPreferredHeight() const noexcept { return preferredHeight; }
  53. void setPreferredHeight (int newHeight) noexcept { preferredHeight = newHeight; }
  54. //==============================================================================
  55. /** Updates the property component if the item it refers to has changed.
  56. A subclass must implement this method, and other objects may call it to
  57. force it to refresh itself.
  58. The subclass should be economical in the amount of work is done, so for
  59. example it should check whether it really needs to do a repaint rather than
  60. just doing one every time this method is called, as it may be called when
  61. the value being displayed hasn't actually changed.
  62. */
  63. virtual void refresh() = 0;
  64. /** The default paint method fills the background and draws a label for the
  65. item's name.
  66. @see LookAndFeel::drawPropertyComponentBackground(), LookAndFeel::drawPropertyComponentLabel()
  67. */
  68. void paint (Graphics&) override;
  69. /** The default resize method positions any child component to the right of this
  70. one, based on the look and feel's default label size.
  71. */
  72. void resized() override;
  73. /** By default, this just repaints the component. */
  74. void enablementChanged() override;
  75. //==============================================================================
  76. /** A set of colour IDs to use to change the colour of various aspects of the combo box.
  77. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  78. methods.
  79. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  80. */
  81. enum ColourIds
  82. {
  83. backgroundColourId = 0x1008300, /**< The background colour to fill the component with. */
  84. labelTextColourId = 0x1008301, /**< The colour for the property's label text. */
  85. };
  86. //==============================================================================
  87. /** This abstract base class is implemented by LookAndFeel classes. */
  88. struct JUCE_API LookAndFeelMethods
  89. {
  90. virtual ~LookAndFeelMethods() = default;
  91. virtual void drawPropertyPanelSectionHeader (Graphics&, const String& name, bool isOpen, int width, int height) = 0;
  92. virtual void drawPropertyComponentBackground (Graphics&, int width, int height, PropertyComponent&) = 0;
  93. virtual void drawPropertyComponentLabel (Graphics&, int width, int height, PropertyComponent&) = 0;
  94. virtual Rectangle<int> getPropertyComponentContentPosition (PropertyComponent&) = 0;
  95. virtual int getPropertyPanelSectionHeaderHeight (const String& sectionTitle) = 0;
  96. };
  97. protected:
  98. /** Used by the PropertyPanel to determine how high this component needs to be.
  99. A subclass can update this value in its constructor but shouldn't alter it later
  100. as changes won't necessarily be picked up.
  101. */
  102. int preferredHeight;
  103. private:
  104. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PropertyComponent)
  105. };
  106. } // namespace juce