UI: Allow showing popup string values as password stars

This commit is contained in:
Henrik Rydgård 2023-06-21 21:59:11 +02:00
parent 2708f0b93e
commit 0a1bf5532d
2 changed files with 13 additions and 1 deletions

View File

@ -1,5 +1,6 @@
#include <algorithm>
#include <sstream>
#include <cstring>
#include "Common/UI/PopupScreens.h"
#include "Common/UI/ViewGroup.h"
@ -582,7 +583,12 @@ void AbstractChoiceWithValueDisplay::Draw(UIContext &dc) {
int paddingX = 12;
dc.SetFontStyle(dc.theme->uiFont);
const std::string valueText = ValueText();
std::string valueText = ValueText();
if (password_) {
// Replace all characters with stars.
memset(&valueText[0], '*', valueText.size());
}
// If there is a label, assume we want at least 20% of the size for it, at a minimum.

View File

@ -191,10 +191,16 @@ public:
void Draw(UIContext &dc) override;
void GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert, float &w, float &h) const override;
void SetPasswordDisplay() {
password_ = true;
}
protected:
virtual std::string ValueText() const = 0;
float CalculateValueScale(const UIContext &dc, const std::string &valueText, float availWidth) const;
bool password_ = false;
};
// Reads and writes value to determine the current selection.