25#ifndef TGUI_CHAT_BOX_HPP
26#define TGUI_CHAT_BOX_HPP
28#include <TGUI/Renderers/ChatBoxRenderer.hpp>
29#include <TGUI/Text.hpp>
30#include <TGUI/Widgets/Scrollbar.hpp>
43 using Ptr = std::shared_ptr<ChatBox>;
44 using ConstPtr = std::shared_ptr<const ChatBox>;
61 explicit ChatBox(
const char* typeName =
StaticWidgetType,
bool initRenderer =
true);
276 TGUI_DEPRECATED(
"Use getScrollbar()->setValue(value) instead") void
setScrollbarValue(
unsigned int value);
283 TGUI_DEPRECATED(
"Use getScrollbar()->getValue() instead") [[nodiscard]]
unsigned int getScrollbarValue() const;
292 TGUI_DEPRECATED(
"Use getScrollbar()->getMaxValue() instead") [[nodiscard]]
unsigned int getScrollbarMaxValue() const;
309 void leftMouseReleased(Vector2f pos) override;
314 void mouseMoved(Vector2f pos) override;
319 bool scrolled(
float delta, Vector2f pos,
bool touch) override;
324 void mouseNoLongerOnWidget() override;
329 void leftMouseButtonNoLongerDown() override;
337 void recalculateLineText(
Line& line);
342 void recalculateAllLines();
347 void recalculateFullTextHeight();
352 void updateDisplayedText();
357 void updateRendering();
380 [[nodiscard]] std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers) const override;
385 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
395 [[nodiscard]] Vector2f getInnerSize() const;
408 std::
size_t m_maxLines = 0;
410 float m_fullTextHeight = 0;
412 bool m_linesStartFromTop = false;
413 bool m_newLinesBelowOthers = true;
415 std::deque<
Line> m_lines;
417 Sprite m_spriteBackground;
420 Borders m_bordersCached;
421 Padding m_paddingCached;
422 Color m_backgroundColorCached;
423 Color m_borderColorCached;
Base class for render targets.
Definition BackendRenderTarget.hpp:46
Definition ChatBoxRenderer.hpp:35
unsigned int getScrollbarValue() const
Returns the thumb position of the scrollbar.
std::shared_ptr< const ChatBox > ConstPtr
Shared constant widget pointer.
Definition ChatBox.hpp:44
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...
std::shared_ptr< ChatBox > Ptr
Shared widget pointer.
Definition ChatBox.hpp:43
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
void removeAllLines()
Removes all lines from the chat box.
bool getLinesStartFromTop() const
Returns whether the first lines start from the top or from the bottom of the chat box.
ChatBoxRenderer * getSharedRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
bool leftMousePressed(Vector2f pos) override
Called by the parent when the left mouse button goes down on top of the widget.
static ChatBox::Ptr create()
Creates a new chat box 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.
unsigned int getScrollbarMaxValue() const
Returns the maximum thumb position of the scrollbar.
void addLine(const String &text, Color color, TextStyles style)
Adds a new line of text to the chat box.
const Color & getTextColor() const
Returns the default color of the text.
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.
bool isMouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
std::size_t getLineLimit() const
Returns the maximum amount of lines in the chat box.
void addLine(const String &text)
Adds a new line of text to the chat box.
bool getNewLinesBelowOthers() const
Returns whether new lines are added below the other lines or above them.
static ChatBox::Ptr copy(const ChatBox::ConstPtr &chatBox)
Makes a copy of another chat box.
void updateTextSize() override
Called when the text size is changed (either by setTextSize or via the renderer).
Color getLineColor(std::size_t lineIndex) const
Returns the color of the requested line.
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.
TextStyles getTextStyle() const
Returns the default text style.
TextStyles getLineTextStyle(std::size_t lineIndex) const
Returns the text style of the requested line.
void setScrollbarValue(unsigned int value)
Changes the thumb position of the scrollbar.
ChatBoxRenderer * getRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
std::size_t getLineAmount() const
Returns the amount of lines in the chat box.
void setTextColor(Color color)
Changes the default color of the text.
void setTextStyle(TextStyles style)
Changes the default text style.
static constexpr char StaticWidgetType[]
Type name of the widget.
Definition ChatBox.hpp:46
String getLine(std::size_t lineIndex) const
Returns the contents of the requested line.
void setLineLimit(std::size_t maxLines)
Sets a maximum amount of lines in the chat box.
bool removeLine(std::size_t lineIndex)
Removes the requested line.
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Wrapper for colors.
Definition Color.hpp:63
Class to store the position or size of a widget.
Definition Layout.hpp:320
Wrapper class to store strings.
Definition String.hpp:94
Wrapper for text styles.
Definition TextStyle.hpp:55
Backend-independent wrapper around the backend-specific text class.
Definition Text.hpp:53
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:37
TextStyle
Enumeration of the text drawing styles.
Definition TextStyle.hpp:38
@ Regular
Regular characters, no style.
Definition TextStyle.hpp:39
Definition ChatBox.hpp:49
States used for drawing.
Definition RenderStates.hpp:38