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
42 Text(Text const &) = default;
44 Text& operator=(Text const &) = default;
46 Text(Text&&) = default;
48 Text& operator=(Text&&) = default;
49
56 virtual void setContent(std::string const & content);
57
63 virtual std::string getContent() const;
64
72 virtual void setRow(unsigned int row, std::string const & content);
73
80 virtual void addRow(std::string const & row);
81
89 virtual void insertRow(std::string const & row, unsigned int position);
90
97 virtual void eraseRow(unsigned int row);
98
106 virtual std::string& getRow(unsigned int row);
107
113 virtual void insert(int character);
114
128 virtual void remove(int numberOfCharacters);
129
135 virtual int getCaretPosition() const;
136
143 virtual void setCaretPosition(int position);
144
153 virtual void setCaretPosition(int x, int y, Font* font);
154
160 virtual int getCaretColumn() const;
161
167 virtual int getCaretRow() const;
168
175 virtual void setCaretColumn(int column);
176
188 virtual void setCaretRow(int row);
189
196 virtual int getCaretX(Font* font) const;
197
204 virtual int getCaretY(Font* font) const;
205
213 virtual Rectangle getDimension(Font* font) const;
214
223 virtual Rectangle getCaretDimension(Font* font) const;
224
233 virtual int getWidth(int row, Font* font) const;
234
240 virtual unsigned int getMaximumCaretRow() const;
241
248 virtual unsigned int getMaximumCaretRow(unsigned int row) const;
249
255 virtual unsigned int getNumberOfRows() const;
256
262 virtual unsigned int getNumberOfCharacters() const;
263
272 virtual unsigned int getNumberOfCharacters(unsigned int row) const;
273
274 protected:
279
283 std::vector<std::string> mRows;
284
289 unsigned int mCaretPosition{0};
290
295 unsigned int mCaretRow{0};
296
301 unsigned int mCaretColumn{0};
302 };
303} // namespace fcn
304
305#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:301
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:295
Text(Text const &)=default
Copy constructor.
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:289
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:283
Text & operator=(Text &&)=default
Move assignment operator.
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
Text(Text &&)=default
Move constructor.
void calculateCaretPositionFromRowAndColumn()
Calculates the caret position from the caret row and caret column.
Definition text.cpp:384
Text & operator=(Text const &)=default
Copy assignment operator.
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