Minor tweak to Add Server

This commit is contained in:
Henrik Rydgård
2026-03-10 09:36:32 +01:00
parent 33c8bdc05b
commit 28d73b6f68
4 changed files with 46 additions and 21 deletions
+30 -12
View File
@@ -410,7 +410,8 @@ void PopupMultiChoice::ChoiceCallback(int num) {
}
}
std::string PopupMultiChoice::ValueText() const {
std::string PopupMultiChoice::ValueText(bool *shadow) const {
*shadow = false;
return valueText_;
}
@@ -502,7 +503,8 @@ static bool IsValidNumberFormatString(std::string_view s) {
return percentCount == 1;
}
std::string PopupSliderChoice::ValueText() const {
std::string PopupSliderChoice::ValueText(bool *shadow) const {
*shadow = false;
// Always good to have space for Unicode.
char temp[256];
temp[0] = '\0';
@@ -543,7 +545,8 @@ void PopupSliderChoiceFloat::HandleChange(EventParams &e) {
}
}
std::string PopupSliderChoiceFloat::ValueText() const {
std::string PopupSliderChoiceFloat::ValueText(bool *shadow) const {
*shadow = false;
char temp[256];
temp[0] = '\0';
if (zeroLabel_.size() && *value_ == 0.0f) {
@@ -809,8 +812,14 @@ void PopupTextInputChoice::HandleClick(EventParams &e) {
screenManager_->push(popupScreen);
}
std::string PopupTextInputChoice::ValueText() const {
return *value_;
std::string PopupTextInputChoice::ValueText(bool *shadow) const {
if (value_->empty()) {
*shadow = true;
return shadowText_;
} else {
*shadow = false;
return *value_;
}
}
LinearLayout *CreateSoftKeyboard(TextEdit *edit, bool *upperCase) {
@@ -932,7 +941,8 @@ void TextEditPopupScreen::OnCompleted(DialogResult result) {
}
void AbstractChoiceWithValueDisplay::GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert, float &w, float &h) const {
const std::string valueText = ValueText();
bool shadow;
const std::string valueText = ValueText(&shadow);
int paddingX = 12;
// Assume we want at least 20% of the size for the label, at a minimum.
float availWidth = (horiz.size - paddingX * 2) * (text_.empty() ? 1.0f : 0.8f);
@@ -972,7 +982,8 @@ void AbstractChoiceWithValueDisplay::Draw(UIContext &dc) {
int paddingX = 12;
dc.SetFontStyle(dc.GetTheme().uiFont);
std::string valueText = ValueText();
bool shadow;
std::string valueText = ValueText(&shadow);
if (passwordMasking_) {
// Replace all characters with stars.
@@ -980,6 +991,10 @@ void AbstractChoiceWithValueDisplay::Draw(UIContext &dc) {
}
// If there is a label, assume we want at least 20% of the size for it, at a minimum.
u32 color = style.fgColor;
if (shadow) {
color = alphaMul(color, 0.4f);
}
if (!text_.empty() && !hideTitle_) {
float availWidth = (bounds_.w - paddingX * 2) * 0.8f;
@@ -996,7 +1011,7 @@ void AbstractChoiceWithValueDisplay::Draw(UIContext &dc) {
}
dc.SetFontScale(scale, scale);
Bounds valueBounds(bounds_.x2() - textPadding_.right - imagePadding, bounds_.y, w, bounds_.h);
dc.DrawTextRect(valueText, valueBounds, style.fgColor, ALIGN_RIGHT | ALIGN_VCENTER | FLAG_WRAP_TEXT);
dc.DrawTextRect(valueText, valueBounds, color, ALIGN_RIGHT | ALIGN_VCENTER | FLAG_WRAP_TEXT);
dc.SetFontScale(1.0f, 1.0f);
} else {
Choice::Draw(dc);
@@ -1009,7 +1024,7 @@ void AbstractChoiceWithValueDisplay::Draw(UIContext &dc) {
float scale = CalculateValueScale(dc, valueText, bounds_.w);
dc.SetFontScale(scale, scale);
dc.DrawTextRect(valueText, bounds_.Expand(-paddingX, 0.0f), style.fgColor, ALIGN_LEFT | ALIGN_VCENTER | FLAG_WRAP_TEXT);
dc.DrawTextRect(valueText, bounds_.Expand(-paddingX, 0.0f), color, ALIGN_LEFT | ALIGN_VCENTER | FLAG_WRAP_TEXT);
dc.SetFontScale(1.0f, 1.0f);
}
}
@@ -1023,7 +1038,8 @@ float AbstractChoiceWithValueDisplay::CalculateValueScale(const UIContext &dc, s
return 1.0f;
}
std::string ChoiceWithValueDisplay::ValueText() const {
std::string ChoiceWithValueDisplay::ValueText(bool *shadow) const {
*shadow = false;
auto category = GetI18NCategory(category_);
std::ostringstream valueText;
if (translateCallback_ && sValue_) {
@@ -1053,7 +1069,8 @@ FileChooserChoice::FileChooserChoice(RequesterToken token, std::string *value, s
});
}
std::string FileChooserChoice::ValueText() const {
std::string FileChooserChoice::ValueText(bool *shadow) const {
*shadow = false;
if (value_->empty()) {
auto di = GetI18NCategory(I18NCat::DIALOG);
return std::string(di->T("Default"));
@@ -1076,7 +1093,8 @@ FolderChooserChoice::FolderChooserChoice(RequesterToken token, std::string *valu
});
}
std::string FolderChooserChoice::ValueText() const {
std::string FolderChooserChoice::ValueText(bool *shadow) const {
*shadow = false;
if (value_->empty()) {
auto di = GetI18NCategory(I18NCat::DIALOG);
return std::string(di->T("Default"));
+12 -7
View File
@@ -330,7 +330,7 @@ public:
UI::Event OnChoice;
protected:
std::string ValueText() const override;
std::string ValueText(bool *shadow) const override;
ImageID ValueImage() const override {
auto iter = icons_.find(*value_);
if (iter != icons_.end()) {
@@ -445,7 +445,7 @@ public:
Event OnChange;
protected:
std::string ValueText() const override;
std::string ValueText(bool *shadow) const override;
private:
void HandleClick(EventParams &e);
@@ -486,7 +486,7 @@ public:
Event OnChange;
protected:
std::string ValueText() const override;
std::string ValueText(bool *shadow) const override;
private:
void HandleClick(EventParams &e);
@@ -517,8 +517,12 @@ public:
minLen_ = minLength;
}
void SetShadowText(std::string_view text) {
shadowText_ = text;
}
protected:
std::string ValueText() const override;
std::string ValueText(bool *shadow) const override;
private:
void HandleClick(EventParams &e);
@@ -527,6 +531,7 @@ private:
std::string *value_;
std::string placeHolder_;
std::string defaultText_;
std::string shadowText_;
int maxLen_;
int minLen_ = 0;
bool restoreFocus_ = false;
@@ -545,7 +550,7 @@ public:
: AbstractChoiceWithValueDisplay(text, layoutParams), sValue_(value), translateCallback_(translateCallback) {}
private:
std::string ValueText() const override;
std::string ValueText(bool *shadow) const override;
std::string *sValue_ = nullptr;
int *iValue_ = nullptr;
@@ -560,7 +565,7 @@ enum class FileChooserFileType {
class FileChooserChoice : public AbstractChoiceWithValueDisplay {
public:
FileChooserChoice(RequesterToken token, std::string *value, std::string_view title, BrowseFileType fileType, LayoutParams *layoutParams = nullptr);
std::string ValueText() const override;
std::string ValueText(bool *shadow) const override;
Event OnChange;
@@ -571,7 +576,7 @@ private:
class FolderChooserChoice : public AbstractChoiceWithValueDisplay {
public:
FolderChooserChoice(RequesterToken token, std::string *value, std::string_view title, LayoutParams *layoutParams = nullptr);
std::string ValueText() const override;
std::string ValueText(bool *shadow) const override;
Event OnChange;
+3 -2
View File
@@ -859,7 +859,7 @@ public:
}
protected:
virtual std::string ValueText() const = 0;
virtual std::string ValueText(bool *shadow) const = 0;
virtual ImageID ValueImage() const { return ImageID::invalid(); }
float CalculateValueScale(const UIContext &dc, std::string_view valueText, float availWidth) const;
@@ -872,7 +872,8 @@ public:
ChoiceWithCallbackValueDisplay(std::string_view text, std::function<std::string()> valueFunc, LayoutParams *layoutParams = nullptr)
: AbstractChoiceWithValueDisplay(text, layoutParams), valueFunc_(valueFunc) {}
protected:
std::string ValueText() const override {
std::string ValueText(bool *shadow) const override {
*shadow = false;
return valueFunc_();
}
std::function<std::string()> valueFunc_;
+1
View File
@@ -17,6 +17,7 @@ public:
auto ni = GetI18NCategory(I18NCat::NETWORKING);
PopupTextInputChoice *textInputChoice = parent->Add(new PopupTextInputChoice(GetRequesterToken(), &editValue_, ni->T("Hostname"), "", 450, screenManager()));
textInputChoice->SetShadowText(ni->T("Hostname"));
parent->Add(new CheckBox(&hasRelay_, ni->T("Relay server mode")));
}