31 textValue (labelText),
32 lastTextValue (labelText)
45 if (ownerComponent !=
nullptr)
46 ownerComponent->removeComponentListener (
this);
56 if (lastTextValue != newText)
58 lastTextValue = newText;
64 if (ownerComponent !=
nullptr)
68 callChangeListeners();
81 if (lastTextValue != textValue.
toString())
101 bool editOnDoubleClick,
102 bool lossOfFocusDiscards)
104 editSingleClick = editOnSingleClick;
105 editDoubleClick = editOnDoubleClick;
106 lossOfFocusDiscardsChanges = lossOfFocusDiscards;
108 const auto isKeybordFocusable = (editOnSingleClick || editOnDoubleClick);
119 if (justification != newJustification)
121 justification = newJustification;
128 if (border != newBorder)
138 return ownerComponent.get();
145 if (ownerComponent !=
nullptr)
146 ownerComponent->removeComponentListener (
this);
148 ownerComponent = owner;
149 leftOfOwnerComp = onLeft;
151 if (ownerComponent !=
nullptr)
154 ownerComponent->addComponentListener (
this);
163 auto f = lf.getLabelFont (*
this);
164 auto borderSize = lf.getLabelBorderSize (*
this);
169 + borderSize.getLeftAndRight(),
176 auto height = borderSize.getTopAndBottom() + 6 +
roundToInt (f.getHeight() + 0.5f);
185 parent->addChildComponent (
this);
221 if (editor ==
nullptr)
224 editor->setSize (10, 10);
226 editor->setText (
getText(),
false);
227 editor->setKeyboardType (keyboardType);
228 editor->addListener (
this);
229 editor->grabKeyboardFocus();
231 if (editor ==
nullptr)
242 editor->grabKeyboardFocus();
246bool Label::updateFromTextEditorContents (
TextEditor& ed)
250 if (textValue.
toString() != newText)
252 lastTextValue = newText;
258 if (ownerComponent !=
nullptr)
269 if (editor !=
nullptr)
277 const bool changed = (! discardCurrentEditorContents)
278 && updateFromTextEditorContents (*outgoingEditor);
279 outgoingEditor.
reset();
281 if (deletionChecker !=
nullptr)
287 if (deletionChecker !=
nullptr)
290 if (changed && deletionChecker !=
nullptr)
291 callChangeListeners();
297 if (editor !=
nullptr)
299 if (lossOfFocusDiscardsChanges)
308 return editor !=
nullptr;
311static void copyColourIfSpecified (
Label& l,
TextEditor& ed,
int colourID,
int targetColourID)
364 if (editor !=
nullptr)
392 minimumHorizontalScale = newScale;
407 if (
auto* container = getKeyboardFocusContainer (parent))
418 if (
auto* container = getKeyboardFocusContainer (parent))
434 Component* getKeyboardFocusContainer (Component* parent)
const
456void Label::callChangeListeners()
459 listeners.callChecked (checker, [
this] (Listener& l) { l.labelTextChanged (
this); });
461 if (checker.shouldBailOut())
470 if (editor !=
nullptr)
476 if (lossOfFocusDiscardsChanges)
486 if (editor !=
nullptr)
491 bool changed = updateFromTextEditorContents (ed);
494 if (changed && deletionChecker !=
nullptr)
498 if (deletionChecker !=
nullptr)
499 callChangeListeners();
506 if (editor !=
nullptr)
510 editor->setText (textValue.
toString(),
false);
526 labelToWrap.
isEditable() ? AccessibilityRole::editableText : AccessibilityRole::label,
527 getAccessibilityActions (labelToWrap),
548 explicit LabelValueInterface (
Label& labelToWrap)
549 : label (labelToWrap)
553 bool isReadOnly()
const override {
return true; }
554 String getCurrentValueAsString()
const override {
return label.getText(); }
555 void setValueAsString (
const String&)
override {}
564 static AccessibilityActions getAccessibilityActions (Label& label)
566 if (label.isEditable())
Base class for accessible Components.
virtual AccessibleState getCurrentState() const
Returns the current state of the UI element.
A value interface that represents a text value.
Represents the state of an accessible UI element.
Specifies a set of gaps to be left around the sides of a rectangle.
A class to keep an eye on a component and check for it being deleted.
bool shouldBailOut() const noexcept
Returns true if either of the two components have been deleted since this object was created.
The base class for all JUCE user-interface objects.
bool contains(Point< int > localPoint)
Returns true if a given point lies within this component or one of its children.
bool isColourSpecified(int colourID) const
Returns true if the specified colour ID has been explicitly set for this component using the setColou...
void copyAllExplicitColoursTo(Component &target) const
This looks for any colours that have been specified for this component, and copies them to the specif...
bool isVisible() const noexcept
Tests whether the component is visible or not.
Component * getParentComponent() const noexcept
Returns the component which this component is inside.
void exitModalState(int returnValue=0)
Ends a component's modal state.
void setFocusContainerType(FocusContainerType containerType) noexcept
Sets whether this component is a container for components that can have their focus traversed,...
int getHeight() const noexcept
Returns the component's height in pixels.
int getX() const noexcept
Returns the x coordinate of the component's left edge.
void addAndMakeVisible(Component *child, int zOrder=-1)
Adds a child component to this one, and also makes the child visible if it isn't already.
FocusChangeType
Enumeration used by the focusGained() and focusLost() methods.
@ focusChangedByTabKey
Means that the user pressed the tab key to move the focus.
bool hasKeyboardFocus(bool trueIfChildIsFocused) const
Returns true if this component currently has the keyboard focus.
bool isCurrentlyBlockedByAnotherModalComponent() const
Checks whether there's a modal component somewhere that's stopping this one from receiving messages.
void repaint()
Marks the whole component as needing to be redrawn.
@ none
The component will not act as a focus container.
@ keyboardFocusContainer
The component will act as a top-level component within which keyboard focus is passed around.
int getY() const noexcept
Returns the y coordinate of the top of this component.
void setBounds(int x, int y, int width, int height)
Changes the component's position and size.
void setColour(int colourID, Colour newColour)
Registers a colour to be used for a particular purpose.
void enterModalState(bool takeKeyboardFocus=true, ModalComponentManager::Callback *callback=nullptr, bool deleteWhenDismissed=false)
Puts the component into a modal state.
void setWantsKeyboardFocus(bool wantsFocus) noexcept
Sets a flag to indicate whether this component wants keyboard focus or not.
Colour findColour(int colourID, bool inheritFromParent=false) const
Looks for a colour that has been registered with the given colour ID number.
int getWidth() const noexcept
Returns the component's width in pixels.
bool isEnabled() const noexcept
Returns true if the component (and all its parents) are enabled.
LookAndFeel & getLookAndFeel() const noexcept
Finds the appropriate look-and-feel to use for this component.
Rectangle< int > getLocalBounds() const noexcept
Returns the component's bounds, relative to its own origin.
Component * findKeyboardFocusContainer() const
Returns the keyboard focus container for this component.
virtual void setVisible(bool shouldBeVisible)
Makes the component visible or invisible.
void invalidateAccessibilityHandler()
Invalidates the AccessibilityHandler that is currently being used for this component.
String getName() const noexcept
Returns the name of this component.
Represents a particular font, including its size, style, etc.
A graphics context, used for drawing a component or image.
Represents a type of justification to be used when positioning graphical items.
Controls the order in which keyboard focus moves between components.
Component * getPreviousComponent(Component *current) override
Returns the component that should be given keyboard focus after the specified one when moving "backwa...
std::vector< Component * > getAllComponents(Component *parentComponent) override
Returns all of the components that can receive keyboard focus within the given parent component in tr...
Component * getNextComponent(Component *current) override
Returns the component that should be given keyboard focus after the specified one when moving "forwar...
Component * getDefaultComponent(Component *parentComponent) override
Returns the component that should receive keyboard focus by default within the given parent component...
AccessibleState getCurrentState() const override
Returns the current state of the UI element.
String getTitle() const override
The title of the UI element.
String getHelp() const override
Some help text for the UI element (if required).
Component * getNextComponent(Component *c) override
Returns the component that should be given keyboard focus after the specified one when moving "forwar...
Component * getPreviousComponent(Component *c) override
Returns the component that should be given keyboard focus after the specified one when moving "backwa...
Component * getDefaultComponent(Component *parent) override
Returns the component that should receive keyboard focus by default within the given parent component...
std::vector< Component * > getAllComponents(Component *parent) override
Returns all of the components that can receive keyboard focus within the given parent component in tr...
A class for receiving events from a Label.
virtual void editorShown(Label *, TextEditor &)
Called when a Label goes into editing mode and displays a TextEditor.
virtual void editorHidden(Label *, TextEditor &)
Called when a Label is about to delete its TextEditor and exit editing mode.
A component that displays a text string, and can optionally become a text editor when clicked.
~Label() override
Destructor.
virtual void editorShown(TextEditor *)
Called when the text editor has just appeared, due to a user click or other focus change.
virtual TextEditor * createEditorComponent()
Creates the TextEditor component that will be used when the user has clicked on the label.
virtual void textWasEdited()
Called after the user changes the text.
std::unique_ptr< AccessibilityHandler > createAccessibilityHandler() override
Override this method to return a custom AccessibilityHandler for this component.
void setEditable(bool editOnSingleClick, bool editOnDoubleClick=false, bool lossOfFocusDiscardsChanges=false)
Makes the label turn into a TextEditor when clicked.
void attachToComponent(Component *owner, bool onLeft)
Makes this label "stick to" another component.
Component * getAttachedComponent() const
If this label has been attached to another component using attachToComponent, this returns the other ...
std::function< void()> onTextChange
You can assign a lambda to this callback object to have it called when the label text is changed.
void componentMovedOrResized(Component &, bool wasMoved, bool wasResized) override
Called when the component's position or size changes.
@ outlineWhenEditingColourId
An optional border colour when the label is being edited.
@ textWhenEditingColourId
The colour for the text when the label is being edited.
@ backgroundWhenEditingColourId
The background colour when the label is being edited.
virtual void editorAboutToBeHidden(TextEditor *)
Called when the text editor is going to be deleted, after editing has finished.
void resized() override
Called when this component's size has been changed.
void setFont(const Font &newFont)
Changes the font to use to draw the text.
void hideEditor(bool discardCurrentEditorContents)
Hides the editor if it was being shown.
bool isEditable() const noexcept
Returns true if the user can edit this label's text.
void valueChanged(Value &) override
Called when a Value object is changed.
void textEditorEscapeKeyPressed(TextEditor &) override
Called when the user presses the escape key.
bool isBeingEdited() const noexcept
Returns true if the editor is currently focused and active.
void showEditor()
Makes the editor appear as if the label had been clicked by the user.
void componentParentHierarchyChanged(Component &) override
Called to indicate that the component's parents have changed.
std::function< void()> onEditorShow
You can assign a lambda to this callback object to have it called when the label's editor is shown.
Label(const String &componentName=String(), const String &labelText=String())
Creates a Label.
void mouseUp(const MouseEvent &) override
Called when a mouse button is released.
void textEditorReturnKeyPressed(TextEditor &) override
Called when the user presses the return key.
std::function< void()> onEditorHide
You can assign a lambda to this callback object to have it called when the label's editor is hidden.
String getText(bool returnActiveEditorContents=false) const
Returns the label's current text.
std::unique_ptr< ComponentTraverser > createKeyboardFocusTraverser() override
Creates a ComponentTraverser object to use to determine the logic by which keyboard focus should be p...
void addListener(Listener *listener)
Registers a listener that will be called when the label's text changes.
void textEditorTextChanged(TextEditor &) override
Called when the user changes the text in some way.
void textEditorFocusLost(TextEditor &) override
Called when the text editor loses focus.
void setMinimumHorizontalScale(float newScale)
Specifies the minimum amount that the font can be squashed horizontally before it starts using ellips...
void removeListener(Listener *listener)
Deregisters a previously-registered listener.
Font getFont() const noexcept
Returns the font currently being used.
void mouseDoubleClick(const MouseEvent &) override
Called when a mouse button has been double-clicked on a component.
void componentVisibilityChanged(Component &) override
Called when the component is made visible or invisible.
void setJustificationType(Justification justification)
Sets the style of justification to be used for positioning the text.
virtual void textWasChanged()
Called when the text has been altered.
TextEditor * getCurrentTextEditor() const noexcept
Returns the currently-visible text editor, or nullptr if none is open.
void setBorderSize(BorderSize< int > newBorderSize)
Changes the border that is left between the edge of the component and the text.
void enablementChanged() override
Callback to indicate that this component has been enabled or disabled.
void colourChanged() override
This method is called when a colour is changed by the setColour() method, or when the look-and-feel i...
void focusGained(FocusChangeType) override
Called to indicate that this component has just acquired the keyboard focus.
void setText(const String &newText, NotificationType notification)
Changes the label text.
void inputAttemptWhenModal() override
Called when the user tries to click on a component that is blocked by another modal component.
void paint(Graphics &) override
Components can override this method to draw their content.
bool isColourSpecified(int colourId) const noexcept
Returns true if the specified colour ID has been explicitly set using the setColour() method.
bool isPopupMenu() const noexcept
Checks whether the user is trying to launch a pop-up menu.
Contains position and status information about a mouse event.
const ModifierKeys mods
The key modifiers associated with the event.
Point< int > getPosition() const noexcept
The position of the mouse when the event occurred.
bool mouseWasDraggedSinceMouseDown() const noexcept
Returns true if the user seems to be performing a drag gesture.
A general-purpose range object, that simply represents any linear range with a start and end point.
int length() const noexcept
Returns the number of characters in the string.
@ backgroundColourId
The colour to use for the text component's background - this can be transparent if necessary.
@ textColourId
The colour that will be used when text is added to the editor.
@ outlineColourId
If this is non-transparent, it will be used to draw a box around the edge of the component.
@ focusedOutlineColourId
If this is non-transparent, it will be used to draw a box around the edge of the component when it ha...
String getText() const
Returns the entire contents of the editor.
void applyFontToAllText(const Font &newFont, bool changeCurrentFont=true)
Applies a font to all the text in the editor.
Represents a shared variant value.
void addListener(Listener *listener)
Adds a listener to receive callbacks when the value changes.
void removeListener(Listener *listener)
Removes a listener that was previously added with addListener().
String toString() const
Returns the value as a string.
This class acts as a pointer which will automatically become null if the object to which it points is...
constexpr bool approximatelyEqual(Type a, Type b, Tolerance< Type > tolerance=Tolerance< Type >{} .withAbsolute(std::numeric_limits< Type >::min()) .withRelative(std::numeric_limits< Type >::epsilon()))
Returns true if the two floating-point numbers are approximately equal.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
NotificationType
These enums are used in various classes to indicate whether a notification event should be sent out.
@ sendNotification
Requests a notification message, either synchronous or not.
@ dontSendNotification
No notification message should be sent.
@ press
Represents a "press" action.
int roundToInt(const FloatType value) noexcept
Fast floating-point-to-integer conversion.