mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-07-16 10:02:59 -07:00
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:
parent
546b915106
commit
9e883ece96
2 changed files with 14 additions and 2 deletions
|
@ -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()) {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue