25#ifndef TGUI_EDIT_BOX_HPP
26#define TGUI_EDIT_BOX_HPP
28#include <TGUI/Widgets/ClickableWidget.hpp>
29#include <TGUI/Renderers/EditBoxRenderer.hpp>
30#include <TGUI/Rect.hpp>
31#include <TGUI/Text.hpp>
45 class TGUI_API EditBox :
public ClickableWidget
49 using Ptr = std::shared_ptr<EditBox>;
50 using ConstPtr = std::shared_ptr<const EditBox>;
64 static TGUI_API
const char32_t*
All;
65 static TGUI_API
const char32_t*
Int;
66 static TGUI_API
const char32_t*
UInt;
67 static TGUI_API
const char32_t*
Float;
173 void selectText(std::size_t start = 0, std::size_t length = String::npos);
236#ifndef TGUI_REMOVE_DEPRECATED_CODE
245 TGUI_DEPRECATED(
"Use setTextWidthLimited instead") void
limitTextWidth(
bool limitWidth = true);
366 void mouseMoved(Vector2f pos)
override;
387 void textEntered(
char32_t key)
override;
421 TGUI_NODISCARD std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
426 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
436 TGUI_NODISCARD
float getFullTextWidth()
const;
441 TGUI_NODISCARD Vector2f getInnerSize()
const;
446 TGUI_NODISCARD
float getVisibleEditBoxWidth()
const;
451 TGUI_NODISCARD std::size_t findCaretPosition(
float posX);
457 void deleteSelectedCharacters();
462 void recalculateTextPositions();
467 void updateSelection();
472 void updateTextColor();
477 bool updateTime(
Duration elapsedTime)
override;
488 void updateSelEnd(
const std::size_t newValue);
503 void deleteWordLeft();
508 void deleteWordRight();
513 void backspaceKeyPressed();
518 void deleteKeyPressed();
523 void copySelectedTextToClipboard();
528 void cutSelectedTextToClipboard();
533 void pasteTextFromClipboard();
538 void moveCaretLeft(
bool shiftPressed);
543 void moveCaretRight(
bool shiftPressed);
548 void moveCaretWordBegin();
553 void moveCaretWordEnd();
567 bool m_caretVisible =
true;
572 bool m_limitTextWidth =
false;
574 bool m_readOnly =
false;
580 String m_regexString = U
".*";
587 std::size_t m_selChars = 0;
588 std::size_t m_selStart = 0;
589 std::size_t m_selEnd = 0;
592 char32_t m_passwordChar =
'\0';
596 unsigned int m_maxChars = 0;
599 unsigned int m_textCropPosition = 0;
602 FloatRect m_selectedTextBackground;
605 FloatRect m_caret = {0, 0, 1, 0};
608 bool m_possibleDoubleClick =
false;
611 Text m_textBeforeSelection;
612 Text m_textSelection;
613 Text m_textAfterSelection;
619 Sprite m_spriteHover;
620 Sprite m_spriteDisabled;
621 Sprite m_spriteFocused;
624 Borders m_bordersCached;
625 Padding m_paddingCached;
626 Color m_borderColorCached;
627 Color m_borderColorHoverCached;
628 Color m_borderColorDisabledCached;
629 Color m_borderColorFocusedCached;
630 Color m_backgroundColorCached;
631 Color m_backgroundColorHoverCached;
632 Color m_backgroundColorDisabledCached;
633 Color m_backgroundColorFocusedCached;
634 Color m_caretColorCached;
635 Color m_caretColorHoverCached;
636 Color m_caretColorFocusedCached;
637 Color m_selectedTextBackgroundColorCached;
638 float m_roundedBorderRadiusCached = 0;
644 bool m_onReturnOrUnfocusEmitted =
false;
Base class for render targets.
Definition BackendRenderTarget.hpp:46
Wrapper for durations.
Definition Duration.hpp:53
Definition EditBoxRenderer.hpp:35
void setFocused(bool focused) override
Focus or unfocus the widget.
static EditBox::Ptr create()
Creates a new edit box widget.
SignalString onReturnOrUnfocus
The return key was pressed or the edit box was unfocused. Optional parameter: text in the edit box.
Definition EditBox.hpp:560
void emitReturnOrUnfocus(const String &text)
Emits the onReturnOrUnfocus signal.
void setReadOnly(bool readOnly=true)
Makes the edit box read-only or make it writable again.
SignalTyped< std::size_t > onCaretPositionChange
The caret's position was changed. Optional parameter: new caret position.
Definition EditBox.hpp:561
const String & getText() const
Returns the text inside the edit box. This text is not affected by the password character.
void selectText(std::size_t start=0, std::size_t length=String::npos)
Selects text in the edit box.
void setCaretPosition(std::size_t charactersBeforeCaret)
Sets the blinking caret to after a specific character.
bool isMouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
SignalString onReturnKeyPress
The return key was pressed. Optional parameter: text in the edit box.
Definition EditBox.hpp:559
bool isTextWidthLimited() const
Checks if the text width is limited to the size of the edit box.
void setMaximumCharacters(unsigned int maxChars)
Changes the character limit.
void updateTextSize() override
Called when the text size is changed (either by setTextSize or via the renderer)
void setAlignment(HorizontalAlignment alignment)
Changes the text alignment.
char32_t getPasswordCharacter() const
Returns the password character.
void setText(const String &text)
Changes the text of the editbox.
const String & getInputValidator() const
Returns the regex to which the text is matched.
SignalString onTextChange
The text was changed. Optional parameter: new text.
Definition EditBox.hpp:558
static constexpr const char StaticWidgetType[]
Type name of the widget.
Definition EditBox.hpp:52
void limitTextWidth(bool limitWidth=true)
Should the text width be limited or should you be able to type even if the edit box is full?
std::size_t getCaretPosition() const
Returns after which character the blinking cursor is currently located.
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the widget to a render target.
bool setInputValidator(const String ®ex=U".*")
Defines how the text input should look like.
HorizontalAlignment Alignment
The text alignment.
Definition EditBox.hpp:57
std::unique_ptr< DataIO::Node > save(SavingRenderersMap &renderers) const override
Saves the widget as a tree node in order to save it to a file.
std::shared_ptr< const EditBox > ConstPtr
Shared constant widget pointer.
Definition EditBox.hpp:50
EditBoxRenderer * getSharedRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
unsigned int getMaximumCharacters() const
Returns the character limit.
void setSuffix(const String &suffix)
Places a suffix at the right side of the edit box.
String getSelectedText() const
Returns the text that you currently have selected. This text is not affected by the password characte...
std::shared_ptr< EditBox > Ptr
Shared widget pointer.
Definition EditBox.hpp:49
HorizontalAlignment getAlignment() const
Gets the current text alignment.
const String & getSuffix() const
Returns the suffix currently displayed on the right side of the edit box.
void setTextWidthLimited(bool limitWidth)
Should the text width be limited or should you be able to type even if the edit box is full?
void setEnabled(bool enabled) override
Enables or disables the widget.
void setSize(const Layout2d &size) override
Changes the size of the edit box.
const String & getDefaultText() const
Returns the default text of the edit box. This is the text drawn when the edit box is empty.
bool canHandleKeyPress(const Event::KeyEvent &event) override
Called by the parent of the widget to check if keyPressed would process the event.
Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
static EditBox::Ptr copy(const EditBox::ConstPtr &editBox)
Makes a copy of another edit box.
void setPasswordCharacter(char32_t passwordChar)
Sets a password character.
bool isReadOnly() const
Checks if the edit box read-only or writable.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
bool leftMousePressed(Vector2f pos) override
Called by the parent when the left mouse button goes down on top of the widget.
EditBoxRenderer * getRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
void setDefaultText(const String &text)
Changes the default text of the editbox. This is the text drawn when the edit box is empty.
Class to store the position or size of a widget.
Definition Layout.hpp:321
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:269
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:59
Wrapper class to store strings.
Definition String.hpp:94
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:36
HorizontalAlignment
The horizontal alignment.
Definition Layout.hpp:60
@ Left
Align to the left side.
Definition Layout.hpp:61
SignalTyped< const String & > SignalString
Signal with one "String" as optional unbound parameter.
Definition Signal.hpp:426
Predefined input validators.
Definition EditBox.hpp:63
static TGUI_API const char32_t * Int
Accept negative and positive integers.
Definition EditBox.hpp:65
static TGUI_API const char32_t * Float
Accept decimal numbers.
Definition EditBox.hpp:67
static TGUI_API const char32_t * UInt
Accept only positive integers.
Definition EditBox.hpp:66
static TGUI_API const char32_t * All
Accept any input.
Definition EditBox.hpp:64
KeyPressed event parameters.
Definition Event.hpp:168
States used for drawing.
Definition RenderStates.hpp:38