while working on the UI i’ve noticed that there’s no straightforward way of handling widgets hovering.
In case of Slate, you have to override mouse enter function. In case of UMG there is a mouse move event, that is executed every tick (could be solved by introducing mouse enter event which is present in Slate) and once the mouse enters widget canvas, which is bad, since that way you can’t handle hovering on specific widgets within your widget.
Why there is no ‘OnHover’ delegate? That first, will solve issue with the full-screen widgets, and second, that will speedup workflow for both Slate and UMG ways.
I might be missing something here, though. Any entries are welcome
Update: Just realized it could fit engine category better.
Update #2: So, 5 minutes of coding and I’ve added hover events for button widget, both Slate and UMG. Should be easy to add it to a lower-level widget
P.S. It’s quite confusing, SButton is a child of SBorder, while UButton isn’t child of UBorder, which has no obvious reasons to do so. Would be better to add these events to border widget, since it’s the one which is presumed to have hovering capabilities, if i understand it correctly.
I’d be glad to make a pull request if anyone is interested
PLEASE DO! This is so simple and needed that I’m curious why it isn’t still in binary version of the engine…
For consistency with existing Slate methods, you should name the events OnMouseEnter and OnMouseLeave. Look at the corresponding functions in SWidget.h, and you should figure out matching delegate signatures:
DECLARE_DELEGATE_TwoParams( FOnMouseEnter, const FGeometry&, const FPointerEvent& )
DECLARE_DELEGATE_OneParam( FOnMouseLeave, const FPointerEvent& )
Indeed, thanks for the note, I’ve always had problems naming things properly, will fix and issue a pull request later next week.
Edit: forgot, actually, why i didn’t name delegates this way is because there are OnMouseEnter and OnMouseLeave functions, as you said. Having some delegates called, for example “OnClicked” and other “OnMouseEnterDelegate” looks a little weird. That’s why there’s no delegate for this in UMG, i think.
Here are two ways to solve this:
- Call it the way i did (or something else, just not OnMouseEnter/OnMouseLeave), which introduces inconsistency
- Call it OnMouseEnterDelegate or similar way, which introduces inconsistency
Second one is actually a little better, but Epics might not like it anyway
Looks like Epic handled that on their own. Master branch has changes that bring hover event to UMG button and maybe some other widgets
And that’s how they solved this:
I’m in dire need of this feature too!
It’s in master branch, should be in 4.11 as well i think.