Floating Components

#21

I was referring to the client’s resources.

I get it now - an oversized container that you drag around - neat! What a cool idea… I bet its a pain to work with in the designer though!

0 Likes

#22

Could you re-post the draggable component code?

I am struggling to make a custom slider with a draggable button. So far I have a mouseMotion/mouseDragged script on a button:

button = event.source.parent.getComponent('MyButton')
system.gui.transform(button,event.x,event.y)

But this transforms the button to the top left of the container. Once i can move it relative to the mouse position, I’ll have to add a few lines of logic to restrict its travel in the x-direction entirely, and in the y-direction inside the bounds of my (background) slider rail.
Thanks!

0 Likes

#23

Was trying to make a dragable component aswell and failed to get the code aswell.
My solution ended up being something like this and it works very well.

In the mouse pressed event add the following code:

event.source.mouseX = event.x
event.source.mouseY = event.y

The code expects two custom properties on the component, integer mouseX and integer mouseY.
Next, in the mouse dragged event on the component add the code

mousePosition = event.source.parent.getMousePosition()

if mousePosition:
	newX = mousePosition.x - event.source.mouseX
	newY = mousePosition.y - event.source.mouseY
	system.gui.transform(event.source, newX=newX, newY=newY)
1 Like