gabdube / native-windows-gui

A light windows GUI toolkit for rust
https://gabdube.github.io/native-windows-gui/
MIT License
1.96k stars 127 forks source link

Allow adding icon to Menu and MenuItem #291

Open eugenesvk opened 5 months ago

eugenesvk commented 5 months ago

So you could have menu items like this

men_icon

Also, is it possible to just add text to that empty area? As emoji icon could serve the purpose of a real image

nickbeth commented 5 months ago

Hey, I wrote some extension methods for native-windows-gui for my app, and that includes a function to set a bitmap to a menu item. Here you can find the implementation, you're free to use it in your project as long as you respect the MIT license ;)

You might need to modify it a little as I'm using the windows-sys crate for the Windows calls and you might want to use winapi instead, but it should take very little effort to adjust it.

eugenesvk commented 5 months ago

Thanks! Will take a look (and MIT is one of the most respected licenses ;))

eugenesvk commented 5 months ago

Do you know how to add an icon to the whole menu group, not just its items (for which your extension works fine, thanks!). I've tried a similar thing for the Menu, but there are no bitmap fields/arguments for the MenuInfo equivalent to menuitems?

nickbeth commented 5 months ago

I have no idea myself, you'll have to dive deep into the Win32 API and see if what you want can be done. If there is a way, it can be done as an extension to native-windows-gui objects.

eugenesvk commented 5 months ago

Another look revealed that Menu is constructed the same way as MenuItem, so I can tweak you impl to apply an icon to it as well