6#include "fifechan/widgets/textfield.hpp"
13#include "fifechan/events/textinputevent.hpp"
14#include "fifechan/font.hpp"
15#include "fifechan/graphics.hpp"
16#include "fifechan/key.hpp"
17#include "fifechan/mouseinput.hpp"
18#include "fifechan/text.hpp"
19#include "fifechan/utf8stringeditor.hpp"
29 addMouseListener(
this);
43 TextField::~TextField()
51 mText->setContent(text);
60 highlightColor = faceColor + 0x303030;
61 highlightColor.
a = alpha;
62 shadowColor = faceColor - 0x303030;
63 shadowColor.
a = alpha;
94 if (
mText->getNumberOfRows() != 0) {
116 if (mouseEvent.
getButton() == MouseEvent::Button::Left) {
130 Key
const key = keyEvent.
getKey();
138 mText->getNumberOfRows() > 0) {
140 }
else if (key.getValue() == fcn::Key::BACKSPACE &&
getCaretPosition() > 0 &&
mText->getNumberOfRows() > 0) {
143 }
else if (key.getValue() == fcn::Key::KEY_RETURN) {
145 }
else if (key.getValue() == fcn::Key::HOME) {
147 }
else if (key.getValue() == fcn::Key::END) {
152 if (key.getValue() != fcn::Key::TAB) {
163 std::string
const & text =
event.getText();
164 if (!text.empty() &&
mText->getNumberOfRows() > 0) {
165 std::string& row =
mText->getRow(0);
174 static_cast<void>(recursion);
200 int const caretX =
mText->getCaretDimension(
getFont()).x;
204 }
else if (caretX -
mXScroll <= 0) {
214 mText->setCaretPosition(position);
219 return mText->getCaretPosition();
224 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 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 down 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()
Ensures the caret remains visible by adjusting horizontal scroll.
int mXScroll
Horizontal scroll offset in pixels.
void resizeToContent(bool recursion=true) override
Resizes the widget's size to fit the content exactly, calls recursively all childs.
void keyPressed(KeyEvent &keyEvent) override
Called if a key is pressed when the widget has keyboard focus.
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 textInput(TextInputEvent &event) override
Called when text input (IME, dead-key, paste) is received.
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.
Text input event for IME (input method editor) composition, dead keys, and pasted text.
Helper class for text manipulation within widgets.
Utility for editing and handling UTF-8 encoded strings.
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.
Used replacement tokens by configure_file():