[studio/modlib] Update ImGui drag/drop, other cleanup
This commit is contained in:
@@ -9,11 +9,20 @@
|
||||
#include <imgui.h>
|
||||
|
||||
#include <ox/std/bit.hpp>
|
||||
#include <ox/std/cstringview.hpp>
|
||||
#include <ox/std/stringparam.hpp>
|
||||
#include <ox/claw/claw.hpp>
|
||||
|
||||
#include <turbine/context.hpp>
|
||||
#include <studio/context.hpp>
|
||||
#include <studio/widget.hpp>
|
||||
|
||||
namespace turbine {
|
||||
class Context;
|
||||
}
|
||||
|
||||
namespace studio {
|
||||
struct Context;
|
||||
}
|
||||
|
||||
namespace studio::ig {
|
||||
|
||||
inline constexpr auto BtnSz = ImVec2{52, 22};
|
||||
@@ -31,18 +40,18 @@ ox::Result<T> getDragDropPayload(ox::CStringViewCR name) noexcept {
|
||||
return ox::Error(1, "No drag/drop payload");
|
||||
}
|
||||
return ox::readClaw<T>({
|
||||
std::launder(reinterpret_cast<char const*>(payload->Data)),
|
||||
static_cast<char const*>(payload->Data),
|
||||
static_cast<size_t>(payload->DataSize)});
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ox::Result<T> getDragDropPayload() noexcept {
|
||||
auto const payload = ImGui::AcceptDragDropPayload(ox::ModelTypeName_v<T>);
|
||||
auto const payload = ImGui::AcceptDragDropPayload(ox::ModelTypeName_v<T>.c_str());
|
||||
if (!payload) {
|
||||
return ox::Error(1, "No drag/drop payload");
|
||||
}
|
||||
return ox::readClaw<T>({
|
||||
reinterpret_cast<char const*>(payload->Data),
|
||||
static_cast<char const*>(payload->Data),
|
||||
static_cast<size_t>(payload->DataSize)});
|
||||
}
|
||||
|
||||
@@ -55,7 +64,7 @@ ox::Error setDragDropPayload(ox::CStringViewCR name, auto const &obj) noexcept {
|
||||
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());
|
||||
ImGui::SetDragDropPayload(ox::ModelTypeName_v<T>.c_str(), buff.data(), buff.size());
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -64,8 +73,8 @@ class DragDropSource {
|
||||
private:
|
||||
bool const m_active{};
|
||||
public:
|
||||
DragDropSource(ImGuiDragDropFlags const flags = 0) noexcept:
|
||||
m_active(ImGui::BeginDragDropSource(flags)) {
|
||||
explicit DragDropSource(ImGuiDragDropFlags const flags = 0) noexcept:
|
||||
m_active{ImGui::BeginDragDropSource(flags)} {
|
||||
}
|
||||
~DragDropSource() noexcept {
|
||||
if (m_active) {
|
||||
|
||||
Reference in New Issue
Block a user