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.

110 lines
4.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #pragma once
  18. //==============================================================================
  19. /**
  20. A button that uses the standard lozenge-shaped background with a line of
  21. text on it.
  22. @see Button, DrawableButton
  23. */
  24. class JUCE_API TextButton : public Button
  25. {
  26. public:
  27. //==============================================================================
  28. /** Creates a TextButton. */
  29. TextButton();
  30. /** Creates a TextButton.
  31. @param buttonName the text to put in the button (the component's name is also
  32. initially set to this string, but these can be changed later
  33. using the setName() and setButtonText() methods)
  34. */
  35. explicit TextButton (const String& buttonName);
  36. /** Creates a TextButton.
  37. @param buttonName the text to put in the button (the component's name is also
  38. initially set to this string, but these can be changed later
  39. using the setName() and setButtonText() methods)
  40. @param toolTip an optional string to use as a toolip
  41. */
  42. TextButton (const String& buttonName, const String& toolTip);
  43. /** Destructor. */
  44. ~TextButton();
  45. //==============================================================================
  46. /** A set of colour IDs to use to change the colour of various aspects of the button.
  47. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  48. methods.
  49. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  50. */
  51. enum ColourIds
  52. {
  53. buttonColourId = 0x1000100, /**< The colour used to fill the button shape (when the button is toggled
  54. 'off'). The look-and-feel class might re-interpret this to add
  55. effects, etc. */
  56. buttonOnColourId = 0x1000101, /**< The colour used to fill the button shape (when the button is toggled
  57. 'on'). The look-and-feel class might re-interpret this to add
  58. effects, etc. */
  59. textColourOffId = 0x1000102, /**< The colour to use for the button's text when the button's toggle state is "off". */
  60. textColourOnId = 0x1000103 /**< The colour to use for the button's text.when the button's toggle state is "on". */
  61. };
  62. //==============================================================================
  63. /** Changes this button's width to fit neatly around its current text, without
  64. changing its height.
  65. */
  66. void changeWidthToFitText();
  67. /** Resizes the button's width to fit neatly around its current text, and gives it
  68. the specified height.
  69. */
  70. void changeWidthToFitText (int newHeight);
  71. /** Returns the width that the LookAndFeel suggests would be best for this button if it
  72. had the given height.
  73. */
  74. int getBestWidthForHeight (int buttonHeight);
  75. //==============================================================================
  76. /** @internal */
  77. void paintButton (Graphics&, bool isMouseOverButton, bool isButtonDown) override;
  78. /** @internal */
  79. void colourChanged() override;
  80. private:
  81. #if JUCE_CATCH_DEPRECATED_CODE_MISUSE
  82. // Note that this method has been removed - instead, see LookAndFeel::getTextButtonFont()
  83. virtual int getFont() { return 0; }
  84. #endif
  85. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TextButton)
  86. };