Skip to main content

Widget

Trait Widget 

Source
pub trait Widget: Sized + 'static {
    type Config: DeserializeOwned;
    type Message: Clone + Debug + Send + Sync + 'static;

    // Required methods
    fn new(config: Self::Config) -> (Self, Task<Self::Message>);
    fn update(&mut self, message: Self::Message) -> Effect<Self::Message>;
    fn item(&self) -> Item<Self::Message>;

    // Provided methods
    fn subscription(&self) -> Subscription<Self::Message> { ... }
    fn popover(&self) -> Option<Panel<Self::Message>> { ... }
    fn notices(&self) -> Vec<Notice<Self::Message>> { ... }
}
Expand description

Something that sits in the bar, with an optional popover.

It follows the same Elm shape as the host: state lives in Self, changes arrive as messages in update, and the views are pure functions of state. update must not block: do I/O in a Task or a Subscription.

Required Associated Types§

Source

type Config: DeserializeOwned

Options from this widget’s entry in config.toml, minus the widget key.

The entry may be empty, so use #[serde(default)] for options that have one.

Source

type Message: Clone + Debug + Send + Sync + 'static

Required Methods§

Source

fn new(config: Self::Config) -> (Self, Task<Self::Message>)

Source

fn update(&mut self, message: Self::Message) -> Effect<Self::Message>

Source

fn item(&self) -> Item<Self::Message>

What the widget shows in the bar.

Provided Methods§

Source

fn subscription(&self) -> Subscription<Self::Message>

Source

fn popover(&self) -> Option<Panel<Self::Message>>

The popover contents, if this widget has one.

When it returns Some and the item has no on_press, a click on the item opens and closes the popover. Returning None while the popover is open closes it.

Source

fn notices(&self) -> Vec<Notice<Self::Message>>

Notifications to show on screen now, newest first. Only for a notification engine: the widget that serves org.freedesktop.Notifications lists here what it received. Any other widget sends its notifications with Notify on the session bus, like any app.

While there are any, the bar’s right island turns into a panel of them, like a popover. The host takes each one away once its key is no longer in the list. Keep the notices you mean to show in your state, and drop one when it’s dismissed or expires.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§