FifeGUI 0.2.0
A C++ GUI library designed for games.
text.hpp
1// SPDX-License-Identifier: LGPL-2.1-or-later OR BSD-3-Clause
2// SPDX-FileCopyrightText: 2004 - 2008 Olof Naessén and Per Larsson
3// SPDX-FileCopyrightText: 2013 - 2026 Fifengine contributors
4
5#ifndef INCLUDE_FIFECHAN_TEXT_HPP_
6#define INCLUDE_FIFECHAN_TEXT_HPP_
7
8#include <string>
9#include <vector>
10
11#include "fifechan/platform.hpp"
12#include "fifechan/rectangle.hpp"
13
14namespace fcn
15{
16 class Font;
17
27 class FIFEGUI_API Text
28 {
29 public:
30 Text();
31
37 explicit Text(std::string const & content);
38
39 virtual ~Text();
40
41 Text(Text const &) = default;
42 Text& operator=(Text const &) = default;
43 Text(Text&&) = default;
44 Text& operator=(Text&&) = default;
45
52 virtual void setContent(std::string const & content);
53
59 virtual std::string getContent() const;
60
68 virtual void setRow(unsigned int row, std::string const & content);
69
76 virtual void addRow(std::string const & row);
77
85 virtual void insertRow(std::string const & row, unsigned int position);
86
93 virtual void eraseRow(unsigned int row);
94
102 virtual std::string& getRow(unsigned int row);
103
109 virtual void insert(int character);
110
124 virtual void remove(int numberOfCharacters);
125
131 virtual int getCaretPosition() const;
132
139 virtual void setCaretPosition(int position);
140
149 virtual void setCaretPosition(int x, int y, Font* font);
150
156 virtual int getCaretColumn() const;
157
163 virtual int getCaretRow() const;
164
171 virtual void setCaretColumn(int column);
172
184 virtual void setCaretRow(int row);
185
192 virtual int getCaretX(Font* font) const;
193
200 virtual int getCaretY(Font* font) const;
201
209 virtual Rectangle getDimension(Font* font) const;
210
219 virtual Rectangle getCaretDimension(Font* font) const;
220
229 virtual int getWidth(int row, Font* font) const;
230
236 virtual unsigned int getMaximumCaretRow() const;
237
244 virtual unsigned int getMaximumCaretRow(unsigned int row) const;
245
251 virtual unsigned int getNumberOfRows() const;
252
258 virtual unsigned int getNumberOfCharacters() const;
259
268 virtual unsigned int getNumberOfCharacters(unsigned int row) const;
269
270 protected:
275
279 std::vector<std::string> mRows;
280
285 unsigned int mCaretPosition{0};
286
291 unsigned int mCaretRow{0};
292
297 unsigned int mCaretColumn{0};
298 };
299} // namespace fcn
300
301#endif // INCLUDE_FIFECHAN_TEXT_HPP_
Abstract interface for font rendering.
Definition font.hpp:24
Represents a rectangular area (X, Y, Width, Height).
Definition rectangle.hpp:20
unsigned int mCaretColumn
Holds the column the caret is in.
Definition text.hpp:297
virtual void setCaretColumn(int column)
Sets the column the caret should be in.
Definition text.cpp:278
virtual unsigned int getNumberOfCharacters() const
Gets the number of characters in the text.
Definition text.cpp:363
virtual unsigned int getMaximumCaretRow() const
Gets the maximum row the caret can be in.
Definition text.cpp:353
virtual void setContent(std::string const &content)
Sets the content of the text.
Definition text.cpp:41
virtual unsigned int getNumberOfRows() const
Gets the number of rows in the text.
Definition text.cpp:370
virtual int getWidth(int row, Font *font) const
Gets the width in pixels of a row.
Definition text.cpp:348
virtual std::string & getRow(unsigned int row)
Gets a reference to a row.
Definition text.cpp:133
virtual void setCaretRow(int row)
Sets the row the caret should be in.
Definition text.cpp:291
virtual int getCaretPosition() const
Gets the caret position.
Definition text.cpp:220
virtual void addRow(std::string const &row)
Adds a row to the content.
Definition text.cpp:90
virtual void setRow(unsigned int row, std::string const &content)
Sets the content of a row.
Definition text.cpp:81
virtual void remove(int numberOfCharacters)
Removes a given number of characters at starting at the current caret position.
Definition text.cpp:166
unsigned int mCaretRow
Holds the row the caret is in.
Definition text.hpp:291
virtual int getCaretColumn() const
Gets the column the caret is currently in.
Definition text.cpp:268
virtual void insertRow(std::string const &row, unsigned int position)
Inserts a row before the specified row position.
Definition text.cpp:102
virtual void setCaretPosition(int position)
Sets the caret position.
Definition text.cpp:225
virtual int getCaretX(Font *font) const
Gets the x coordinate of the caret in pixels given a font.
Definition text.cpp:304
unsigned int mCaretPosition
Holds the position of the caret.
Definition text.hpp:285
virtual int getCaretRow() const
Gets the row the caret is currently in.
Definition text.cpp:273
virtual void eraseRow(unsigned int row)
Erases the given row.
Definition text.cpp:124
virtual int getCaretY(Font *font) const
Gets the y coordinate of the caret in pixels given a font.
Definition text.cpp:313
std::vector< std::string > mRows
Holds the text row by row.
Definition text.hpp:279
virtual std::string getContent() const
Gets the content of the text.
Definition text.cpp:65
virtual void insert(int character)
Inserts a character at the current caret position.
Definition text.cpp:142
void calculateCaretPositionFromRowAndColumn()
Calculates the caret position from the caret row and caret column.
Definition text.cpp:384
virtual Rectangle getDimension(Font *font) const
Gets the dimension in pixels of the text given a font.
Definition text.cpp:319
virtual Rectangle getCaretDimension(Font *font) const
Gets the caret dimension relative to this text.
Definition text.cpp:337