Support for hiding text box input, hide server connection password box by default

This commit is contained in:
Kae 2023-06-28 01:40:55 +10:00
parent 4c006afc94
commit cd497bbcf3
4 changed files with 28 additions and 3 deletions

View File

@ -0,0 +1,5 @@
{
"password" : {
"hidden" : true
}
}

View File

@ -8,6 +8,7 @@ namespace Star {
TextBoxWidget::TextBoxWidget(String const& startingText, String const& hint, WidgetCallbackFunc callback) TextBoxWidget::TextBoxWidget(String const& startingText, String const& hint, WidgetCallbackFunc callback)
: m_text(startingText), m_hint(hint), m_callback(callback) { : m_text(startingText), m_hint(hint), m_callback(callback) {
auto assets = Root::singleton().assets(); auto assets = Root::singleton().assets();
m_textHidden = false;
m_regex = ".*"; m_regex = ".*";
m_repeatKeyThreshold = 0; m_repeatKeyThreshold = 0;
m_repeatCode = SpecialRepeatKeyCodes::None; m_repeatCode = SpecialRepeatKeyCodes::None;
@ -61,6 +62,11 @@ void TextBoxWidget::renderImpl() {
context()->renderInterfaceText(m_hint, {pos, m_hAnchor, m_vAnchor}); context()->renderInterfaceText(m_hint, {pos, m_hAnchor, m_vAnchor});
} else { } else {
context()->setFontColor(m_color.mix(Color::rgbf(0, 0, 1), blueRate).toRgba()); context()->setFontColor(m_color.mix(Color::rgbf(0, 0, 1), blueRate).toRgba());
if (m_textHidden) {
String hiddenText('*', m_text.length());
context()->renderInterfaceText(hiddenText, { pos, m_hAnchor, m_vAnchor });
}
else
context()->renderInterfaceText(m_text, { pos, m_hAnchor, m_vAnchor }); context()->renderInterfaceText(m_text, { pos, m_hAnchor, m_vAnchor });
} }
context()->setDefaultFont(); context()->setDefaultFont();
@ -136,7 +142,7 @@ void TextBoxWidget::update() {
} }
} }
String TextBoxWidget::getText() { String TextBoxWidget::getText() const {
return m_text; return m_text;
} }
@ -155,6 +161,14 @@ bool TextBoxWidget::setText(String const& text, bool callback) {
return true; return true;
} }
bool TextBoxWidget::getHidden() const {
return m_textHidden;
}
void TextBoxWidget::setHidden(bool hidden) {
m_textHidden = hidden;
}
String TextBoxWidget::getRegex() { String TextBoxWidget::getRegex() {
return m_regex; return m_regex;
} }

View File

@ -14,9 +14,12 @@ public:
virtual void update() override; virtual void update() override;
String getText(); String getText() const;
bool setText(String const& text, bool callback = true); bool setText(String const& text, bool callback = true);
bool getHidden() const;
void setHidden(bool hidden);
// Set the regex that the text-box must match. Defaults to .* // Set the regex that the text-box must match. Defaults to .*
String getRegex(); String getRegex();
void setRegex(String const& regex); void setRegex(String const& regex);
@ -56,6 +59,7 @@ private:
bool modText(String const& text); bool modText(String const& text);
bool newTextValid(String const& text) const; bool newTextValid(String const& text) const;
bool m_textHidden;
String m_text; String m_text;
String m_hint; String m_hint;
String m_regex; String m_regex;

View File

@ -432,6 +432,8 @@ WidgetConstructResult WidgetParser::textboxHandler(String const& name, Json cons
textbox->setMaxWidth(config.getInt("maxWidth")); textbox->setMaxWidth(config.getInt("maxWidth"));
if (config.contains("regex")) if (config.contains("regex"))
textbox->setRegex(config.getString("regex")); textbox->setRegex(config.getString("regex"));
if (config.contains("hidden"))
textbox->setHidden(config.getBool("hidden"));
common(textbox, config); common(textbox, config);