Browse Source

Implemented changeToggleButtonWidthToFitText() in LookAndFeel_V4 and updated LookAndFeel_V2 to calculate width more accurately

tags/2021-05-28
ed 7 years ago
parent
commit
1af959a423
3 changed files with 16 additions and 3 deletions
  1. +4
    -3
      modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp
  2. +10
    -0
      modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V4.cpp
  3. +2
    -0
      modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V4.h

+ 4
- 3
modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp View File

@@ -367,11 +367,12 @@ void LookAndFeel_V2::drawToggleButton (Graphics& g, ToggleButton& button,
void LookAndFeel_V2::changeToggleButtonWidthToFitText (ToggleButton& button)
{
Font font (jmin (15.0f, button.getHeight() * 0.6f));
auto fontSize = jmin (15.0f, button.getHeight() * 0.75f);
auto tickWidth = fontSize * 1.1f;
const int tickWidth = jmin (24, button.getHeight());
Font font (fontSize);
button.setSize (font.getStringWidth (button.getButtonText()) + tickWidth + 8,
button.setSize (font.getStringWidth (button.getButtonText()) + roundToInt (tickWidth) + 9,
button.getHeight());
}


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

@@ -365,6 +365,16 @@ void LookAndFeel_V4::drawTickBox (Graphics& g, Component& component,
}
}
void LookAndFeel_V4::changeToggleButtonWidthToFitText (ToggleButton& button)
{
auto fontSize = jmin (15.0f, button.getHeight() * 0.75f);
auto tickWidth = fontSize * 1.1f;
Font font (fontSize);
button.setSize (font.getStringWidth (button.getButtonText()) + roundToInt (tickWidth) + 14, button.getHeight());
}
//==============================================================================
AlertWindow* LookAndFeel_V4::createAlertWindow (const String& title, const String& message,
const String& button1, const String& button2, const String& button3,


+ 2
- 0
modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V4.h View File

@@ -113,6 +113,8 @@ public:
float x, float y, float w, float h,
bool ticked, bool isEnabled, bool isMouseOverButton, bool isButtonDown) override;
void changeToggleButtonWidthToFitText (ToggleButton&) override;
//==============================================================================
AlertWindow* createAlertWindow (const String& title, const String& message,
const String& button1,


Loading…
Cancel
Save