It's probably ill-advised, but I'm trying to make my own list gadget in which the user can reorder the items, since drag and drop remains broken on macOS and I fear it will never work.
How can I make the mouse follow the line more accurately? It sometimes gets farther away from the mouse.
Code: Select all
EnableExplicit
Declare OnCanvasEvents()
Declare DrawItems()
Global rowH = 30
OpenWindow(0, 0, 0, 250, 300, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
CanvasGadget(0, 0, 0, 250, 300)
BindGadgetEvent(0, @OnCanvasEvents(), #PB_All)
DrawItems()
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Procedure OnCanvasEvents()
Protected mX, mY, y
mX = GetGadgetAttribute(0, #PB_Canvas_MouseX)
mY = GetGadgetAttribute(0, #PB_Canvas_MouseY)
Select EventType()
Case #PB_EventType_MouseMove
If GetGadgetAttribute(0, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton
DrawItems()
If StartDrawing(CanvasOutput(0))
Box(0, mY / rowH * rowH, OutputWidth(), 2, RGBA(0, 0, 0, 255))
EndIf
StopDrawing()
EndIf
Case #PB_EventType_LeftButtonDown, #PB_EventType_LeftButtonUp
DrawItems()
EndSelect
EndProcedure
Procedure DrawItems()
Protected i, x, y, txtH
If StartDrawing(CanvasOutput(0))
Box(0, 0, OutputWidth(), OutputHeight(), RGB(255, 255, 255))
DrawingMode(#PB_2DDrawing_Transparent)
txtH = TextHeight("0")
x = 10
For i = 0 To 15
y = i * rowH
DrawText(x, y + ((rowH - txtH) / 2), "Item " + i, RGB(0, 0, 0))
y + rowH
Next
StopDrawing()
EndIf
EndProcedure