74 lines
2.2 KiB
C++
74 lines
2.2 KiB
C++
#pragma once
|
|
|
|
#include <XCEditor/Collections/UIEditorDragDropInteraction.h>
|
|
|
|
#include <string_view>
|
|
|
|
namespace XCEngine::UI::Editor::Collections::GridDragDrop {
|
|
|
|
using ::XCEngine::UI::UIPoint;
|
|
using DragDropInteraction::kDefaultDragThreshold;
|
|
using DragDropInteraction::ProcessResult;
|
|
using DragDropInteraction::State;
|
|
|
|
inline void ResetTransientRequests(State& state) {
|
|
DragDropInteraction::ResetTransientRequests(state);
|
|
}
|
|
|
|
inline bool HasActivePointerCapture(const State& state) {
|
|
return DragDropInteraction::HasActivePointerCapture(state);
|
|
}
|
|
|
|
template <typename Callbacks>
|
|
ProcessResult ProcessInputEvents(
|
|
State& state,
|
|
const std::vector<DragDropInteraction::UIInputEvent>& inputEvents,
|
|
Callbacks& callbacks,
|
|
float dragThreshold = kDefaultDragThreshold) {
|
|
struct AdaptedCallbacks {
|
|
Callbacks& callbacks;
|
|
|
|
std::string ResolveDraggableItem(const UIPoint& point) const {
|
|
return callbacks.ResolveDraggableItem(point);
|
|
}
|
|
|
|
void ResetDropTarget(State& state) const {
|
|
state.dropTargetItemId.clear();
|
|
state.validDropTarget = false;
|
|
}
|
|
|
|
void UpdateDropTarget(
|
|
State& state,
|
|
std::string_view draggedItemId,
|
|
const UIPoint& point) const {
|
|
state.dropTargetItemId =
|
|
callbacks.ResolveDropTargetItem(draggedItemId, point);
|
|
state.validDropTarget =
|
|
!state.dropTargetItemId.empty() &&
|
|
callbacks.CanDropOnItem(draggedItemId, state.dropTargetItemId);
|
|
}
|
|
|
|
bool IsItemSelected(std::string_view itemId) const {
|
|
return callbacks.IsItemSelected(itemId);
|
|
}
|
|
|
|
bool SelectDraggedItem(std::string_view itemId) const {
|
|
return callbacks.SelectDraggedItem(itemId);
|
|
}
|
|
|
|
bool CommitDrop(State& state, ProcessResult&) const {
|
|
return callbacks.CommitDropOnItem(
|
|
state.draggedItemId,
|
|
state.dropTargetItemId);
|
|
}
|
|
} adaptedCallbacks{ callbacks };
|
|
|
|
return DragDropInteraction::ProcessInputEvents(
|
|
state,
|
|
inputEvents,
|
|
adaptedCallbacks,
|
|
dragThreshold);
|
|
}
|
|
|
|
} // namespace XCEngine::UI::Editor::Collections::GridDragDrop
|