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;
435 bool leftMousePressed(
Vector2f pos)
override;
440 void leftMouseReleased(
Vector2f pos)
override;
445 void mouseMoved(
Vector2f pos)
override;
455 void textEntered(
char32_t key)
override;
460 bool scrolled(
float delta,
Vector2f pos,
bool touch)
override;
465 void mouseNoLongerOnWidget()
override;
470 void leftMouseButtonNoLongerDown()
override;
493 void deleteSelectedCharacters();
501 void insertTextAtCaretPosition(
String text);
507 void rearrangeText(
bool keepSelection,
const bool emitCaretChangedPosition =
true);
513 void updateScrollbars();
519 void updateSelectionTexts();
525 void backspaceKeyPressed();
530 void deleteKeyPressed();
535 void copySelectedTextToClipboard();
540 void cutSelectedTextToClipboard();
545 void pasteTextFromClipboard();
550 void selectAllText();
555 void moveCaretPageUp();
560 void moveCaretPageDown();
565 void moveCaretLeft(
bool shiftPressed);
570 void moveCaretRight(
bool shiftPressed);
575 void moveCaretWordBegin();
580 void moveCaretWordEnd();
599 void setCaretPositionImpl(std::size_t charactersBeforeCaret,
bool selEndNeedUpdate,
bool emitCaretChangedPosition);
608 TGUI_NODISCARD
Vector2f getInnerSize()
const;
614 bool updateTime(
Duration elapsedTime)
override;
620 void recalculatePositions();
626 void recalculateVisibleLines();
653 TGUI_NODISCARD std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
659 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
685 Signal onSelectionChange = {
"SelectionChanged"};
686 Signal onCaretPositionChange = {
"CaretPositionChanged"};
693 float m_lineHeight = 24;
696 float m_maxLineWidth = 0;
698 std::vector<String> m_lines;
701 std::size_t m_maxChars = 0;
704 std::size_t m_topLine = 1;
705 std::size_t m_visibleLines = 1;
714 bool m_caretVisible =
true;
719 Text m_textBeforeSelection;
720 Text m_textSelection1;
721 Text m_textSelection2;
722 Text m_textAfterSelection1;
723 Text m_textAfterSelection2;
726 std::vector<FloatRect> m_selectionRects;
735 bool m_possibleDoubleClick =
false;
737 bool m_readOnly =
false;
739 bool m_monospacedFontOptimizationEnabled =
false;
741 Sprite m_spriteBackground;
746 Color m_borderColorCached;
747 Color m_backgroundColorCached;
748 Color m_caretColorCached;
749 Color m_selectedTextBackgroundColorCached;
750 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:289
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.
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.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
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