25#ifndef TGUI_EDIT_BOX_HPP
26#define TGUI_EDIT_BOX_HPP
29#include <TGUI/Widgets/ClickableWidget.hpp>
37 class EditBoxRenderer;
58 typedef std::shared_ptr<EditBox>
Ptr;
59 typedef std::shared_ptr<const EditBox>
ConstPtr;
83 static TGUI_API std::string
Int;
84 static TGUI_API std::string
UInt;
85 static TGUI_API std::string
Float;
123 return std::static_pointer_cast<EditBoxRenderer>(m_renderer);
224 return m_defaultText.getString();
255 return m_textFull.getCharacterSize();
283 return m_passwordChar;
330 return m_textAlignment;
354 return m_limitTextWidth;
395 return m_caret.getSize().x;
455 virtual void leftMousePressed(
float x,
float y)
override;
460 virtual void mouseMoved(
float x,
float y)
override;
465 virtual void keyPressed(
const sf::Event::KeyEvent& event)
override;
470 virtual void textEntered(sf::Uint32 Key)
override;
475 virtual void widgetFocused()
override;
480 virtual void widgetUnfocused()
override;
498 virtual void reload(
const std::string& primary =
"",
const std::string& secondary =
"",
bool force =
false)
override;
504 float getVisibleEditBoxWidth();
510 std::size_t findCaretPosition(
float posX);
517 void deleteSelectedCharacters();
523 void recalculateTextPositions();
529 void updateSelection();
537 return std::make_shared<EditBox>(*
this);
544 virtual void update(sf::Time elapsedTime)
override;
550 virtual void draw(sf::RenderTarget& target, sf::RenderStates states)
const override;
557 bool m_caretVisible =
true;
562 bool m_limitTextWidth =
false;
565 sf::String m_displayedText;
568 std::string m_regexString =
".*";
569 std::regex m_regex = std::regex{m_regexString};
572 unsigned int m_textSize = 0;
575 Alignment m_textAlignment = Alignment::Left;
578 std::size_t m_selChars = 0;
579 std::size_t m_selStart = 0;
580 std::size_t m_selEnd = 0;
583 char m_passwordChar =
'\0';
587 unsigned int m_maxChars = 0;
590 unsigned int m_textCropPosition = 0;
593 sf::RectangleShape m_selectedTextBackground;
596 sf::RectangleShape m_caret;
599 sf::Text m_textBeforeSelection;
600 sf::Text m_textSelection;
601 sf::Text m_textAfterSelection;
603 sf::Text m_defaultText;
606 bool m_possibleDoubleClick =
false;
609 friend class EditBoxRenderer;
640 virtual void setProperty(std::string property,
const std::string& value)
override;
846 void draw(sf::RenderTarget& target, sf::RenderStates states)
const;
855 Padding getScaledPadding()
const;
861 virtual std::shared_ptr<WidgetRenderer> clone(
Widget* widget)
override;
869 sf::Color m_textColor;
870 sf::Color m_selectedTextColor;
871 sf::Color m_selectedTextBackgroundColor;
872 sf::Color m_defaultTextColor;
873 sf::Color m_backgroundColorNormal;
874 sf::Color m_backgroundColorHover;
875 sf::Color m_caretColor;
876 sf::Color m_borderColor;
Definition: Borders.hpp:38
Implicit converter for colors.
Definition: Color.hpp:40
Definition: EditBox.hpp:619
void setTextColor(const Color &textColor)
Set the text color that will be used inside the edit box.
void setDefaultTextStyle(sf::Uint32 style)
Changes the text style of the default text (the text drawn when the edit box is empty)
void setHoverTexture(const Texture &texture)
Change the image that is displayed when the mouse is located on top of the edit box.
virtual void setProperty(std::string property, const std::string &value) override
Change a property of the renderer.
void setFocusTexture(const Texture &texture)
Change the image that is drawn on top of the edit box image when the edit box is focused.
void setSelectedTextColor(const Color &selectedTextColor)
Set the text color of the selected text that will be used inside the edit box.
virtual void setPadding(const Padding &padding) override
Changes the padding of the edit box.
void setBackgroundColor(const Color &color)
Changes the color of the background.
virtual void setProperty(std::string property, ObjectConverter &&value) override
Change a property of the renderer.
void setBackgroundColorNormal(const Color &color)
Changes the color of the background in the normal state (mouse not on edit box).
virtual std::map< std::string, ObjectConverter > getPropertyValuePairs() const override
Get a map with all properties and their values.
void setCaretColor(const Color &caretColor)
Set the color that will be used inside the edit box for the blinking caret.
void setCaretWidth(float width)
This will change the width of the caret.
void setBackgroundColorHover(const Color &color)
Changes the color of the background in the hover state (mouse on edit box, but not pressed).
void setDefaultTextColor(const Color &defaultTextColor)
Set the color of the default text that can optionally be displayed when the edit box is empty.
void setNormalTexture(const Texture &texture)
Change the image that is displayed when the mouse is not on the edit box.
void setSelectedTextBackgroundColor(const Color &selectedTextBackgroundColor)
Set the background color of the selected text that will be used inside the edit box.
void setBorderColor(const Color &color)
Changes the color of the borders.
EditBoxRenderer(EditBox *editBox)
Constructor.
Definition: EditBox.hpp:628
virtual ObjectConverter getProperty(std::string property) const override
Retrieve the value of a certain property.
Edit box widget.
Definition: EditBox.hpp:55
static EditBox::Ptr create()
Creates a new edit box widget.
void setPasswordCharacter(char passwordChar)
Sets a password character.
sf::String getText() const
Returns the text inside the edit box. This text is not affected by the password character.
Definition: EditBox.hpp:197
virtual sf::Vector2f getFullSize() const override
Returns the full size of the edit box.
bool isTextWidthLimited()
Check if the text width is limited to the size of the edit box.
Definition: EditBox.hpp:352
void setCaretPosition(std::size_t charactersBeforeCaret)
Sets the blinking caret to after a specific character.
sf::String getDefaultText() const
Returns the default text of the edit box. This is the text drawn when the edit box is empty.
Definition: EditBox.hpp:222
Alignment
The text alignment.
Definition: EditBox.hpp:66
Alignment getAlignment()
Get the current text alignment.
Definition: EditBox.hpp:328
void setMaximumCharacters(unsigned int maxChars)
Change the character limit.
const std::string & getInputValidator()
Returns the regex to which the text is matched.
virtual sf::Vector2f getWidgetOffset() const override
Returns the distance between the position where the widget is drawn and where the widget is placed.
void setInputValidator(const std::string ®ex=".*")
Define how the text input should look like.
void selectText()
Selects the entire text in 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?
std::size_t getCaretPosition() const
Returns after which character the blinking cursor is currently located.
std::shared_ptr< EditBoxRenderer > getRenderer() const
Returns the renderer, which gives access to functions that determine how the widget is displayed.
Definition: EditBox.hpp:121
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.
virtual void setFont(const Font &font) override
Changes the font of the text in the widget.
void setAlignment(Alignment alignment)
Change the text alignment.
unsigned int getMaximumCharacters() const
Returns the character limit.
Definition: EditBox.hpp:307
std::shared_ptr< const EditBox > ConstPtr
Shared constant widget pointer.
Definition: EditBox.hpp:59
static EditBox::Ptr copy(EditBox::ConstPtr editBox)
Makes a copy of another edit box.
virtual void setPosition(const Layout2d &position) override
Set the position of the widget.
virtual void setOpacity(float opacity) override
Changes the opacity of the widget.
void setDefaultText(const sf::String &text)
Changes the default text of the editbox. This is the text drawn when the edit box is empty.
virtual void reload(const std::string &primary="", const std::string &secondary="", bool force=false) override
Reload the widget.
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: EditBox.hpp:535
void setSize(const Layout2d &size) override
Changes the size of the edit box.
std::shared_ptr< EditBox > Ptr
Shared widget pointer.
Definition: EditBox.hpp:58
void setCaretWidth(float width)
This will change the width of the caret.
float getCaretWidth()
Returns the width of the caret.
Definition: EditBox.hpp:393
void setTextSize(unsigned int textSize)
Changes the character size of the text.
unsigned int getTextSize() const
Returns the character size of the text.
Definition: EditBox.hpp:253
char getPasswordCharacter() const
Returns the password character.
Definition: EditBox.hpp:281
Class to store the position or size of a widget.
Definition: Layout.hpp:255
Implicit converter for settable properties.
Definition: ObjectConverter.hpp:43
Definition: Texture.hpp:45
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:34
Predefined input validators.
Definition: EditBox.hpp:82
static TGUI_API std::string Float
Accept decimal numbers.
Definition: EditBox.hpp:85
static TGUI_API std::string UInt
Accept only positive integers.
Definition: EditBox.hpp:84
static TGUI_API std::string Int
Accept negative and positive integers.
Definition: EditBox.hpp:83