25#ifndef TGUI_TEXT_AREA_HPP
26#define TGUI_TEXT_AREA_HPP
28#include <TGUI/CopiedSharedPtr.hpp>
29#include <TGUI/Widgets/Scrollbar.hpp>
30#include <TGUI/Renderers/TextAreaRenderer.hpp>
31#include <TGUI/Text.hpp>
35TGUI_MODULE_EXPORT
namespace tgui
47 using Ptr = std::shared_ptr<TextArea>;
48 using ConstPtr = std::shared_ptr<const TextArea>;
50 static constexpr const char StaticWidgetType[] =
"TextArea";
59 TextArea(
const char* typeName = StaticWidgetType,
bool initRenderer =
true);
99 using Widget::setSize;
406 void leftMouseReleased(
Vector2f pos)
override;
411 void mouseMoved(
Vector2f pos)
override;
432 void textEntered(
char32_t key)
override;
442 void mouseNoLongerOnWidget()
override;
447 void leftMouseButtonNoLongerDown()
override;
466 void deleteSelectedCharacters();
473 void insertTextAtCaretPosition(
String text);
478 void rearrangeText(
bool keepSelection,
const bool emitCaretChangedPosition =
true);
483 void updateScrollbars();
488 void updateSelectionTexts();
493 void backspaceKeyPressed();
498 void deleteKeyPressed();
503 void copySelectedTextToClipboard();
508 void cutSelectedTextToClipboard();
513 void pasteTextFromClipboard();
518 void selectAllText();
523 void moveCaretPageUp();
528 void moveCaretPageDown();
533 void moveCaretLeft(
bool shiftPressed);
538 void moveCaretRight(
bool shiftPressed);
543 void moveCaretWordBegin();
548 void moveCaretWordEnd();
564 void setCaretPositionImpl(std::size_t charactersBeforeCaret,
bool selEndNeedUpdate,
bool emitCaretChangedPosition);
572 TGUI_NODISCARD
Vector2f getInnerSize()
const;
577 bool updateTime(
Duration elapsedTime)
override;
582 void recalculatePositions();
587 void recalculateVisibleLines();
610 TGUI_NODISCARD std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
615 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
637 Signal onSelectionChange = {
"SelectionChanged"};
638 Signal onCaretPositionChange = {
"CaretPositionChanged"};
644 float m_lineHeight = 24;
647 float m_maxLineWidth = 0;
649 std::vector<String> m_lines;
652 std::size_t m_maxChars = 0;
655 std::size_t m_topLine = 1;
656 std::size_t m_visibleLines = 1;
665 bool m_caretVisible =
true;
670 Text m_textBeforeSelection;
671 Text m_textSelection1;
672 Text m_textSelection2;
673 Text m_textAfterSelection1;
674 Text m_textAfterSelection2;
677 std::vector<FloatRect> m_selectionRects;
686 bool m_possibleDoubleClick =
false;
688 bool m_readOnly =
false;
690 bool m_monospacedFontOptimizationEnabled =
false;
692 Sprite m_spriteBackground;
697 Color m_borderColorCached;
698 Color m_backgroundColorCached;
699 Color m_caretColorCached;
700 Color m_selectedTextBackgroundColorCached;
701 float m_caretWidthCached = 1;
Base class for render targets.
Definition BackendRenderTarget.hpp:46
Wrapper for colors.
Definition Color.hpp:73
Definition CopiedSharedPtr.hpp:42
Wrapper for durations.
Definition Duration.hpp:55
Class to store the position or size of a widget.
Definition Layout.hpp:313
Definition Outline.hpp:38
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:61
Wrapper class to store strings.
Definition String.hpp:96
Text area widget.
Definition TextArea.hpp:44
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.
TGUI_NODISCARD unsigned int getVerticalScrollbarMaxValue() const
Returns the maximum thumb position of the vertical scrollbar.
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:48
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:47
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 unsigned int getHorizontalScrollbarMaxValue() const
Returns the maximum 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.
Definition TextAreaRenderer.hpp:35
Backend-independent wrapper around the backend-specific text class.
Definition Text.hpp:48
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38
KeyPressed event parameters.
Definition Event.hpp:168
States used for drawing.
Definition RenderStates.hpp:38