LMMS
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
80
81 //==============================================================================
85 void setFont (const Font& newFont);
86
91 Font getFont() const noexcept;
92
93 //==============================================================================
114
115 //==============================================================================
119 void setJustificationType (Justification justification);
120
123
128 void setBorderSize (BorderSize<int> newBorderSize);
129
132
142 void attachToComponent (Component* owner, bool onLeft);
143
149 Component* getAttachedComponent() const;
150
157
163 void setMinimumHorizontalScale (float newScale);
164
167
170
171 //==============================================================================
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 //==============================================================================
206 std::function<void()> onTextChange;
207
209 std::function<void()> onEditorShow;
210
212 std::function<void()> onEditorHide;
213
214 //==============================================================================
235 void setEditable (bool editOnSingleClick,
236 bool editOnDoubleClick = false,
237 bool lossOfFocusDiscardsChanges = false);
238
241
244
247
250
254 void showEditor();
255
264 void hideEditor (bool discardCurrentEditorContents);
265
267 bool isBeingEdited() const noexcept;
268
270 TextEditor* getCurrentTextEditor() const noexcept;
271
272 //==============================================================================
277 {
278 virtual ~LookAndFeelMethods() = default;
279
280 virtual void drawLabel (Graphics&, Label&) = 0;
281 virtual Font getLabelFont (Label&) = 0;
283 };
284
285protected:
286 //==============================================================================
291
293 virtual void textWasEdited();
294
296 virtual void textWasChanged();
297
299 virtual void editorShown (TextEditor*);
300
302 virtual void editorAboutToBeHidden (TextEditor*);
303
304 //==============================================================================
306 void paint (Graphics&) override;
308 void resized() override;
310 void mouseUp (const MouseEvent&) override;
312 void mouseDoubleClick (const MouseEvent&) override;
314 void componentMovedOrResized (Component&, bool wasMoved, bool wasResized) override;
318 void componentVisibilityChanged (Component&) override;
320 void inputAttemptWhenModal() override;
322 void focusGained (FocusChangeType) override;
324 void enablementChanged() override;
326 std::unique_ptr<ComponentTraverser> createKeyboardFocusTraverser() override;
328 void textEditorTextChanged (TextEditor&) override;
330 void textEditorReturnKeyPressed (TextEditor&) override;
332 void textEditorEscapeKeyPressed (TextEditor&) override;
334 void textEditorFocusLost (TextEditor&) override;
336 void colourChanged() override;
338 void valueChanged (Value&) override;
340 void callChangeListeners();
341
342private:
343 //==============================================================================
346 Font font { 15.0f };
348 std::unique_ptr<TextEditor> editor;
351 BorderSize<int> border { 1, 5, 1, 5 };
354 bool editSingleClick = false;
355 bool editDoubleClick = false;
357 bool leftOfOwnerComp = false;
358
359 std::unique_ptr<AccessibilityHandler> createAccessibilityHandler() override;
361
363};
364
365
366} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
CAdPlugDatabase::CRecord::RecordType type
Definition adplugdb.cpp:93
Definition juce_BorderSize.h:42
Definition juce_Component.h:36
FocusChangeType
Definition juce_Component.h:1890
String componentName
Definition juce_Component.h:2534
Component() noexcept
Definition juce_Component.cpp:517
Definition juce_ComponentListener.h:43
Definition juce_Font.h:42
Definition juce_GraphicsContext.h:45
Definition juce_Justification.h:41
@ centredLeft
Definition juce_Justification.h:143
Definition juce_Label.h:183
virtual void labelTextChanged(Label *labelThatHasChanged)=0
virtual void editorShown(Label *, TextEditor &)
Definition juce_Label.h:192
virtual void editorHidden(Label *, TextEditor &)
Definition juce_Label.h:195
virtual ~Listener()=default
virtual void editorShown(TextEditor *)
Definition juce_Label.cpp:197
WeakReference< Component > ownerComponent
Definition juce_Label.h:350
virtual TextEditor * createEditorComponent()
Definition juce_Label.cpp:319
virtual void textWasEdited()
Definition juce_Label.cpp:194
bool editDoubleClick
Definition juce_Label.h:355
std::unique_ptr< AccessibilityHandler > createAccessibilityHandler() override
Definition juce_Label.cpp:581
void setEditable(bool editOnSingleClick, bool editOnDoubleClick=false, bool lossOfFocusDiscardsChanges=false)
Definition juce_Label.cpp:100
ListenerList< Listener > listeners
Definition juce_Label.h:349
bool isEditableOnDoubleClick() const noexcept
Definition juce_Label.h:243
std::function< void()> onTextChange
Definition juce_Label.h:206
void callChangeListeners()
Definition juce_Label.cpp:458
void componentMovedOrResized(Component &, bool wasMoved, bool wasResized) override
Definition juce_Label.cpp:160
ColourIds
Definition juce_Label.h:105
@ outlineColourId
Definition juce_Label.h:108
@ outlineWhenEditingColourId
Definition juce_Label.h:112
@ backgroundColourId
Definition juce_Label.h:106
@ textWhenEditingColourId
Definition juce_Label.h:111
@ backgroundWhenEditingColourId
Definition juce_Label.h:110
@ textColourId
Definition juce_Label.h:107
virtual void editorAboutToBeHidden(TextEditor *)
Definition juce_Label.cpp:209
void resized() override
Definition juce_Label.cpp:364
Font font
Definition juce_Label.h:346
Value & getTextValue() noexcept
Definition juce_Label.h:79
bool isEditable() const noexcept
Definition juce_Label.h:249
BorderSize< int > getBorderSize() const noexcept
Definition juce_Label.h:131
void valueChanged(Value &) override
Definition juce_Label.cpp:79
Justification getJustificationType() const noexcept
Definition juce_Label.h:122
void textEditorEscapeKeyPressed(TextEditor &) override
Definition juce_Label.cpp:507
String lastTextValue
Definition juce_Label.h:345
bool doesLossOfFocusDiscardChanges() const noexcept
Definition juce_Label.h:246
void componentParentHierarchyChanged(Component &) override
Definition juce_Label.cpp:182
std::function< void()> onEditorShow
Definition juce_Label.h:209
Label(const String &componentName=String(), const String &labelText=String())
Definition juce_Label.cpp:29
std::unique_ptr< TextEditor > editor
Definition juce_Label.h:348
bool isEditableOnSingleClick() const noexcept
Definition juce_Label.h:240
float getMinimumHorizontalScale() const noexcept
Definition juce_Label.h:166
Justification justification
Definition juce_Label.h:347
bool leftOfOwnerComp
Definition juce_Label.h:357
float minimumHorizontalScale
Definition juce_Label.h:352
bool editSingleClick
Definition juce_Label.h:354
Value textValue
Definition juce_Label.h:344
void mouseUp(const MouseEvent &) override
Definition juce_Label.cpp:343
void textEditorReturnKeyPressed(TextEditor &) override
Definition juce_Label.cpp:487
std::function< void()> onEditorHide
Definition juce_Label.h:212
String getText(bool returnActiveEditorContents=false) const
Definition juce_Label.cpp:72
bool isAttachedOnLeft() const noexcept
Definition juce_Label.h:156
std::unique_ptr< ComponentTraverser > createKeyboardFocusTraverser() override
Definition juce_Label.cpp:449
TextInputTarget::VirtualKeyboardType keyboardType
Definition juce_Label.h:353
bool updateFromTextEditorContents(TextEditor &)
Definition juce_Label.cpp:248
void textEditorTextChanged(TextEditor &) override
Definition juce_Label.cpp:471
bool lossOfFocusDiscardsChanges
Definition juce_Label.h:356
void setKeyboardType(TextInputTarget::VirtualKeyboardType type) noexcept
Definition juce_Label.h:169
void textEditorFocusLost(TextEditor &) override
Definition juce_Label.cpp:518
void mouseDoubleClick(const MouseEvent &) override
Definition juce_Label.cpp:354
void componentVisibilityChanged(Component &) override
Definition juce_Label.cpp:188
BorderSize< int > border
Definition juce_Label.h:351
virtual void textWasChanged()
Definition juce_Label.cpp:195
void enablementChanged() override
Definition juce_Label.cpp:380
void colourChanged() override
Definition juce_Label.cpp:385
void focusGained(FocusChangeType) override
Definition juce_Label.cpp:370
void setText(const String &newText, NotificationType notification)
Definition juce_Label.cpp:52
void inputAttemptWhenModal() override
Definition juce_Label.cpp:297
void paint(Graphics &) override
Definition juce_Label.cpp:338
Definition juce_ListenerList.h:70
Definition juce_MouseEvent.h:39
Definition juce_String.h:53
Definition juce_TextEditor.h:315
Definition juce_TextEditor.h:43
VirtualKeyboardType
Definition juce_TextInputTarget.h:81
@ textKeyboard
Definition juce_TextInputTarget.h:82
Definition juce_Value.h:139
Definition juce_Value.h:51
Definition juce_WeakReference.h:78
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
#define JUCE_API
Definition juce_StandardHeader.h:152
Definition carla_juce.cpp:31
NotificationType
Definition juce_NotificationType.h:32
Definition juce_Label.h:277
virtual ~LookAndFeelMethods()=default
virtual Font getLabelFont(Label &)=0
virtual BorderSize< int > getLabelBorderSize(Label &)=0
virtual void drawLabel(Graphics &, Label &)=0
#define void
Definition unzip.h:396
#define const
Definition zconf.h:137