2 ==============================================================================
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
7 JUCE is an open source library subject to commercial or open-source
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
23 ==============================================================================
29 HyperlinkButton::HyperlinkButton (const String
& linkText
,
33 font (14.0f
, Font::underlined
),
35 justification (Justification::centred
)
37 setMouseCursor (MouseCursor::PointingHandCursor
);
38 setTooltip (linkURL
.toString (false));
41 HyperlinkButton::HyperlinkButton()
43 font (14.0f
, Font::underlined
),
45 justification (Justification::centred
)
47 setMouseCursor (MouseCursor::PointingHandCursor
);
50 HyperlinkButton::~HyperlinkButton()
54 //==============================================================================
55 void HyperlinkButton::setFont (const Font
& newFont
,
56 const bool resizeToMatchComponentHeight
,
57 Justification justificationType
)
60 resizeFont
= resizeToMatchComponentHeight
;
61 justification
= justificationType
;
65 void HyperlinkButton::setURL (const URL
& newURL
) noexcept
68 setTooltip (newURL
.toString (false));
71 Font
HyperlinkButton::getFontToUse() const
74 return font
.withHeight ((float) getHeight() * 0.7f
);
79 void HyperlinkButton::changeWidthToFitText()
81 setSize (getFontToUse().getStringWidth (getButtonText()) + 6, getHeight());
84 void HyperlinkButton::setJustificationType (Justification newJustification
)
86 if (justification
!= newJustification
)
88 justification
= newJustification
;
93 void HyperlinkButton::colourChanged()
98 //==============================================================================
99 void HyperlinkButton::clicked()
101 if (url
.isWellFormed())
102 url
.launchInDefaultBrowser();
105 void HyperlinkButton::paintButton (Graphics
& g
,
106 bool shouldDrawButtonAsHighlighted
,
107 bool shouldDrawButtonAsDown
)
109 const Colour
textColour (findColour (textColourId
));
112 g
.setColour ((shouldDrawButtonAsHighlighted
) ? textColour
.darker ((shouldDrawButtonAsDown
) ? 1.3f
: 0.4f
)
115 g
.setColour (textColour
.withMultipliedAlpha (0.4f
));
117 g
.setFont (getFontToUse());
119 g
.drawText (getButtonText(), getLocalBounds().reduced (1, 0),
120 justification
.getOnlyHorizontalFlags() | Justification::verticallyCentred
,