[studio] Add variant of InputText that returns an IString

This commit is contained in:
Gary Talent 2024-10-02 20:55:12 -05:00
parent cb3ef0e79d
commit cb16687641

View File

@ -128,9 +128,35 @@ void centerNextWindow(turbine::Context &ctx) noexcept;
bool PushButton(ox::CStringView lbl, ImVec2 const&btnSz = BtnSz) noexcept;
template<typename Str>
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<size_t MaxChars = 50>
TextInput<ox::IString<MaxChars>> InputText(
ox::CStringViewCR label,
ox::StringViewCR currentText,
ImGuiInputTextFlags const flags = 0,
ImGuiInputTextCallback const callback = nullptr,
void *user_data = nullptr) noexcept {
TextInput<ox::IString<MaxChars>> 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<size_t StrCap>
bool InputText(
ox::CStringView label,
ox::CStringViewCR label,
ox::IString<StrCap> &text,
ImGuiInputTextFlags const flags = 0,
ImGuiInputTextCallback const callback = nullptr,