-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
810 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-License-Identifier: MIT | ||
|
||
use crate::{menu::CheckMenuItem, Manager, Runtime}; | ||
|
||
/// A builder type for [`CheckMenuItem`] | ||
pub struct CheckMenuItemBuilder { | ||
text: String, | ||
enabled: bool, | ||
checked: bool, | ||
accelerator: Option<String>, | ||
} | ||
|
||
impl Default for CheckMenuItemBuilder { | ||
fn default() -> Self { | ||
Self::new("") | ||
} | ||
} | ||
|
||
impl CheckMenuItemBuilder { | ||
/// Create a new menu item builder. | ||
pub fn new<S: AsRef<str>>(text: S) -> Self { | ||
Self { | ||
text: text.as_ref().to_string(), | ||
enabled: true, | ||
checked: true, | ||
accelerator: None, | ||
} | ||
} | ||
|
||
/// Set the text for this menu item. | ||
pub fn text<S: AsRef<str>>(mut self, text: S) -> Self { | ||
self.text = text.as_ref().to_string(); | ||
self | ||
} | ||
|
||
/// Set the enabled state for this menu item. | ||
pub fn enabled(mut self, enabled: bool) -> Self { | ||
self.enabled = enabled; | ||
self | ||
} | ||
|
||
/// Set the checked state for this menu item. | ||
pub fn checked(mut self, checked: bool) -> Self { | ||
self.checked = checked; | ||
self | ||
} | ||
|
||
/// Set the accelerator for this menu item. | ||
pub fn accelerator<S: AsRef<str>>(mut self, accelerator: S) -> Self { | ||
self.accelerator.replace(accelerator.as_ref().to_string()); | ||
self | ||
} | ||
|
||
/// Build the menu item | ||
pub fn build<R: Runtime, M: Manager<R>>(self, manager: &M) -> CheckMenuItem<R> { | ||
CheckMenuItem::new( | ||
manager, | ||
self.text, | ||
self.enabled, | ||
self.checked, | ||
self.accelerator, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-License-Identifier: MIT | ||
|
||
use tauri_runtime::menu::icon::NativeIcon; | ||
|
||
use crate::{menu::IconMenuItem, Icon, Manager, Runtime}; | ||
|
||
/// A builder type for [`IconMenuItem`] | ||
pub struct IconMenuItemBuilder { | ||
text: String, | ||
enabled: bool, | ||
icon: Option<Icon>, | ||
native_icon: Option<NativeIcon>, | ||
accelerator: Option<String>, | ||
} | ||
|
||
impl Default for IconMenuItemBuilder { | ||
fn default() -> Self { | ||
Self::new("") | ||
} | ||
} | ||
|
||
impl IconMenuItemBuilder { | ||
/// Create a new menu item builder. | ||
pub fn new<S: AsRef<str>>(text: S) -> Self { | ||
Self { | ||
text: text.as_ref().to_string(), | ||
enabled: true, | ||
icon: None, | ||
native_icon: None, | ||
accelerator: None, | ||
} | ||
} | ||
|
||
/// Set the text for this menu item. | ||
pub fn text<S: AsRef<str>>(mut self, text: S) -> Self { | ||
self.text = text.as_ref().to_string(); | ||
self | ||
} | ||
|
||
/// Set the enabled state for this menu item. | ||
pub fn enabled(mut self, enabled: bool) -> Self { | ||
self.enabled = enabled; | ||
self | ||
} | ||
|
||
/// Set the accelerator for this menu item. | ||
pub fn accelerator<S: AsRef<str>>(mut self, accelerator: S) -> Self { | ||
self.accelerator.replace(accelerator.as_ref().to_string()); | ||
self | ||
} | ||
|
||
/// Set the icon for this menu item. | ||
/// | ||
/// **Note:** This method conflicts with [`Self::native_icon`] | ||
/// so calling one of them, will reset the other. | ||
pub fn icon(mut self, icon: Icon) -> Self { | ||
self.icon.replace(icon); | ||
self.native_icon = None; | ||
self | ||
} | ||
|
||
/// Set the icon for this menu item. | ||
/// | ||
/// **Note:** This method conflicts with [`Self::icon`] | ||
/// so calling one of them, will reset the other. | ||
pub fn native_icon(mut self, icon: NativeIcon) -> Self { | ||
self.native_icon.replace(icon); | ||
self.icon = None; | ||
self | ||
} | ||
|
||
/// Build the menu item | ||
pub fn build<R: Runtime, M: Manager<R>>(self, manager: &M) -> IconMenuItem<R> { | ||
if self.icon.is_some() { | ||
IconMenuItem::new( | ||
manager, | ||
self.text, | ||
self.enabled, | ||
self.icon, | ||
self.accelerator, | ||
) | ||
} else { | ||
IconMenuItem::with_native_icon( | ||
manager, | ||
self.text, | ||
self.enabled, | ||
self.native_icon, | ||
self.accelerator, | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.