5#include <fifechan/widgets/passwordfield.hpp>
7#include <fifechan/key.hpp>
8#include <fifechan/text.hpp>
9#include <fifechan/utf8stringeditor.hpp>
20 PasswordField::~PasswordField()
30 mText->setCaretPosition(
mText->getCaretPosition() - 1);
31 setActualTextCaretPosition(
34 mText->setCaretPosition(
mText->getCaretPosition() + 1);
35 setActualTextCaretPosition(
39 mText->getNumberOfRows() > 0) {
41 setActualTextCaretPosition(
43 mActualText->getRow(0),
static_cast<int>(getActualTextCaretPosition())));
47 setActualTextCaretPosition(
49 mActualText->getRow(0),
static_cast<int>(getActualTextCaretPosition())));
50 setActualTextCaretPosition(
52 mActualText->getRow(0),
static_cast<int>(getActualTextCaretPosition())));
53 }
else if (key.
getValue() == Key::Enter) {
55 }
else if (key.
getValue() == Key::Home) {
56 mText->setCaretColumn(0);
57 setActualTextCaretPosition(0);
58 }
else if (key.
getValue() == Key::End) {
59 mText->setCaretColumn(
mText->getNumberOfCharacters(0));
60 setActualTextCaretPosition(
getText().size());
68 setActualTextCaretPosition(
70 mActualText->getRow(0), getActualTextCaretPosition(), key.
getValue()));
84 std::string asterisks;
85 asterisks.assign(text.size(),
'*');
87 mText->setContent(asterisks);
88 mActualText->setContent(text);
93 return mActualText->getContent();
96 void PasswordField::setActualTextCaretPosition(
unsigned int position)
101 unsigned int PasswordField::getActualTextCaretPosition()
const
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.
std::string getText() const override
Gets the text of the text field.
PasswordField(std::string const &text="")
Constructor.
void keyPressed(KeyEvent &keyEvent) override
Called if a key is pressed when the widget has keyboard focus.
void setText(std::string const &text) override
Sets the text of the text field.
bool mEditable
True if the text field is editable, false otherwise.
unsigned int getCaretPosition() const
Gets the caret position.
void fixScroll()
Scrolls the text horizontally so that the caret shows if needed.
Text * mText
Holds the text of the text field.
Helper class for text manipulation within widgets.
virtual int getCaretPosition() const
Gets the caret position.
virtual void setCaretPosition(int position)
Sets the caret position.
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.