B4J Question B4XView, Dragged view pane1 to pane2

ivanomonti

Expert
Licensed User
Longtime User
I need to make a MouseDragged to post a view from one panel to another, is it possible?
 

Attachments

  • 2020-05-08_001948.png
    2020-05-08_001948.png
    23.7 KB · Views: 298

mangojack

Well-Known Member
Licensed User
Longtime User
Upvote 0

ivanomonti

Expert
Licensed User
Longtime User
I think I've made the right or clear question, pardon my English,

  • A button with parent Pane1 is selected
  • I drag it (button) to the Bread2
  • release the right button
  • the button inherits a new parent (parent2) by leaving the Paren1

I already use the DrangDrop library but I don't think it can be used for this, if you don't know how.

2020-05-08_101852.png
 
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
pardon my English,
If you ask in the Italian forum, you don't have to fight with English.

I don't think you're talking about the Designer, right?

If you want to change the parent of a View at runtime, you have to remove it from its current parent and then add it to the new one.
Dragging, you have to "intercept" the view on which you will drop the view dragged.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Just wait "a moment". I downloaded the Erel's b4xlib version and his example...
Hard to understand how it works.

The Erel's example drags text files onto a TextArea, setting this as "dragging destination", without setting the "dragging source" (and it works as expected, as always).

In your case, @ivanomonti, I think you should set the "dragging source". I started trying so:
B4X:
Sub btnMoveMe_MousePressed (EventData As MouseEvent)
    If EventData.SecondaryButtonPressed Then
        Log("right button pressed")
        DragAndDrop1.MakeDragSource(Sender, "DragSource")
        ' I don't know what parameters the SetDragModeAndData requires but I think it is necessary.
'        DragAndDrop1.SetDragModeAndData(TransferMode.MOVE, Array As String("I don'tknow"), Array(Sender))
    End If
End Sub

I think that without setting well that "SetDragModeAndData" the "dragging events" will not trigger (DragEntered, DragOver, DragExited and DragDropped).

I also need help :(
 
Upvote 0

ivanomonti

Expert
Licensed User
Longtime User
and almost perfect, but consider that it's never a question of multiple panel, and must be able to be put back on the starting panel
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
and almost perfect
No, it isn't. I did it roughly, it's not the right way.

In that test project the btnMoveMe Button is moved, while the project should be able to move any View.
The main problem is the type of the third parameter of the SetDragModeAndData method. In another example project I saw that an Image is passed to this method, so I passed what the method Snapshot of Button returns and this works but in the Drop event you cannot detect the real view dragged, the button.

must be able to be put back on the starting panel
This is a secondary problem; "we" (Erel or @stevel05 😄) must solve the first one, before.

H E L P 😄
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
The Java drag and drop Class is intended for use with Data. I haven't tried it with nodes. It may be possible to use part of it as a base, but it may also be easier to write the functionality as a new class. I will take a look a bit later.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Here is a quick and dirty example, it will need refining but should get you started.

Edit: Version2 maintains click position on the node.
 

Attachments

  • DDV.zip
    2.7 KB · Views: 218
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
1 - I thought you needed a DragAndDrop object for each View (Node) to drag (or change it every time). Instead:
B4X:
    DragDrop.Initialize(Me)
    DragDrop.MakeDragSource(Button1,"BDrag")
    DragDrop.MakeDragSource(Button2,"BDrag")
    DragDrop.MakeDragSource(Pane3,"BDrag")
    DragDrop.MakeDragTarget(Pane1,"PDrag")
    DragDrop.MakeDragTarget(Pane2,"PDrag")

👍
 
Upvote 0
Top