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.

103 lines
3.9KB

  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 contains an on/off toggle button.
  18. This type of property component can be used if you have a boolean value to
  19. toggle on/off.
  20. @see PropertyComponent
  21. @tags{GUI}
  22. */
  23. class JUCE_API BooleanPropertyComponent : public PropertyComponent
  24. {
  25. protected:
  26. //==============================================================================
  27. /** Creates a button component.
  28. If you use this constructor, you must override the getState() and setState()
  29. methods.
  30. @param propertyName the property name to be passed to the PropertyComponent
  31. @param buttonTextWhenTrue the text shown in the button when the value is true
  32. @param buttonTextWhenFalse the text shown in the button when the value is false
  33. */
  34. BooleanPropertyComponent (const String& propertyName,
  35. const String& buttonTextWhenTrue,
  36. const String& buttonTextWhenFalse);
  37. public:
  38. /** Creates a button component.
  39. Note that if you call this constructor then you must use the Value to interact with the
  40. button state, and you can't override the class with your own setState or getState methods.
  41. If you want to use getState and setState, call the other constructor instead.
  42. @param valueToControl a Value object that this property should refer to.
  43. @param propertyName the property name to be passed to the PropertyComponent
  44. @param buttonText the text shown in the ToggleButton component
  45. */
  46. BooleanPropertyComponent (const Value& valueToControl,
  47. const String& propertyName,
  48. const String& buttonText);
  49. /** Destructor. */
  50. ~BooleanPropertyComponent() override;
  51. //==============================================================================
  52. /** Called to change the state of the boolean value. */
  53. virtual void setState (bool newState);
  54. /** Must return the current value of the property. */
  55. virtual bool getState() const;
  56. //==============================================================================
  57. /** A set of colour IDs to use to change the colour of various aspects of the component.
  58. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  59. methods.
  60. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  61. */
  62. enum ColourIds
  63. {
  64. backgroundColourId = 0x100e801, /**< The colour to fill the background of the button area. */
  65. outlineColourId = 0x100e803, /**< The colour to use to draw an outline around the text area. */
  66. };
  67. //==============================================================================
  68. /** @internal */
  69. void paint (Graphics&) override;
  70. /** @internal */
  71. void refresh() override;
  72. private:
  73. ToggleButton button;
  74. String onText, offText;
  75. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BooleanPropertyComponent)
  76. };
  77. } // namespace juce