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>
33#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
39TGUI_MODULE_EXPORT
namespace tgui
51 using Ptr = std::shared_ptr<EditBox>;
52 using ConstPtr = std::shared_ptr<const EditBox>;
54 static constexpr const char StaticWidgetType[] =
"EditBox";
66 static TGUI_API
const char32_t*
All;
67 static TGUI_API
const char32_t*
Int;
68 static TGUI_API
const char32_t*
UInt;
69 static TGUI_API
const char32_t*
Float;
79 EditBox(
const char* typeName = StaticWidgetType,
bool initRenderer =
true);
102 TGUI_NODISCARD
const EditBoxRenderer* getSharedRenderer()
const override;
117 using Widget::setSize;
175 void selectText(std::size_t start = 0, std::size_t length = String::npos);
238#ifndef TGUI_REMOVE_DEPRECATED_CODE
247 TGUI_DEPRECATED(
"Use setTextWidthLimited instead") void limitTextWidth(
bool limitWidth = true);
368 void mouseMoved(
Vector2f pos)
override;
389 void textEntered(
char32_t key)
override;
423 TGUI_NODISCARD std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
428 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
438 TGUI_NODISCARD
float getFullTextWidth()
const;
443 TGUI_NODISCARD
Vector2f getInnerSize()
const;
448 TGUI_NODISCARD
float getVisibleEditBoxWidth()
const;
453 TGUI_NODISCARD std::size_t findCaretPosition(
float posX);
459 void deleteSelectedCharacters();
464 void recalculateTextPositions();
469 void updateSelection();
474 void updateTextColor();
479 bool updateTime(
Duration elapsedTime)
override;
490 void updateSelEnd(
const std::size_t newValue);
505 void backspaceKeyPressed();
510 void deleteKeyPressed();
515 void copySelectedTextToClipboard();
520 void cutSelectedTextToClipboard();
525 void pasteTextFromClipboard();
530 void moveCaretLeft(
bool shiftPressed);
535 void moveCaretRight(
bool shiftPressed);
540 void moveCaretWordBegin();
545 void moveCaretWordEnd();
559 bool m_caretVisible =
true;
564 bool m_limitTextWidth =
false;
566 bool m_readOnly =
false;
572 String m_regexString = U
".*";
579 std::size_t m_selChars = 0;
580 std::size_t m_selStart = 0;
581 std::size_t m_selEnd = 0;
584 char32_t m_passwordChar =
'\0';
588 unsigned int m_maxChars = 0;
591 unsigned int m_textCropPosition = 0;
600 bool m_possibleDoubleClick =
false;
603 Text m_textBeforeSelection;
604 Text m_textSelection;
605 Text m_textAfterSelection;
611 Sprite m_spriteHover;
612 Sprite m_spriteDisabled;
613 Sprite m_spriteFocused;
616 Borders m_bordersCached;
617 Padding m_paddingCached;
618 Color m_borderColorCached;
619 Color m_borderColorHoverCached;
620 Color m_borderColorDisabledCached;
621 Color m_borderColorFocusedCached;
622 Color m_backgroundColorCached;
623 Color m_backgroundColorHoverCached;
624 Color m_backgroundColorDisabledCached;
625 Color m_backgroundColorFocusedCached;
626 Color m_caretColorCached;
627 Color m_caretColorHoverCached;
628 Color m_caretColorFocusedCached;
629 Color m_selectedTextBackgroundColorCached;
635 bool m_onReturnOrUnfocusEmitted =
false;
Base class for render targets.
Definition BackendRenderTarget.hpp:46
Wrapper for durations.
Definition Duration.hpp:55
Definition EditBoxRenderer.hpp:35
Edit box widget.
Definition EditBox.hpp:48
void setFocused(bool focused) override
Focus or unfocus the widget.
static EditBox::Ptr create()
Creates a new edit box widget.
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.
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.
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.
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:52
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:51
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:323
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:61
Wrapper class to store strings.
Definition String.hpp:96
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38
HorizontalAlignment
The horizontal alignment.
Definition Layout.hpp:62
Predefined input validators.
Definition EditBox.hpp:65
static TGUI_API const char32_t * Int
Accept negative and positive integers.
Definition EditBox.hpp:67
static TGUI_API const char32_t * Float
Accept decimal numbers.
Definition EditBox.hpp:69
static TGUI_API const char32_t * UInt
Accept only positive integers.
Definition EditBox.hpp:68
static TGUI_API const char32_t * All
Accept any input.
Definition EditBox.hpp:66
KeyPressed event parameters.
Definition Event.hpp:168
States used for drawing.
Definition RenderStates.hpp:38