@@ -223,23 +223,8 @@ module Editor
223
223
end
224
224
end
225
225
226
- # our entities are both drag sources and drag targets here!
227
- if CImGui. BeginDragDropSource (CImGui. ImGuiDragDropFlags_None)
228
- @c CImGui. SetDragDropPayload (" Entity" , & n, sizeof (Cint)) # set payload to carry the index of our item (could be anything)
229
- CImGui. Text (" Move $(filteredEntities[n]. name) " )
230
- CImGui. EndDragDropSource ()
231
- end
232
- if CImGui. BeginDragDropTarget ()
233
- payload = CImGui. AcceptDragDropPayload (" Entity" )
234
- if payload != C_NULL
235
- payload = unsafe_load (payload)
236
- origin = unsafe_load (Ptr {Cint} (payload. Data))
237
- destination = n
238
- filteredEntities[origin]. parent = filteredEntities[destination]
239
- @assert payload. DataSize == sizeof (Cint)
240
- end
241
- CImGui. EndDragDropTarget ()
242
- end
226
+ handle_drag_and_drop (filteredEntities, n)
227
+
243
228
244
229
# Reorder entities: We can only reorder entities if the entiities are not being filtered
245
230
if length (filteredEntities) == length (currentSceneMain. scene. entities)
@@ -611,6 +596,7 @@ module Editor
611
596
# We only need to do this in the case where the origin index is less than the destination index, because the other way around, the destination index is already "adjusted" because the items before it are not shifted
612
597
destination -= 1
613
598
end
599
+ originEntity. parent = C_NULL
614
600
updatedEntities = [entities[destination], originEntity]
615
601
616
602
splice! (entities, destination : destination, updatedEntities)
@@ -627,4 +613,24 @@ module Editor
627
613
@warn " Error in renderloop!" exception= e
628
614
end
629
615
end
616
+
617
+ function handle_drag_and_drop (filteredEntities, n)
618
+ # our entities are both drag sources and drag targets here!
619
+ if CImGui. BeginDragDropSource (CImGui. ImGuiDragDropFlags_None)
620
+ @c CImGui. SetDragDropPayload (" Entity" , & n, sizeof (Cint)) # set payload to carry the index of our item (could be anything)
621
+ CImGui. Text (" Move $(filteredEntities[n]. name) " )
622
+ CImGui. EndDragDropSource ()
623
+ end
624
+ if CImGui. BeginDragDropTarget ()
625
+ payload = CImGui. AcceptDragDropPayload (" Entity" )
626
+ if payload != C_NULL
627
+ payload = unsafe_load (payload)
628
+ origin = unsafe_load (Ptr {Cint} (payload. Data))
629
+ destination = n
630
+ filteredEntities[origin]. parent = filteredEntities[destination]
631
+ @assert payload. DataSize == sizeof (Cint)
632
+ end
633
+ CImGui. EndDragDropTarget ()
634
+ end
635
+ end
630
636
end
0 commit comments