Terminal.Gui icon indicating copy to clipboard operation
Terminal.Gui copied to clipboard

`MouseEvent`/`MouseClick` can't be externally controlled - was `Slider` does not seem to respect click handlers

Open tznind opened this issue 1 year ago • 3 comments

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;
    }
}

tznind avatar Sep 01 '24 10:09 tznind

Perhaps the SliderView respond to ButtonPressed and thus you must also suppress it?

BDisp avatar Sep 01 '24 10:09 BDisp

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;

tznind avatar Sep 01 '24 10:09 tznind

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

tig avatar Sep 01 '24 15:09 tig