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_Label.h
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
29//==============================================================================
36class JUCE_API Label : public Component,
38 protected TextEditor::Listener,
39 private ComponentListener,
40 private Value::Listener
41{
42public:
43 //==============================================================================
49 Label (const String& componentName = String(),
50 const String& labelText = String());
51
53 ~Label() override;
54
55 //==============================================================================
61 void setText (const String& newText,
62 NotificationType notification);
63
73 String getText (bool returnActiveEditorContents = false) const;
74
79 Value& getTextValue() noexcept { return textValue; }
80
81 //==============================================================================
85 void setFont (const Font& newFont);
86
91 Font getFont() const noexcept;
92
93 //==============================================================================
105 {
106 backgroundColourId = 0x1000280,
107 textColourId = 0x1000281,
108 outlineColourId = 0x1000282,
110 backgroundWhenEditingColourId = 0x1000283,
111 textWhenEditingColourId = 0x1000284,
112 outlineWhenEditingColourId = 0x1000285
113 };
114
115 //==============================================================================
119 void setJustificationType (Justification justification);
120
122 Justification getJustificationType() const noexcept { return justification; }
123
128 void setBorderSize (BorderSize<int> newBorderSize);
129
131 BorderSize<int> getBorderSize() const noexcept { return border; }
132
142 void attachToComponent (Component* owner, bool onLeft);
143
149 Component* getAttachedComponent() const;
150
156 bool isAttachedOnLeft() const noexcept { return leftOfOwnerComp; }
157
163 void setMinimumHorizontalScale (float newScale);
164
166 float getMinimumHorizontalScale() const noexcept { return minimumHorizontalScale; }
167
169 void setKeyboardType (TextInputTarget::VirtualKeyboardType type) noexcept { keyboardType = type; }
170
171 //==============================================================================
182 class JUCE_API Listener
183 {
184 public:
186 virtual ~Listener() = default;
187
189 virtual void labelTextChanged (Label* labelThatHasChanged) = 0;
190
192 virtual void editorShown (Label*, TextEditor&) {}
193
195 virtual void editorHidden (Label*, TextEditor&) {}
196 };
197
199 void addListener (Listener* listener);
200
202 void removeListener (Listener* listener);
203
204 //==============================================================================
207
210
213
214 //==============================================================================
235 void setEditable (bool editOnSingleClick,
236 bool editOnDoubleClick = false,
237 bool lossOfFocusDiscardsChanges = false);
238
240 bool isEditableOnSingleClick() const noexcept { return editSingleClick; }
241
243 bool isEditableOnDoubleClick() const noexcept { return editDoubleClick; }
244
246 bool doesLossOfFocusDiscardChanges() const noexcept { return lossOfFocusDiscardsChanges; }
247
249 bool isEditable() const noexcept { return editSingleClick || editDoubleClick; }
250
254 void showEditor();
255
264 void hideEditor (bool discardCurrentEditorContents);
265
267 bool isBeingEdited() const noexcept;
268
270 TextEditor* getCurrentTextEditor() const noexcept;
271
272 //==============================================================================
276 struct JUCE_API LookAndFeelMethods
277 {
278 virtual ~LookAndFeelMethods() = default;
279
280 virtual void drawLabel (Graphics&, Label&) = 0;
281 virtual Font getLabelFont (Label&) = 0;
282 virtual BorderSize<int> getLabelBorderSize (Label&) = 0;
283 };
284
286 std::unique_ptr<AccessibilityHandler> createAccessibilityHandler() override;
287
288protected:
289 //==============================================================================
293 virtual TextEditor* createEditorComponent();
294
296 virtual void textWasEdited();
297
299 virtual void textWasChanged();
300
302 virtual void editorShown (TextEditor*);
303
305 virtual void editorAboutToBeHidden (TextEditor*);
306
307 //==============================================================================
309 void paint (Graphics&) override;
311 void resized() override;
313 void mouseUp (const MouseEvent&) override;
315 void mouseDoubleClick (const MouseEvent&) override;
317 void componentMovedOrResized (Component&, bool wasMoved, bool wasResized) override;
319 void componentParentHierarchyChanged (Component&) override;
321 void componentVisibilityChanged (Component&) override;
323 void inputAttemptWhenModal() override;
325 void focusGained (FocusChangeType) override;
327 void enablementChanged() override;
329 std::unique_ptr<ComponentTraverser> createKeyboardFocusTraverser() override;
331 void textEditorTextChanged (TextEditor&) override;
333 void textEditorReturnKeyPressed (TextEditor&) override;
335 void textEditorEscapeKeyPressed (TextEditor&) override;
337 void textEditorFocusLost (TextEditor&) override;
339 void colourChanged() override;
341 void valueChanged (Value&) override;
343 void callChangeListeners();
344
345private:
346 //==============================================================================
347 Value textValue;
348 String lastTextValue;
349 Font font { 15.0f };
350 Justification justification = Justification::centredLeft;
352 ListenerList<Listener> listeners;
353 WeakReference<Component> ownerComponent;
354 BorderSize<int> border { 1, 5, 1, 5 };
355 float minimumHorizontalScale = 0;
356 TextInputTarget::VirtualKeyboardType keyboardType = TextInputTarget::textKeyboard;
357 bool editSingleClick = false;
358 bool editDoubleClick = false;
359 bool lossOfFocusDiscardsChanges = false;
360 bool leftOfOwnerComp = false;
361
362 bool updateFromTextEditorContents (TextEditor&);
363
365};
366
367
368} // namespace juce
Specifies a set of gaps to be left around the sides of a rectangle.
Gets informed about changes to a component's hierarchy or position.
The base class for all JUCE user-interface objects.
FocusChangeType
Enumeration used by the focusGained() and focusLost() methods.
Represents a particular font, including its size, style, etc.
Definition juce_Font.h:42
A graphics context, used for drawing a component or image.
Represents a type of justification to be used when positioning graphical items.
A class for receiving events from a Label.
Definition juce_Label.h:183
virtual void labelTextChanged(Label *labelThatHasChanged)=0
Called when a Label's text has changed.
virtual void editorShown(Label *, TextEditor &)
Called when a Label goes into editing mode and displays a TextEditor.
Definition juce_Label.h:192
virtual void editorHidden(Label *, TextEditor &)
Called when a Label is about to delete its TextEditor and exit editing mode.
Definition juce_Label.h:195
virtual ~Listener()=default
Destructor.
A component that displays a text string, and can optionally become a text editor when clicked.
Definition juce_Label.h:41
bool isEditableOnDoubleClick() const noexcept
Returns true if this option was set using setEditable().
Definition juce_Label.h:243
std::function< void()> onTextChange
You can assign a lambda to this callback object to have it called when the label text is changed.
Definition juce_Label.h:206
ColourIds
A set of colour IDs to use to change the colour of various aspects of the label.
Definition juce_Label.h:105
Value & getTextValue() noexcept
Returns the text content as a Value object.
Definition juce_Label.h:79
bool isEditable() const noexcept
Returns true if the user can edit this label's text.
Definition juce_Label.h:249
BorderSize< int > getBorderSize() const noexcept
Returns the size of the border to be left around the text.
Definition juce_Label.h:131
Justification getJustificationType() const noexcept
Returns the type of justification, as set in setJustificationType().
Definition juce_Label.h:122
bool doesLossOfFocusDiscardChanges() const noexcept
Returns true if this option has been set in a call to setEditable().
Definition juce_Label.h:246
std::function< void()> onEditorShow
You can assign a lambda to this callback object to have it called when the label's editor is shown.
Definition juce_Label.h:209
bool isEditableOnSingleClick() const noexcept
Returns true if this option was set using setEditable().
Definition juce_Label.h:240
float getMinimumHorizontalScale() const noexcept
Specifies the amount that the font can be squashed horizontally.
Definition juce_Label.h:166
std::function< void()> onEditorHide
You can assign a lambda to this callback object to have it called when the label's editor is hidden.
Definition juce_Label.h:212
bool isAttachedOnLeft() const noexcept
If the label is attached to the left of another component, this returns true.
Definition juce_Label.h:156
void setKeyboardType(TextInputTarget::VirtualKeyboardType type) noexcept
Set a keyboard type for use when the text editor is shown.
Definition juce_Label.h:169
Holds a set of objects and can invoke a member function callback on each object in the set with a sin...
Contains position and status information about a mouse event.
An implementation of TooltipClient that stores the tooltip string and a method for changing it.
The JUCE String class!
Definition juce_String.h:53
Receives callbacks from a TextEditor component when it changes.
An editable text box.
VirtualKeyboardType
A set of possible on-screen keyboard types, for use in the getKeyboardType() method.
Receives callbacks when a Value object changes.
Definition juce_Value.h:139
Represents a shared variant value.
Definition juce_Value.h:51
This class acts as a pointer which will automatically become null if the object to which it points is...
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and JUCE_LEAK_DETECTOR macro for ...
JUCE Namespace.
@ valueChanged
Indicates that the UI element's value has changed.
NotificationType
These enums are used in various classes to indicate whether a notification event should be sent out.
This abstract base class is implemented by LookAndFeel classes to provide label drawing functionality...
Definition juce_Label.h:277