rds1983 / Myra

UI Library for MonoGame, FNA and Stride
MIT License
704 stars 94 forks source link

Input events fall through a container no matter it has been handled or not #387

Open XCYRKDSDA opened 1 year ago

XCYRKDSDA commented 1 year ago

Let's say there's a button (button1) and there's a panel above it, and there're two buttons in this panel where one button (button3) is above the other one (button2). When I click button3, everything's ok, only button3 will response to the mouse input. But when I click the overlap part of button1 and button2, both buttons will receive the input and be clicked.

issue

The layout code is shown below.

<Project>
  <Grid>
    <TextButton Text="Button1" Width="200" Height="100" BorderThickness="2" Border="#666666FF" />
    <Panel Left="125" Top="60">
      <TextButton Text="Button2" Width="200" Height="100" BorderThickness="2" Border="#666666FF" />
      <TextButton Text="Button3" Left="125" Top="60" Width="200" Height="100" BorderThickness="2" Border="#666666FF" />
    </Panel>
  </Grid>
</Project>

I think this is because a container's (in this case, the grid's) input processing loop only breaks when the input can't FallsThrough a child widget, but does not consider whether the input has been handled or not. Perhaps adding a return value to the method OnTouchDown and other input handlers to indicate whether the input has been handled can fix this problem. For example:

var doBreak = (w.Desktop != null && !w.FallsThrough(w.Desktop.TouchPosition));
var inputHandled = w.OnTouchDown();
if (doBreak || inputHandled)
    break;