`MouseEvent`/`MouseClick` can't be externally controlled - was `Slider` does not seem to respect click handlers
Describe the bug Not sure exactly what is going on but I am trying to stop clicks going through to SliderView in TGD. This approach seems to work for other views.
I tried looking at gui.cs\UnitTests\Views\SliderTests.cs` for mouse tests but couldn't see any to adapt for repro.
if (subView.GetType().IsGenericType(typeof(Slider<>)))
{
// TODO: Does not seem to work
subView.MouseEvent += (s, e) => SuppressNativeClickEvents(s, e,true);
subView.MouseClick += (s, e) => SuppressNativeClickEvents(s,e, true);
}
...
private void SuppressNativeClickEvents(object? sender, MouseEventEventArgs obj, bool alsoSuppressClick = false)
{
if (alsoSuppressClick)
{
obj.Handled = true;
}
else
{
// Suppress everything except single click (selection)
obj.Handled = obj.MouseEvent.Flags != MouseFlags.Button1Clicked;
}
}
Perhaps the SliderView respond to ButtonPressed and thus you must also suppress it?
I don't see a ButtonPressed event.
The above code passes true for alsoSuppressClick so it suppress everything, making the method effectively just be blanket:
obj.Handled = true;
Slider overrides OnMouseEvent.
EDIT: Oct 2, 2025:
This raises a real issue with this, particuarly for MouseEvent: It is not possible for code external to a View like Slider that overrides OnMouseEvent to prevent mouse events from going to the View. The same thing applies to MouseClick.
See #4262