diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp index 31d282417a..b595d65418 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp @@ -1475,6 +1475,8 @@ Label* LookAndFeel_V2::createSliderTextBox (Slider& slider) l->setColour (TextEditor::highlightColourId, slider.findColour (Slider::textBoxHighlightColourId)); + l->setKeyboardType (TextInputTarget::numericKeyboard); + return l; } diff --git a/modules/juce_gui_basics/widgets/juce_Label.cpp b/modules/juce_gui_basics/widgets/juce_Label.cpp index 7ab3d5e231..ea6322afa2 100644 --- a/modules/juce_gui_basics/widgets/juce_Label.cpp +++ b/modules/juce_gui_basics/widgets/juce_Label.cpp @@ -30,6 +30,7 @@ Label::Label (const String& name, const String& labelText) justification (Justification::centredLeft), border (1, 5, 1, 5), minimumHorizontalScale (0.7f), + keyboardType (TextEditor::textKeyboard), editSingleClick (false), editDoubleClick (false), lossOfFocusDiscardsChanges (false) @@ -208,6 +209,7 @@ void Label::showEditor() { addAndMakeVisible (editor = createEditorComponent()); editor->setText (getText(), false); + editor->setKeyboardType (keyboardType); editor->addListener (this); editor->grabKeyboardFocus(); diff --git a/modules/juce_gui_basics/widgets/juce_Label.h b/modules/juce_gui_basics/widgets/juce_Label.h index 825b0a03d8..e71e5d522f 100644 --- a/modules/juce_gui_basics/widgets/juce_Label.h +++ b/modules/juce_gui_basics/widgets/juce_Label.h @@ -117,7 +117,7 @@ public: void setJustificationType (Justification justification); /** Returns the type of justification, as set in setJustificationType(). */ - Justification getJustificationType() const noexcept { return justification; } + Justification getJustificationType() const noexcept { return justification; } /** Changes the border that is left between the edge of the component and the text. By default there's a small gap left at the sides of the component to allow for @@ -126,7 +126,7 @@ public: void setBorderSize (BorderSize newBorderSize); /** Returns the size of the border to be left around the text. */ - BorderSize getBorderSize() const noexcept { return border; } + BorderSize getBorderSize() const noexcept { return border; } /** Makes this label "stick to" another component. @@ -151,7 +151,7 @@ public: Returns false if the label is above the other component. This is only relevent if attachToComponent() has been called. */ - bool isAttachedOnLeft() const noexcept { return leftOfOwnerComp; } + bool isAttachedOnLeft() const noexcept { return leftOfOwnerComp; } /** Specifies the minimum amount that the font can be squashed horizontally before it starts using ellipsis. @@ -161,7 +161,10 @@ public: void setMinimumHorizontalScale (float newScale); /** Specifies the amount that the font can be squashed horizontally. */ - float getMinimumHorizontalScale() const noexcept { return minimumHorizontalScale; } + float getMinimumHorizontalScale() const noexcept { return minimumHorizontalScale; } + + /** Set a keyboard type for use when the text editor is shown. */ + void setKeyboardType (TextInputTarget::VirtualKeyboardType type) noexcept { keyboardType = type; } //============================================================================== /** @@ -331,6 +334,7 @@ private: WeakReference ownerComponent; BorderSize border; float minimumHorizontalScale; + TextInputTarget::VirtualKeyboardType keyboardType; bool editSingleClick; bool editDoubleClick; bool lossOfFocusDiscardsChanges; diff --git a/modules/juce_gui_basics/widgets/juce_TextEditor.cpp b/modules/juce_gui_basics/widgets/juce_TextEditor.cpp index 02ee09cee3..416076aaa1 100644 --- a/modules/juce_gui_basics/widgets/juce_TextEditor.cpp +++ b/modules/juce_gui_basics/widgets/juce_TextEditor.cpp @@ -921,6 +921,7 @@ TextEditor::TextEditor (const String& name, totalNumChars (0), caretPosition (0), passwordCharacter (passwordChar), + keyboardType (TextInputTarget::textKeyboard), dragType (notDragging) { setOpaque (true); @@ -1292,8 +1293,8 @@ void TextEditor::moveCaret (int newCaretPos) { if (newCaretPos < 0) newCaretPos = 0; - else if (newCaretPos > getTotalNumChars()) - newCaretPos = getTotalNumChars(); + else + newCaretPos = jmin (newCaretPos, getTotalNumChars()); if (newCaretPos != getCaretPosition()) { @@ -2128,7 +2129,7 @@ void TextEditor::enablementChanged() repaint(); } -void TextEditor::setTemporaryUnderlining (const Array >& newUnderlinedSections) +void TextEditor::setTemporaryUnderlining (const Array >& newUnderlinedSections) { underlinedSections = newUnderlinedSections; repaint(); diff --git a/modules/juce_gui_basics/widgets/juce_TextEditor.h b/modules/juce_gui_basics/widgets/juce_TextEditor.h index 4dd5b2106c..006badd23d 100644 --- a/modules/juce_gui_basics/widgets/juce_TextEditor.h +++ b/modules/juce_gui_basics/widgets/juce_TextEditor.h @@ -569,7 +569,7 @@ public: void setInputFilter (InputFilter* newFilter, bool takeOwnership); /** Returns the current InputFilter, as set by setInputFilter(). */ - InputFilter* getInputFilter() const noexcept { return inputFilter; } + InputFilter* getInputFilter() const noexcept { return inputFilter; } /** Sets limits on the characters that can be entered. This is just a shortcut that passes an instance of the LengthAndCharacterRestriction @@ -583,6 +583,8 @@ public: void setInputRestrictions (int maxTextLength, const String& allowedCharacters = String::empty); + void setKeyboardType (VirtualKeyboardType type) noexcept { keyboardType = type; } + //============================================================================== /** This abstract base class is implemented by LookAndFeel classes to provide TextEditor drawing functionality. @@ -631,7 +633,9 @@ public: /** @internal */ bool isTextInputActive() const override; /** @internal */ - void setTemporaryUnderlining (const Array >&) override; + void setTemporaryUnderlining (const Array >&) override; + /** @internal */ + VirtualKeyboardType getKeyboardType() override { return keyboardType; } protected: //============================================================================== @@ -692,6 +696,7 @@ private: juce_wchar passwordCharacter; OptionalScopedPointer inputFilter; Value textValue; + VirtualKeyboardType keyboardType; enum { @@ -700,8 +705,8 @@ private: draggingSelectionEnd } dragType; - ListenerList listeners; - Array > underlinedSections; + ListenerList listeners; + Array > underlinedSections; void moveCaret (int newCaretPos); void moveCaretTo (int newPosition, bool isSelecting);