alfiare
Topic Author
Posts: 16
Joined: 30 Nov 2017, 23:47

Popup Not Working With Hit Test in Unity

20 Aug 2021, 17:03

A Popup like the example below doesn't ever hit using the VisualTreeHelper.HitTest. This becomes interesting when it's used as a dropdown for a combobox. Is there another way to hit test or some way to make Popups hit?
<Popup IsOpen="True">
            <Border BorderBrush="Red"
                    Background="Beige"
                    Width="100"
                    Height="100"
                    BorderThickness="1">
                <Grid>
                    <Button Content="Test"
                            Style="{StaticResource STButtonSquare}"></Button>
                </Grid>
            </Border>
        </Popup>
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: Popup Not Working With Hit Test in Unity

20 Aug 2021, 17:38

If you follow the proposed code in this post: viewtopic.php?f=3&t=2397#p13179, you'll see I used VisualTreeHelper.GetRoot() to get the root element of the View. You should use that element to start the HitTest search because is the one containing the popup layers as children.

Please let me know if that works.
 
alfiare
Topic Author
Posts: 16
Joined: 30 Nov 2017, 23:47

Re: Popup Not Working With Hit Test in Unity

20 Aug 2021, 18:51

Sorry I missed that, that does fix a Popup by itself, but it doesn't seem to fix a Popup being used in a template for a ComboBox dropdown. If I change the content of a combobox item to be a button the button does hit test correctly, but the rest of the area of the dropdown does not.
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: Popup Not Working With Hit Test in Unity

23 Aug 2021, 10:16

Using our Noesis theme I can't reproduce that behavior, I get the elements forming the ComboBoxItems when calling HitTest.
Are you using your own template? Do you have IsHitTestVisible set to false in any of the template elements?
 
alfiare
Topic Author
Posts: 16
Joined: 30 Nov 2017, 23:47

Re: Popup Not Working With Hit Test in Unity

24 Aug 2021, 17:38

You are right, I made a new Unity project and imported NOESIS using the built in themes by default, and it works. I was using a custom template and such but in my project even converting to use the NOESIS theme it still doesn't hit test the dropdown on the combobox. So it has to be something about my project setup is the only thing I can think of, I have all the noesis settings the same between the two now and still in my project it doesn't work.
 
alfiare
Topic Author
Posts: 16
Joined: 30 Nov 2017, 23:47

Re: Popup Not Working With Hit Test in Unity

24 Aug 2021, 18:45

So I made a super simple test page (XAML below), and with the Noesis settings in the image below tried it, so trying to remove any of my custom stuff at all, same result though, hit test works over the combobox itself but not over the dropdown, it does work over the button in the dropdown which would seem to indicate it's in the visual tree properly etc. Any ideas what I'm doing wrong?


Image of Noesis Settings
https://1drv.ms/u/s!AlRye2-nz3FElbkl-e6 ... g?e=FfqJce




<UserControl x:Class="Stratheon.Client.UI.MainMenu.TestPage"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:Stratheon.Client.UI.MainMenu"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>

        <ComboBox>
            <ComboBoxItem Content="Item1"></ComboBoxItem>
            <ComboBoxItem>
                <Button Content="Item 2"></Button>
            </ComboBoxItem>
            <ComboBoxItem>
                <Grid Background="Aqua">
                    <TextBlock Text="Item 3"></TextBlock>
                </Grid>
            </ComboBoxItem>
            <ComboBoxItem>
                <Border BorderBrush="Red"
                        BorderThickness="1"
                        Background="Beige">
                    <TextBlock Text="Item 4"></TextBlock>
                </Border>
            </ComboBoxItem>
        </ComboBox>
    </Grid>
</UserControl>
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: Popup Not Working With Hit Test in Unity

25 Aug 2021, 11:31

When you say hit test is not working, you mean calling VisualTreeHelper.HitTest() function or using your mouse?
If you attach the following behavior to the Main Camera where the NoesisView component is added, do you get messages when moving the mouse over the drop down items?
using UnityEngine;
using Noesis;

public class HitTestBehavior : MonoBehaviour
{
    Visual lastHit;
    Visual root;

    void Start()
    {
        NoesisView view = GetComponent<NoesisView>();
        root = (Visual)VisualTreeHelper.GetRoot(view.Content);
    }

    void Update()
    {
        Vector3 mousePos = Input.mousePosition;
        Point pos = root.PointFromScreen(new Point(mousePos.x, Screen.height - mousePos.y));
        HitTestResult hit = VisualTreeHelper.HitTest(root, pos);
        if (hit.VisualHit != lastHit)
        {
            lastHit = (Visual)hit.VisualHit;
            if (lastHit != null)
            {
                Debug.Log($"HitTest -> {lastHit.GetType()}");
            }
        }
    }
}
 
alfiare
Topic Author
Posts: 16
Joined: 30 Nov 2017, 23:47

Re: Popup Not Working With Hit Test in Unity

25 Aug 2021, 20:58

OK I think I figured this out, I was doing my hit test downstream of the new Unity Input System, if I do the hit test on a script (like the one you provided) on the camera itself then the hit testing works as expected, properly finds the hit against the popup of the dropdown of the combobox. So I'm guessing that the hit to the combobox dropdown is registering in Noesis, which is then removing the popup, then the Unity Input System must be firing after that, and by that time the popup is gone and therefore not there to find a hit. So I think I can solve this by simply putting a hit test script on the camera, hit test every frame there, and then when there's a click through the Input System just check that script on the camera if it had a hit this frame or not.

Thanks for all your help tracking this down!
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: Popup Not Working With Hit Test in Unity

27 Aug 2021, 10:14

Glad you figured it out, thanks for the update.

Who is online

Users browsing this forum: No registered users and 39 guests