JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
text.hpp
Go to the documentation of this file.
1// Copyright 2012-2026 Jan Niklas Hasse <jhasse@bixense.com>
2// For conditions of distribution and use, see copyright notice in LICENSE.txt
4
5#pragma once
6
7#include "Drawable.hpp"
8#include "Mat3.hpp"
9
10#include <memory>
11#include <string>
12#include <vector>
13
14namespace jngl {
15
17enum class Alignment : uint8_t { LEFT, RIGHT, CENTER };
18
19class Font;
20class FontInterface;
21
39class Text : public Drawable {
40public:
42 explicit Text(const std::string& text = "");
43
51 void setText(const std::string&, double maxWidth = std::numeric_limits<double>::max());
52
54 void setFont(Font&);
55
57
60
62 void step() override;
63
65 void draw() const override;
66 void draw(Mat3 modelview) const;
67
68private:
70 void addLine(const std::string& text, double maxWidth);
71
72 class Line;
75 Alignment align = Alignment::LEFT;
76};
77
78} // namespace jngl
Contains jngl::Drawable class.
Contains jngl::Mat3 class.
Base class for drawable objects with a position and a rectangle size.
Definition Drawable.hpp:15
Font loaded from a TTF or OTF file.
Definition font.hpp:19
3x3 matrix
Definition Mat3.hpp:18
Rectangle shaped text block.
Definition text.hpp:39
void draw() const override
Simply draws the Text object.
Text(const std::string &text="")
Constructor, text may contain \n newlines.
void setAlign(Alignment)
Alignment of this text block.
void setText(const std::string &, double maxWidth=std::numeric_limits< double >::max())
The text to display (may contain \n newlines)
void step() override
Does nothing.
void setFont(Font &)
Font family.
JNGL's main namespace.
Alignment
How multiple lines should be aligned in a text block.
Definition text.hpp:17
jngl::Mat3 modelview()
Returns a copy of the global ModelView matrix.