Skip to content

Commit

Permalink
Make masking character configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
gbaudic committed Nov 14, 2024
1 parent a346dc7 commit 2b6fd31
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
15 changes: 12 additions & 3 deletions include/guisan/widgets/passwordfield.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ namespace gcn
{
/**
* A text field in which you can write or display a line of text.
* Unlike a TextField the text will appear as '*' instead of the real content.
* If for some reason the Font you are using does not contain this character, the
* Unlike a TextField the text will appear as masked, instead of the real content.
* If for some reason the Font you are using does not contain the character, the
* PasswordField will be filled by spaces.
*/
class GCN_CORE_DECLSPEC PasswordField:
Expand All @@ -88,7 +88,16 @@ namespace gcn
// Inherited from Widget

void draw(Graphics* graphics) override;


/**
* Set the masking character to hide the password
*
* @param mask the masking character
*/
void setMaskingChar(const char mask);

private:
char masking('*');
};
}

Expand Down
7 changes: 6 additions & 1 deletion src/widgets/passwordfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,17 @@ namespace gcn
void PasswordField::draw(Graphics* graphics)
{
const std::string realText(mText->getRow(0));
const std::string encodedText(realText.size(), '*');
const std::string encodedText(realText.size(), masking);

// Switch replacement text before drawing it to hide it
mText->setRow(0, encodedText);
TextField::draw(graphics);
mText->setRow(0, realText);
}

void PasswordField::setMaskingChar(const char mask)
{
masking = mask;
}

}

0 comments on commit 2b6fd31

Please sign in to comment.