Browse Source

Added changeTextButtonWidthToFitText to the look + feel classes.

tags/2021-05-28
jules 11 years ago
parent
commit
dd24e058c7
5 changed files with 32 additions and 25 deletions
  1. +4
    -2
      modules/juce_gui_basics/buttons/juce_Button.h
  2. +10
    -16
      modules/juce_gui_basics/buttons/juce_TextButton.cpp
  3. +7
    -7
      modules/juce_gui_basics/buttons/juce_TextButton.h
  4. +10
    -0
      modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp
  5. +1
    -0
      modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.h

+ 4
- 2
modules/juce_gui_basics/buttons/juce_Button.h View File

@@ -360,10 +360,12 @@ public:
{
virtual ~LookAndFeelMethods() {}
virtual void drawButtonBackground (Graphics&, Button& button, const Colour& backgroundColour,
virtual void drawButtonBackground (Graphics&, Button&, const Colour& backgroundColour,
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. */
virtual void drawButtonText (Graphics&, TextButton&, bool isMouseOverButton, bool isButtonDown) = 0;


+ 10
- 16
modules/juce_gui_basics/buttons/juce_TextButton.cpp View File

@@ -22,6 +22,10 @@
==============================================================================
*/
TextButton::TextButton() : Button (String())
{
}
TextButton::TextButton (const String& name, const String& toolTip)
: 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();
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()
@@ -61,9 +59,5 @@ Font TextButton::getFont()
void TextButton::changeWidthToFitText (const int newHeight)
{
if (newHeight >= 0)
setSize (jmax (1, getWidth()), newHeight);
setSize (getFont().getStringWidth (getButtonText()) + getHeight(),
getHeight());
getLookAndFeel().changeTextButtonWidthToFitText (*this, newHeight);
}

+ 7
- 7
modules/juce_gui_basics/buttons/juce_TextButton.h View File

@@ -37,17 +37,18 @@ class JUCE_API TextButton : public Button
{
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
initially set to this string, but these can be changed later
using the setName() and setButtonText() methods)
@param toolTip an optional string to use as a toolip
@see Button
*/
TextButton (const String& buttonName = String::empty,
const String& toolTip = String::empty);
explicit TextButton (const String& buttonName,
const String& toolTip = String::empty);
/** Destructor. */
~TextButton();
@@ -74,19 +75,18 @@ public:
//==============================================================================
/** Resizes the button to fit neatly around its current text.
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.
*/
void changeWidthToFitText (int newHeight = -1);
/** 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.
*/
virtual Font getFont();
protected:
//==============================================================================
/** @internal */
void paintButton (Graphics&, bool isMouseOverButton, bool isButtonDown) override;
/** @internal */


+ 10
- 0
modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp View File

@@ -243,6 +243,16 @@ Font LookAndFeel_V2::getTextButtonFont (TextButton& button)
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*/)
{
Font font (getTextButtonFont (button));


+ 1
- 0
modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.h View File

@@ -46,6 +46,7 @@ public:
void drawButtonText (Graphics&, TextButton& button,
bool isMouseOverButton, bool isButtonDown) override;
void changeTextButtonWidthToFitText (TextButton&, int newHeight) override;
void drawToggleButton (Graphics&, ToggleButton& button, bool isMouseOverButton, bool isButtonDown) override;


Loading…
Cancel
Save