5#include "fifechan/widgets/textfield.hpp"
10#include "fifechan/font.hpp"
11#include "fifechan/graphics.hpp"
12#include "fifechan/key.hpp"
13#include "fifechan/mouseinput.hpp"
14#include "fifechan/text.hpp"
15#include "fifechan/utf8stringeditor.hpp"
25 addMouseListener(
this);
39 TextField::~TextField()
47 mText->setContent(text);
56 highlightColor = faceColor + 0x303030;
57 highlightColor.
a = alpha;
58 shadowColor = faceColor - 0x303030;
59 shadowColor.
a = alpha;
90 if (
mText->getNumberOfRows() != 0) {
112 if (mouseEvent.
getButton() == MouseEvent::Button::Left) {
138 }
else if (key.
getValue() == Key::Enter) {
140 }
else if (key.
getValue() == Key::Home) {
142 }
else if (key.
getValue() == Key::End) {
164 static_cast<void>(recursion);
190 int const caretX =
mText->getCaretDimension(
getFont()).x;
194 }
else if (caretX -
mXScroll <= 0) {
204 mText->setCaretPosition(position);
209 return mText->getCaretPosition();
214 return mText->getContent();
A rectangle specifically used for clipping rendering regions.
uint8_t a
Alpha color component (0-255).
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
virtual void popClipArea()
Removes the top most clip area from the stack.
void drawText(std::string const &text, int x, int y)
Draws text with a default left alignment.
virtual ClipRectangle const & getCurrentClipArea()
Gets the current clip area.
virtual bool pushClipArea(Rectangle area)
Pushes a clip area onto the stack.
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 drawRectangle(Rectangle const &rectangle)=0
Draws a simple, non-filled rectangle with a one pixel width.
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 adjustSizeImpl()
Adjusts the size of the button to fit the caption.
void setCaretPosition(unsigned int position)
Sets the caret position.
bool mEditable
True if the text field is editable, false otherwise.
void mousePressed(MouseEvent &mouseEvent) override
Called when a mouse button has been pressed on the widget area.
virtual void drawCaret(Graphics *graphics, int x)
Draws the caret.
UTF8StringEditor * mStringEditor
String editor for UTF8 support.
unsigned int getCaretPosition() const
Gets the caret position.
void fixScroll()
Scrolls the text horizontally so that the caret shows if needed.
int mXScroll
Holds the amount scrolled in x.
void keyPressed(KeyEvent &keyEvent) override
Called if a key is pressed when the widget has keyboard focus.
void resizeToContent()
Resizes the widget's size to fit the content exactly, calls recursively all childs.
void mouseDragged(MouseEvent &mouseEvent) override
Called when the mouse has moved and the mouse has previously been pressed on the widget.
virtual void setText(std::string const &text)
Sets the text of the text field.
virtual std::string getText() const
Gets the text of the text field.
void setEditable(bool editable)
Sets the text field to be editable or not.
void adjustSize() override
Adjusts the size of the text field to fit the text.
bool isEditable() const
Checks if the text field is editable.
void adjustHeight()
Adjusts the height of the text field to fit caption.
void draw(Graphics *graphics) override
Draws the widget.
Text * mText
Holds the text of the text field.
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 eraseChar(std::string &text, int byteOffset)
Erase character at specified byte offset.
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.