1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Added an underline toggle to FontsDemo

This commit is contained in:
ed 2020-08-04 09:28:42 +01:00
parent 508d6de04e
commit a4d43c16e3
2 changed files with 20 additions and 12 deletions

View file

@ -70,6 +70,7 @@ public:
addAndMakeVisible (scaleSlider); addAndMakeVisible (scaleSlider);
addAndMakeVisible (boldToggle); addAndMakeVisible (boldToggle);
addAndMakeVisible (italicToggle); addAndMakeVisible (italicToggle);
addAndMakeVisible (underlineToggle);
addAndMakeVisible (styleBox); addAndMakeVisible (styleBox);
addAndMakeVisible (horizontalJustificationBox); addAndMakeVisible (horizontalJustificationBox);
addAndMakeVisible (verticalJustificationBox); addAndMakeVisible (verticalJustificationBox);
@ -86,9 +87,10 @@ public:
kerningSlider.addListener (this); kerningSlider.addListener (this);
scaleSlider .addListener (this); scaleSlider .addListener (this);
boldToggle .onClick = [this] { refreshPreviewBoxFont(); }; boldToggle .onClick = [this] { refreshPreviewBoxFont(); };
italicToggle.onClick = [this] { refreshPreviewBoxFont(); }; italicToggle .onClick = [this] { refreshPreviewBoxFont(); };
styleBox .onChange = [this] { refreshPreviewBoxFont(); }; underlineToggle.onClick = [this] { refreshPreviewBoxFont(); };
styleBox .onChange = [this] { refreshPreviewBoxFont(); };
Font::findFonts (fonts); // Generate the list of fonts Font::findFonts (fonts); // Generate the list of fonts
@ -130,6 +132,8 @@ public:
demoTextBox.setColour (TextEditor::textColourId, Colours::black); demoTextBox.setColour (TextEditor::textColourId, Colours::black);
demoTextBox.setColour (TextEditor::backgroundColourId, Colours::white); demoTextBox.setColour (TextEditor::backgroundColourId, Colours::white);
demoTextBox.setWhitespaceUnderlined (false);
resetButton.onClick = [this] { resetToDefaultParameters(); }; resetButton.onClick = [this] { resetToDefaultParameters(); };
setupJustificationOptions(); setupJustificationOptions();
@ -171,8 +175,10 @@ public:
auto row = r.removeFromBottom (30); auto row = r.removeFromBottom (30);
row.removeFromLeft (labelWidth); row.removeFromLeft (labelWidth);
boldToggle.setBounds (row.removeFromLeft (row.getWidth() / 2)); auto toggleWidth = row.getWidth() / 3;
italicToggle.setBounds (row); boldToggle .setBounds (row.removeFromLeft (toggleWidth));
italicToggle .setBounds (row.removeFromLeft (toggleWidth));
underlineToggle.setBounds (row);
r.removeFromBottom (8); r.removeFromBottom (8);
horizontalJustificationBox.setBounds (r.removeFromBottom (30).withTrimmedLeft (labelWidth * 3)); horizontalJustificationBox.setBounds (r.removeFromBottom (30).withTrimmedLeft (labelWidth * 3));
@ -231,7 +237,7 @@ private:
TextEditor demoTextBox; TextEditor demoTextBox;
const double defaultScale = 1.0, defaultHeight = 20.0, defaultKerning = 0.0; 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; const int defaultStyle = 0, defaultHorizontalJustification = 0, defaultVerticalJustification = 0;
Label heightLabel { {}, "Height:" }, Label heightLabel { {}, "Height:" },
@ -241,8 +247,9 @@ private:
horizontalJustificationLabel { {}, "Justification (horizontal):" }, horizontalJustificationLabel { {}, "Justification (horizontal):" },
verticalJustificationLabel { {}, "Justification (vertical):" }; verticalJustificationLabel { {}, "Justification (vertical):" };
ToggleButton boldToggle { "Bold" }, ToggleButton boldToggle { "Bold" },
italicToggle { "Italic" }; italicToggle { "Italic" },
underlineToggle { "Underlined" };
TextButton resetButton { "Reset" }; TextButton resetButton { "Reset" };
@ -265,8 +272,9 @@ private:
heightSlider .setValue (defaultHeight); heightSlider .setValue (defaultHeight);
kerningSlider.setValue (defaultKerning); kerningSlider.setValue (defaultKerning);
boldToggle .setToggleState (defaultBold, sendNotificationSync); boldToggle .setToggleState (defaultBold, sendNotificationSync);
italicToggle.setToggleState (defaultItalic, sendNotificationSync); italicToggle .setToggleState (defaultItalic, sendNotificationSync);
underlineToggle.setToggleState (defaultUnderlined, sendNotificationSync);
styleBox.setSelectedItemIndex (defaultStyle); styleBox.setSelectedItemIndex (defaultStyle);
horizontalJustificationBox.setSelectedItemIndex (defaultHorizontalJustification); horizontalJustificationBox.setSelectedItemIndex (defaultHorizontalJustification);
@ -315,6 +323,8 @@ private:
if (useStyle) if (useStyle)
font = font.withTypefaceStyle (styleBox.getText()); font = font.withTypefaceStyle (styleBox.getText());
font.setUnderline (underlineToggle.getToggleState());
demoTextBox.applyFontToAllText (font); demoTextBox.applyFontToAllText (font);
} }

View file

@ -303,7 +303,6 @@ public:
/** Returns true if the font is underlined. */ /** Returns true if the font is underlined. */
bool isUnderlined() const noexcept; bool isUnderlined() const noexcept;
//============================================================================== //==============================================================================
/** Returns the font's horizontal scale. /** Returns the font's horizontal scale.
A value of 1.0 is the normal scale, less than this will be narrower, greater 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); static Font fromString (const String& fontDescription);
private: private:
//============================================================================== //==============================================================================
class SharedFontInternal; class SharedFontInternal;