From 04ad0f02640b65d8888f625ca51bc6c8046f3fdc Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Fri, 24 Jan 2025 23:26:30 -0600 Subject: [PATCH] [studio] Add drag/drop functions that use model TypeName for name --- .../modlib/include/studio/imguiutil.hpp | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) 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(); } }