Canvas mouse down event

I have implemented custom drop down lists for my components using GH_ComponentAttributes (image below). The problem is that the RespondToMouseDown callback only fires when the mouse is clicked when on top of the component, while when the list is open the options appear beyond the layout bounds of the component.

To register the mouse events, I have therefore skipped RespondToMouseDown altogether and I am using ActiveCanvas events like so:

if (Grasshopper.Instances.ActiveCanvas != null) {
    Grasshopper.Instances.ActiveCanvas.MouseMove += mouseMoved;
    Grasshopper.Instances.ActiveCanvas.MouseDown += mouseDown;
}

The issue I am facing with this approach is that the callback functions for these events do not have a way to notify Grasshopper that the mouse event was handled elsewhere. Therefore, the clicks are handled by me and are also handled by Grasshopper itself leading to, for example, dragging the component.

The RespondToMouseDown callback function has a GH_ObjectResponse return type which allows you to inform Grasshopper that the click was handled so it won’t bother handling it as well. The ActiveCanvas events do not have such a mechanism. Is there a way to go around that?

image

Why not subscribe to an event on the drop-down itself (like OnSelectionChanged) or something like that. Wouldn’t that make more sense than to subscribe to events on the canvas?

I have created the dropdown by rendering rectangles and texts on the component, therefore I am using the mouse down event to create my version of “OnSelectionChanged”. Are you suggesting there is a better way by using an existing drop down control?

Yes. My recommendation would be to use something like the DropDown class from Eto to handle your collection of items. This way you don’t have to handle a lot of the stuff you’re trying to deal with regarding mouse over/down events and you can also let the system handle all the drawing code.

Thanks for bringing this to my attention. I took a look and it seems that with Eto you can create dialogs, but can you attach those controls onto components as the ones shown in my picture?