fixup: improved documentation and refactored naming to be more self-explanatory
Note: This is the actual correct commit. The previous one contained files touched by cargo fmt which are unrelated. Sorry for that.
This commit is contained in:
1 parent
906c466e78
commit
cbfb80d5c6
2 files changed
+15
-9
No files matched your search
@@ -36,7 +36,7 @@ pub struct Config {
|
|||||||
pub(crate) root_name: String,
|
pub(crate) root_name: String,
|
||||||
pub(crate) background_color: Option<(u8, u8, u8, u8)>,
|
pub(crate) background_color: Option<(u8, u8, u8, u8)>,
|
||||||
pub(crate) last_window_close_behaviour: WindowCloseBehaviour,
|
pub(crate) last_window_close_behaviour: WindowCloseBehaviour,
|
||||||
pub(crate) disable_default_menu_bar: bool,
|
pub(crate) enable_default_menu_bar: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
type DropHandler = Box<dyn Fn(&Window, FileDropEvent) -> bool>;
|
type DropHandler = Box<dyn Fn(&Window, FileDropEvent) -> bool>;
|
||||||
@@ -66,13 +66,15 @@ impl Config {
|
|||||||
root_name: "main".to_string(),
|
root_name: "main".to_string(),
|
||||||
background_color: None,
|
background_color: None,
|
||||||
last_window_close_behaviour: WindowCloseBehaviour::LastWindowExitsApp,
|
last_window_close_behaviour: WindowCloseBehaviour::LastWindowExitsApp,
|
||||||
disable_default_menu_bar: false,
|
enable_default_menu_bar: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set whether the default menu bar should be disabled.
|
/// Set whether the default menu bar should be enabled.
|
||||||
pub fn with_disable_default_menu_bar(mut self, disable: bool) -> Self {
|
///
|
||||||
self.disable_default_menu_bar = disable;
|
/// > Note: `enable` is `true` by default. To disable the default menu bar pass `false`.
|
||||||
|
pub fn with_default_menu_bar(mut self, enable: bool) -> Self {
|
||||||
|
self.enable_default_menu_bar = enable;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ pub fn build(
|
|||||||
let index_file = cfg.custom_index.clone();
|
let index_file = cfg.custom_index.clone();
|
||||||
let root_name = cfg.root_name.clone();
|
let root_name = cfg.root_name.clone();
|
||||||
|
|
||||||
if !cfg.disable_default_menu_bar {
|
if cfg.enable_default_menu_bar {
|
||||||
builder = builder.with_menu(create_default_menu_bar());
|
builder = builder.with_menu(build_default_menu_bar());
|
||||||
}
|
}
|
||||||
|
|
||||||
let window = builder.with_visible(false).build(event_loop).unwrap();
|
let window = builder.with_visible(false).build(event_loop).unwrap();
|
||||||
@@ -103,8 +103,12 @@ pub fn build(
|
|||||||
(webview.build().unwrap(), web_context)
|
(webview.build().unwrap(), web_context)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a standard menu bar depending on the platform
|
/// Builds a standard menu bar depending on the users platform. It may be used as a starting point
|
||||||
fn create_default_menu_bar() -> MenuBar {
|
/// 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() -> MenuBar {
|
||||||
let mut menu_bar = MenuBar::new();
|
let mut menu_bar = MenuBar::new();
|
||||||
|
|
||||||
// since it is uncommon on windows to have an "application menu"
|
// since it is uncommon on windows to have an "application menu"
|
||||||
|
|||||||
Reference in new issue
Block a user