25#ifndef TGUI_TEXT_AREA_HPP
26#define TGUI_TEXT_AREA_HPP
28#include <TGUI/Renderers/TextAreaRenderer.hpp>
29#include <TGUI/Text.hpp>
30#include <TGUI/Widgets/Scrollbar.hpp>
45 using Ptr = std::shared_ptr<TextArea>;
46 using ConstPtr = std::shared_ptr<const TextArea>;
57 explicit TextArea(
const char* typeName =
StaticWidgetType,
bool initRenderer =
true);
285 TGUI_DEPRECATED(
"Use getVerticalScrollbar->setPolicy(policy) instead")
294 TGUI_DEPRECATED(
"Use getVerticalScrollbar->getPolicy() instead")
303 TGUI_DEPRECATED(
"Use getHorizontalScrollbar->setPolicy(policy) instead")
312 TGUI_DEPRECATED(
"Use getHorizontalScrollbar->getPolicy() instead")
359 TGUI_DEPRECATED(
"Use getVerticalScrollbar->getValue() instead")
369 TGUI_DEPRECATED(
"Use getVerticalScrollbar->getMaxValue() instead")
377 TGUI_DEPRECATED(
"Use getHorizontalScrollbar->setValue(value) instead")
385 TGUI_DEPRECATED(
"Use getHorizontalScrollbar->getValue() instead")
395 TGUI_DEPRECATED(
"Use getHorizontalScrollbar->getMaxValue() instead")
413 void leftMouseReleased(Vector2f pos) override;
418 void mouseMoved(Vector2f pos) override;
423 void keyPressed(const
Event::KeyEvent& event) override;
439 void textEntered(
char32_t key) override;
444 bool scrolled(
float delta, Vector2f pos,
bool touch) override;
449 void mouseNoLongerOnWidget() override;
454 void leftMouseButtonNoLongerDown() override;
462 [[nodiscard]]
Vector2<std::
size_t> findCaretPosition(Vector2f position) const;
467 [[nodiscard]] std::
size_t getIndexOfSelectionPos(
Vector2<std::
size_t> selectionPos) const;
473 void deleteSelectedCharacters();
480 void insertTextAtCaretPosition(
String text);
485 void rearrangeText(
bool keepSelection,
bool emitCaretChangedPosition = true);
490 void updateScrollbars();
495 void updateSelectionTexts();
500 void deleteWordLeft();
505 void deleteWordRight();
510 void backspaceKeyPressed();
515 void deleteKeyPressed();
520 void copySelectedTextToClipboard();
525 void cutSelectedTextToClipboard();
530 void pasteTextFromClipboard();
535 void selectAllText();
540 void moveCaretPageUp();
545 void moveCaretPageDown();
550 void moveCaretLeft(
bool shiftPressed);
555 void moveCaretRight(
bool shiftPressed);
560 void moveCaretWordBegin();
565 void moveCaretWordEnd();
581 void setCaretPositionImpl(std::
size_t charactersBeforeCaret,
bool selEndNeedUpdate,
bool emitCaretChangedPosition);
589 [[nodiscard]] Vector2f getInnerSize() const;
594 bool updateTime(
Duration elapsedTime) override;
599 void recalculatePositions();
604 void recalculateVisibleLines();
627 [[nodiscard]] std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers) const override;
632 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
656 void updateSelEnd(const
Vector2<std::
size_t>& newValue);
669 float m_lineHeight = 24;
672 float m_maxLineWidth = 0;
674 std::vector<String> m_lines;
677 std::size_t m_maxChars = 0;
680 std::size_t m_topLine = 1;
681 std::size_t m_visibleLines = 1;
689 Vector2f m_caretPosition;
690 bool m_caretVisible =
true;
695 Text m_textBeforeSelection;
696 Text m_textSelection1;
697 Text m_textSelection2;
698 Text m_textAfterSelection1;
699 Text m_textAfterSelection2;
702 std::vector<FloatRect> m_selectionRects;
705 bool m_possibleDoubleClick =
false;
707 bool m_readOnly =
false;
709 bool m_monospacedFontOptimizationEnabled =
false;
711 Sprite m_spriteBackground;
714 Borders m_bordersCached;
715 Padding m_paddingCached;
716 Color m_borderColorCached;
717 Color m_backgroundColorCached;
718 Color m_caretColorCached;
719 Color m_selectedTextBackgroundColorCached;
720 float m_caretWidthCached = 1;
721 float m_roundedBorderRadiusCached = 0;
Base class for render targets.
Definition BackendRenderTarget.hpp:46
Wrapper for colors.
Definition Color.hpp:63
Wrapper for durations.
Definition Duration.hpp:52
Class to store the position or size of a widget.
Definition Layout.hpp:320
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:59
Wrapper class to store strings.
Definition String.hpp:94
Definition TextAreaRenderer.hpp:35
void setTabString(String tabText)
Changes the string that is inserted when the Tab key is pressed.
Signal onCaretPositionChange
Caret position changed.
Definition TextArea.hpp:663
void setReadOnly(bool readOnly=true)
Makes the text area read-only or make it writable again.
Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
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.
String getText() const
Returns the text of the text area.
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.
const String & getDefaultText() const
Returns the default text of the text area. This is the text drawn when the text area is empty.
std::shared_ptr< const TextArea > ConstPtr
Shared constant widget pointer.
Definition TextArea.hpp:46
void setHorizontalScrollbarValue(unsigned int value)
Changes the thumb position of the horizontal scrollbar.
TextAreaRenderer * getSharedRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
bool isMouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
SignalString onTextChange
The text was changed. Optional parameter: new text.
Definition TextArea.hpp:661
void scrollbarPolicyChanged(Orientation orientation) override
Called when the policy of one of the scrollbars has been changed calling either getVerticalScrollbar(...
Scrollbar::Policy getHorizontalScrollbarPolicy() const
Returns when the horizontal scrollbar should be displayed.
std::size_t getCaretPosition() const
Returns after which character the blinking cursor is currently located.
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:45
std::size_t getSelectionEnd() const
Returns the index where the selection ends.
static TextArea::Ptr copy(const TextArea::ConstPtr &textArea)
Makes a copy of another text area.
void setText(String text)
Changes the text of the text area.
bool isReadOnly() const
Checks if the text area read-only or writable.
std::size_t getLinesCount() const
Returns the amount of lines that the text occupies in the TextArea.
unsigned int getHorizontalScrollbarValue() const
Returns the thumb position of the horizontal scrollbar.
void setMaximumCharacters(std::size_t maxChars=0)
Changes the maximum character limit.
void setCaretPosition(std::size_t charactersBeforeCaret)
Sets the blinking caret to after a specific character.
String getSelectedText() const
Returns the text that you currently have selected.
void setSelectedText(std::size_t selectionStartIndex, std::size_t selectionEndIndex)
Changes which part of the text is selected.
unsigned int getVerticalScrollbarMaxValue() const
Returns the maximum thumb position of the vertical scrollbar.
void setHorizontalScrollbarPolicy(Scrollbar::Policy policy)
Changes when the horizontal scrollbar should be displayed.
TextAreaRenderer * getRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
void setVerticalScrollbarValue(unsigned int value)
Changes the thumb position of the vertical scrollbar.
bool canHandleKeyPress(const Event::KeyEvent &event) override
Called by the parent of the widget to check if keyPressed would process the event.
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
unsigned int getVerticalScrollbarValue() const
Returns the thumb position of the vertical scrollbar.
std::size_t getSelectionStart() const
Returns the index where the selection starts.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
static constexpr char StaticWidgetType[]
Type name of the widget.
Definition TextArea.hpp:48
static TextArea::Ptr create()
Creates a new text area widget.
std::size_t getCaretLine() const
Returns which line the blinking cursor is currently located on.
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...
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the widget to a render target.
std::size_t getMaximumCharacters() const
Returns the maximum character limit.
void setDefaultText(const String &text)
Changes the default text of the text area. This is the text drawn when the text area is empty.
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.
unsigned int getHorizontalScrollbarMaxValue() const
Returns the maximum thumb position of the horizontal scrollbar.
void setSize(const Layout2d &size) override
Changes the size of the text area.
Scrollbar::Policy getVerticalScrollbarPolicy() const
Returns when the vertical scrollbar should be displayed.
void setVerticalScrollbarPolicy(Scrollbar::Policy policy)
Changes when the vertical scrollbar should be displayed.
String getTabString() const
Returns the string that is inserted when the Tab key is pressed.
std::size_t getCaretColumn() const
Returns which column the blinking cursor is currently located on.
void updateTextSize() override
Called when the text size is changed (either by setTextSize or via the renderer).
Signal onSelectionChange
Selected text changed.
Definition TextArea.hpp:662
Backend-independent wrapper around the backend-specific text class.
Definition Text.hpp:53
Definition Vector2.hpp:42
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:37
Orientation
Orientation of the object.
Definition Layout.hpp:50
SignalTyped< const String & > SignalString
Signal with one "String" as optional unbound parameter.
Definition Signal.hpp:413
States used for drawing.
Definition RenderStates.hpp:38