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.

112 lines
4.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. #pragma once
  20. //==============================================================================
  21. /**
  22. A button that uses the standard lozenge-shaped background with a line of
  23. text on it.
  24. @see Button, DrawableButton
  25. */
  26. class JUCE_API TextButton : public Button
  27. {
  28. public:
  29. //==============================================================================
  30. /** Creates a TextButton. */
  31. TextButton();
  32. /** Creates a TextButton.
  33. @param buttonName the text to put in the button (the component's name is also
  34. initially set to this string, but these can be changed later
  35. using the setName() and setButtonText() methods)
  36. */
  37. explicit TextButton (const String& buttonName);
  38. /** Creates a TextButton.
  39. @param buttonName the text to put in the button (the component's name is also
  40. initially set to this string, but these can be changed later
  41. using the setName() and setButtonText() methods)
  42. @param toolTip an optional string to use as a toolip
  43. */
  44. TextButton (const String& buttonName, const String& toolTip);
  45. /** Destructor. */
  46. ~TextButton();
  47. //==============================================================================
  48. /** A set of colour IDs to use to change the colour of various aspects of the button.
  49. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  50. methods.
  51. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  52. */
  53. enum ColourIds
  54. {
  55. buttonColourId = 0x1000100, /**< The colour used to fill the button shape (when the button is toggled
  56. 'off'). The look-and-feel class might re-interpret this to add
  57. effects, etc. */
  58. buttonOnColourId = 0x1000101, /**< The colour used to fill the button shape (when the button is toggled
  59. 'on'). The look-and-feel class might re-interpret this to add
  60. effects, etc. */
  61. textColourOffId = 0x1000102, /**< The colour to use for the button's text when the button's toggle state is "off". */
  62. textColourOnId = 0x1000103 /**< The colour to use for the button's text.when the button's toggle state is "on". */
  63. };
  64. //==============================================================================
  65. /** Changes this button's width to fit neatly around its current text, without
  66. changing its height.
  67. */
  68. void changeWidthToFitText();
  69. /** Resizes the button's width to fit neatly around its current text, and gives it
  70. the specified height.
  71. */
  72. void changeWidthToFitText (int newHeight);
  73. /** Returns the width that the LookAndFeel suggests would be best for this button if it
  74. had the given height.
  75. */
  76. int getBestWidthForHeight (int buttonHeight);
  77. //==============================================================================
  78. /** @internal */
  79. void paintButton (Graphics&, bool isMouseOverButton, bool isButtonDown) override;
  80. /** @internal */
  81. void colourChanged() override;
  82. private:
  83. #if JUCE_CATCH_DEPRECATED_CODE_MISUSE
  84. // Note that this method has been removed - instead, see LookAndFeel::getTextButtonFont()
  85. virtual int getFont() { return 0; }
  86. #endif
  87. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TextButton)
  88. };