simonkrauter/NiGui

Allow dragging of controls

shujidev opened this issue · 2 comments

Would it be possible to modify this condition
if uMsg == WM_LBUTTONUP and control == pLastMouseButtonDownControl
This would allow to trigger a mousebuttonup event on a different control so that a behavior like dragging elements or transference of attributes could be implemented

https://github.com/simonkrauter/NiGui/blob/master/src/nigui/private/windows/platform_impl.nim#L1282

Difficult to say, how to implement drag and drop, I have never tried it.

Hi thank you for your interest I was misunderstanding your code, but I could find the real problem if you return PWndProcResult_True or return PWndProcResult_False at the end of a Mouse ButtonDown message windows will allow a mouseup event to be handled correctly on another control (my problem was that a mouseup event was triggered only on the same control mousedown was triggered)

Example try dragging a button into another button:

import nigui
app.init()
var window = newWindow("Gui")
window.show()
let button = newButton("button")
let button2 = newButton("button2")
let container = newLayoutContainer(Layout_Vertical)
window.add container
container.add button
container.add button2

button.onMouseButtonDown = proc(event: MouseEvent) = echo "mousedown Button"
button2.onMouseButtonDown = proc(event: MouseEvent) = echo "mousedown Button2"
button.onMouseButtonUp = proc(event: MouseEvent) = echo "mouseup Button"
button2.onMouseButtonUp = proc(event: MouseEvent) = echo "mouseup Button2"
    
app.run()

Then try after adding a return PWndProcResult_False to the end of the WM_LBUTTONDOWN message handling