mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
LookAndFeel: Allow specifying a default typeface metrics kind to use
This commit is contained in:
parent
fa81badb30
commit
4533077b75
26 changed files with 82 additions and 60 deletions
|
|
@ -184,6 +184,19 @@ public:
|
|||
*/
|
||||
virtual Typeface::Ptr getTypefaceForFont (const Font&);
|
||||
|
||||
/** Widgets can call this to find out the kind of metrics they should use when creating their
|
||||
own fonts.
|
||||
|
||||
The default implementation returns the legacy metrics kind, but you can override this if
|
||||
you want to use the portable metrics kind instead. Using portable metrics may cause text
|
||||
to render at a different size, so you should check that text in your app still renders at an
|
||||
appropriate size, and potentially adjust font sizes where necessary after overriding this.
|
||||
*/
|
||||
virtual TypefaceMetricsKind getDefaultMetricsKind() const { return TypefaceMetricsKind::legacy; }
|
||||
|
||||
/** Returns a copy of the FontOptions with the LookAndFeel's default metrics kind set. */
|
||||
FontOptions withDefaultMetrics (FontOptions opt) const { return opt.withMetricsKind (getDefaultMetricsKind()); }
|
||||
|
||||
/** Allows you to supply a default typeface that will be returned as the default
|
||||
sans-serif font.
|
||||
|
||||
|
|
|
|||
|
|
@ -371,7 +371,7 @@ void LookAndFeel_V1::drawComboBox (Graphics& g, int width, int height,
|
|||
|
||||
Font LookAndFeel_V1::getComboBoxFont (ComboBox& box)
|
||||
{
|
||||
Font f (FontOptions { jmin (15.0f, (float) box.getHeight() * 0.85f) });
|
||||
Font f (withDefaultMetrics (FontOptions { jmin (15.0f, (float) box.getHeight() * 0.85f) }));
|
||||
f.setHorizontalScale (0.9f);
|
||||
return f;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -260,7 +260,7 @@ void LookAndFeel_V2::drawButtonBackground (Graphics& g,
|
|||
|
||||
Font LookAndFeel_V2::getTextButtonFont (TextButton&, int buttonHeight)
|
||||
{
|
||||
return FontOptions (jmin (15.0f, (float) buttonHeight * 0.6f));
|
||||
return withDefaultMetrics (FontOptions (jmin (15.0f, (float) buttonHeight * 0.6f)));
|
||||
}
|
||||
|
||||
int LookAndFeel_V2::getTextButtonWidthToFitText (TextButton& b, int buttonHeight)
|
||||
|
|
@ -359,7 +359,7 @@ void LookAndFeel_V2::changeToggleButtonWidthToFitText (ToggleButton& button)
|
|||
auto fontSize = jmin (15.0f, (float) button.getHeight() * 0.75f);
|
||||
auto tickWidth = fontSize * 1.1f;
|
||||
|
||||
Font font (FontOptions { fontSize });
|
||||
Font font (withDefaultMetrics (FontOptions { fontSize }));
|
||||
|
||||
button.setSize (font.getStringWidth (button.getButtonText()) + roundToInt (tickWidth) + 9,
|
||||
button.getHeight());
|
||||
|
|
@ -471,7 +471,7 @@ void LookAndFeel_V2::drawAlertBox (Graphics& g, AlertWindow& alert,
|
|||
}
|
||||
|
||||
GlyphArrangement ga;
|
||||
ga.addFittedText (FontOptions ((float) iconRect.getHeight() * 0.9f, Font::bold),
|
||||
ga.addFittedText (withDefaultMetrics (FontOptions ((float) iconRect.getHeight() * 0.9f, Font::bold)),
|
||||
String::charToString ((juce_wchar) (uint8) character),
|
||||
(float) iconRect.getX(), (float) iconRect.getY(),
|
||||
(float) iconRect.getWidth(), (float) iconRect.getHeight(),
|
||||
|
|
@ -528,12 +528,12 @@ Font LookAndFeel_V2::getAlertWindowTitleFont()
|
|||
|
||||
Font LookAndFeel_V2::getAlertWindowMessageFont()
|
||||
{
|
||||
return FontOptions (15.0f);
|
||||
return withDefaultMetrics (FontOptions (15.0f));
|
||||
}
|
||||
|
||||
Font LookAndFeel_V2::getAlertWindowFont()
|
||||
{
|
||||
return FontOptions (12.0f);
|
||||
return withDefaultMetrics (FontOptions (12.0f));
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -864,7 +864,7 @@ void LookAndFeel_V2::setComponentEffectForBubbleComponent (BubbleComponent& bubb
|
|||
//==============================================================================
|
||||
Font LookAndFeel_V2::getPopupMenuFont()
|
||||
{
|
||||
return FontOptions (17.0f);
|
||||
return withDefaultMetrics (FontOptions (17.0f));
|
||||
}
|
||||
|
||||
void LookAndFeel_V2::getIdealPopupMenuItemSize (const String& text, const bool isSeparator,
|
||||
|
|
@ -1112,7 +1112,7 @@ void LookAndFeel_V2::drawMenuBarBackground (Graphics& g, int width, int height,
|
|||
|
||||
Font LookAndFeel_V2::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/)
|
||||
{
|
||||
return FontOptions ((float) menuBar.getHeight() * 0.7f);
|
||||
return withDefaultMetrics (FontOptions ((float) menuBar.getHeight() * 0.7f));
|
||||
}
|
||||
|
||||
int LookAndFeel_V2::getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText)
|
||||
|
|
@ -1264,7 +1264,7 @@ void LookAndFeel_V2::drawComboBox (Graphics& g, int width, int height, const boo
|
|||
|
||||
Font LookAndFeel_V2::getComboBoxFont (ComboBox& box)
|
||||
{
|
||||
return FontOptions (jmin (15.0f, (float) box.getHeight() * 0.85f));
|
||||
return withDefaultMetrics (FontOptions (jmin (15.0f, (float) box.getHeight() * 0.85f)));
|
||||
}
|
||||
|
||||
Label* LookAndFeel_V2::createComboBoxTextBox (ComboBox&)
|
||||
|
|
@ -1645,7 +1645,7 @@ ImageEffectFilter* LookAndFeel_V2::getSliderEffect (Slider&)
|
|||
|
||||
Font LookAndFeel_V2::getSliderPopupFont (Slider&)
|
||||
{
|
||||
return FontOptions (15.0f, Font::bold);
|
||||
return withDefaultMetrics (FontOptions (15.0f, Font::bold));
|
||||
}
|
||||
|
||||
int LookAndFeel_V2::getSliderPopupPlacement (Slider&)
|
||||
|
|
@ -1728,7 +1728,7 @@ Slider::SliderLayout LookAndFeel_V2::getSliderLayout (Slider& slider)
|
|||
//==============================================================================
|
||||
Rectangle<int> LookAndFeel_V2::getTooltipBounds (const String& tipText, Point<int> screenPos, Rectangle<int> parentArea)
|
||||
{
|
||||
const TextLayout tl (detail::LookAndFeelHelpers::layoutTooltipText (tipText, Colours::black));
|
||||
const TextLayout tl (detail::LookAndFeelHelpers::layoutTooltipText (getDefaultMetricsKind(), tipText, Colours::black));
|
||||
|
||||
auto w = (int) (tl.getWidth() + 14.0f);
|
||||
auto h = (int) (tl.getHeight() + 6.0f);
|
||||
|
|
@ -1748,7 +1748,7 @@ void LookAndFeel_V2::drawTooltip (Graphics& g, const String& text, int width, in
|
|||
g.drawRect (0, 0, width, height, 1);
|
||||
#endif
|
||||
|
||||
detail::LookAndFeelHelpers::layoutTooltipText (text, findColour (TooltipWindow::textColourId))
|
||||
detail::LookAndFeelHelpers::layoutTooltipText (getDefaultMetricsKind(), text, findColour (TooltipWindow::textColourId))
|
||||
.draw (g, Rectangle<float> ((float) width, (float) height));
|
||||
}
|
||||
|
||||
|
|
@ -1784,7 +1784,7 @@ void LookAndFeel_V2::drawConcertinaPanelHeader (Graphics& g, const Rectangle<int
|
|||
g.drawRect (area);
|
||||
|
||||
g.setColour (Colours::white);
|
||||
g.setFont (Font (FontOptions { (float) area.getHeight() * 0.7f }).boldened());
|
||||
g.setFont (Font (withDefaultMetrics (FontOptions { (float) area.getHeight() * 0.7f })).boldened());
|
||||
g.drawFittedText (panel.getName(), 4, 0, area.getWidth() - 6, area.getHeight(), Justification::centredLeft, 1);
|
||||
}
|
||||
|
||||
|
|
@ -1884,7 +1884,7 @@ void LookAndFeel_V2::drawDocumentWindowTitleBar (DocumentWindow& window, Graphic
|
|||
window.getBackgroundColour().contrasting (isActive ? 0.15f : 0.05f), (float) h));
|
||||
g.fillAll();
|
||||
|
||||
Font font (FontOptions { (float) h * 0.65f, Font::bold });
|
||||
Font font (withDefaultMetrics (FontOptions { (float) h * 0.65f, Font::bold }));
|
||||
g.setFont (font);
|
||||
|
||||
int textW = font.getStringWidth (window.getName());
|
||||
|
|
@ -2124,7 +2124,7 @@ void LookAndFeel_V2::drawGroupComponentOutline (Graphics& g, int width, int heig
|
|||
const float textEdgeGap = 4.0f;
|
||||
auto cs = 5.0f;
|
||||
|
||||
Font f (FontOptions { textH });
|
||||
Font f (withDefaultMetrics (FontOptions { textH }));
|
||||
|
||||
Path p;
|
||||
auto x = indent;
|
||||
|
|
@ -2190,7 +2190,7 @@ int LookAndFeel_V2::getTabButtonSpaceAroundImage()
|
|||
|
||||
int LookAndFeel_V2::getTabButtonBestWidth (TabBarButton& button, int tabDepth)
|
||||
{
|
||||
int width = Font (FontOptions { (float) tabDepth * 0.6f }).getStringWidth (button.getButtonText().trim())
|
||||
int width = Font (withDefaultMetrics (FontOptions { (float) tabDepth * 0.6f })).getStringWidth (button.getButtonText().trim())
|
||||
+ getTabButtonOverlap (tabDepth) * 2;
|
||||
|
||||
if (auto* extraComponent = button.getExtraComponent())
|
||||
|
|
@ -2312,7 +2312,7 @@ void LookAndFeel_V2::fillTabButtonShape (TabBarButton& button, Graphics& g, cons
|
|||
|
||||
Font LookAndFeel_V2::getTabButtonFont (TabBarButton&, float height)
|
||||
{
|
||||
return FontOptions { height * 0.6f };
|
||||
return withDefaultMetrics (FontOptions { height * 0.6f });
|
||||
}
|
||||
|
||||
void LookAndFeel_V2::drawTabButtonText (TabBarButton& button, Graphics& g, bool isMouseOver, bool isMouseDown)
|
||||
|
|
@ -2515,7 +2515,7 @@ void LookAndFeel_V2::drawTableHeaderColumn (Graphics& g, TableHeaderComponent& h
|
|||
}
|
||||
|
||||
g.setColour (header.findColour (TableHeaderComponent::textColourId));
|
||||
g.setFont (FontOptions ((float) height * 0.5f, Font::bold));
|
||||
g.setFont (withDefaultMetrics (FontOptions ((float) height * 0.5f, Font::bold)));
|
||||
g.drawFittedText (columnName, area, Justification::centredLeft, 1);
|
||||
}
|
||||
|
||||
|
|
@ -2585,7 +2585,7 @@ void LookAndFeel_V2::drawPropertyPanelSectionHeader (Graphics& g, const String&
|
|||
auto textX = (int) (buttonIndent * 2.0f + buttonSize + 2.0f);
|
||||
|
||||
g.setColour (Colours::black);
|
||||
g.setFont (FontOptions ((float) height * 0.7f, Font::bold));
|
||||
g.setFont (withDefaultMetrics (FontOptions ((float) height * 0.7f, Font::bold)));
|
||||
g.drawText (name, textX, 0, width - textX - 4, height, Justification::centredLeft, true);
|
||||
}
|
||||
|
||||
|
|
@ -2660,8 +2660,8 @@ AttributedString LookAndFeel_V2::createFileChooserHeaderText (const String& titl
|
|||
s.setJustification (Justification::centred);
|
||||
|
||||
auto colour = findColour (FileChooserDialogBox::titleTextColourId);
|
||||
s.append (title + "\n\n", FontOptions (17.0f, Font::bold), colour);
|
||||
s.append (instructions, FontOptions (14.0f), colour);
|
||||
s.append (title + "\n\n", withDefaultMetrics (FontOptions (17.0f, Font::bold)), colour);
|
||||
s.append (instructions, withDefaultMetrics (FontOptions (14.0f)), colour);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
|
@ -2950,7 +2950,7 @@ void LookAndFeel_V2::drawKeymapChangeButton (Graphics& g, int width, int height,
|
|||
//==============================================================================
|
||||
Font LookAndFeel_V2::getSidePanelTitleFont (SidePanel&)
|
||||
{
|
||||
return FontOptions (18.0f);
|
||||
return withDefaultMetrics (FontOptions (18.0f));
|
||||
}
|
||||
|
||||
Justification LookAndFeel_V2::getSidePanelTitleJustification (SidePanel& panel)
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ void LookAndFeel_V3::drawConcertinaPanelHeader (Graphics& g, const Rectangle<int
|
|||
g.fillRect (area.withTop (area.getBottom() - 1));
|
||||
|
||||
g.setColour (bkg.contrasting());
|
||||
g.setFont (Font (FontOptions { (float) area.getHeight() * 0.6f }).boldened());
|
||||
g.setFont (Font (withDefaultMetrics (FontOptions { (float) area.getHeight() * 0.6f })).boldened());
|
||||
g.drawFittedText (panel.getName(), 4, 0, area.getWidth() - 6, area.getHeight(), Justification::centredLeft, 1);
|
||||
}
|
||||
|
||||
|
|
@ -187,7 +187,7 @@ int LookAndFeel_V3::getTabButtonSpaceAroundImage() { return 0
|
|||
void LookAndFeel_V3::createTabTextLayout (const TabBarButton& button, float length, float depth,
|
||||
Colour colour, TextLayout& textLayout)
|
||||
{
|
||||
Font font (FontOptions { depth * 0.5f });
|
||||
Font font (button.withDefaultMetrics (FontOptions { depth * 0.5f }));
|
||||
font.setUnderline (button.hasKeyboardFocus (false));
|
||||
|
||||
AttributedString s;
|
||||
|
|
|
|||
|
|
@ -244,7 +244,7 @@ void LookAndFeel_V4::drawDocumentWindowTitleBar (DocumentWindow& window, Graphic
|
|||
g.setColour (getCurrentColourScheme().getUIColour (ColourScheme::widgetBackground));
|
||||
g.fillAll();
|
||||
|
||||
Font font (FontOptions { (float) h * 0.65f, Font::plain });
|
||||
Font font (withDefaultMetrics (FontOptions { (float) h * 0.65f, Font::plain }));
|
||||
g.setFont (font);
|
||||
|
||||
auto textW = font.getStringWidth (window.getName());
|
||||
|
|
@ -284,7 +284,7 @@ void LookAndFeel_V4::drawDocumentWindowTitleBar (DocumentWindow& window, Graphic
|
|||
//==============================================================================
|
||||
Font LookAndFeel_V4::getTextButtonFont (TextButton&, int buttonHeight)
|
||||
{
|
||||
return FontOptions { jmin (16.0f, (float) buttonHeight * 0.6f) };
|
||||
return withDefaultMetrics (FontOptions { jmin (16.0f, (float) buttonHeight * 0.6f) });
|
||||
}
|
||||
|
||||
void LookAndFeel_V4::drawButtonBackground (Graphics& g,
|
||||
|
|
@ -384,7 +384,7 @@ void LookAndFeel_V4::changeToggleButtonWidthToFitText (ToggleButton& button)
|
|||
auto fontSize = jmin (15.0f, (float) button.getHeight() * 0.75f);
|
||||
auto tickWidth = fontSize * 1.1f;
|
||||
|
||||
Font font (FontOptions { fontSize });
|
||||
Font font (withDefaultMetrics (FontOptions { fontSize }));
|
||||
|
||||
button.setSize (font.getStringWidth (button.getButtonText()) + roundToInt (tickWidth) + 14, button.getHeight());
|
||||
}
|
||||
|
|
@ -462,7 +462,7 @@ void LookAndFeel_V4::drawAlertBox (Graphics& g, AlertWindow& alert,
|
|||
}
|
||||
|
||||
GlyphArrangement ga;
|
||||
ga.addFittedText (FontOptions { (float) iconRect.getHeight() * 0.9f, Font::bold },
|
||||
ga.addFittedText (withDefaultMetrics (FontOptions { (float) iconRect.getHeight() * 0.9f, Font::bold }),
|
||||
String::charToString ((juce_wchar) (uint8) character),
|
||||
static_cast<float> (iconRect.getX()), static_cast<float> (iconRect.getY()),
|
||||
static_cast<float> (iconRect.getWidth()), static_cast<float> (iconRect.getHeight()),
|
||||
|
|
@ -485,9 +485,9 @@ void LookAndFeel_V4::drawAlertBox (Graphics& g, AlertWindow& alert,
|
|||
}
|
||||
|
||||
int LookAndFeel_V4::getAlertWindowButtonHeight() { return 40; }
|
||||
Font LookAndFeel_V4::getAlertWindowTitleFont() { return FontOptions { 18.0f, Font::bold }; }
|
||||
Font LookAndFeel_V4::getAlertWindowMessageFont() { return FontOptions { 16.0f }; }
|
||||
Font LookAndFeel_V4::getAlertWindowFont() { return FontOptions { 14.0f }; }
|
||||
Font LookAndFeel_V4::getAlertWindowTitleFont() { return withDefaultMetrics (FontOptions { 18.0f, Font::bold }); }
|
||||
Font LookAndFeel_V4::getAlertWindowMessageFont() { return withDefaultMetrics (FontOptions { 16.0f }); }
|
||||
Font LookAndFeel_V4::getAlertWindowFont() { return withDefaultMetrics (FontOptions { 14.0f }); }
|
||||
|
||||
//==============================================================================
|
||||
void LookAndFeel_V4::drawProgressBar (Graphics& g, ProgressBar& progressBar,
|
||||
|
|
@ -629,7 +629,7 @@ void LookAndFeel_V4::drawCircularProgressBar (Graphics& g, const ProgressBar& pr
|
|||
if (textToShow.isNotEmpty())
|
||||
{
|
||||
g.setColour (progressBar.findColour (TextButton::textColourOffId));
|
||||
g.setFont (FontOptions { 12.0f, Font::italic });
|
||||
g.setFont (progressBar.withDefaultMetrics (FontOptions { 12.0f, Font::italic }));
|
||||
g.drawText (textToShow, barBounds, Justification::centred, false);
|
||||
}
|
||||
}
|
||||
|
|
@ -950,7 +950,7 @@ void LookAndFeel_V4::drawComboBox (Graphics& g, int width, int height, bool,
|
|||
|
||||
Font LookAndFeel_V4::getComboBoxFont (ComboBox& box)
|
||||
{
|
||||
return FontOptions { jmin (16.0f, (float) box.getHeight() * 0.85f) };
|
||||
return withDefaultMetrics (FontOptions { jmin (16.0f, (float) box.getHeight() * 0.85f) });
|
||||
}
|
||||
|
||||
void LookAndFeel_V4::positionComboBoxText (ComboBox& box, Label& label)
|
||||
|
|
@ -1162,7 +1162,7 @@ void LookAndFeel_V4::drawTooltip (Graphics& g, const String& text, int width, in
|
|||
g.setColour (findColour (TooltipWindow::outlineColourId));
|
||||
g.drawRoundedRectangle (bounds.toFloat().reduced (0.5f, 0.5f), cornerSize, 1.0f);
|
||||
|
||||
detail::LookAndFeelHelpers::layoutTooltipText (text, findColour (TooltipWindow::textColourId))
|
||||
detail::LookAndFeelHelpers::layoutTooltipText (getDefaultMetricsKind(), text, findColour (TooltipWindow::textColourId))
|
||||
.draw (g, { static_cast<float> (width), static_cast<float> (height) });
|
||||
}
|
||||
|
||||
|
|
@ -1268,7 +1268,7 @@ void LookAndFeel_V4::drawPropertyPanelSectionHeader (Graphics& g, const String&
|
|||
|
||||
g.setColour (findColour (PropertyComponent::labelTextColourId));
|
||||
|
||||
g.setFont (FontOptions { (float) height * 0.7f, Font::bold });
|
||||
g.setFont (withDefaultMetrics (FontOptions { (float) height * 0.7f, Font::bold }));
|
||||
g.drawText (name, textX, 0, width - textX - 4, height, Justification::centredLeft, true);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue