cnjinhao / nana

a modern C++ GUI library
https://nana.acemind.cn
Boost Software License 1.0
2.3k stars 331 forks source link

Introduce command to share with menu and toolbar #609

Open qPCR4vir opened 3 years ago

qPCR4vir commented 3 years ago

Hi, The goal of this PR is to:

Introduce command to share with menu, toolbar, button and checkbox

please, compare: widget_show2 manual item creation with: widget_show2 created with command

This is my first version, and you will need to review and redesign a few thing in it, but I hope this is the first draft of what we wanted. Maybe the correct way is to create a command "interface" to add to any of the supported classes?

First just I will try to compare/document the possible affected parts:

cnjinhao commented 3 years ago

First of all, thanks for your efforet, very good idea!

no struct arg_menu ?

Because menu::item_proxy is like a handle/proxy of a menu item, not an event_arg.

really need 'linked'?

What does linked mean? Does it mean that dropdown_item directly refers to the shared command? I think it would be better to make dropdown_item directly refers to the shared command, in default, and make it Copy-on-Write. Then the redundant data members can be eliminated.

reuse renderer_interface?

Yes, the renderer is cloneable. We can make tiny changes based on the current renderer just with a small piece of code.

dropdown_item construct take a menu and vice ferse?

Sorry, I don't understand, would you please explain it.

qPCR4vir commented 3 years ago

really need 'linked'?

What does linked mean?

oh, sorry, I just wanted to know how menu_item_type::linked member works.

Does it mean that dropdown_item directly refers to the shared command? I think it would be better to make dropdown_item directly refers to the shared command, in default, and make it Copy-on-Write. Then the redundant data members can be eliminated.

yes, something like that is a good solution! It is not trivial to have a really good solution. I only implemented the simplest possibility, and then, maybe, you will have some day time to make it better! I will try to implement a few more details, but for a robust design one need more experience.

dropdown_item construct take a menu and vice verse?

Sorry, I don't understand, would you please explain it.

My bad. I mean that a sub-menu and a toolbar dropdown are both a kind of containers of "command-items" and it could be great if we could just pass a menu to toolbar::append or item_proxy::dropdown_append to add all the items in one instruction.