mono / xwt

A cross-platform UI toolkit for creating desktop applications with .NET and Mono
MIT License
1.37k stars 240 forks source link

Assign widgets a Menu as a ContextMenu #27

Open ermau opened 12 years ago

ermau commented 12 years ago

Instead of making the user manually add a click event and invoke Menu.Popup, let's remove Popup and add

Menu IWidget.ContextMenu { get; set; }

In this way, the platform is responsible for when the right time to open a context menu.

slluis commented 12 years ago

I'm ok about adding the ContextMenu property, but we need a way to have a more control on the position where the menu will be shown. For example, if you are implementing a widget in a Canvas and you want to show a context menu when clicking on specific regions of the canvas.

luiscubal commented 12 years ago

BTW, click events are not a good way to trigger popup menus.

For instance, my keyboard has a "context menu key"(left of right ctrl, right of right windows key), so it definitively should be possible to trigger popup menus without mouse events.

As for the specific position for the menu to show up, wouldn't this sort of thing be automatic behavior? Wouldn't the popup menu just automatically appear on the mouse location? Why would we even need to worry about this on XWT?

It also has a "declarative feel" that click+popup() lacks, which means a HTML/XUL/XAML-like language for XWT would also benefit from this.

In other words, I like this proposal.

That said, I still think there should be some way to programatically trigger the popup menu.

ermau commented 12 years ago

I'm ok about adding the ContextMenu property, but we need a way to have a more control on the position where the menu will be shown. For example, if you are implementing a widget in a Canvas and you want to show a context menu when clicking on specific regions of the canvas.

When or where? It sounds like you're asking for two different things.

slluis commented 12 years ago

For instance, my keyboard has a "context menu key"(left of right ctrl, right of right windows key), so it definitively should be possible to trigger popup menus without mouse events.

Yes, we need an event specifically for showing the context menu, since it may not be triggered using the keyboard.

As for the specific position for the menu to show up, wouldn't this sort of thing be automatic behavior? Wouldn't the popup menu just automatically appear on the mouse location? Why would we even need to worry about this on XWT?

Actually, you're right. That should work in most cases (although it doesn't cover all cases, so the Popup method is still useful).

mhutch commented 12 years ago

When the event is activated from the keyboard, it doesn't make sense to position it at the mouse cursor. It should be beside the selected item or at the widget's origin.

Wouldn't it be better to have a Func<some,args,Menu> to create the menu, so it can be created/populated when it's needed?

ermau commented 12 years ago

When the event is activated from the keyboard, it doesn't make sense to position it at the mouse cursor. It should be beside the selected item or at the widget's origin.

Hmm, true. For most things this is a non-issue, but for the aforementioned issue this is still a problem.

Frankly I'd just say whatever is being custom needs to be done in such a way that there's a layer of widgets so the platforms can all handle this naturally. Not sure if it's feasible, but at least worth considering.