From 9e883ece96bd4cad524bed518e9dd93d1d94502f Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Tue, 18 Mar 2025 04:26:09 -0400 Subject: [PATCH] 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. --- soh/soh/SohGui/UIWidgets.cpp | 9 +++++++-- soh/soh/SohGui/UIWidgets.hpp | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/soh/soh/SohGui/UIWidgets.cpp b/soh/soh/SohGui/UIWidgets.cpp index 7fbad6705..18abb0094 100644 --- a/soh/soh/SohGui/UIWidgets.cpp +++ b/soh/soh/SohGui/UIWidgets.cpp @@ -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()) { diff --git a/soh/soh/SohGui/UIWidgets.hpp b/soh/soh/SohGui/UIWidgets.hpp index ebf483194..649395b43 100644 --- a/soh/soh/SohGui/UIWidgets.hpp +++ b/soh/soh/SohGui/UIWidgets.hpp @@ -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);