diff --git a/src/olympic/studio/modlib/include/studio/imguiutil.hpp b/src/olympic/studio/modlib/include/studio/imguiutil.hpp index e0053901..cc343bf1 100644 --- a/src/olympic/studio/modlib/include/studio/imguiutil.hpp +++ b/src/olympic/studio/modlib/include/studio/imguiutil.hpp @@ -128,9 +128,35 @@ void centerNextWindow(turbine::Context &ctx) noexcept; bool PushButton(ox::CStringView lbl, ImVec2 const&btnSz = BtnSz) noexcept; +template +struct TextInput { + bool changed{}; + Str text; + explicit constexpr operator ox::String() const noexcept { return ox::String{text}; } + constexpr operator ox::CStringView() const noexcept { return text; } + constexpr operator ox::StringView() const noexcept { return text; } + constexpr operator bool() const noexcept { return changed; } +}; + +template +TextInput> InputText( + ox::CStringViewCR label, + ox::StringViewCR currentText, + ImGuiInputTextFlags const flags = 0, + ImGuiInputTextCallback const callback = nullptr, + void *user_data = nullptr) noexcept { + TextInput> out = {.text = currentText}; + out.changed = ImGui::InputText( + label.c_str(), out.text.data(), MaxChars + 1, flags, callback, user_data); + if (out.changed) { + std::ignore = out.text.unsafeResize(ox::strlen(out.text.c_str())); + } + return out; +} + template bool InputText( - ox::CStringView label, + ox::CStringViewCR label, ox::IString &text, ImGuiInputTextFlags const flags = 0, ImGuiInputTextCallback const callback = nullptr,