Skip to main content

MenuItemBuilder

Struct MenuItemBuilder 

Source
pub struct MenuItemBuilder {
    pub options: Options,
    pub callback: Option<Callback<CallbackClosure<JsValue>>>,
}
Expand description

MenuItem Builder

For usage example please refer to Examples

Fields§

§options: Options

Accumulated NW.js menu item options being configured.

§callback: Option<Callback<CallbackClosure<JsValue>>>

Optional callback invoked when the menu item is clicked.

Implementations§

Source§

impl MenuItemBuilder

Source

pub fn new() -> Self

Creates a new, empty menu item builder.

Source

pub fn set_type(self, t: MenuItemType) -> Self

Type of MenuItem

NWJS Documentation

Source

pub fn label(self, label: &str) -> Self

Label for normal item or checkbox

NWJS Documentation

Source

pub fn icon(self, icon: &str) -> Self

Icon for normal item or checkbox

NWJS Documentation

Source

pub fn tooltip(self, tooltip: &str) -> Self

Tooltip for normal item or checkbox

NWJS Documentation

Source

pub fn callback<F>(self, callback: F) -> Self
where F: FnMut(JsValue) -> Result<(), JsValue> + 'static,

The callback function when item is triggered by mouse click or keyboard shortcut

NWJS Documentation

Source

pub fn enabled(self, enabled: bool) -> Self

Whether the item is enabled or disabled. It’s set to true by default.

NWJS Documentation

Source

pub fn checked(self, checked: bool) -> Self

Whether the checkbox is checked or not. It’s set to false by default.

NWJS Documentation

Source

pub fn submenu(self, submenu: &Menu) -> Self

A submenu

NWJS Documentation

Source

pub fn submenus(self, items: Vec<MenuItem>) -> Self

Create submenu from menu items

NWJS Documentation

Source

pub fn key(self, key: &str) -> Self

The key of the shortcut

NWJS Documentation

Source

pub fn modifiers(self, modifiers: &str) -> Self

The modifiers of the shortcut

NWJS Documentation

Source

pub fn build(self) -> Result<MenuItem>

Builds the configured MenuItem, retaining any click callback in the application so it remains valid.

Source

pub fn finalize( self, ) -> Result<(MenuItem, Option<Callback<CallbackClosure<JsValue>>>)>

Builds the MenuItem and returns it together with its click callback (if any), leaving the caller responsible for retaining the callback.

Trait Implementations§

Source§

impl Default for MenuItemBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Any for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Source§

fn type_name(&self) -> &'static str

Source§

impl<T> AnySync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more