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 dialog(&self) -> Option<Panel<Self::Message>> { ... }
    fn notices(&self) -> Vec<Notice<Self::Message>> { ... }
    fn actions(&self) -> Vec<Action<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 dialog(&self) -> Option<Panel<Self::Message>>

The dialog contents, if this widget has one: a panel in the middle of the screen, wider than a popover, for what needs room, like a conversation. It opens only when asked (Effect::open_dialog), never on a click. Returning None while it’s 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.

Source

fn actions(&self) -> Vec<Action<Self::Message>>

What the widget can do, for the dormer: the host’s search dialog, which a keybind opens. Typing finds an action by its title, subtitle and keywords, and picking it sends its message to this widget, like a click would.

The host reads them only while the dormer is open, after each of your messages, so they can follow your state: “Mute” while sound plays, “Unmute” while muted. Leave out what can’t be done right now. Keep it pure and cheap, like the views.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§