25#ifndef TGUI_EDIT_BOX_HPP
26#define TGUI_EDIT_BOX_HPP
29#include <TGUI/Widgets/ClickableWidget.hpp>
30#include <TGUI/Renderers/EditBoxRenderer.hpp>
31#include <TGUI/Rect.hpp>
32#include <TGUI/Text.hpp>
49 using Ptr = std::shared_ptr<EditBox>;
50 using ConstPtr = std::shared_ptr<const EditBox>;
52 static constexpr const char StaticWidgetType[] =
"EditBox";
76 static TGUI_API
const char*
All;
77 static TGUI_API
const char*
Int;
78 static TGUI_API
const char*
UInt;
79 static TGUI_API
const char*
Float;
90 EditBox(
const char* typeName = StaticWidgetType,
bool initRenderer =
true);
135 using Widget::setSize;
204 void selectText(std::size_t start = 0, std::size_t length = String::npos);
412 void leftMousePressed(
Vector2f pos)
override;
417 void mouseMoved(
Vector2f pos)
override;
427 void textEntered(
char32_t key)
override;
467 std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
473 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
485 float getFullTextWidth()
const;
497 float getVisibleEditBoxWidth()
const;
503 std::size_t findCaretPosition(
float posX);
510 void deleteSelectedCharacters();
516 void recalculateTextPositions();
522 void updateSelection();
528 void updateTextColor();
534 bool updateTime(
Duration elapsedTime)
override;
549 void backspaceKeyPressed();
554 void deleteKeyPressed();
559 void copySelectedTextToClipboard();
564 void cutSelectedTextToClipboard();
569 void pasteTextFromClipboard();
574 void moveCaretLeft(
bool shiftPressed);
579 void moveCaretRight(
bool shiftPressed);
584 void moveCaretWordBegin();
589 void moveCaretWordEnd();
604 bool m_caretVisible =
true;
609 bool m_limitTextWidth =
false;
611 bool m_readOnly =
false;
617 String m_regexString = U
".*";
621 Alignment m_textAlignment = Alignment::Left;
624 std::size_t m_selChars = 0;
625 std::size_t m_selStart = 0;
626 std::size_t m_selEnd = 0;
629 char32_t m_passwordChar =
'\0';
633 unsigned int m_maxChars = 0;
636 unsigned int m_textCropPosition = 0;
645 bool m_possibleDoubleClick =
false;
648 Text m_textBeforeSelection;
649 Text m_textSelection;
650 Text m_textAfterSelection;
656 Sprite m_spriteHover;
657 Sprite m_spriteDisabled;
658 Sprite m_spriteFocused;
661 Borders m_bordersCached;
662 Padding m_paddingCached;
663 Color m_borderColorCached;
664 Color m_borderColorHoverCached;
665 Color m_borderColorDisabledCached;
666 Color m_borderColorFocusedCached;
667 Color m_backgroundColorCached;
668 Color m_backgroundColorHoverCached;
669 Color m_backgroundColorDisabledCached;
670 Color m_backgroundColorFocusedCached;
671 Color m_caretColorCached;
672 Color m_caretColorHoverCached;
673 Color m_caretColorFocusedCached;
674 Color m_selectedTextBackgroundColorCached;
Base class for render targets.
Definition: BackendRenderTarget.hpp:48
Wrapper for durations.
Definition: Duration.hpp:52
Definition: EditBoxRenderer.hpp:37
Edit box widget.
Definition: EditBox.hpp:46
void setFocused(bool focused) override
Focus or unfocus the widget.
static EditBox::Ptr create()
Creates a new edit box widget.
void setReadOnly(bool readOnly=true)
Makes the edit box read-only or make it writable again.
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.
Alignment
The text alignment.
Definition: EditBox.hpp:59
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)
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.
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.
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
void setAlignment(Alignment alignment)
Changes the text alignment.
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
Alignment 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 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.
Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
EditBoxRenderer * getSharedRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
EditBoxRenderer * getRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
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.
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:284
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:58
Wrapper class to store strings.
Definition: String.hpp:79
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Predefined input validators.
Definition: EditBox.hpp:75
static TGUI_API const char * All
Accept any input.
Definition: EditBox.hpp:76
static TGUI_API const char * Float
Accept decimal numbers.
Definition: EditBox.hpp:79
static TGUI_API const char * Int
Accept negative and positive integers.
Definition: EditBox.hpp:77
static TGUI_API const char * UInt
Accept only positive integers.
Definition: EditBox.hpp:78
KeyPressed event parameters.
Definition: Event.hpp:167
States used for drawing.
Definition: RenderStates.hpp:39