JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_HyperlinkButton.cpp
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
30 const URL& linkURL)
31 : Button (linkText),
32 url (linkURL),
33 font (14.0f, Font::underlined),
34 resizeFont (true),
35 justification (Justification::centred)
36{
38 setTooltip (linkURL.toString (false));
39}
40
42 : Button (String()),
43 font (14.0f, Font::underlined),
44 resizeFont (true),
45 justification (Justification::centred)
46{
48}
49
53
54//==============================================================================
58{
59 font = newFont;
61 justification = justificationType;
62 repaint();
63}
64
65void HyperlinkButton::setURL (const URL& newURL) noexcept
66{
67 url = newURL;
68 setTooltip (newURL.toString (false));
69}
70
71Font HyperlinkButton::getFontToUse() const
72{
73 if (resizeFont)
74 return font.withHeight ((float) getHeight() * 0.7f);
75
76 return font;
77}
78
80{
81 setSize (getFontToUse().getStringWidth (getButtonText()) + 6, getHeight());
82}
83
85{
86 if (justification != newJustification)
87 {
88 justification = newJustification;
89 repaint();
90 }
91}
92
97
98//==============================================================================
100{
101 if (url.isWellFormed())
103}
104
108{
110
111 if (isEnabled())
113 : textColour);
114 else
115 g.setColour (textColour.withMultipliedAlpha (0.4f));
116
117 g.setFont (getFontToUse());
118
121 true);
122}
123
125{
126 return std::make_unique<detail::ButtonAccessibilityHandler> (*this, AccessibilityRole::hyperlink);
127}
128
129} // namespace juce
A base class for buttons.
Definition juce_Button.h:43
const String & getButtonText() const
Returns the text displayed in the button.
Definition juce_Button.h:67
void setTooltip(const String &newTooltip) override
Sets the tooltip for this button.
Represents a colour, also including a transparency value.
Definition juce_Colour.h:38
int getHeight() const noexcept
Returns the component's height in pixels.
void setMouseCursor(const MouseCursor &cursorType)
Changes the mouse cursor shape to use when the mouse is over this component.
void repaint()
Marks the whole component as needing to be redrawn.
void setSize(int newWidth, int newHeight)
Changes the size of the component.
Colour findColour(int colourID, bool inheritFromParent=false) const
Looks for a colour that has been registered with the given colour ID number.
bool isEnabled() const noexcept
Returns true if the component (and all its parents) are enabled.
Rectangle< int > getLocalBounds() const noexcept
Returns the component's bounds, relative to its own origin.
Represents a particular font, including its size, style, etc.
Definition juce_Font.h:42
Font withHeight(float height) const
Returns a copy of this font with a new height.
A graphics context, used for drawing a component or image.
void drawText(const String &text, int x, int y, int width, int height, Justification justificationType, bool useEllipsesIfTooBig=true) const
Draws a line of text within a specified rectangle.
void setFont(const Font &newFont)
Changes the font to use for subsequent text-drawing functions.
void setColour(Colour newColour)
Changes the current drawing colour.
~HyperlinkButton() override
Destructor.
void setJustificationType(Justification justification)
Sets the style of justification to be used for positioning the text.
void setURL(const URL &newURL) noexcept
Changes the URL that the button will trigger.
void clicked() override
This method is called when the button has been clicked.
void colourChanged() override
This method is called when a colour is changed by the setColour() method, or when the look-and-feel i...
void setFont(const Font &newFont, bool resizeToMatchComponentHeight, Justification justificationType=Justification::horizontallyCentred)
Changes the font to use for the text.
std::unique_ptr< AccessibilityHandler > createAccessibilityHandler() override
Override this method to return a custom AccessibilityHandler for this component.
@ textColourId
The colour to use for the URL text.
void changeWidthToFitText()
Resizes the button horizontally to fit snugly around the text.
void paintButton(Graphics &, bool, bool) override
Subclasses should override this to actually paint the button's contents.
HyperlinkButton()
Creates a HyperlinkButton.
Represents a type of justification to be used when positioning graphical items.
@ verticallyCentred
Indicates that the item should be placed in the centre between the top and bottom sides of the availa...
int getOnlyHorizontalFlags() const noexcept
Returns just the flags from this object that deal with horizontal layout.
@ PointingHandCursor
A hand with a pointing finger, for clicking on web-links.
Rectangle reduced(ValueType deltaX, ValueType deltaY) const noexcept
Returns a rectangle that is smaller than this one by a given amount.
The JUCE String class!
Definition juce_String.h:53
Represents a URL and has a bunch of useful functions to manipulate it.
Definition juce_URL.h:38
bool isWellFormed() const
True if it seems to be valid.
Definition juce_URL.cpp:332
bool launchInDefaultBrowser() const
Tries to launch the system's default browser to open the URL.
Definition juce_URL.cpp:993
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88