Added support for hidden text fields (intended for passwords).

This commit is contained in:
Leon Styhre 2020-11-07 12:50:30 +01:00
parent 8131b81761
commit 1af7e3eda4
4 changed files with 35 additions and 3 deletions

View file

@ -319,15 +319,24 @@ const Transform4x4f& GuiComponent::getTransform()
return mTransform;
}
std::string GuiComponent::getValue() const
{
return "";
}
void GuiComponent::setValue(const std::string& /*value*/)
{
}
std::string GuiComponent::getValue() const
std::string GuiComponent::getHiddenValue() const
{
return "";
}
void GuiComponent::setHiddenValue(const std::string& /*value*/)
{
}
void GuiComponent::textInput(const char* text)
{
for (auto iter = mChildren.cbegin(); iter != mChildren.cend(); iter++)

View file

@ -161,6 +161,9 @@ public:
virtual std::string getValue() const;
virtual void setValue(const std::string& value);
virtual std::string getHiddenValue() const;
virtual void setHiddenValue(const std::string& value);
virtual void onFocusGained() {};
virtual void onFocusLost() {};

View file

@ -114,6 +114,11 @@ void TextComponent::setText(const std::string& text)
onTextChanged();
}
void TextComponent::setHiddenText(const std::string& text)
{
mHiddenText = text;
}
void TextComponent::setUppercase(bool uppercase)
{
mUppercase = uppercase;
@ -265,14 +270,24 @@ void TextComponent::setLineSpacing(float spacing)
onTextChanged();
}
std::string TextComponent::getValue() const
{
return mText;
}
void TextComponent::setValue(const std::string& value)
{
setText(value);
}
std::string TextComponent::getValue() const
std::string TextComponent::getHiddenValue() const
{
return mText;
return mHiddenText;
}
void TextComponent::setHiddenValue(const std::string& value)
{
setHiddenText(value);
}
void TextComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view,

View file

@ -39,6 +39,7 @@ public:
void setUppercase(bool uppercase);
void onSizeChanged() override;
void setText(const std::string& text);
void setHiddenText(const std::string& text);
void setColor(unsigned int color) override;
void setHorizontalAlignment(Alignment align);
void setVerticalAlignment(Alignment align);
@ -52,6 +53,9 @@ public:
std::string getValue() const override;
void setValue(const std::string& value) override;
std::string getHiddenValue() const override;
void setHiddenValue(const std::string& value) override;
unsigned char getOpacity() const override;
void setOpacity(unsigned char opacity) override;
@ -64,6 +68,7 @@ protected:
virtual void onTextChanged();
std::string mText;
std::string mHiddenText;
std::shared_ptr<Font> mFont;
private: