I want to add some buttons on a exist ui at mouse position when mouse button is clicked.
I have some questions:
How can I know which widget is under the mouse?
2.Is there mouse click event associated to widget? I seems only found mouse enter and mouse leave event.
3.How to set the added widget position at runtime?
How to create a dragable and resizable ui window?
There’s no global list accessible in Slate/UMG. You need to check IsHovered on the widgets you care about.
Click is currently only implemented on Buttons in slate. So just make whatever you want to be clickable inside a button.
If you added it to the vewport, Set FullScreen Position, if you added it as a child of another widget, there’s a few options; If you added it to a canvas, take the slot property cast it to a canvas panel slot, and adjust the position through the offset. Another option is to adjust the render transform’s translation, which works on any widget, but has different effects because it can extend past the clipping rectangle of the parent widget.
Draggable/resizable UI, you’d need to override the functions for mouse down/mouse move/mouse up on the widget and move the widget accordingly. Re-size same thing, but probably based on some area or handled by another widget that reports the events to the parent.
You may also want to just implement it in Slate and then wrap it as a control you can use in UMG. UMG in 4.5 doesn’t allow for user controls to have later specified content in the designer, so you’d need to hack around it by spawning the content dynamically based on a class property. Depending on how many of these windows you’re making, guessing more than 1, you’ll want it to be reusable.
Right now what I did is as you said: cast the widget to canvas slot then adjust the layout offset, but if I moved/resized the widget, I need to get it’s new offset/translation to move/resize it. Seems in 4.5 I can’t get widget’s render transform too. So how to based last position to adjust the widget?