simonkrauter / NiGui

Cross-platform desktop GUI toolkit written in Nim
MIT License
724 stars 49 forks source link

Allow dragging of controls #159

Open shujidev opened 1 year ago

shujidev commented 1 year ago

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

simonkrauter commented 1 year ago

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

shujidev commented 1 year ago

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