From 2b6fd317aa995162a2df6882550315b801f937c7 Mon Sep 17 00:00:00 2001 From: Gwilherm Baudic Date: Thu, 14 Nov 2024 20:05:46 +0100 Subject: [PATCH] Make masking character configurable --- include/guisan/widgets/passwordfield.hpp | 15 ++++++++++++--- src/widgets/passwordfield.cpp | 7 ++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/guisan/widgets/passwordfield.hpp b/include/guisan/widgets/passwordfield.hpp index 68572eb..efe7b48 100644 --- a/include/guisan/widgets/passwordfield.hpp +++ b/include/guisan/widgets/passwordfield.hpp @@ -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: @@ -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('*'); }; } diff --git a/src/widgets/passwordfield.cpp b/src/widgets/passwordfield.cpp index dadccff..b34b567 100644 --- a/src/widgets/passwordfield.cpp +++ b/src/widgets/passwordfield.cpp @@ -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; + } }