diff --git a/src/olympic/studio/modlib/include/studio/imguiutil.hpp b/src/olympic/studio/modlib/include/studio/imguiutil.hpp index e9a4d1d7..0f71da88 100644 --- a/src/olympic/studio/modlib/include/studio/imguiutil.hpp +++ b/src/olympic/studio/modlib/include/studio/imguiutil.hpp @@ -34,19 +34,37 @@ ox::Result getDragDropPayload(ox::CStringViewCR name) noexcept { static_cast(payload->DataSize)}); } +template +ox::Result getDragDropPayload() noexcept { + auto const payload = ImGui::AcceptDragDropPayload(ox::ModelTypeName_v); + if (!payload) { + return ox::Error(1, "No drag/drop payload"); + } + return ox::readClaw({ + reinterpret_cast(payload->Data), + static_cast(payload->DataSize)}); +} + ox::Error setDragDropPayload(ox::CStringViewCR name, auto const&obj) noexcept { OX_REQUIRE(buff, ox::writeClaw(obj, ox::ClawFormat::Metal)); ImGui::SetDragDropPayload(name.c_str(), buff.data(), buff.size()); return {}; } +template +ox::Error setDragDropPayload(T const&obj) noexcept { + OX_REQUIRE(buff, ox::writeClaw(obj, ox::ClawFormat::Metal)); + ImGui::SetDragDropPayload(ox::ModelTypeName_v, buff.data(), buff.size()); + return {}; +} + class DragDropSource { private: bool const m_active{}; public: - DragDropSource() noexcept: - m_active(ImGui::BeginDragDropSource()) { + DragDropSource(ImGuiDragDropFlags const flags = 0) noexcept: + m_active(ImGui::BeginDragDropSource(flags)) { } ~DragDropSource() noexcept { if (m_active) { @@ -58,14 +76,14 @@ class DragDropSource { } }; -auto dragDropSource(auto const&cb) noexcept { +auto dragDropSource(auto const&cb, ImGuiDragDropFlags const flags = 0) noexcept { if constexpr(ox::is_same_v) { - if (ig::DragDropSource const tgt; tgt) [[unlikely]] { + if (ig::DragDropSource const tgt{flags}; tgt) [[unlikely]] { return cb(); } return ox::Error{}; } else { - if (ig::DragDropSource const tgt; tgt) [[unlikely]] { + if (ig::DragDropSource const tgt{flags}; tgt) [[unlikely]] { cb(); } }