The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

128 lines
5.7KB

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