26#ifndef TGUI_TEXT_AREA_HPP
27#define TGUI_TEXT_AREA_HPP
30#include <TGUI/CopiedSharedPtr.hpp>
31#include <TGUI/Widgets/Scrollbar.hpp>
32#include <TGUI/Renderers/TextAreaRenderer.hpp>
33#include <TGUI/Text.hpp>
37TGUI_MODULE_EXPORT
namespace tgui
49 using Ptr = std::shared_ptr<TextArea>;
50 using ConstPtr = std::shared_ptr<const TextArea>;
52 static constexpr const char StaticWidgetType[] =
"TextArea";
62 TextArea(
const char* typeName = StaticWidgetType,
bool initRenderer =
true);
108 using Widget::setSize;
440 void leftMouseReleased(
Vector2f pos)
override;
445 void mouseMoved(
Vector2f pos)
override;
466 void textEntered(
char32_t key)
override;
476 void mouseNoLongerOnWidget()
override;
481 void leftMouseButtonNoLongerDown()
override;
504 void deleteSelectedCharacters();
512 void insertTextAtCaretPosition(
String text);
518 void rearrangeText(
bool keepSelection,
const bool emitCaretChangedPosition =
true);
524 void updateScrollbars();
530 void updateSelectionTexts();
536 void backspaceKeyPressed();
541 void deleteKeyPressed();
546 void copySelectedTextToClipboard();
551 void cutSelectedTextToClipboard();
556 void pasteTextFromClipboard();
561 void selectAllText();
566 void moveCaretPageUp();
571 void moveCaretPageDown();
576 void moveCaretLeft(
bool shiftPressed);
581 void moveCaretRight(
bool shiftPressed);
586 void moveCaretWordBegin();
591 void moveCaretWordEnd();
610 void setCaretPositionImpl(std::size_t charactersBeforeCaret,
bool selEndNeedUpdate,
bool emitCaretChangedPosition);
619 TGUI_NODISCARD
Vector2f getInnerSize()
const;
625 bool updateTime(
Duration elapsedTime)
override;
631 void recalculatePositions();
637 void recalculateVisibleLines();
664 TGUI_NODISCARD std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
670 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
696 Signal onSelectionChange = {
"SelectionChanged"};
697 Signal onCaretPositionChange = {
"CaretPositionChanged"};
704 float m_lineHeight = 24;
707 float m_maxLineWidth = 0;
709 std::vector<String> m_lines;
712 std::size_t m_maxChars = 0;
715 std::size_t m_topLine = 1;
716 std::size_t m_visibleLines = 1;
725 bool m_caretVisible =
true;
730 Text m_textBeforeSelection;
731 Text m_textSelection1;
732 Text m_textSelection2;
733 Text m_textAfterSelection1;
734 Text m_textAfterSelection2;
737 std::vector<FloatRect> m_selectionRects;
746 bool m_possibleDoubleClick =
false;
748 bool m_readOnly =
false;
750 bool m_monospacedFontOptimizationEnabled =
false;
752 Sprite m_spriteBackground;
757 Color m_borderColorCached;
758 Color m_backgroundColorCached;
759 Color m_caretColorCached;
760 Color m_selectedTextBackgroundColorCached;
761 float m_caretWidthCached = 1;
Base class for render targets.
Definition BackendRenderTarget.hpp:48
Wrapper for colors.
Definition Color.hpp:72
Definition CopiedSharedPtr.hpp:45
Wrapper for durations.
Definition Duration.hpp:56
Class to store the position or size of a widget.
Definition Layout.hpp:305
Definition Outline.hpp:39
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:62
Wrapper class to store strings.
Definition String.hpp:101
Definition TextAreaRenderer.hpp:37
Text area widget.
Definition TextArea.hpp:46
void setTabString(String tabText)
Changes the string that is inserted when the Tab key is pressed.
TGUI_NODISCARD unsigned int getVerticalScrollbarValue() const
Returns the thumb position of the vertical scrollbar.
void setReadOnly(bool readOnly=true)
Makes the text area read-only or make it writable again.
void enableMonospacedFontOptimization(bool enable=true)
Changes whether an optimization is made that only works when using a monospaced font.
bool leftMousePressed(Vector2f pos) override
Called by the parent when the left mouse button goes down 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.
void setFocused(bool focused) override
Focus or unfocus the widget.
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.
std::shared_ptr< const TextArea > ConstPtr
Shared constant widget pointer.
Definition TextArea.hpp:50
void setHorizontalScrollbarValue(unsigned int value)
Changes the thumb position of the horizontal scrollbar.
TGUI_NODISCARD std::size_t getCaretColumn() const
Returns which column the blinking cursor is currently located on.
static TGUI_NODISCARD TextArea::Ptr create()
Creates a new text area widget.
void addText(String text)
Appends some text to the text that was already in the text area.
std::shared_ptr< TextArea > Ptr
Shared widget pointer.
Definition TextArea.hpp:49
void setText(String text)
Changes the text of the text area.
TGUI_NODISCARD std::size_t getCaretPosition() const
Returns after which character the blinking cursor is currently located.
TGUI_NODISCARD Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
TGUI_NODISCARD TextAreaRenderer * getSharedRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
static TGUI_NODISCARD TextArea::Ptr copy(const TextArea::ConstPtr &textArea)
Makes a copy of another text area.
TGUI_NODISCARD bool isReadOnly() const
Checks if the text area read-only or writable.
void setMaximumCharacters(std::size_t maxChars=0)
Changes the maximum character limit.
TGUI_NODISCARD const String & getDefaultText() const
Returns the default text of the text area. This is the text drawn when the text area is empty.
void setCaretPosition(std::size_t charactersBeforeCaret)
Sets the blinking caret to after a specific character.
TGUI_NODISCARD TextAreaRenderer * getRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
TGUI_NODISCARD Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
void setSelectedText(std::size_t selectionStartIndex, std::size_t selectionEndIndex)
Changes which part of the text is selected.
void setHorizontalScrollbarPolicy(Scrollbar::Policy policy)
Changes when the horizontal scrollbar should be displayed.
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 setVerticalScrollbarValue(unsigned int value)
Changes the thumb position of the vertical scrollbar.
TGUI_NODISCARD std::size_t getSelectionEnd() const
Returns the index where the selection ends.
TGUI_NODISCARD std::size_t getSelectionStart() const
Returns the index where the selection starts.
TGUI_NODISCARD std::size_t getMaximumCharacters() const
Returns the maximum character limit.
bool canHandleKeyPress(const Event::KeyEvent &event) override
Called by the parent of the widget to check if keyPressed would process the event.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
bool scrolled(float delta, Vector2f pos, bool touch) override
Called by the parent on scroll event (either from mouse wheel of from two finger scrolling on a touch...
TGUI_NODISCARD std::size_t getLinesCount() const
Returns the amount of lines that the text occupies in the TextArea.
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the widget to a render target.
void setDefaultText(const String &text)
Changes the default text of the text area. This is the text drawn when the text area is empty.
void setSize(const Layout2d &size) override
Changes the size of the text area.
void setVerticalScrollbarPolicy(Scrollbar::Policy policy)
Changes when the vertical scrollbar should be displayed.
TGUI_NODISCARD unsigned int getHorizontalScrollbarValue() const
Returns the thumb position of the horizontal scrollbar.
TGUI_NODISCARD std::size_t getCaretLine() const
Returns which line the blinking cursor is currently located on.
TGUI_NODISCARD String getText() const
Returns the text of the text area.
TGUI_NODISCARD String getTabString() const
Returns the string that is inserted when the Tab key is pressed.
void updateTextSize() override
Called when the text size is changed (either by setTextSize or via the renderer)
TGUI_NODISCARD Scrollbar::Policy getHorizontalScrollbarPolicy() const
Returns when the horizontal scrollbar should be displayed.
TGUI_NODISCARD String getSelectedText() const
Returns the text that you currently have selected.
TGUI_NODISCARD Scrollbar::Policy getVerticalScrollbarPolicy() const
Returns when the vertical scrollbar should be displayed.
Backend-independent wrapper around the backend-specific text class.
Definition Text.hpp:50
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39
KeyPressed event parameters.
Definition Event.hpp:169
States used for drawing.
Definition RenderStates.hpp:39