Fix/modern menu/secret flag (#5131)

* Adds ability to set InputString fields as "secret"

Meaning it shows the text as dots like a password field. Currently nothing that is merged into the main branch uses this but Anchor will need it.

* Adds an `addedFlags` field to InputOptions.
This commit is contained in:
Christopher Leggett 2025-03-18 04:26:09 -04:00 committed by GitHub
parent 546b915106
commit 9e883ece96
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 2 deletions

View file

@ -777,7 +777,12 @@ bool InputString(const char* label, std::string* value, const InputOptions& opti
}
}
ImGui::SetNextItemWidth(width);
if (ImGui::InputText(label, (char*)value->c_str(), value->capacity() + 1, ImGuiInputTextFlags_CallbackResize, InputTextResizeCallback, value)) {
ImGuiInputTextFlags flags = ImGuiInputTextFlags_CallbackResize;
if (options.secret) {
flags |= ImGuiInputTextFlags_Password;
}
flags |= options.addedFlags;
if (ImGui::InputText(label, (char*)value->c_str(), value->capacity() + 1, flags, InputTextResizeCallback, value)) {
dirty = true;
}
if (value->empty() && !options.placeholder.empty()) {
@ -828,7 +833,7 @@ bool InputInt(const char* label, int32_t* value, const InputOptions& options) {
}
}
ImGui::SetNextItemWidth(width);
if (ImGui::InputScalar(label, ImGuiDataType_S32, value)) {
if (ImGui::InputScalar(label, ImGuiDataType_S32, value, nullptr, nullptr, nullptr, options.addedFlags)) {
dirty = true;
}
if ((ImGui::GetItemStatusFlags() & ImGuiItemStatusFlags_Edited) && !options.placeholder.empty()) {

View file

@ -425,6 +425,8 @@ namespace UIWidgets {
std::string placeholder = "";
InputTypes type = InputTypes::String;
std::string defaultValue = "";
bool secret = false;
ImGuiInputFlags addedFlags = 0;
InputOptions& Tooltip(const char* tooltip_) {
WidgetOptions::tooltip = tooltip_;
@ -463,6 +465,11 @@ namespace UIWidgets {
defaultValue = defaultValue_;
return *this;
}
InputOptions& IsSecret(bool secret_ = false) {
secret = secret_;
return *this;
}
};
void PushStyleMenu(const ImVec4& color);