Skip to content

Commit

Permalink
Integrate passwordfield directly into textfield.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarod42 committed Dec 3, 2024
1 parent a11f952 commit d6ffce4
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 216 deletions.
1 change: 0 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ widget_headers = [
'include/guisan/widgets/label.hpp',
'include/guisan/widgets/listbox.hpp',
'include/guisan/widgets/messagebox.hpp',
'include/guisan/widgets/passwordfield.hpp',
'include/guisan/widgets/progressbar.hpp',
'include/guisan/widgets/radiobutton.hpp',
'include/guisan/widgets/scrollarea.hpp',
Expand Down
7 changes: 4 additions & 3 deletions examples/widgets_example.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ namespace WidgetsExample

textField = std::make_unique<gcn::TextField>("Text field");

passwordField = std::make_unique<gcn::PasswordField>("password");
passwordField = std::make_unique<gcn::TextField>("password");
passwordField->setMaskingChar('*');

textBox = std::make_unique<gcn::TextBox>("Lorem ipsum dolor sit amet consectetur\n"
"adipiscing elit Integer vitae ultrices\n"
Expand Down Expand Up @@ -129,7 +130,7 @@ namespace WidgetsExample
top->add(imageButton.get(), 10, 290);
top->add(imageTextButton.get(), 10, 380);
top->add(textField.get(), 375, 10);
top->add(passwordField.get(), 425, 10);
top->add(passwordField.get(), 375, 30);
top->add(textBoxScrollArea.get(), 290, 50);
top->add(inputBox.get(), 270, 180);
top->add(listBox.get(), 290, 200);
Expand Down Expand Up @@ -208,7 +209,7 @@ namespace WidgetsExample
std::unique_ptr<gcn::ImageTextButton> imageTextButton; // An image text button
std::unique_ptr<gcn::InputBox> inputBox; // An input box
std::unique_ptr<gcn::TextField> textField; // One-line text field
std::unique_ptr<gcn::PasswordField> passwordField; // One-line password field
std::unique_ptr<gcn::TextField> passwordField; // One-line password field
std::unique_ptr<gcn::TextBox> textBox; // Multi-line text box
std::unique_ptr<gcn::ScrollArea> textBoxScrollArea; // Scroll area for the text box
std::unique_ptr<gcn::ListBox> listBox; // A list box
Expand Down
1 change: 0 additions & 1 deletion include/guisan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@
#include <guisan/widgets/label.hpp>
#include <guisan/widgets/listbox.hpp>
#include <guisan/widgets/messagebox.hpp>
#include <guisan/widgets/passwordfield.hpp>
#include <guisan/widgets/progressbar.hpp>
#include <guisan/widgets/scrollarea.hpp>
#include <guisan/widgets/slider.hpp>
Expand Down
111 changes: 0 additions & 111 deletions include/guisan/widgets/passwordfield.hpp

This file was deleted.

19 changes: 19 additions & 0 deletions include/guisan/widgets/textfield.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@ namespace gcn
*/
unsigned int getCaretPosition() const;

/**
* Set the masking character to hide the password, or '\0'
*
* @param passwordMasking the masking character
*/
void setMaskingChar(char passwordMasking);

/**
* Get the masking character
*
* @return the masking character if any or '\0'
*/
char getMaskingChar() const;

// Inherited from Widget

void draw(Graphics* graphics) override;
Expand Down Expand Up @@ -204,6 +218,11 @@ namespace gcn
* text needs to scroll in order to show the last type character.
*/
int mXScroll = 0;

/**
* Replacement character for password field, or '\0'.
*/
char mPasswordMasking = '\0';
};
}

Expand Down
1 change: 0 additions & 1 deletion src/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ widget_sources = [
'widgets/label.cpp',
'widgets/listbox.cpp',
'widgets/messagebox.cpp',
'widgets/passwordfield.cpp',
'widgets/progressbar.cpp',
'widgets/radiobutton.cpp',
'widgets/scrollarea.cpp',
Expand Down
99 changes: 0 additions & 99 deletions src/widgets/passwordfield.cpp

This file was deleted.

16 changes: 16 additions & 0 deletions src/widgets/textfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ namespace gcn

void TextField::draw(Graphics* graphics)
{
// Switch replacement text before drawing it to possibly hide it
const std::string realText(mText->getRow(0));
const std::string encodedText = mPasswordMasking ? std::string(realText.size(), mPasswordMasking) : realText;
mText->setRow(0, encodedText);

Color faceColor = getBaseColor();
Color highlightColor, shadowColor;
int alpha = getBaseColor().a;
Expand Down Expand Up @@ -143,6 +148,7 @@ namespace gcn
graphics->drawText(mText->getRow(0), 1 - mXScroll, 2, Graphics::Left, isEnabled());

graphics->popClipArea();
mText->setRow(0, realText);
}

void TextField::drawCaret(Graphics* graphics, int x)
Expand Down Expand Up @@ -286,4 +292,14 @@ namespace gcn
{
fixScroll();
}

void TextField::setMaskingChar(char passwordMasking)
{
mPasswordMasking = passwordMasking;
}

char TextField::getMaskingChar() const
{
return mPasswordMasking;
}
}

0 comments on commit d6ffce4

Please sign in to comment.