[studio] Add variant of InputText that returns an IString
This commit is contained in:
parent
cb3ef0e79d
commit
cb16687641
@ -128,9 +128,35 @@ void centerNextWindow(turbine::Context &ctx) noexcept;
|
|||||||
|
|
||||||
bool PushButton(ox::CStringView lbl, ImVec2 const&btnSz = BtnSz) 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>
|
template<size_t StrCap>
|
||||||
bool InputText(
|
bool InputText(
|
||||||
ox::CStringView label,
|
ox::CStringViewCR label,
|
||||||
ox::IString<StrCap> &text,
|
ox::IString<StrCap> &text,
|
||||||
ImGuiInputTextFlags const flags = 0,
|
ImGuiInputTextFlags const flags = 0,
|
||||||
ImGuiInputTextCallback const callback = nullptr,
|
ImGuiInputTextCallback const callback = nullptr,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user