5#include <fifechan/widgets/textbox.hpp>
7#include <fifechan/font.hpp>
8#include <fifechan/graphics.hpp>
9#include <fifechan/key.hpp>
10#include <fifechan/mouseinput.hpp>
11#include <fifechan/text.hpp>
12#include <fifechan/utf8stringeditor.hpp>
13#include <fifechan/util/utf8/utf8.hpp>
37 mText->setContent(text);
56 for (i = 0; i <
mText->getNumberOfRows(); i++) {
70 if (mouseEvent.
getButton() == MouseEvent::Button::Left) {
94 }
else if (key.
getValue() == Key::Right) {
103 }
else if (key.
getValue() == Key::Down) {
105 }
else if (key.
getValue() == Key::Up) {
107 }
else if (key.
getValue() == Key::Home) {
109 }
else if (key.
getValue() == Key::End) {
143 }
else if (key.
getValue() == Key::PageUp) {
146 if (par !=
nullptr) {
149 int const newCaretRow =
getCaretRow() - rowsPerPage;
150 if (newCaretRow >= 0) {
157 }
else if (key.
getValue() == Key::PageDown) {
160 if (par !=
nullptr) {
184 utf8::internal::UTF8_OK);
187 utf8::internal::UTF8_OK);
193 static_cast<void>(recursion);
210 mText->setCaretPosition(position);
215 return mText->getCaretPosition();
220 mText->setCaretRow(row);
221 mText->setCaretColumn(column);
226 mText->setCaretRow(row);
231 return mText->getCaretRow();
236 mText->setCaretColumn(column);
241 return mText->getCaretColumn();
246 return mText->getRow(row);
251 mText->setRow(row, text);
257 return mText->getNumberOfRows();
262 return mText->getContent();
virtual int getHeight() const =0
Gets the height of the glyphs in the font.
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
void drawText(std::string const &text, int x, int y)
Draws text with a default left alignment.
virtual void setFont(Font *font)
Sets the font to use when drawing text.
virtual void drawLine(int x1, int y1, int x2, int y2)=0
Draws a line.
virtual void setColor(Color const &color)=0
Sets the color to use when drawing.
virtual void fillRectangle(Rectangle const &rectangle)=0
Draws a filled rectangle.
Key const & getKey() const
Gets the key of the event.
Represents a keyboard key or character code.
int getValue() const
Gets the value of the key.
bool isCharacter() const
Checks if a key is a character.
Represents a mouse event.
int getX() const
Gets the x coordinate of the mouse event.
int getY() const
Gets the y coordinate of the mouse event.
MouseEvent::Button getButton() const
Gets the button of the mouse event.
Represents a rectangular area (X, Y, Width, Height).
int width
Holds the width of the rectangle.
int height
Holds the height of the rectangle.
void fontChanged() override
Called when the font has changed.
virtual void scrollToCaret()
Scrolls the text to the caret if the text box is in a scroll area.
void setCaretColumnUTF8(int column)
Sets caret column (UTF-8 aware).
virtual void addRow(std::string const &row)
Adds a row of text to the end of the text.
void keyPressed(KeyEvent &keyEvent) override
Called if a key is pressed when the widget has keyboard focus.
std::string getTextRow(int row) const
Gets a certain row from the text.
Text * mText
Holds the text of the text box.
void setCaretRowColumn(int row, int column)
Sets the row and the column where the caret should be currently located.
void draw(Graphics *graphics) override
Draws the widget.
void setTextRow(int row, std::string const &text)
Sets the text of a certain row of the text.
bool mEditable
True if the text box is editable, false otherwise.
void adjustSizeImpl()
Adjusts the size of the button to fit the caption.
unsigned int getCaretPosition() const
Gets the caret position in the text.
virtual void drawCaret(Graphics *graphics, int x, int y)
Draws the caret.
bool mOpaque
True if the text box is opaque, false otherwise.
std::string getText() const
Gets the text of the text box.
void setCaretColumn(int column)
Sets the column where the caret should be currently located.
TextBox(std::string const &text="")
Constructor.
unsigned int getCaretColumn() const
Gets the column where the caret is currently located.
void setCaretRow(int row)
Sets the row where the caret should be currently located.
void resizeToContent()
Resizes the widget's size to fit the content exactly, calls recursively all childs.
void mousePressed(MouseEvent &mouseEvent) override
Called when a mouse button has been pressed on the widget area.
void setEditable(bool editable)
Sets the text box to be editable or not.
void adjustSize() override
Adjusts the text box's size to fit the text.
void setCaretRowUTF8(int row)
Sets caret row (UTF-8 aware).
void mouseDragged(MouseEvent &mouseEvent) override
Called when the mouse has moved and the mouse has previously been pressed on the widget.
unsigned int getCaretRow() const
Gets the row number where the caret is currently located.
void setText(std::string const &text)
Sets the text of the text box.
bool isOpaque() const
Checks if the text box is opaque.
void setOpaque(bool opaque)
Sets the text box to be opaque or not.
UTF8StringEditor * mStringEditor
UTF8StringEditor for UTF8 support.
unsigned int getNumberOfRows() const
Gets the number of rows in the text.
bool isEditable() const
Checks if the text box is editable.
void setCaretPosition(unsigned int position)
Sets the position of the caret in the text.
void setCaretRowColumnUTF8(int row, int column)
Sets the caret row and column (UTF-8 aware).
Helper class for text manipulation within widgets.
Utility for editing and handling UTF-8 encoded strings.
static int insertChar(std::string &text, int byteOffset, int ch)
Insert a character at specified byte offset.
static int countChars(std::string const &text, int byteOffset)
Counts characters up to byteOffset.
static int eraseChar(std::string &text, int byteOffset)
Erase character at specified byte offset.
static int getOffset(std::string const &text, int charIndex)
Gets byte offset for character index.
static int nextChar(std::string const &text, int byteOffset)
Returns byte offset of the next character.
static int prevChar(std::string const &text, int byteOffset)
Returns byte offset of the previous character.