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);
380 void leftMousePressed(
Vector2f pos)
override;
385 void leftMouseReleased(
Vector2f pos)
override;
390 void mouseMoved(
Vector2f pos)
override;
400 void textEntered(
char32_t key)
override;
405 bool mouseWheelScrolled(
float delta,
Vector2f pos)
override;
410 void mouseNoLongerOnWidget()
override;
415 void leftMouseButtonNoLongerDown()
override;
438 void selectText(
float posX,
float posY);
445 void deleteSelectedCharacters();
451 void rearrangeText(
bool keepSelection);
456 void updateScrollbars();
461 void updateSelectionTexts();
467 void backspaceKeyPressed();
472 void deleteKeyPressed();
477 void copySelectedTextToClipboard();
482 void cutSelectedTextToClipboard();
487 void pasteTextFromClipboard();
492 void selectAllText();
497 void moveCaretPageUp();
502 void moveCaretPageDown();
507 void moveCaretLeft(
bool shiftPressed);
512 void moveCaretRight(
bool shiftPressed);
517 void moveCaretWordBegin();
522 void moveCaretWordEnd();
547 bool updateTime(
Duration elapsedTime)
override;
553 void recalculatePositions();
559 void recalculateVisibleLines();
586 std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
592 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
611 Signal onSelectionChange = {
"SelectionChanged"};
618 unsigned int m_lineHeight = 24;
621 float m_maxLineWidth;
623 std::vector<String> m_lines;
626 std::size_t m_maxChars = 0;
629 std::size_t m_topLine = 1;
630 std::size_t m_visibleLines = 1;
639 bool m_caretVisible =
true;
641 Text m_textBeforeSelection;
642 Text m_textSelection1;
643 Text m_textSelection2;
644 Text m_textAfterSelection1;
645 Text m_textAfterSelection2;
648 std::vector<FloatRect> m_selectionRects;
657 bool m_possibleDoubleClick =
false;
659 bool m_readOnly =
false;
661 bool m_monospacedFontOptimizationEnabled =
false;
663 Sprite m_spriteBackground;
668 Color m_borderColorCached;
669 Color m_backgroundColorCached;
670 Color m_caretColorCached;
671 Color m_selectedTextBackgroundColorCached;
672 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:284
Definition: Outline.hpp:39
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:58
Definition: Sprite.hpp:45
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.
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.
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.
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.
void updateTextSize() override
Called when the text size is changed (either by setTextSize or via the renderer)
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