Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add icon to submenu #277

Open
wants to merge 14 commits into
base: dev
Choose a base branch
from
Open

feat: add icon to submenu #277

wants to merge 14 commits into from

Conversation

s00d
Copy link

@s00d s00d commented Feb 26, 2025

This PR introduces the ability to add icons to submenu items on macOS by providing a new set_icon and set_native_icon method in the Submenu API.

What’s Changed

  • macOS: Implemented icon support for submenus, enabling developers to display an icon next to their submenu entries.
  • Windows: Implemented icon support for submenus by allowing a submenu’s icon to be set just like regular menu items.
  • Linux: Implemented icon support for submenus by allowing a submenu’s icon to be set just like regular menu items.
  • Submenu: Added a new set_icon and set_native_icon method to change the icon after the submenu has been created.
image

Thank you for reviewing this pull request!

s00d added 14 commits February 27, 2025 01:31
Implement functionality to set icons for menu items in the macOS
platform. This enhancement allows for improved visual representation
of menu items by utilizing the `menuitem_set_icon` function.
Added a `set_icon` method to the `Submenu` struct, allowing for
changing or removing the icon of a menu item. This enhances the
flexibility of menu customization in the user interface.
Introduce a new submenu within the "Window" menu, allowing for
additional icon items. This enhances the user interface by providing
more options directly accessible from the menu. The default menu
option for macOS is commented out to allow for customization.
Icons are now properly set for the new submenu and its items.
Enhances the menu item functionality by integrating native icons. The
`menuitem_set_native_icon` function is now called to set the native
icon for the menu item, improving the visual consistency with
platform standards. This change enables better user experience on
macOS applications.
Consolidate import statements for better readability and maintainability.
Update submenu icon setting to use `NativeIcon::Add` for improved
consistency across platforms. This change enhances the user interface
by ensuring the correct icon is displayed for the submenu.
Introduce a new method `set_native_icon` to allow changing the menu
item icon to a native image. This method currently supports macOS,
while remaining unsupported on Windows and Linux platforms.
The addition enhances the customization options for submenu items.
Reorganized the import statements in `src/items/submenu.rs` to
enhance code readability. Each import is now on a separate line,
following Rust's style guidelines for clarity and maintainability.
Enhances the menu system by allowing submenu items to display icons.
This change introduces checks for `MenuItemType::Submenu`, and if an
icon is present, it retrieves the bitmap and updates the menu item
info accordingly. This provides a more visually consistent and
informative user interface.
Refactor icon setting logic to ensure that native icons are set
properly only if they are provided. This change improves the
handling of menu item icons, preventing potential null references
and ensuring that both native and regular icons are assigned
correctly.
Reorganize `use` statements for better clarity and remove unnecessary
whitespace. Adjust comments for consistency and clarity. This enhances
the overall readability of the code without changing its functionality.
This commit introduces the `gtk` dependency for Linux targets in the
`examples/windows-common-controls-v6/Cargo.toml` file, enabling
cross-platform compatibility with GTK-based UI elements.
This commit introduces the `gtk` dependency for Linux targets in the
`examples/windows-common-controls-v6/Cargo.toml` file, enabling
cross-platform compatibility with GTK-based UI elements.
Included the `gtk::prelude::*` import conditionally for Linux
platforms to ensure compatibility with GTK-based UI components.
This change enhances the cross-platform functionality of the
application by properly handling Linux-specific dependencies.
Add support for custom layout in menu items by introducing a new
parameter `for_menu_bar`. This allows for specific styling when
creating menu items for the menu bar. The layout now includes an
image and label in a horizontal box, improving the visual
appearance and usability of menu items. Adjustments to CSS styling
are also included to better align items when not used in the menu
bar.
@s00d
Copy link
Author

s00d commented Feb 27, 2025

Fully completed the implementation and tested it on macOS, Windows, and Linux. It seems there are no issues with how it runs. As an example, I added the ability to launch on Linux (there’s a warning that there’s no parent, but it doesn’t interfere with testing—this warning only appears in the example).

The task is related to:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant