[studio] Add drag/drop functions that use model TypeName for name

This commit is contained in:
Gary Talent 2025-01-24 23:26:30 -06:00
parent 695e7a4561
commit 04ad0f0264

@ -34,19 +34,37 @@ ox::Result<T> getDragDropPayload(ox::CStringViewCR name) noexcept {
static_cast<size_t>(payload->DataSize)});
}
template<typename T>
ox::Result<T> getDragDropPayload() noexcept {
auto const payload = ImGui::AcceptDragDropPayload(ox::ModelTypeName_v<T>);
if (!payload) {
return ox::Error(1, "No drag/drop payload");
}
return ox::readClaw<T>({
reinterpret_cast<char const*>(payload->Data),
static_cast<size_t>(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<typename T>
ox::Error setDragDropPayload(T const&obj) noexcept {
OX_REQUIRE(buff, ox::writeClaw(obj, ox::ClawFormat::Metal));
ImGui::SetDragDropPayload(ox::ModelTypeName_v<T>, 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<decltype(cb()), ox::Error>) {
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();
}
}