From a4d43c16e300b5c38535efac3ca4dcd8ceab526c Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 4 Aug 2020 09:28:42 +0100 Subject: [PATCH] Added an underline toggle to FontsDemo --- examples/GUI/FontsDemo.h | 30 ++++++++++++++++--------- modules/juce_graphics/fonts/juce_Font.h | 2 -- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/examples/GUI/FontsDemo.h b/examples/GUI/FontsDemo.h index 35785ba7dc..60053be609 100644 --- a/examples/GUI/FontsDemo.h +++ b/examples/GUI/FontsDemo.h @@ -70,6 +70,7 @@ public: addAndMakeVisible (scaleSlider); addAndMakeVisible (boldToggle); addAndMakeVisible (italicToggle); + addAndMakeVisible (underlineToggle); addAndMakeVisible (styleBox); addAndMakeVisible (horizontalJustificationBox); addAndMakeVisible (verticalJustificationBox); @@ -86,9 +87,10 @@ public: kerningSlider.addListener (this); scaleSlider .addListener (this); - boldToggle .onClick = [this] { refreshPreviewBoxFont(); }; - italicToggle.onClick = [this] { refreshPreviewBoxFont(); }; - styleBox .onChange = [this] { refreshPreviewBoxFont(); }; + boldToggle .onClick = [this] { refreshPreviewBoxFont(); }; + italicToggle .onClick = [this] { refreshPreviewBoxFont(); }; + underlineToggle.onClick = [this] { refreshPreviewBoxFont(); }; + styleBox .onChange = [this] { refreshPreviewBoxFont(); }; Font::findFonts (fonts); // Generate the list of fonts @@ -130,6 +132,8 @@ public: demoTextBox.setColour (TextEditor::textColourId, Colours::black); demoTextBox.setColour (TextEditor::backgroundColourId, Colours::white); + demoTextBox.setWhitespaceUnderlined (false); + resetButton.onClick = [this] { resetToDefaultParameters(); }; setupJustificationOptions(); @@ -171,8 +175,10 @@ public: auto row = r.removeFromBottom (30); row.removeFromLeft (labelWidth); - boldToggle.setBounds (row.removeFromLeft (row.getWidth() / 2)); - italicToggle.setBounds (row); + auto toggleWidth = row.getWidth() / 3; + boldToggle .setBounds (row.removeFromLeft (toggleWidth)); + italicToggle .setBounds (row.removeFromLeft (toggleWidth)); + underlineToggle.setBounds (row); r.removeFromBottom (8); horizontalJustificationBox.setBounds (r.removeFromBottom (30).withTrimmedLeft (labelWidth * 3)); @@ -231,7 +237,7 @@ private: TextEditor demoTextBox; const double defaultScale = 1.0, defaultHeight = 20.0, defaultKerning = 0.0; - const bool defaultBold = false, defaultItalic = false; + const bool defaultBold = false, defaultItalic = false, defaultUnderlined = false; const int defaultStyle = 0, defaultHorizontalJustification = 0, defaultVerticalJustification = 0; Label heightLabel { {}, "Height:" }, @@ -241,8 +247,9 @@ private: horizontalJustificationLabel { {}, "Justification (horizontal):" }, verticalJustificationLabel { {}, "Justification (vertical):" }; - ToggleButton boldToggle { "Bold" }, - italicToggle { "Italic" }; + ToggleButton boldToggle { "Bold" }, + italicToggle { "Italic" }, + underlineToggle { "Underlined" }; TextButton resetButton { "Reset" }; @@ -265,8 +272,9 @@ private: heightSlider .setValue (defaultHeight); kerningSlider.setValue (defaultKerning); - boldToggle .setToggleState (defaultBold, sendNotificationSync); - italicToggle.setToggleState (defaultItalic, sendNotificationSync); + boldToggle .setToggleState (defaultBold, sendNotificationSync); + italicToggle .setToggleState (defaultItalic, sendNotificationSync); + underlineToggle.setToggleState (defaultUnderlined, sendNotificationSync); styleBox.setSelectedItemIndex (defaultStyle); horizontalJustificationBox.setSelectedItemIndex (defaultHorizontalJustification); @@ -315,6 +323,8 @@ private: if (useStyle) font = font.withTypefaceStyle (styleBox.getText()); + font.setUnderline (underlineToggle.getToggleState()); + demoTextBox.applyFontToAllText (font); } diff --git a/modules/juce_graphics/fonts/juce_Font.h b/modules/juce_graphics/fonts/juce_Font.h index c0d4da6b98..0d72f57b33 100644 --- a/modules/juce_graphics/fonts/juce_Font.h +++ b/modules/juce_graphics/fonts/juce_Font.h @@ -303,7 +303,6 @@ public: /** Returns true if the font is underlined. */ bool isUnderlined() const noexcept; - //============================================================================== /** Returns the font's horizontal scale. A value of 1.0 is the normal scale, less than this will be narrower, greater @@ -464,7 +463,6 @@ public: */ static Font fromString (const String& fontDescription); - private: //============================================================================== class SharedFontInternal;