neither am I, I'm a carpenter. I just love these challenges
Check again how Chrome move open tabs . Once you're halfway through, it instantly goes to the other side
My attempt to make it "smoothly positioned" probably had the opposite result.
Here are the results
; https://www.autoitscript.com/forum/topic/211959-drag-and-drop-items-labels-vertically-among-themselves/?do=findComment&comment=1534586
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#include <StaticConstants.au3>
#include <WinAPIGdi.au3>
#include <Array.au3>
Global $iStart = 70, $iSpace = 5, $iLeft = 20, $iLabelHeight = 50
Global $hGUI = GUICreate('Dragging items vertically (this is a draft)', 500, ($iLabelHeight + $iSpace) * 12)
GUISetBkColor(0x00FF00) ; background color is green
Global $aLabel[10][2]
$aLabel[0][0] = 9 ;NumOfLabels
For $i = 1 To $aLabel[0][0] ;Creating test items (labels)
$aLabel[$i][1] = (($iLabelHeight + $iSpace) * ($i - 1)) + $iStart
$aLabel[$i][0] = GUICtrlCreateLabel("Label " & $i, $iLeft, $aLabel[$i][1], 460, $iLabelHeight, BitOR($SS_SUNKEN, $SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, 0xFF0000)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetFont(-1, 14, 700, 'Tahoma')
Next
GUISetState(@SW_SHOW, $hGUI)
;**********************************
While 1
Switch GUIGetMsg()
Case -3 ;$GUI_EVENT_CLOSE
ExitLoop
EndSwitch
_IsDragging()
Sleep(10)
WEnd
;**********************************
Exit
;--------------------------------------------------------------------------------------------------------------------------------
Func _IsDragging()
Local Static $iOffset = Int($iLabelHeight / 2)
If Not WinActive($hGUI) Then Return SetError(1, 0, False)
Local $aCtrl = GUIGetCursorInfo($hGUI)
If Not $aCtrl[2] Then Return SetError(2, 0, False)
Local $ActiveCtrl = Null
For $i = 1 To $aLabel[0][0]
If $aLabel[$i][0] = $aCtrl[4] Then
$ActiveCtrl = $aCtrl[4]
EndIf
Next
If $ActiveCtrl = Null Then Return SetError(3, 0, False)
Opt("MouseCoordMode", 2) ;1=absolute, 0=relative, 2=client
Local $iCursorId = MouseGetCursor()
GUISetCursor(11, 1, $hGUI)
GUICtrlSetBkColor($ActiveCtrl, 0xCC0000) ;0xFF0000
Local $iOldPos, $iStp
Do
$aCtrl = GUIGetCursorInfo($hGUI)
ControlMove($hGUI, '', $ActiveCtrl, Default, MouseGetPos(1) - $iOffset)
;Reposition of Labels
_ArraySort($aLabel, 0, 1, 0, 1)
For $i = 1 To $aLabel[0][0]
If $aLabel[$i][0] = $ActiveCtrl Then
$aLabel[$i][1] = MouseGetPos(1) - $iOffset
ContinueLoop
EndIf
$aLabel[$i][1] = (($iLabelHeight + $iSpace) * ($i - 1)) + $iStart
$iOldPos = ControlGetPos($hGUI, '', $aLabel[$i][0])[1]
$iStp = ($iOldPos > $aLabel[$i][1] ? -5 : 5)
For $Y = $iOldPos To $aLabel[$i][1] Step $iStp
GUICtrlSetPos($aLabel[$i][0], $iLeft, $Y)
Sleep(10)
Next
Next
;~ Sleep(10)
Until Not $aCtrl[2]
Opt("MouseCoordMode", 1) ;1=absolute, 0=relative, 2=client
GUISetCursor($iCursorId, 1, $hGUI)
GUICtrlSetBkColor($ActiveCtrl, 0xFF0000)
For $i = 1 To $aLabel[0][0]
$aLabel[$i][1] = (($iLabelHeight + $iSpace) * ($i - 1)) + $iStart
;ConsoleWrite(GUICtrlRead($aLabel[$i][0]) & " " & $aLabel[$i][1] & @CRLF)
GUICtrlSetPos($aLabel[$i][0], $iLeft, $aLabel[$i][1])
Next
ConsoleWrite("" & @CRLF)
_WinAPI_RedrawWindow($hGUI)
EndFunc ;==>_IsDragging
;--------------------------------------------------------------------------------------------------------------------------------