How can I create a popup menu? #3640
-
Using: Win11、Rust、Slint I want to create a popup menu, and I've noticed the #38. Below code shows where I neet the window handle: #[cfg(target_os = "windows")]
menu.show_context_menu_for_hwnd(window.hwnd() as isize, Some(position.into())); I can get the window handle use below code before: pin_window.window().with_winit_window(|winit_win: &winit::window::Window| {
let raw_window_handle = winit_win.raw_window_handle();
if let raw_window_handle::RawWindowHandle::Win32(win32_window_handle) = raw_window_handle {
let hwnd = win32_window_handle.hwnd as isize;
let position = muda::PhysicalPosition { x: 100., y: 120. };
menu.show_context_menu_for_hwnd(hwnd as isize, Some(position.into()));
}
}); But now, |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 12 replies
-
It shouldn't be, as it comes from the raw window handle trait that winit implements. Could you post the error message you're seeing? |
Beta Was this translation helpful? Give feedback.
-
While we still need to implement a PopupMenu builtin in Slint, you should be able to do it with the help of PopupWindow. |
Beta Was this translation helpful? Give feedback.
-
A new problem arose :( pin_window.on_show_menu(move |mouse_x, mouse_y| {
let pin_window = pin_window_clone.unwrap();
pin_window.window().with_winit_window(|winit_win: &winit::window::Window| {
let raw_window_handle = winit_win.raw_window_handle();
if let raw_window_handle::RawWindowHandle::Win32(win32_window_handle) = raw_window_handle {
let hwnd = win32_window_handle.hwnd as isize;
let position = muda::LogicalPosition { x: mouse_x, y: mouse_y };
menu.show_context_menu_for_hwnd(hwnd as isize, Some(position.into()));
}
});
println!("show_menu begin");
// need to do something for menu event
if let Ok(event) = MenuEvent::receiver().try_recv() {
match event.id {
id if id == save_item.id() => {
println!("save_item");
},
id if id == minimize_item.id() => {
println!("minimize_item");
},
id if id == exit_item.id() => {
println!("exit_item");
},
id if id == finish_item.id() => {
println!("finish_item");
},
_ => {}
}
}
println!("show_menu end");
}); I think But when I click "save", "minimize" and "exit" menuitem, the output will be:
This means that I did not capture the menu event after the first click. This may have something to do with the way Slint handles events, but I don't know how to capture the menu event in time. Can you help me? @ogoffart @tronical |
Beta Was this translation helpful? Give feedback.
-
Is there any way can help me manually handle the eventloop? |
Beta Was this translation helpful? Give feedback.
Ooh, nevermind, I see that you're using
raw-window-handle
version0.6.0
butwinit
0.28.6
implements only the traits inraw-window-handle
version0.5.2
. Does it work if you change yourCargo.toml
to match theraw-window-handle
version to0.5.2
?