Skip to main content

TrayMenuBuilder

Struct TrayMenuBuilder 

Source
pub struct TrayMenuBuilder {
    pub options: Options,
    pub menu: Option<Menu>,
    pub tooltip: Option<String>,
    pub callback: Option<Callback<CallbackClosure<MouseEvent>>>,
}
Expand description

Provides a builder pattern for constructing a system tray menu for the application.

For usage example please refer to Examples

Fields§

§options: Options

Accumulated NW.js tray options being configured.

§menu: Option<Menu>

Optional menu shown when the tray icon is clicked.

§tooltip: Option<String>

Optional tooltip shown when hovering the tray icon.

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

Optional callback invoked when the tray icon is clicked.

Implementations§

Source§

impl TrayMenuBuilder

Source

pub fn new() -> Self

Creates a new, empty tray menu builder.

Source

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

Sets a raw option key to value on the underlying tray options object.

Source

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

Set the title of the tray.

NWJS Documentation

Source

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

Set the tooltip of the tray. tooltip shows when you hover the Tray with mouse.

Note: tooltip is showed on all three platforms. Should be set as Tray property rather from option object constructor.

NWJS Documentation

Source

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

Set the icon of the tray, icon must receive a path to your icon file. It can be a relative path which points to an icon in your app, or an absolute path pointing to a file in user’s system.

Mac OS X caveat: when used in notification context, png icon is not sized down like in windows notification area, it is rather displayed in 1:1 ratio.

NWJS Documentation

Source

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

(Mac) Set the alternate (active) tray icon.

NWJS Documentation

Source

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

(Mac) Set whether icon and alticon images are treated as “templates” (true by default). When the property is set to true the images are treated as “templates” and the system automatically ensures proper styling according to the various states of the status item (e.g. dark menu, light menu, etc.). Template images should consist only of black and clear colours and can use the alpha channel in the image to adjust the opacity of black content.

NWJS Documentation

Source

pub fn menu(self, menu: Menu) -> Self

Set the menu of the tray, menu will be showed when you click on the tray icon.

On Mac OS X the menu will be showed when you click on the tray (which is the only action available for tray icons on Mac OS X). On Windows and Linux, the menu will be showed when you single click on the tray with right mouse button, clicking with left mouse button sends the click event and does not show a menu.

In order to reduce differences from different platforms, setting menu property is the only way to bind a menu to tray, there’s no way to popup a menu with left mouse button click on Linux and Windows.

NWJS Documentation

Source

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

The callback function when tray icon is clicked.

NWJS Documentation

Source

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

A submenu

NWJS Documentation

Source

pub fn build_impl( self, ) -> Result<(Tray, Option<Callback<CallbackClosure<MouseEvent>>>)>

Constructs the Tray from the accumulated options, attaching the menu, tooltip and click handler, and returns it with its callback (if any).

Source

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

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

Source

pub fn finalize( self, ) -> Result<(Tray, Option<Callback<CallbackClosure<MouseEvent>>>)>

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

Trait Implementations§

Source§

impl Default for TrayMenuBuilder

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