malena
Why malena
Quick start
Tutorials
API docs
GitHub
GitHub
Tutorials
Loading...
Searching...
No Matches
Graphics
Controls
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
8
#include <
Malena/Engine/Messaging/ChatMessage.h
>
9
#include <
Malena/Core/Component.h
>
10
#include <
Malena/Traits/Communication/Messenger.h
>
11
#include <
Malena/Graphics/Primitives/RoundedRectangle.h
>
12
#include <
Malena/Graphics/Text/Text.h
>
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.
17
namespace
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
28
ml::RoundedRectangle
_bg;
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
:
43
ChatBubble
();
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
;
53
sf::FloatRect
getGlobalBounds
()
const override
;
54
55
protected
:
56
void
draw
(
sf::RenderTarget
& target,
sf::RenderStates
states)
const override
;
57
};
58
}
59
60
61
#endif
//CHATBUBBLE_H
ChatMessage.h
Component.h
Messenger.h
RoundedRectangle.h
Text.h
ml::ChatBubble::setMessage
void setMessage(const ChatMessage &msg, float containerWidth)
ml::ChatBubble::setPosition
void setPosition(const sf::Vector2f &pos) override
ml::ChatBubble::ChatBubble
ChatBubble()
ml::ChatBubble::getHeight
float getHeight() const
Definition
ChatBubble.h:49
ml::ChatBubble::getGlobalBounds
sf::FloatRect getGlobalBounds() const override
ml::ChatBubble::draw
void draw(sf::RenderTarget &target, sf::RenderStates states) const override
ml::ChatBubble::getPosition
sf::Vector2f getPosition() const override
ml::Component
Primary base class for all user-facing Malena components.
Definition
Component.h:292
ml::RoundedRectangle
An sf::Shape subclass that draws a rectangle with rounded corners.
Definition
RoundedRectangle.h:45
ml::Text
A framework-integrated text object with word-wrap support.
Definition
Text.h:57
sf::RenderTarget
ml
Definition
Component.h:22
sf::FloatRect
Rect< float > FloatRect
sf::Vector2f
Vector2< float > Vector2f
ml::ChatMessage
Definition
ChatMessage.h:12
sf::RenderStates