Loading...
Searching...
No Matches
ChatBubble.h
Go to the documentation of this file.
1//
2// Created by Dave Smith on 4/30/26.
3//
4
5#ifndef CHATBUBBLE_H
6#define CHATBUBBLE_H
7
13
14// A single message bubble — left-aligned for others, right-aligned for mine.
15// Add to a ScrollPane (or any ml::Core container) to include it in layout.
16// Call setMessage() whenever the message content or container width changes.
17namespace ml
18{
19 class ChatBubble : public ml::Component<ml::Messenger>
20 {
21 static constexpr float PADDING = 12.f;
22 static constexpr float CORNER_R = 14.f;
23 static constexpr float MAX_W_RATIO = 0.72f;
24 static constexpr float EDGE_MARGIN = 8.f;
25 static constexpr float TS_GAP = 4.f;
26 static constexpr float SENDER_GAP = 3.f;
27
29 ml::Text _senderText;
30 ml::Text _messageText;
31 ml::Text _timestampText;
32
33 bool _isMine = false;
34 float _containerWidth = 0.f;
35 float _totalHeight = 0.f;
36 float _senderH = 0.f;
37 sf::Vector2f _bubbleSize;
38 sf::Vector2f _position;
39
40 void applyLayout();
41
42 public:
44
45 // Feed message data and the pixel width of the containing scroll area.
46 // Re-call when the container is resized.
47 void setMessage(const ChatMessage& msg, float containerWidth);
48
49 float getHeight() const { return _totalHeight; }
50
51 void setPosition(const sf::Vector2f& pos) override;
52 sf::Vector2f getPosition() const override;
54
55 protected:
56 void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
57 };
58}
59
60
61#endif //CHATBUBBLE_H
void setMessage(const ChatMessage &msg, float containerWidth)
void setPosition(const sf::Vector2f &pos) override
float getHeight() const
Definition ChatBubble.h:49
sf::FloatRect getGlobalBounds() const override
void draw(sf::RenderTarget &target, sf::RenderStates states) const override
sf::Vector2f getPosition() const override
Primary base class for all user-facing Malena components.
Definition Component.h:292
An sf::Shape subclass that draws a rectangle with rounded corners.
A framework-integrated text object with word-wrap support.
Definition Text.h:57
Definition Component.h:22
Rect< float > FloatRect
Vector2< float > Vector2f