| @@ -360,10 +360,12 @@ public: | |||||
| { | { | ||||
| virtual ~LookAndFeelMethods() {} | virtual ~LookAndFeelMethods() {} | ||||
| virtual void drawButtonBackground (Graphics&, Button& button, const Colour& backgroundColour, | |||||
| virtual void drawButtonBackground (Graphics&, Button&, const Colour& backgroundColour, | |||||
| bool isMouseOverButton, bool isButtonDown) = 0; | bool isMouseOverButton, bool isButtonDown) = 0; | ||||
| virtual Font getTextButtonFont (TextButton& button) = 0; | |||||
| virtual Font getTextButtonFont (TextButton&) = 0; | |||||
| virtual void changeTextButtonWidthToFitText (TextButton&, int newHeight) = 0; | |||||
| /** Draws the text for a TextButton. */ | /** Draws the text for a TextButton. */ | ||||
| virtual void drawButtonText (Graphics&, TextButton&, bool isMouseOverButton, bool isButtonDown) = 0; | virtual void drawButtonText (Graphics&, TextButton&, bool isMouseOverButton, bool isButtonDown) = 0; | ||||
| @@ -22,6 +22,10 @@ | |||||
| ============================================================================== | ============================================================================== | ||||
| */ | */ | ||||
| TextButton::TextButton() : Button (String()) | |||||
| { | |||||
| } | |||||
| TextButton::TextButton (const String& name, const String& toolTip) | TextButton::TextButton (const String& name, const String& toolTip) | ||||
| : Button (name) | : Button (name) | ||||
| { | { | ||||
| @@ -32,21 +36,15 @@ TextButton::~TextButton() | |||||
| { | { | ||||
| } | } | ||||
| void TextButton::paintButton (Graphics& g, | |||||
| bool isMouseOverButton, | |||||
| bool isButtonDown) | |||||
| void TextButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown) | |||||
| { | { | ||||
| LookAndFeel& lf = getLookAndFeel(); | LookAndFeel& lf = getLookAndFeel(); | ||||
| lf.drawButtonBackground (g, *this, | lf.drawButtonBackground (g, *this, | ||||
| findColour (getToggleState() ? buttonOnColourId | |||||
| : buttonColourId), | |||||
| isMouseOverButton, | |||||
| isButtonDown); | |||||
| lf.drawButtonText (g, *this, | |||||
| isMouseOverButton, | |||||
| isButtonDown); | |||||
| findColour (getToggleState() ? buttonOnColourId : buttonColourId), | |||||
| isMouseOverButton, isButtonDown); | |||||
| lf.drawButtonText (g, *this, isMouseOverButton, isButtonDown); | |||||
| } | } | ||||
| void TextButton::colourChanged() | void TextButton::colourChanged() | ||||
| @@ -61,9 +59,5 @@ Font TextButton::getFont() | |||||
| void TextButton::changeWidthToFitText (const int newHeight) | void TextButton::changeWidthToFitText (const int newHeight) | ||||
| { | { | ||||
| if (newHeight >= 0) | |||||
| setSize (jmax (1, getWidth()), newHeight); | |||||
| setSize (getFont().getStringWidth (getButtonText()) + getHeight(), | |||||
| getHeight()); | |||||
| getLookAndFeel().changeTextButtonWidthToFitText (*this, newHeight); | |||||
| } | } | ||||
| @@ -37,17 +37,18 @@ class JUCE_API TextButton : public Button | |||||
| { | { | ||||
| public: | public: | ||||
| //============================================================================== | //============================================================================== | ||||
| /** Creates a TextButton. | |||||
| /** Creates a TextButton. */ | |||||
| TextButton(); | |||||
| /** Creates a TextButton. | |||||
| @param buttonName the text to put in the button (the component's name is also | @param buttonName the text to put in the button (the component's name is also | ||||
| initially set to this string, but these can be changed later | initially set to this string, but these can be changed later | ||||
| using the setName() and setButtonText() methods) | using the setName() and setButtonText() methods) | ||||
| @param toolTip an optional string to use as a toolip | @param toolTip an optional string to use as a toolip | ||||
| @see Button | @see Button | ||||
| */ | */ | ||||
| TextButton (const String& buttonName = String::empty, | |||||
| const String& toolTip = String::empty); | |||||
| explicit TextButton (const String& buttonName, | |||||
| const String& toolTip = String::empty); | |||||
| /** Destructor. */ | /** Destructor. */ | ||||
| ~TextButton(); | ~TextButton(); | ||||
| @@ -74,19 +75,18 @@ public: | |||||
| //============================================================================== | //============================================================================== | ||||
| /** Resizes the button to fit neatly around its current text. | /** Resizes the button to fit neatly around its current text. | ||||
| If newHeight is >= 0, the button's height will be changed to this | If newHeight is >= 0, the button's height will be changed to this | ||||
| value. If it's less than zero, its height will be unaffected. | value. If it's less than zero, its height will be unaffected. | ||||
| */ | */ | ||||
| void changeWidthToFitText (int newHeight = -1); | void changeWidthToFitText (int newHeight = -1); | ||||
| /** This can be overridden to use different fonts than the default one. | /** This can be overridden to use different fonts than the default one. | ||||
| Note that you'll need to set the font's size appropriately, too. | Note that you'll need to set the font's size appropriately, too. | ||||
| */ | */ | ||||
| virtual Font getFont(); | virtual Font getFont(); | ||||
| protected: | |||||
| //============================================================================== | |||||
| /** @internal */ | /** @internal */ | ||||
| void paintButton (Graphics&, bool isMouseOverButton, bool isButtonDown) override; | void paintButton (Graphics&, bool isMouseOverButton, bool isButtonDown) override; | ||||
| /** @internal */ | /** @internal */ | ||||
| @@ -243,6 +243,16 @@ Font LookAndFeel_V2::getTextButtonFont (TextButton& button) | |||||
| return button.getFont(); | return button.getFont(); | ||||
| } | } | ||||
| void LookAndFeel_V2::changeTextButtonWidthToFitText (TextButton& b, int newHeight) | |||||
| { | |||||
| if (newHeight >= 0) | |||||
| b.setSize (jmax (1, b.getWidth()), newHeight); | |||||
| else | |||||
| newHeight = b.getHeight(); | |||||
| b.setSize (getTextButtonFont (b).getStringWidth (b.getButtonText()) + newHeight, newHeight); | |||||
| } | |||||
| void LookAndFeel_V2::drawButtonText (Graphics& g, TextButton& button, bool /*isMouseOverButton*/, bool /*isButtonDown*/) | void LookAndFeel_V2::drawButtonText (Graphics& g, TextButton& button, bool /*isMouseOverButton*/, bool /*isButtonDown*/) | ||||
| { | { | ||||
| Font font (getTextButtonFont (button)); | Font font (getTextButtonFont (button)); | ||||
| @@ -46,6 +46,7 @@ public: | |||||
| void drawButtonText (Graphics&, TextButton& button, | void drawButtonText (Graphics&, TextButton& button, | ||||
| bool isMouseOverButton, bool isButtonDown) override; | bool isMouseOverButton, bool isButtonDown) override; | ||||
| void changeTextButtonWidthToFitText (TextButton&, int newHeight) override; | |||||
| void drawToggleButton (Graphics&, ToggleButton& button, bool isMouseOverButton, bool isButtonDown) override; | void drawToggleButton (Graphics&, ToggleButton& button, bool isMouseOverButton, bool isButtonDown) override; | ||||