Sybaris
Topic Author
Posts: 32
Joined: 21 Feb 2019, 10:13

Click through bug

20 Oct 2021, 11:38

Hi everybody,

in our application we overlay the Unity scene with Noesis (user) controls. Clicks in the UI are also handled by Unity which means that we constantly select objects in the scene although we're just clicking around in the UI. We call that the "click through bug". We tried to exclude clicks from the Unity handling by using the HitTest method of Noesis, which works more or less.
But...
First of all we have the impression that the coordinate system that HitTest uses, is upside down?
And HitTest obviously doesn't recognize popups, like menus, combo box popups etc.
Is there a way to also get popups with the HitTest method? This way clicking a context menu item also selects a different object in the scene, which changes the object that the context menu was displayed for which is extremely annoying.

Thanks in advance!

PS: I tried to bind IsSubmenuOpen of MenuItem to a property in the view model and to "lock" the view as long as the popup is open; that basically worked under WPF but crashed Unity completely. Is that a known issue?

Tags:
 
User avatar
sfernandez
Site Admin
Posts: 2387
Joined: 22 Dec 2011, 19:20

Re: Click through bug

20 Oct 2021, 11:48

Hi,

In NoesisView.cs you can see how we are doing the HitTest for input events. As you said vertical coordinates should be inverted from Unity:
Point p = new Point(ev.mousePosition.x, UnityEngine.Screen.height - ev.mousePosition.y);
And in order to check the entire tree (including popups) you need to call the HitTest method starting on the View's root:
Visual root = (Visual)VisualTreeHelper.GetRoot(view.Content);
return VisualTreeHelper.HitTest(root, p).VisualHit != null;
Regarding the crashes with IsSubmenuOpen they are not a known issue, please create a ticket in our bugtracker and attach the crash dumps, thanks.
 
Sybaris
Topic Author
Posts: 32
Joined: 21 Feb 2019, 10:13

Re: Click through bug

20 Oct 2021, 12:29

Thanks for the quick response!
That's what I have right now:
        NoesisView view = _camera.GetComponent<NoesisView>();
        Visual root = (Visual)VisualTreeHelper.GetRoot(view.Content);
        Point clickPoint = new Point(Input.mousePosition.x, screenHeight - Input.mousePosition.y);
        HitTestResult hitres = VisualTreeHelper.HitTest(root, clickPoint);
        bool isNoesisArea = hitres.VisualHit != null;
But clicking in a menu while the mouse is over the unity scene still goes through...
 
User avatar
sfernandez
Site Admin
Posts: 2387
Joined: 22 Dec 2011, 19:20

Re: Click through bug

20 Oct 2021, 13:26

Inside which event are you executing that code? I tried both OnMouseDown and Update of a MonoBehavior and it detects fine clicks on popup menus.
 
Sybaris
Topic Author
Posts: 32
Joined: 21 Feb 2019, 10:13

Re: Click through bug

20 Oct 2021, 16:42

We are doing this in Update().
We are using our own template for the menu items; maybe this is the cause.
Is there something special to use, something like IsHitTestVisible or "Transparent", that is necessary so the click doesn't go through?
 
User avatar
sfernandez
Site Admin
Posts: 2387
Joined: 22 Dec 2011, 19:20

Re: Click through bug

21 Oct 2021, 11:47

If the menu items are clickable, I mean they work as expected when you click on them it means that HitTest should be already working, because that is what we use internally.
I don't think that would be the cause, but does it work if you use our Theme styles?
 
Sybaris
Topic Author
Posts: 32
Joined: 21 Feb 2019, 10:13

Re: Click through bug

21 Oct 2021, 12:11

I just tried to use the blue Noesis theme and it obviously has the same problem - clicks go through to Unity although hittested.
We are still using 3.0.11 - could it be that that behaviour changed since then?

Also strange is that the main menu and the context menu items behave different; when a menu item that has a sub menu header item is clicked in the main menu, then the sub menu opens but the menu itself stays open; if we click a sub menu header item in the context menu, then the whole menu closes.
This behaviour is the same under WPF as under Unity, so it's probably not a problem on Noesis side.

EDIT: One thing is different between WPF and Noesis: if I hover over the icon or the text of the menu item then under WPF the submenu opens; under Noesis it stays closed until I hover over the arrow on the right hand side.
 
User avatar
sfernandez
Site Admin
Posts: 2387
Joined: 22 Dec 2011, 19:20

Re: Click through bug

21 Oct 2021, 20:21

I just test it with NoesisGUI 3.0.11 and your code works as expected. Please try the attached example.
Also strange is that the main menu and the context menu items behave different; when a menu item that has a sub menu header item is clicked in the main menu, then the sub menu opens but the menu itself stays open; if we click a sub menu header item in the context menu, then the whole menu closes.
This behaviour is the same under WPF as under Unity, so it's probably not a problem on Noesis side.
Yes, this is the way it is expected to work. If you click a menu item with children it will open the submenu. If the menu item doesn't have children then it will execute the Click event (and associated command).
EDIT: One thing is different between WPF and Noesis: if I hover over the icon or the text of the menu item then under WPF the submenu opens; under Noesis it stays closed until I hover over the arrow on the right hand side.
Using our theme styles it behaves as WPF (it opens the submenu by just hovering anywhere in the item), so it makes me think that your MenuItem template does not provide a background (even using Transparent brush should be enough). Perhaps this was the origin of your problem.
Attachments
TestHit.unitypackage
(4.53 KiB) Downloaded 52 times
 
Sybaris
Topic Author
Posts: 32
Joined: 21 Feb 2019, 10:13

Re: Click through bug

22 Oct 2021, 10:41

Thanks for your detailed reply and the demo app.

Yesterday I imported all the menu styles/templates from the Noesis Theme and adapted them to our look and now it seems to work. To be honest: I have no idea what the problem was. What I could figure out was, that 1) the header content presenter and the icon have to have IsHitTestVisible=false, otherwise they'll block the click from getting through to the border behind (and they're also responsible for closing the menu when clicking on an sub menu item), and 2) the position of the popup inside the menu templates has to be chosen very carefully, because if you put it after the wrong control, it will have a lot of strange effects.

Thanks a lot for your support and sorry for the hazzle.
 
User avatar
sfernandez
Site Admin
Posts: 2387
Joined: 22 Dec 2011, 19:20

Re: Click through bug

22 Oct 2021, 11:32

You're welcome, glad you make it work.

1) It shouldn't matter if you set IsHitTestVisible=false on the header ContentPresenter or the Icon because hovering/clicking any element inside the template of the MenuItem (that is not part of the Popup) will trigger the MouseButtonDown event and the corresponding Click of the header.

2) A Popup by default uses its Parent element as target (its bounds), so you have to take that into account to determine where you want to show it.

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], simonb and 3 guests