26#ifndef TGUI_TEXT_BOX_HPP
27#define TGUI_TEXT_BOX_HPP
30#include <TGUI/Widget.hpp>
37 class TextBoxRenderer;
54 typedef std::shared_ptr<TextBox>
Ptr;
55 typedef std::shared_ptr<const TextBox>
ConstPtr;
112 return std::static_pointer_cast<TextBoxRenderer>(m_renderer);
330 virtual bool mouseOnWidget(
float x,
float y)
const override;
335 virtual void leftMousePressed(
float x,
float y)
override;
340 virtual void leftMouseReleased(
float x,
float y)
override;
345 virtual void mouseMoved(
float x,
float y)
override;
350 virtual void keyPressed(
const sf::Event::KeyEvent& event)
override;
355 virtual void textEntered(sf::Uint32 Key)
override;
360 virtual void mouseWheelMoved(
int delta,
int x,
int y)
override;
365 virtual void mouseNoLongerOnWidget()
override;
370 virtual void mouseNoLongerDown()
override;
375 virtual void widgetFocused()
override;
380 virtual void widgetUnfocused()
override;
390 sf::Vector2<std::size_t> findCaretPosition(sf::Vector2f position);
396 std::pair<std::size_t, std::size_t> findTextCaretPosition();
403 void selectText(
float posX,
float posY);
410 void deleteSelectedCharacters();
416 void rearrangeText(
bool keepSelection);
422 void updateSelectionTexts();
431 virtual void update(sf::Time elapsedTime)
override;
446 virtual void reload(
const std::string& primary =
"",
const std::string& secondary =
"",
bool force =
false)
override;
454 return std::make_shared<TextBox>(*
this);
461 virtual void draw(sf::RenderTarget& target, sf::RenderStates states)
const override;
468 unsigned int m_textSize = 18;
469 unsigned int m_lineHeight = 24;
471 std::vector<sf::String> m_lines = std::vector<sf::String>{
""};
474 std::size_t m_maxChars = 0;
477 std::size_t m_topLine = 1;
478 std::size_t m_visibleLines = 1;
481 sf::Vector2<std::size_t> m_selStart;
482 sf::Vector2<std::size_t> m_selEnd;
485 sf::Vector2f m_caretPosition;
486 bool m_caretVisible =
true;
488 sf::Text m_textBeforeSelection;
489 sf::Text m_textSelection1;
490 sf::Text m_textSelection2;
491 sf::Text m_textAfterSelection1;
492 sf::Text m_textAfterSelection2;
494 std::vector<sf::FloatRect> m_selectionRects;
500 bool m_possibleDoubleClick =
false;
502 bool m_readOnly =
false;
504 friend class TextBoxRenderer;
535 virtual void setProperty(std::string property,
const std::string& value)
override;
664 void draw(sf::RenderTarget& target, sf::RenderStates states)
const;
673 Padding getScaledPadding()
const;
679 virtual std::shared_ptr<WidgetRenderer> clone(
Widget* widget)
override;
687 float m_caretWidth = 1;
691 sf::Color m_textColor;
692 sf::Color m_selectedTextColor;
693 sf::Color m_caretColor;
694 sf::Color m_backgroundColor;
695 sf::Color m_selectedTextBgrColor;
696 sf::Color m_borderColor;
Definition: Borders.hpp:38
Implicit converter for colors.
Definition: Color.hpp:40
Class to store the position or size of a widget.
Definition: Layout.hpp:255
Implicit converter for settable properties.
Definition: ObjectConverter.hpp:43
Definition: TextBox.hpp:513
void setBackgroundColor(const Color &backgroundColor)
Set the background color that will be used inside the text box.
void setBorderColor(const Color &borderColor)
Set the border color that will be used inside the text box.
virtual void setPadding(const Padding &padding) override
Changes the padding of the text box.
void setCaretColor(const Color &caretColor)
Set the color that will be used inside the text box for the blinking caret.
virtual std::map< std::string, ObjectConverter > getPropertyValuePairs() const override
Get a map with all properties and their values.
void setTextColor(const Color &textColor)
Set the text color that will be used inside the text box.
virtual void setProperty(std::string property, const std::string &value) override
Change a property of the renderer.
void setSelectedTextColor(const Color &selectedTextColor)
Set the text color of the selected text that will be used inside the text box.
void setBackgroundTexture(const Texture &texture)
Changes the background image.
virtual void setProperty(std::string property, ObjectConverter &&value) override
Change a property of the renderer.
virtual ObjectConverter getProperty(std::string property) const override
Retrieve the value of a certain property.
void setSelectedTextBackgroundColor(const Color &selectedTextBackgroundColor)
Set the background color of the selected text that will be used inside the text box.
TextBoxRenderer(TextBox *textBox)
Constructor.
Definition: TextBox.hpp:522
void setCaretWidth(float width)
This will change the width of the blinking caret.
Text box widget.
Definition: TextBox.hpp:51
void setScrollbar(Scrollbar::Ptr scrollbar)
Changes the scrollbar of the text box.
std::shared_ptr< TextBox > Ptr
Shared widget pointer.
Definition: TextBox.hpp:54
void setMaximumCharacters(std::size_t maxChars=0)
Changes the maximum character limit.
virtual void setFont(const Font &font) override
Changes the font of the text in the widget.
virtual sf::Vector2f getWidgetOffset() const override
Returns the distance between the position where the widget is drawn and where the widget is placed.
bool isReadOnly() const
Check if the text box read-only or writable.
virtual void setPosition(const Layout2d &position) override
Set the position of the widget.
static TextBox::Ptr create()
Creates a new text box widget.
unsigned int getTextSize() const
Returns the character size of the text.
Definition: TextBox.hpp:221
void setText(const sf::String &text)
Changes the text of the text box.
virtual void setSize(const Layout2d &size) override
Changes the size of the text box.
virtual void setOpacity(float opacity) override
Changes the opacity of the widget.
TextBox(const TextBox ©)
Copy constructor.
virtual sf::Vector2f getFullSize() const override
Returns the full size of the text box.
void setTextSize(unsigned int size)
Changes the character size of the text.
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: TextBox.hpp:452
std::shared_ptr< TextBoxRenderer > getRenderer() const
Returns the renderer, which gives access to functions that determine how the widget is displayed.
Definition: TextBox.hpp:110
sf::String getText() const
Returns the text of the text box.
Definition: TextBox.hpp:190
void setReadOnly(bool readOnly=true)
Make the text box read-only or make it writable again.
static TextBox::Ptr copy(TextBox::ConstPtr textBox)
Makes a copy of another text box.
Scrollbar::Ptr getScrollbar()
Access the scrollbar of the text box.
std::shared_ptr< const TextBox > ConstPtr
Shared constant widget pointer.
Definition: TextBox.hpp:55
void addText(const sf::String &text)
Appends some text to the text that was already in the text box.
std::size_t getMaximumCharacters() const
Returns the maximum character limit.
Definition: TextBox.hpp:248
sf::String getSelectedText() const
Returns the text that you currently have selected.
Definition: Texture.hpp:45
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:34