[studio] Add drag/drop functions that use model TypeName for name
All checks were successful
Build / build (push) Successful in 3m23s
All checks were successful
Build / build (push) Successful in 3m23s
This commit is contained in:
parent
695e7a4561
commit
04ad0f0264
@ -34,19 +34,37 @@ ox::Result<T> getDragDropPayload(ox::CStringViewCR name) noexcept {
|
|||||||
static_cast<size_t>(payload->DataSize)});
|
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::Error setDragDropPayload(ox::CStringViewCR name, auto const&obj) noexcept {
|
||||||
OX_REQUIRE(buff, ox::writeClaw(obj, ox::ClawFormat::Metal));
|
OX_REQUIRE(buff, ox::writeClaw(obj, ox::ClawFormat::Metal));
|
||||||
ImGui::SetDragDropPayload(name.c_str(), buff.data(), buff.size());
|
ImGui::SetDragDropPayload(name.c_str(), buff.data(), buff.size());
|
||||||
return {};
|
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 {
|
class DragDropSource {
|
||||||
private:
|
private:
|
||||||
bool const m_active{};
|
bool const m_active{};
|
||||||
public:
|
public:
|
||||||
DragDropSource() noexcept:
|
DragDropSource(ImGuiDragDropFlags const flags = 0) noexcept:
|
||||||
m_active(ImGui::BeginDragDropSource()) {
|
m_active(ImGui::BeginDragDropSource(flags)) {
|
||||||
}
|
}
|
||||||
~DragDropSource() noexcept {
|
~DragDropSource() noexcept {
|
||||||
if (m_active) {
|
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 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 cb();
|
||||||
}
|
}
|
||||||
return ox::Error{};
|
return ox::Error{};
|
||||||
} else {
|
} else {
|
||||||
if (ig::DragDropSource const tgt; tgt) [[unlikely]] {
|
if (ig::DragDropSource const tgt{flags}; tgt) [[unlikely]] {
|
||||||
cb();
|
cb();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user