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/FloatRect.hpp> 
   32#include <TGUI/Text.hpp> 
   49        typedef std::shared_ptr<EditBox> 
Ptr; 
 
   50        typedef std::shared_ptr<const EditBox> 
ConstPtr; 
 
   74#if TGUI_COMPILED_WITH_CPP_VER >= 17 
   75            static inline const std::string All   = 
".*";                    
 
   76            static inline const std::string Int   = 
"[+-]?[0-9]*";           
 
   77            static inline const std::string UInt  = 
"[0-9]*";                
 
   78            static inline const std::string Float = 
"[+-]?[0-9]*\\.?[0-9]*"; 
 
   80            static TGUI_API 
const std::string All;   
 
   81            static TGUI_API 
const std::string Int;   
 
   82            static TGUI_API 
const std::string UInt;  
 
   83            static TGUI_API 
const std::string Float; 
 
  206        void selectText(std::size_t start = 0, std::size_t length = sf::String::InvalidPos);
 
  433        void leftMousePressed(
Vector2f pos) 
override;
 
  438        void mouseMoved(
Vector2f pos) 
override;
 
  443        void keyPressed(
const sf::Event::KeyEvent& event) 
override;
 
  448        void textEntered(std::uint32_t Key) 
override;
 
  458        void draw(sf::RenderTarget& target, sf::RenderStates states) 
const override;
 
  488        std::unique_ptr<DataIO::Node> 
save(SavingRenderersMap& renderers) 
const override;
 
  494        void load(
const std::unique_ptr<DataIO::Node>& node, 
const LoadingRenderersMap& renderers) 
override;
 
  500        float getFullTextWidth() 
const;
 
  512        float getVisibleEditBoxWidth() 
const;
 
  518        std::size_t findCaretPosition(
float posX);
 
  525        void deleteSelectedCharacters();
 
  531        void recalculateTextPositions();
 
  537        void updateSelection();
 
  543        void updateTextColor();
 
  549        bool update(sf::Time elapsedTime) 
override;
 
  557            return std::make_shared<EditBox>(*
this);
 
  567        void backspaceKeyPressed();
 
  572        void deleteKeyPressed();
 
  577        void copySelectedTextToClipboard();
 
  582        void cutSelectedTextToClipboard();
 
  587        void pasteTextFromClipboard();
 
  592        void moveCaretLeft(
bool shiftPressed);
 
  597        void moveCaretRight(
bool shiftPressed);
 
  602        void moveCaretWordBegin();
 
  607        void moveCaretWordEnd();
 
  613        SignalString onTextChange     = {
"TextChanged"};        
 
  614        SignalString onReturnKeyPress = {
"ReturnKeyPressed"};   
 
  621        bool          m_caretVisible = 
true;
 
  626        bool          m_limitTextWidth = 
false;
 
  628        bool          m_readOnly = 
false;
 
  633        std::string   m_regexString = 
".*";
 
  634        std::regex    m_regex = std::regex{m_regexString};
 
  637        Alignment     m_textAlignment = Alignment::Left;
 
  640        std::size_t   m_selChars = 0;
 
  641        std::size_t   m_selStart = 0;
 
  642        std::size_t   m_selEnd = 0;
 
  645        char          m_passwordChar = 
'\0';
 
  649        unsigned int  m_maxChars = 0;
 
  652        unsigned int  m_textCropPosition = 0;
 
  655        FloatRect     m_selectedTextBackground;
 
  658        FloatRect     m_caret = {{0, 0, 1, 0}};
 
  661        bool m_possibleDoubleClick = 
