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_MultiChoicePropertyComponent.h 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 PropertyComponent that shows its value as an expandable list of ToggleButtons.
  18. This type of property component contains a list of options where multiple options
  19. can be selected at once.
  20. @see PropertyComponent, PropertyPanel
  21. @tags{GUI}
  22. */
  23. class MultiChoicePropertyComponent : public PropertyComponent
  24. {
  25. private:
  26. /** Delegating constructor. */
  27. MultiChoicePropertyComponent (const String&, const StringArray&, const Array<var>&);
  28. public:
  29. /** Creates the component. Note that the underlying var object that the Value refers to must be an array.
  30. @param valueToControl the value that the ToggleButtons will read and control
  31. @param propertyName the name of the property
  32. @param choices the list of possible values that will be represented
  33. @param correspondingValues a list of values corresponding to each item in the 'choices' StringArray.
  34. These are the values that will be read and written to the
  35. valueToControl value. This array must contain the same number of items
  36. as the choices array
  37. @param maxChoices the maximum number of values which can be selected at once. The default of
  38. -1 will not limit the number that can be selected
  39. */
  40. MultiChoicePropertyComponent (const Value& valueToControl,
  41. const String& propertyName,
  42. const StringArray& choices,
  43. const Array<var>& correspondingValues,
  44. int maxChoices = -1);
  45. /** Creates the component using a ValueWithDefault object. This will select the default options.
  46. @param valueToControl the ValueWithDefault object that contains the Value object that the ToggleButtons will read and control.
  47. @param propertyName the name of the property
  48. @param choices the list of possible values that will be represented
  49. @param correspondingValues a list of values corresponding to each item in the 'choices' StringArray.
  50. These are the values that will be read and written to the
  51. valueToControl value. This array must contain the same number of items
  52. as the choices array
  53. @param maxChoices the maximum number of values which can be selected at once. The default of
  54. -1 will not limit the number that can be selected
  55. */
  56. MultiChoicePropertyComponent (ValueWithDefault& valueToControl,
  57. const String& propertyName,
  58. const StringArray& choices,
  59. const Array<var>& correspondingValues,
  60. int maxChoices = -1);
  61. ~MultiChoicePropertyComponent() override;
  62. //==============================================================================
  63. /** Returns true if the list of options is expanded. */
  64. bool isExpanded() const noexcept { return expanded; }
  65. /** Expands or shrinks the list of options.
  66. N.B. This will just set the preferredHeight value of the PropertyComponent and attempt to
  67. call PropertyPanel::resized(), so if you are not displaying this object in a PropertyPanel
  68. then you should use the onHeightChange callback to resize it when the height changes.
  69. @see onHeightChange
  70. */
  71. void setExpanded (bool expanded) noexcept;
  72. /** You can assign a lambda to this callback object to have it called when the MultiChoicePropertyComponent height changes. */
  73. std::function<void()> onHeightChange;
  74. //==============================================================================
  75. /** @internal */
  76. void paint (Graphics& g) override;
  77. /** @internal */
  78. void resized() override;
  79. /** @internal */
  80. void refresh() override {}
  81. private:
  82. //==============================================================================
  83. class MultiChoiceRemapperSource;
  84. class MultiChoiceRemapperSourceWithDefault;
  85. //==============================================================================
  86. void lookAndFeelChanged() override;
  87. //==============================================================================
  88. WeakReference<ValueWithDefault> valueWithDefault;
  89. int maxHeight = 0;
  90. int numHidden = 0;
  91. bool expanded = false;
  92. OwnedArray<ToggleButton> choiceButtons;
  93. ShapeButton expandButton { "Expand", Colours::transparentBlack, Colours::transparentBlack, Colours::transparentBlack };
  94. //==============================================================================
  95. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MultiChoicePropertyComponent)
  96. };
  97. } // namespace juce