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

Add ability to assign a menu when creating a window on Windows #1842

Merged
merged 3 commits into from
Feb 4, 2021

Conversation

madsmtm
Copy link
Member

@madsmtm madsmtm commented Jan 26, 2021

  • Tested on all platforms changed
  • Compilation warnings were addressed
  • cargo fmt has been run on this branch
  • cargo doc builds successfully
  • Added an entry to CHANGELOG.md if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality
  • Updated feature matrix, if new features were added or implemented

Added WindowBuilderExtWindows::with_menu.

The primary reason for doing it here instead of just assigning a menu later on with winapi::um::winuser::SetMenu is to avoid that with_inner_size breaks, since the menu takes up some space that is not taken into account, which means the user would have to use set_inner_size again after adding the menu.
This, I'm guessing, could cause a jarring effect for the user (that the window resizes when starting).

Unresolved:

  • Child windows cannot have a menu, so perhaps this should be represented typewise?

The primary reason for doing this here instead of just assigning a menu later on with `SetMenu` is to avoid that `with_inner_size` breaks, since the menu takes up some space that is not taken into account, which means the user would have to use `set_inner_size` again after adding the menu.

Notes:
- Child windows cannot have a menu, so perhaps this should be represented typewise?
- Dark mode doesn't look good with win32 menus, unfortunately not fixable, see ysc3839/win32-darkmode#1
@msiglreith msiglreith self-requested a review February 1, 2021 22:34
@msiglreith msiglreith added DS - windows C - waiting on maintainer A maintainer must review this code S - api Design and usability labels Feb 1, 2021
Copy link
Member

@msiglreith msiglreith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LGTM

@@ -17,7 +17,9 @@ use crate::window::Theme;

#[derive(Clone)]
pub struct PlatformSpecificWindowBuilderAttributes {
// TODO: parent and menu are mutually exclusive; a child window cannot have a menu!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be added the with_menu documentationa and I would say a warn during the creation if that case is hit would be enough

@madsmtm
Copy link
Member Author

madsmtm commented Feb 4, 2021

Done. Should I do a rebase?

It also occurs to me, both with_parent_window and with_menu are probably unsafe, since you could safely pass just about any pointer to these, and bad things would probably happen then?

Also, with_win32_menu is maybe a better name? Though not so important.

@msiglreith
Copy link
Member

Done. Should I do a rebase?

Thanks - no, we squash-merge here :D

It also occurs to me, both with_parent_window and with_menu are probably unsafe, since you could safely pass just about any pointer to these, and bad things would probably happen then?

Agree, but I think that's a different issue right now, I would like to handle this separately. There is also an open issue regarding exposing typedefs like HWND or HMENU in public API without exporting.

Also, with_win32_menu is maybe a better name? Though not so important.

The current name looks totally fine to me!

@msiglreith msiglreith merged commit b1d3531 into rust-windowing:master Feb 4, 2021
@madsmtm madsmtm deleted the add-windows-ext-menu branch December 1, 2021 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C - waiting on maintainer A maintainer must review this code DS - windows S - api Design and usability
Development

Successfully merging this pull request may close these issues.

2 participants