false;
 
  664        Text m_textBeforeSelection;
 
  665        Text m_textSelection;
 
  666        Text m_textAfterSelection;
 
  672        Sprite m_spriteHover;
 
  673        Sprite m_spriteDisabled;
 
  674        Sprite m_spriteFocused;
 
  677        Borders m_bordersCached;
 
  678        Padding m_paddingCached;
 
  679        Color   m_borderColorCached;
 
  680        Color   m_borderColorHoverCached;
 
  681        Color   m_borderColorDisabledCached;
 
  682        Color   m_borderColorFocusedCached;
 
  683        Color   m_backgroundColorCached;
 
  684        Color   m_backgroundColorHoverCached;
 
  685        Color   m_backgroundColorDisabledCached;
 
  686        Color   m_backgroundColorFocusedCached;
 
  687        Color   m_caretColorCached;
 
  688        Color   m_caretColorHoverCached;
 
  689        Color   m_caretColorFocusedCached;
 
  690        Color   m_selectedTextBackgroundColorCached;
 
Definition: EditBoxRenderer.hpp:37
 
Edit box widget.
Definition: EditBox.hpp:46
 
const sf::String & getText() const
Returns the text inside the edit box. This text is not affected by the password character.
 
void setFocused(bool focused) override
Focus or unfocus the widget.
 
static EditBox::Ptr create()
Creates a new edit box widget.
 
void setPasswordCharacter(char passwordChar)
Sets a password character.
 
void rendererChanged(const std::string &property) override
Function called when one of the properties of the renderer is changed.
 
const sf::String & getDefaultText() const
Returns the default text of the edit box. This is the text drawn when the edit box is empty.
 
void setSuffix(const sf::String &suffix)
Places a suffix at the right side of the edit box.
 
void setReadOnly(bool readOnly=true)
Makes the edit box read-only or make it writable again.
 
unsigned int getTextSize() const override
Returns the character size of the text.
 
void setCaretPosition(std::size_t charactersBeforeCaret)
Sets the blinking caret to after a specific character.
 
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: EditBox.hpp:555
 
Alignment
The text alignment.
Definition: EditBox.hpp:57
 
bool mouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
 
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.
 
Signal & getSignal(std::string signalName) override
Retrieves a signal based on its name.
 
const sf::String & getSuffix() const
Returns the suffix currently displayed on the right side of the edit box.
 
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(sf::RenderTarget &target, sf::RenderStates states) const override
Draw the widget to a render target.
 
std::size_t getCaretPosition() const
Returns after which character the blinking cursor is currently located.
 
const std::string & getInputValidator() const
Returns the regex to which the text is matched.
 
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.
 
sf::String getSelectedText() const
Returns the text that you currently have selected. This text is not affected by the password characte...
 
void setText(const sf::String &text)
Changes the text of the editbox.
 
void setAlignment(Alignment alignment)
Changes the text alignment.
 
unsigned int getMaximumCharacters() const
Returns the character limit.
 
void setTextSize(unsigned int textSize) override
Changes the character size of the text.
 
std::shared_ptr< const EditBox > ConstPtr
Shared constant widget pointer.
Definition: EditBox.hpp:50
 
static EditBox::Ptr copy(EditBox::ConstPtr editBox)
Makes a copy of another edit box.
 
Alignment getAlignment() const
Gets the current text alignment.
 
void setDefaultText(const sf::String &text)
Changes the default text of the editbox. This is the text drawn when the edit box is empty.
 
void setEnabled(bool enabled) override
Enables or disables the widget.
 
void setSize(const Layout2d &size) override
Changes the size of the edit box.
 
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.
 
std::shared_ptr< EditBox > Ptr
Shared widget pointer.
Definition: EditBox.hpp:49
 
bool setInputValidator(const std::string ®ex=".*")
Defines how the text input should look like.
 
bool isReadOnly() const
Checks if the edit box read-only or writable.
 
void selectText(std::size_t start=0, std::size_t length=sf::String::InvalidPos)
Selects text in the edit box.
 
char getPasswordCharacter() const
Returns the password character.
 
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
 
Class to store the position or size of a widget.
Definition: Layout.hpp:260
 
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:231
 
Definition: Vector2f.hpp:39
 
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:37
 
Predefined input validators.
Definition: EditBox.hpp:73