|
FifeGUI 0.3.0
A C++ GUI library designed for games.
|
#include <text.hpp>
Public Member Functions | |
| virtual void | addRow (std::string const &row) |
| virtual void | eraseRow (unsigned int row) |
| virtual int | getCaretColumn () const |
| virtual Rectangle | getCaretDimension (Font *font) const |
| virtual int | getCaretPosition () const |
| virtual int | getCaretRow () const |
| virtual int | getCaretX (Font *font) const |
| virtual int | getCaretY (Font *font) const |
| virtual std::string | getContent () const |
| virtual Rectangle | getDimension (Font *font) const |
| virtual unsigned int | getMaximumCaretRow () const |
| virtual unsigned int | getMaximumCaretRow (unsigned int row) const |
| virtual unsigned int | getNumberOfCharacters () const |
| virtual unsigned int | getNumberOfCharacters (unsigned int row) const |
| virtual unsigned int | getNumberOfRows () const |
| virtual std::string & | getRow (unsigned int row) |
| virtual int | getWidth (int row, Font *font) const |
| virtual void | insert (int character) |
| virtual void | insertRow (std::string const &row, unsigned int position) |
| Text & | operator= (Text &&)=default |
| Text & | operator= (Text const &)=default |
| virtual void | remove (int numberOfCharacters) |
| virtual void | setCaretColumn (int column) |
| virtual void | setCaretPosition (int position) |
| virtual void | setCaretPosition (int x, int y, Font *font) |
| virtual void | setCaretRow (int row) |
| virtual void | setContent (std::string const &content) |
| virtual void | setRow (unsigned int row, std::string const &content) |
| Text (std::string const &content) | |
| Text (Text &&)=default | |
| Text (Text const &)=default | |
| virtual | ~Text () |
Protected Member Functions | |
| void | calculateCaretPositionFromRowAndColumn () |
Protected Attributes | |
| unsigned int | mCaretColumn {0} |
| unsigned int | mCaretPosition {0} |
| unsigned int | mCaretRow {0} |
| std::vector< std::string > | mRows |
Helper class for text manipulation within widgets.
A utility class to ease working with text in widgets such as TextBox and TextField. The class wraps common text operations such as inserting and deleting text.
|
explicit |
|
virtual |
Adds a row to the content.
Calling this method will not change the current caret position.
| row | The row to add. |
Definition at line 112 of file text.cpp.
References mRows, and fcn::throwException().
Referenced by insertRow(), and operator=().
|
protected |
Calculates the caret position from the caret row and caret column.
Definition at line 449 of file text.cpp.
References mCaretColumn, mCaretPosition, mCaretRow, and mRows.
Referenced by operator=(), and setCaretColumn().
|
virtual |
Erases the given row.
Calling this method will not change the current caret position.
| row | Row to be erased. |
Definition at line 146 of file text.cpp.
References mRows, and fcn::throwException().
Referenced by operator=().
|
virtual |
Gets the column the caret is currently in.
Definition at line 324 of file text.cpp.
References mCaretColumn.
Referenced by operator=().
Gets the caret dimension relative to this text.
The returned dimension is perfect for use with Widget::showPart so the caret is always shown.
| font | The font to use when calculating the dimension. |
Definition at line 400 of file text.cpp.
References fcn::Rectangle::height, mCaretColumn, mCaretRow, mRows, fcn::Rectangle::width, fcn::Rectangle::x, and fcn::Rectangle::y.
Referenced by operator=().
|
virtual |
Gets the caret position.
Definition at line 250 of file text.cpp.
References mCaretPosition.
Referenced by insert(), and operator=().
|
virtual |
Gets the row the caret is currently in.
Definition at line 329 of file text.cpp.
References mCaretRow.
Referenced by operator=().
|
virtual |
Gets the x coordinate of the caret in pixels given a font.
| font | The font to use when calculating the x coordinate. |
Definition at line 360 of file text.cpp.
References mCaretColumn, mCaretRow, and mRows.
Referenced by operator=().
|
virtual |
Gets the y coordinate of the caret in pixels given a font.
| font | The font to use when calculating the y coordinate. |
Definition at line 371 of file text.cpp.
References mCaretRow.
Referenced by operator=().
|
virtual |
Gets the content of the text.
Definition at line 86 of file text.cpp.
References mRows.
Referenced by operator=().
Gets the dimension in pixels of the text given a font.
If there is no text present a dimension of a white space will be returned.
| font | The font to use when calculating the dimension. |
Definition at line 379 of file text.cpp.
References mRows.
Referenced by operator=().
|
virtual |
Gets the maximum row the caret can be in.
Definition at line 418 of file text.cpp.
Referenced by operator=().
|
virtual |
|
virtual |
Gets the number of characters in the text.
Definition at line 428 of file text.cpp.
References mRows.
Referenced by operator=(), remove(), and setCaretPosition().
|
virtual |
Gets the number of characters in a certain row in the text.
If the row does not exist, zero will be returned.
| row | The row to get the number of characters in. |
Definition at line 440 of file text.cpp.
References mRows.
|
virtual |
Gets the number of rows in the text.
Definition at line 435 of file text.cpp.
References mRows.
Referenced by operator=().
|
virtual |
Gets a reference to a row.
| row | The row to get the content of. |
| Exception | when no such row exists. |
Definition at line 155 of file text.cpp.
References mRows, and fcn::throwException().
Referenced by operator=().
|
virtual |
Gets the width in pixels of a row.
If the row is not present in the text zero will be returned.
| row | The row to get the width of. |
| font | The font to use when calculating the width. |
Definition at line 413 of file text.cpp.
Referenced by operator=().
|
virtual |
Inserts a character at the current caret position.
| character | The character to insert. |
Definition at line 164 of file text.cpp.
References getCaretPosition(), mCaretColumn, mCaretRow, mRows, and setCaretPosition().
Referenced by operator=().
|
virtual |
Inserts a row before the specified row position.
Calling this method will not change the current caret position.
| row | The row to add. |
| position | Inserts new row before this row. |
Definition at line 124 of file text.cpp.
References addRow(), mRows, and fcn::throwException().
Referenced by operator=().
|
virtual |
Removes a given number of characters at starting at the current caret position.
If the number of characters to remove is negative characters will be removed left of the caret position. If the number is positive characters will be removed right of the caret position. If a line feed is removed the row with the line feed will be merged with the row above the line feed.
| numberOfCharacters | The number of characters to remove. |
Definition at line 191 of file text.cpp.
References getNumberOfCharacters(), mCaretColumn, mCaretPosition, mCaretRow, mRows, setCaretColumn(), setCaretPosition(), and setCaretRow().
Referenced by operator=().
|
virtual |
Sets the column the caret should be in.
The column will be clamp to the current row.
| column | The column the caret should be in. |
Definition at line 334 of file text.cpp.
References calculateCaretPositionFromRowAndColumn(), mCaretColumn, mCaretRow, and mRows.
Referenced by operator=(), remove(), setCaretPosition(), and setCaretRow().
|
virtual |
Sets the caret position.
The position will be clamp to the dimension of the content.
| position | The position of the caret. |
Definition at line 255 of file text.cpp.
References getNumberOfCharacters(), mCaretColumn, mCaretPosition, mCaretRow, and mRows.
Referenced by insert(), operator=(), and remove().
|
virtual |
Sets the caret position given an x and y coordinate in pixels relative to the text.
The coordinates will be clamp to the content.
| x | The x coordinate of the caret. |
| y | The y coordinate of the caret. |
| font | The font to use when calculating the position. |
Definition at line 311 of file text.cpp.
References mCaretRow, mRows, setCaretColumn(), and setCaretRow().
|
virtual |
Sets the row the caret should be in.
If the row lies o outside of the text, the row will be set to zero or the maximum row depending on where the row lies outside of the text.
Calling this function trigger a recalculation of the caret column.
| row | The row the caret should be in. |
Definition at line 347 of file text.cpp.
References mCaretColumn, mCaretRow, mRows, and setCaretColumn().
Referenced by operator=(), remove(), and setCaretPosition().
|
virtual |
Sets the content of the text.
Will completely remove any previous text and reset the caret position.
| content | The content of the text. |
Definition at line 57 of file text.cpp.
References mCaretColumn, mCaretPosition, mCaretRow, and mRows.
Referenced by operator=().
|
virtual |
Sets the content of a row.
| row | The row to set the text of. |
| content | The content of the row. |
| Exception | when the row does not exist. |
Definition at line 102 of file text.cpp.
References mRows, and fcn::throwException().
Referenced by operator=().
|
protected |
Holds the column the caret is in.
This variable should always be valid.
Definition at line 319 of file text.hpp.
Referenced by calculateCaretPositionFromRowAndColumn(), getCaretColumn(), getCaretDimension(), getCaretX(), insert(), remove(), setCaretColumn(), setCaretPosition(), setCaretRow(), and setContent().
|
protected |
Holds the position of the caret.
This variable should always be valid.
Definition at line 307 of file text.hpp.
Referenced by calculateCaretPositionFromRowAndColumn(), getCaretPosition(), remove(), setCaretPosition(), and setContent().
|
protected |
Holds the row the caret is in.
This variable should always be valid.
Definition at line 313 of file text.hpp.
Referenced by calculateCaretPositionFromRowAndColumn(), getCaretDimension(), getCaretRow(), getCaretX(), getCaretY(), insert(), remove(), setCaretColumn(), setCaretPosition(), setCaretPosition(), setCaretRow(), and setContent().
|
protected |
Holds the text row by row.
Definition at line 301 of file text.hpp.
Referenced by addRow(), calculateCaretPositionFromRowAndColumn(), eraseRow(), getCaretDimension(), getCaretX(), getContent(), getDimension(), getNumberOfCharacters(), getNumberOfCharacters(), getNumberOfRows(), getRow(), insert(), insertRow(), remove(), setCaretColumn(), setCaretPosition(), setCaretPosition(), setCaretRow(), setContent(), setRow(), and Text().