26#ifndef TGUI_CHAT_BOX_HPP
27#define TGUI_CHAT_BOX_HPP
30#include <TGUI/CopiedSharedPtr.hpp>
31#include <TGUI/Widgets/Scrollbar.hpp>
32#include <TGUI/Renderers/ChatBoxRenderer.hpp>
33#include <TGUI/Text.hpp>
35#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
41TGUI_MODULE_EXPORT
namespace tgui
49 using Ptr = std::shared_ptr<ChatBox>;
50 using ConstPtr = std::shared_ptr<const ChatBox>;
52 static constexpr const char StaticWidgetType[] =
"ChatBox";
68 ChatBox(
const char* typeName = StaticWidgetType,
bool initRenderer =
true);
96 TGUI_NODISCARD
const ChatBoxRenderer* getSharedRenderer()
const override;
115 using Widget::setSize;
348 void leftMouseReleased(
Vector2f pos)
override;
353 void mouseMoved(
Vector2f pos)
override;
363 void mouseNoLongerOnWidget()
override;
368 void leftMouseButtonNoLongerDown()
override;
377 void recalculateLineText(
Line& line);
383 void recalculateAllLines();
389 void recalculateFullTextHeight();
395 void updateDisplayedText();
401 void updateRendering();
429 TGUI_NODISCARD std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
435 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
447 TGUI_NODISCARD
Vector2f getInnerSize()
const;
459 Color m_textColor = Color::Black;
462 std::size_t m_maxLines = 0;
464 float m_fullTextHeight = 0;
466 bool m_linesStartFromTop =
false;
467 bool m_newLinesBelowOthers =
true;
471 std::deque<Line> m_lines;
473 Sprite m_spriteBackground;
478 Color m_backgroundColorCached;
479 Color m_borderColorCached;
Base class for render targets.
Definition BackendRenderTarget.hpp:48
Definition ChatBoxRenderer.hpp:37
Definition ChatBox.hpp:46
std::shared_ptr< const ChatBox > ConstPtr
Shared constant widget pointer.
Definition ChatBox.hpp:50
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
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...
TGUI_NODISCARD 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.
std::shared_ptr< ChatBox > Ptr
Shared widget pointer.
Definition ChatBox.hpp:49
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
TGUI_NODISCARD unsigned int getScrollbarValue() const
Returns the thumb position of the scrollbar.
TGUI_NODISCARD std::size_t getLineLimit()
Returns the maximum amount of lines in the chat box.
void removeAllLines()
Removes all lines from the chat box.
bool leftMousePressed(Vector2f pos) override
Called by the parent when the left mouse button goes down on top of the widget.
void setLinesStartFromTop(bool startFromTop=true)
Lets the first lines start from the top or from the bottom of the chat box.
void addLine(const String &text, Color color)
Adds a new line of text to the chat box.
TGUI_NODISCARD TextStyles getTextStyle() const
Returns the default text style.
TGUI_NODISCARD String getLine(std::size_t lineIndex) const
Returns the contents of the requested line.
TGUI_NODISCARD bool getNewLinesBelowOthers() const
Returns whether new lines are added below the other lines or above them.
void addLine(const String &text, Color color, TextStyles style)
Adds a new line of text to the chat box.
static TGUI_NODISCARD ChatBox::Ptr copy(const ChatBox::ConstPtr &chatBox)
Makes a copy of another chat box.
TGUI_NODISCARD TextStyles getLineTextStyle(std::size_t lineIndex) const
Returns the text style of the requested line.
TGUI_NODISCARD ChatBoxRenderer * getRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
void addLine(const String &text)
Adds a new line of text to the chat box.
void updateTextSize() override
Called when the text size is changed (either by setTextSize or via the renderer)
TGUI_NODISCARD ChatBoxRenderer * getSharedRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
void setSize(const Layout2d &size) override
Changes the size of the chat box.
void setNewLinesBelowOthers(bool newLinesBelowOthers=true)
Sets whether new lines are added below the other lines or above them.
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the widget to a render target.
void setScrollbarValue(unsigned int value)
Changes the thumb position of the scrollbar.
TGUI_NODISCARD Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
void setTextColor(Color color)
Changes the default color of the text.
void setTextStyle(TextStyles style)
Changes the default text style.
TGUI_NODISCARD std::size_t getLineAmount()
Returns the amount of lines in the chat box.
void setLineLimit(std::size_t maxLines)
Sets a maximum amount of lines in the chat box.
TGUI_NODISCARD Color getLineColor(std::size_t lineIndex) const
Returns the color of the requested line.
TGUI_NODISCARD bool getLinesStartFromTop() const
Returns whether the first lines start from the top or from the bottom of the chat box.
bool removeLine(std::size_t lineIndex)
Removes the requested line.
TGUI_NODISCARD const Color & getTextColor() const
Returns the default color of the text.
static TGUI_NODISCARD ChatBox::Ptr create()
Creates a new chat box widget.
TGUI_NODISCARD bool isMouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
Wrapper for colors.
Definition Color.hpp:72
Definition CopiedSharedPtr.hpp:45
Class to store the position or size of a widget.
Definition Layout.hpp:305
Definition Outline.hpp:39
Wrapper class to store strings.
Definition String.hpp:101
Wrapper for text styles.
Definition TextStyle.hpp:57
Backend-independent wrapper around the backend-specific text class.
Definition Text.hpp:50
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39
Definition ChatBox.hpp:55
States used for drawing.
Definition RenderStates.hpp:39