Tweak menubar export
This commit is contained in:
3 files changed
+62
-60
No files matched your search
@@ -15,6 +15,7 @@ mod events;
|
|||||||
mod file_upload;
|
mod file_upload;
|
||||||
mod hooks;
|
mod hooks;
|
||||||
mod ipc;
|
mod ipc;
|
||||||
|
mod menubar;
|
||||||
mod protocol;
|
mod protocol;
|
||||||
mod query;
|
mod query;
|
||||||
mod shortcut;
|
mod shortcut;
|
||||||
@@ -28,10 +29,6 @@ mod collect_assets;
|
|||||||
#[cfg(any(target_os = "ios", target_os = "android"))]
|
#[cfg(any(target_os = "ios", target_os = "android"))]
|
||||||
mod mobile_shortcut;
|
mod mobile_shortcut;
|
||||||
|
|
||||||
// menu bar is only supported on desktop platforms
|
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
|
||||||
mod menubar;
|
|
||||||
|
|
||||||
// The main entrypoint for this crate
|
// The main entrypoint for this crate
|
||||||
pub use launch::*;
|
pub use launch::*;
|
||||||
mod launch;
|
mod launch;
|
||||||
@@ -50,6 +47,5 @@ pub use desktop_context::{
|
|||||||
window, DesktopContext, DesktopService, WryEventHandler, WryEventHandlerId,
|
window, DesktopContext, DesktopService, WryEventHandler, WryEventHandlerId,
|
||||||
};
|
};
|
||||||
pub use hooks::{use_asset_handler, use_global_shortcut, use_window, use_wry_event_handler};
|
pub use hooks::{use_asset_handler, use_global_shortcut, use_window, use_wry_event_handler};
|
||||||
pub use menubar::build_default_menu_bar;
|
|
||||||
pub use shortcut::{ShortcutHandle, ShortcutId, ShortcutRegistryError};
|
pub use shortcut::{ShortcutHandle, ShortcutId, ShortcutRegistryError};
|
||||||
pub use wry::RequestAsyncResponder;
|
pub use wry::RequestAsyncResponder;
|
||||||
@@ -1,69 +1,75 @@
|
|||||||
use muda::{Menu, PredefinedMenuItem, Submenu};
|
|
||||||
use tao::window::Window;
|
use tao::window::Window;
|
||||||
|
|
||||||
pub fn build_menu(window: &Window, default_menu_bar: bool) {
|
pub fn build_menu(window: &Window, default_menu_bar: bool) {
|
||||||
if default_menu_bar {
|
if default_menu_bar {
|
||||||
build_menu_bar(build_default_menu_bar(), window)
|
#[cfg(not(any(target_os = "ios", target_os = "android")))]
|
||||||
|
impl_::build_menu_bar(impl_::build_default_menu_bar(), window)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused)]
|
#[cfg(not(any(target_os = "ios", target_os = "android")))]
|
||||||
pub fn build_menu_bar(menu: Menu, window: &Window) {
|
mod impl_ {
|
||||||
#[cfg(target_os = "windows")]
|
use super::*;
|
||||||
menu.init_for_hwnd(window);
|
use muda::{Menu, PredefinedMenuItem, Submenu};
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[allow(unused)]
|
||||||
{
|
pub fn build_menu_bar(menu: Menu, window: &Window) {
|
||||||
use tao::platform::unix::WindowExtUnix;
|
#[cfg(target_os = "windows")]
|
||||||
menu.init_for_gtk_window(window, None);
|
menu.init_for_hwnd(window);
|
||||||
// menu.init_for_gtk_window(window, Some(&ertical_gtk_box));
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
{
|
||||||
|
use tao::platform::unix::WindowExtUnix;
|
||||||
|
menu.init_for_gtk_window(window, None);
|
||||||
|
// menu.init_for_gtk_window(window, Some(&ertical_gtk_box));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
menu.init_for_nsapp();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
/// Builds a standard menu bar depending on the users platform. It may be used as a starting point
|
||||||
menu.init_for_nsapp();
|
/// to further customize the menu bar and pass it to a [`WindowBuilder`](tao::window::WindowBuilder).
|
||||||
}
|
/// > Note: The default menu bar enables macOS shortcuts like cut/copy/paste.
|
||||||
|
/// > The menu bar differs per platform because of constraints introduced
|
||||||
|
/// > by [`MenuItem`](tao::menu::MenuItem).
|
||||||
|
pub fn build_default_menu_bar() -> Menu {
|
||||||
|
let menu = Menu::new();
|
||||||
|
|
||||||
/// Builds a standard menu bar depending on the users platform. It may be used as a starting point
|
// since it is uncommon on windows to have an "application menu"
|
||||||
/// to further customize the menu bar and pass it to a [`WindowBuilder`](tao::window::WindowBuilder).
|
// we add a "window" menu to be more consistent across platforms with the standard menu
|
||||||
/// > Note: The default menu bar enables macOS shortcuts like cut/copy/paste.
|
let window_menu = Submenu::new("Window", true);
|
||||||
/// > The menu bar differs per platform because of constraints introduced
|
window_menu
|
||||||
/// > by [`MenuItem`](tao::menu::MenuItem).
|
.append_items(&[
|
||||||
pub fn build_default_menu_bar() -> Menu {
|
&PredefinedMenuItem::fullscreen(None),
|
||||||
let menu = Menu::new();
|
&PredefinedMenuItem::separator(),
|
||||||
|
&PredefinedMenuItem::hide(None),
|
||||||
|
&PredefinedMenuItem::hide_others(None),
|
||||||
|
&PredefinedMenuItem::show_all(None),
|
||||||
|
&PredefinedMenuItem::maximize(None),
|
||||||
|
&PredefinedMenuItem::minimize(None),
|
||||||
|
&PredefinedMenuItem::close_window(None),
|
||||||
|
&PredefinedMenuItem::separator(),
|
||||||
|
&PredefinedMenuItem::quit(None),
|
||||||
|
])
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// since it is uncommon on windows to have an "application menu"
|
let edit_menu = Submenu::new("Window", true);
|
||||||
// we add a "window" menu to be more consistent across platforms with the standard menu
|
edit_menu
|
||||||
let window_menu = Submenu::new("Window", true);
|
.append_items(&[
|
||||||
window_menu
|
&PredefinedMenuItem::undo(None),
|
||||||
.append_items(&[
|
&PredefinedMenuItem::redo(None),
|
||||||
&PredefinedMenuItem::fullscreen(None),
|
&PredefinedMenuItem::separator(),
|
||||||
&PredefinedMenuItem::separator(),
|
&PredefinedMenuItem::cut(None),
|
||||||
&PredefinedMenuItem::hide(None),
|
&PredefinedMenuItem::copy(None),
|
||||||
&PredefinedMenuItem::hide_others(None),
|
&PredefinedMenuItem::paste(None),
|
||||||
&PredefinedMenuItem::show_all(None),
|
&PredefinedMenuItem::separator(),
|
||||||
&PredefinedMenuItem::maximize(None),
|
&PredefinedMenuItem::select_all(None),
|
||||||
&PredefinedMenuItem::minimize(None),
|
])
|
||||||
&PredefinedMenuItem::close_window(None),
|
.unwrap();
|
||||||
&PredefinedMenuItem::separator(),
|
|
||||||
&PredefinedMenuItem::quit(None),
|
|
||||||
])
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let edit_menu = Submenu::new("Window", true);
|
menu.append_items(&[&window_menu, &edit_menu]).unwrap();
|
||||||
edit_menu
|
|
||||||
.append_items(&[
|
|
||||||
&PredefinedMenuItem::undo(None),
|
|
||||||
&PredefinedMenuItem::redo(None),
|
|
||||||
&PredefinedMenuItem::separator(),
|
|
||||||
&PredefinedMenuItem::cut(None),
|
|
||||||
&PredefinedMenuItem::copy(None),
|
|
||||||
&PredefinedMenuItem::paste(None),
|
|
||||||
&PredefinedMenuItem::separator(),
|
|
||||||
&PredefinedMenuItem::select_all(None),
|
|
||||||
])
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
menu.append_items(&[&window_menu, &edit_menu]).unwrap();
|
menu
|
||||||
|
}
|
||||||
menu
|
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use wry::application::event_loop::EventLoopWindowTarget;
|
use tao::event_loop::EventLoopWindowTarget;
|
||||||
|
|
||||||
use dioxus_html::input_data::keyboard_types::Modifiers;
|
use dioxus_html::input_data::keyboard_types::Modifiers;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user