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>
46 using Ptr = std::shared_ptr<TextArea>;
47 using ConstPtr = std::shared_ptr<const TextArea>;
405 void leftMouseReleased(Vector2f pos) override;
410 void mouseMoved(Vector2f pos) override;
415 void keyPressed(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 deleteWordLeft();
497 void deleteWordRight();
502 void backspaceKeyPressed();
507 void deleteKeyPressed();
512 void copySelectedTextToClipboard();
517 void cutSelectedTextToClipboard();
522 void pasteTextFromClipboard();
527 void selectAllText();
532 void moveCaretPageUp();
537 void moveCaretPageDown();
542 void moveCaretLeft(
bool shiftPressed);
547 void moveCaretRight(
bool shiftPressed);
552 void moveCaretWordBegin();
557 void moveCaretWordEnd();
573 void setCaretPositionImpl(std::
size_t charactersBeforeCaret,
bool selEndNeedUpdate,
bool emitCaretChangedPosition);
581 TGUI_NODISCARD Vector2f getInnerSize() const;
586 bool updateTime(
Duration elapsedTime) override;
591 void recalculatePositions();
596 void recalculateVisibleLines();
619 TGUI_NODISCARD std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers) const override;
624 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
648 void updateSelEnd(const
Vector2<std::
size_t>& newValue);
661 float m_lineHeight = 24;
664 float m_maxLineWidth = 0;
666 std::vector<String> m_lines;
669 std::size_t m_maxChars = 0;
672 std::size_t m_topLine = 1;
673 std::size_t m_visibleLines = 1;
681 Vector2f m_caretPosition;
682 bool m_caretVisible =
true;
687 Text m_textBeforeSelection;
688 Text m_textSelection1;
689 Text m_textSelection2;
690 Text m_textAfterSelection1;
691 Text m_textAfterSelection2;
694 std::vector<FloatRect> m_selectionRects;
697 bool m_possibleDoubleClick =
false;
699 bool m_readOnly =
false;
701 bool m_monospacedFontOptimizationEnabled =
false;
703 Sprite m_spriteBackground;
706 Borders m_bordersCached;
707 Padding m_paddingCached;
708 Color m_borderColorCached;
709 Color m_backgroundColorCached;
710 Color m_caretColorCached;
711 Color m_selectedTextBackgroundColorCached;
712 float m_caretWidthCached = 1;
713 float m_roundedBorderRadiusCached = 0;
Base class for render targets.
Definition BackendRenderTarget.hpp:46
Wrapper for colors.
Definition Color.hpp:71
Wrapper for durations.
Definition Duration.hpp:53
Class to store the position or size of a widget.
Definition Layout.hpp:321
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:655
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.
static constexpr const char StaticWidgetType[]
Type name of the widget.
Definition TextArea.hpp:49
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:47
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:653
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: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.
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 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:654
Backend-independent wrapper around the backend-specific text class.
Definition Text.hpp:53
Definition Vector2.hpp:41
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:36
Orientation
Orientation of the object.
Definition Layout.hpp:50
SignalTyped< const String & > SignalString
Signal with one "String" as optional unbound parameter.
Definition Signal.hpp:426
States used for drawing.
Definition RenderStates.hpp:38