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>
34#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
40TGUI_MODULE_EXPORT
namespace tgui
52 using Ptr = std::shared_ptr<EditBox>;
53 using ConstPtr = std::shared_ptr<const EditBox>;
55 static constexpr const char StaticWidgetType[] =
"EditBox";
79 static TGUI_API
const char32_t*
All;
80 static TGUI_API
const char32_t*
Int;
81 static TGUI_API
const char32_t*
UInt;
82 static TGUI_API
const char32_t*
Float;
93 EditBox(
const char* typeName = StaticWidgetType,
bool initRenderer =
true);
121 TGUI_NODISCARD
const EditBoxRenderer* getSharedRenderer()
const override;
138 using Widget::setSize;
207 void selectText(std::size_t start = 0, std::size_t length = String::npos);
420 void mouseMoved(
Vector2f pos)
override;
441 void textEntered(
char32_t key)
override;
481 TGUI_NODISCARD std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
487 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
499 TGUI_NODISCARD
float getFullTextWidth()
const;
505 TGUI_NODISCARD
Vector2f getInnerSize()
const;
511 TGUI_NODISCARD
float getVisibleEditBoxWidth()
const;
517 TGUI_NODISCARD std::size_t findCaretPosition(
float posX);
524 void deleteSelectedCharacters();
530 void recalculateTextPositions();
536 void updateSelection();
542 void updateTextColor();
548 bool updateTime(
Duration elapsedTime)
override;
561 void updateSelEnd(
const std::size_t newValue);
570 void backspaceKeyPressed();
575 void deleteKeyPressed();
580 void copySelectedTextToClipboard();
585 void cutSelectedTextToClipboard();
590 void pasteTextFromClipboard();
595 void moveCaretLeft(
bool shiftPressed);
600 void moveCaretRight(
bool shiftPressed);
605 void moveCaretWordBegin();
610 void moveCaretWordEnd();
626 bool m_caretVisible =
true;
631 bool m_limitTextWidth =
false;
633 bool m_readOnly =
false;
639 String m_regexString = U
".*";
643 Alignment m_textAlignment = Alignment::Left;
646 std::size_t m_selChars = 0;
647 std::size_t m_selStart = 0;
648 std::size_t m_selEnd = 0;
651 char32_t m_passwordChar =
'\0';
655 unsigned int m_maxChars = 0;
658 unsigned int m_textCropPosition = 0;
667 bool m_possibleDoubleClick =
false;
670 Text m_textBeforeSelection;
671 Text m_textSelection;
672 Text m_textAfterSelection;
678 Sprite m_spriteHover;
679 Sprite m_spriteDisabled;
680 Sprite m_spriteFocused;
683 Borders m_bordersCached;
684 Padding m_paddingCached;
685 Color m_borderColorCached;
686 Color m_borderColorHoverCached;
687 Color m_borderColorDisabledCached;
688 Color m_borderColorFocusedCached;
689 Color m_backgroundColorCached;
690 Color m_backgroundColorHoverCached;
691 Color m_backgroundColorDisabledCached;
692 Color m_backgroundColorFocusedCached;
693 Color m_caretColorCached;
694 Color m_caretColorHoverCached;
695 Color m_caretColorFocusedCached;
696 Color m_selectedTextBackgroundColorCached;
Base class for render targets.
Definition BackendRenderTarget.hpp:48
Wrapper for durations.
Definition Duration.hpp:56
Definition EditBoxRenderer.hpp:37
Edit box widget.
Definition EditBox.hpp:49
void setFocused(bool focused) override
Focus or unfocus the widget.
TGUI_NODISCARD char32_t getPasswordCharacter() const
Returns the password character.
void setReadOnly(bool readOnly=true)
Makes the edit box read-only or make it writable again.
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.
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:62
TGUI_NODISCARD Alignment getAlignment() const
Gets the current text alignment.
void setMaximumCharacters(unsigned int maxChars)
Changes the character limit.
static TGUI_NODISCARD EditBox::Ptr create()
Creates a new edit box widget.
void updateTextSize() override
Called when the text size is changed (either by setTextSize or via the renderer)
TGUI_NODISCARD 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.
TGUI_NODISCARD const String & getInputValidator() const
Returns the regex to which the text is matched.
void setText(const String &text)
Changes the text of the editbox.
TGUI_NODISCARD EditBoxRenderer * getSharedRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
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?
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.
TGUI_NODISCARD EditBoxRenderer * getRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
TGUI_NODISCARD std::size_t getCaretPosition() const
Returns after which character the blinking cursor is currently located.
std::shared_ptr< const EditBox > ConstPtr
Shared constant widget pointer.
Definition EditBox.hpp:53
TGUI_NODISCARD unsigned int getMaximumCharacters() const
Returns the character limit.
void setAlignment(Alignment alignment)
Changes the text alignment.
TGUI_NODISCARD const String & getSuffix() const
Returns the suffix currently displayed on the right side of the edit box.
TGUI_NODISCARD Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
void setSuffix(const String &suffix)
Places a suffix at the right side of the edit box.
std::shared_ptr< EditBox > Ptr
Shared widget pointer.
Definition EditBox.hpp:52
TGUI_NODISCARD bool isReadOnly() const
Checks if the edit box read-only or writable.
TGUI_NODISCARD String getSelectedText() const
Returns the text that you currently have selected. This text is not affected by the password characte...
void setEnabled(bool enabled) override
Enables or disables the widget.
void setSize(const Layout2d &size) override
Changes the size of the edit box.
TGUI_NODISCARD Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
bool canHandleKeyPress(const Event::KeyEvent &event) override
Called by the parent of the widget to check if keyPressed would process the event.
TGUI_NODISCARD const String & getDefaultText() const
Returns the default text of the edit box. This is the text drawn when the edit box is empty.
TGUI_NODISCARD bool isTextWidthLimited() const
Checks if the text width is limited to the size of the edit box.
void setPasswordCharacter(char32_t passwordChar)
Sets a password character.
static TGUI_NODISCARD EditBox::Ptr copy(const EditBox::ConstPtr &editBox)
Makes a copy of another edit box.
TGUI_NODISCARD const String & getText() const
Returns the text inside the edit box. This text is not affected by the password character.
TGUI_NODISCARD bool isMouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
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.
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:305
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:62
Wrapper class to store strings.
Definition String.hpp:101
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39
Predefined input validators.
Definition EditBox.hpp:78
static TGUI_API const char32_t * Int
Accept negative and positive integers.
Definition EditBox.hpp:80
static TGUI_API const char32_t * Float
Accept decimal numbers.
Definition EditBox.hpp:82
static TGUI_API const char32_t * UInt
Accept only positive integers.
Definition EditBox.hpp:81
static TGUI_API const char32_t * All
Accept any input.
Definition EditBox.hpp:79
KeyPressed event parameters.
Definition Event.hpp:169
States used for drawing.
Definition RenderStates.hpp:39