25#ifndef TGUI_TEXT_AREA_HPP
26#define TGUI_TEXT_AREA_HPP
28#include <TGUI/Widgets/Scrollbar.hpp>
29#include <TGUI/Renderers/TextAreaRenderer.hpp>
30#include <TGUI/Text.hpp>
34TGUI_MODULE_EXPORT
namespace tgui
46 using Ptr = std::shared_ptr<TextArea>;
47 using ConstPtr = std::shared_ptr<const TextArea>;
49 static constexpr const char StaticWidgetType[] =
"TextArea";
58 TextArea(
const char* typeName = StaticWidgetType,
bool initRenderer =
true);
98 using Widget::setSize;
286 TGUI_DEPRECATED(
"Use getVerticalScrollbar->setPolicy(policy) instead") void setVerticalScrollbarPolicy(
Scrollbar::Policy policy);
294 TGUI_DEPRECATED("Use getVerticalScrollbar->getPolicy() instead") TGUI_NODISCARD
Scrollbar::Policy getVerticalScrollbarPolicy() const;
302 TGUI_DEPRECATED("Use getHorizontalScrollbar->setPolicy(policy) instead")
void setHorizontalScrollbarPolicy(
Scrollbar::Policy policy);
310 TGUI_DEPRECATED("Use getHorizontalScrollbar->getPolicy() instead") TGUI_NODISCARD
Scrollbar::Policy getHorizontalScrollbarPolicy() const;
319 TGUI_NODISCARD std::
size_t getLinesCount() const;
329 void setFocused(
bool focused) override;
342 void enableMonospacedFontOptimization(
bool enable = true);
349 TGUI_DEPRECATED("Use getVerticalScrollbar->setValue(value) instead")
void setVerticalScrollbarValue(
unsigned int value);
356 TGUI_DEPRECATED("Use getVerticalScrollbar->getValue() instead") TGUI_NODISCARD
unsigned int getVerticalScrollbarValue() const;
365 TGUI_DEPRECATED("Use getVerticalScrollbar->getMaxValue() instead") TGUI_NODISCARD
unsigned int getVerticalScrollbarMaxValue() const;
372 TGUI_DEPRECATED("Use getHorizontalScrollbar->setValue(value) instead")
void setHorizontalScrollbarValue(
unsigned int value);
379 TGUI_DEPRECATED("Use getHorizontalScrollbar->getValue() instead") TGUI_NODISCARD
unsigned int getHorizontalScrollbarValue() const;
388 TGUI_DEPRECATED("Use getHorizontalScrollbar->getMaxValue() instead") TGUI_NODISCARD
unsigned int getHorizontalScrollbarMaxValue() const;
395 TGUI_NODISCARD
bool isMouseOnWidget(
Vector2f pos) const override;
405 void leftMouseReleased(
Vector2f pos) override;
410 void mouseMoved(
Vector2f pos) override;
415 void keyPressed(const
Event::KeyEvent& event) override;
426 bool canHandleKeyPress(const
Event::KeyEvent& event) override;
431 void textEntered(
char32_t key) override;
436 bool scrolled(
float delta,
Vector2f pos,
bool touch) override;
441 void mouseNoLongerOnWidget() override;
446 void leftMouseButtonNoLongerDown() override;
454 TGUI_NODISCARD
Vector2<std::
size_t> findCaretPosition(
Vector2f position) const;
459 TGUI_NODISCARD std::
size_t getIndexOfSelectionPos(
Vector2<std::
size_t> selectionPos) const;
465 void deleteSelectedCharacters();
472 void insertTextAtCaretPosition(
String text);
477 void rearrangeText(
bool keepSelection, const
bool emitCaretChangedPosition = true);
482 void updateScrollbars();
487 void updateSelectionTexts();
492 void backspaceKeyPressed();
497 void deleteKeyPressed();
502 void copySelectedTextToClipboard();
507 void cutSelectedTextToClipboard();
512 void pasteTextFromClipboard();
517 void selectAllText();
522 void moveCaretPageUp();
527 void moveCaretPageDown();
532 void moveCaretLeft(
bool shiftPressed);
537 void moveCaretRight(
bool shiftPressed);
542 void moveCaretWordBegin();
547 void moveCaretWordEnd();
563 void setCaretPositionImpl(std::
size_t charactersBeforeCaret,
bool selEndNeedUpdate,
bool emitCaretChangedPosition);
571 TGUI_NODISCARD
Vector2f getInnerSize() const;
576 bool updateTime(
Duration elapsedTime) override;
581 void recalculatePositions();
586 void recalculateVisibleLines();
604 void rendererChanged(const
String& property) override;
609 TGUI_NODISCARD std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
614 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
619 void updateTextSize() override;
638 void updateSelEnd(const
Vector2<std::
size_t>& newValue);
644 Signal onSelectionChange = {
"SelectionChanged"};
645 Signal onCaretPositionChange = {
"CaretPositionChanged"};
651 float m_lineHeight = 24;
654 float m_maxLineWidth = 0;
656 std::vector<String> m_lines;
659 std::size_t m_maxChars = 0;
662 std::size_t m_topLine = 1;
663 std::size_t m_visibleLines = 1;
672 bool m_caretVisible =
true;
677 Text m_textBeforeSelection;
678 Text m_textSelection1;
679 Text m_textSelection2;
680 Text m_textAfterSelection1;
681 Text m_textAfterSelection2;
684 std::vector<FloatRect> m_selectionRects;
687 bool m_possibleDoubleClick =
false;
689 bool m_readOnly =
false;
691 bool m_monospacedFontOptimizationEnabled =
false;
693 Sprite m_spriteBackground;
698 Color m_borderColorCached;
699 Color m_backgroundColorCached;
700 Color m_caretColorCached;
701 Color m_selectedTextBackgroundColorCached;
702 float m_caretWidthCached = 1;
Base class for render targets.
Definition BackendRenderTarget.hpp:46
Wrapper for colors.
Definition Color.hpp:73
Wrapper for durations.
Definition Duration.hpp:55
Class to store the position or size of a widget.
Definition Layout.hpp:323
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
Definition TextAreaRenderer.hpp:35
Text area widget.
Definition TextArea.hpp:43
void setTabString(String tabText)
Changes the string that is inserted when the Tab key is pressed.
void setReadOnly(bool readOnly=true)
Makes the text area read-only or make it writable again.
String getText() const
Returns the text of the text area.
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:47
TextAreaRenderer * getSharedRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is 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:46
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.
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.
TextAreaRenderer * getRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
std::size_t getSelectionStart() const
Returns the index where the selection starts.
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.
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.
void setSize(const Layout2d &size) override
Changes the size of the text area.
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.
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
Orientation
Orientation of the object.
Definition Layout.hpp:52
States used for drawing.
Definition RenderStates.hpp:38