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>
49 typedef std::shared_ptr<TextArea>
Ptr;
50 typedef std::shared_ptr<const TextArea>
ConstPtr;
60 TextArea(
const char* typeName =
"TextArea",
bool initRenderer =
true);
107 using Widget::setSize;
390 void leftMousePressed(
Vector2f pos)
override;
395 void leftMouseReleased(
Vector2f pos)
override;
400 void mouseMoved(
Vector2f pos)
override;
410 void textEntered(
char32_t key)
override;
415 bool mouseWheelScrolled(
float delta,
Vector2f pos)
override;
420 void mouseNoLongerOnWidget()
override;
425 void leftMouseButtonNoLongerDown()
override;
448 void selectText(
float posX,
float posY);
455 void deleteSelectedCharacters();
461 void rearrangeText(
bool keepSelection);
466 void updateScrollbars();
471 void updateSelectionTexts();
477 void backspaceKeyPressed();
482 void deleteKeyPressed();
487 void copySelectedTextToClipboard();
492 void cutSelectedTextToClipboard();
497 void pasteTextFromClipboard();
502 void selectAllText();
507 void moveCaretPageUp();
512 void moveCaretPageDown();
517 void moveCaretLeft(
bool shiftPressed);
522 void moveCaretRight(
bool shiftPressed);
527 void moveCaretWordBegin();
532 void moveCaretWordEnd();
557 bool updateTime(
Duration elapsedTime)
override;
563 void recalculatePositions();
569 void recalculateVisibleLines();
596 std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
602 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
610 return std::make_shared<TextArea>(*
this);
618 Signal onSelectionChange = {
"SelectionChanged"};
625 unsigned int m_lineHeight = 24;
628 float m_maxLineWidth;
630 std::vector<String> m_lines;
633 std::size_t m_maxChars = 0;
636 std::size_t m_topLine = 1;
637 std::size_t m_visibleLines = 1;
646 bool m_caretVisible =
true;
648 Text m_textBeforeSelection;
649 Text m_textSelection1;
650 Text m_textSelection2;
651 Text m_textAfterSelection1;
652 Text m_textAfterSelection2;
655 std::vector<FloatRect> m_selectionRects;
664 bool m_possibleDoubleClick =
false;
666 bool m_readOnly =
false;
668 bool m_monospacedFontOptimizationEnabled =
false;
670 Sprite m_spriteBackground;
675 Color m_borderColorCached;
676 Color m_backgroundColorCached;
677 Color m_caretColorCached;
678 Color m_selectedTextBackgroundColorCached;
679 float m_caretWidthCached = 1;
Base class for render targets.
Definition BackendRenderTarget.hpp:48
Wrapper for colors.
Definition Color.hpp:63
Definition CopiedSharedPtr.hpp:40
Wrapper for durations.
Definition Duration.hpp:52
Class to store the position or size of a widget.
Definition Layout.hpp:262
Definition Outline.hpp:39
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:58
Wrapper class to store strings.
Definition String.hpp:79
Definition TextAreaRenderer.hpp:37
Text area widget.
Definition TextArea.hpp:46
std::shared_ptr< TextArea > Ptr
Shared widget pointer.
Definition TextArea.hpp:49
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.
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.
void setText(const String &text)
Changes the text of the text area.
void setHorizontalScrollbarValue(unsigned int value)
Changes the thumb position of the horizontal scrollbar.
bool isMouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
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.
TextAreaRenderer * getRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
std::size_t getSelectionEnd() const
Returns the index where the selection ends.
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.
void setHorizontalScrollbarPolicy(Scrollbar::Policy policy)
Changes when the horizontal scrollbar should be displayed.
TextAreaRenderer * getSharedRenderer()
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.
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition TextArea.hpp:608
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.
static TextArea::Ptr copy(TextArea::ConstPtr textArea)
Makes a copy of another text area.
std::shared_ptr< const TextArea > ConstPtr
Shared constant widget pointer.
Definition TextArea.hpp:50
void addText(const String &text)
Appends some text to the text that was already in the text area.
std::size_t getMaximumCharacters() const
Returns the maximum character limit.
void draw(BackendRenderTargetBase &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.
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.
void setTextSize(unsigned int size) override
Changes the character size of the text.
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.
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:36
KeyPressed event parameters.
Definition Event.hpp:167
States used for drawing.
Definition RenderStates.hpp:39