mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Added changeTextButtonWidthToFitText to the look + feel classes.
This commit is contained in:
parent
87348c4467
commit
dd24e058c7
5 changed files with 31 additions and 24 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
findColour (getToggleState() ? buttonOnColourId : buttonColourId),
|
||||
isMouseOverButton, isButtonDown);
|
||||
|
||||
lf.drawButtonText (g, *this,
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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…
Add table
Add a link
Reference in a new issue