Struct WidgetCollection

Source
pub struct WidgetCollection { /* private fields */ }
Expand description

The collection of widgets

in i3monkit a status bar is abstracted as an widget collection.

To create a i3 bar application with i3monkit, what needs to be done is:

    let bar = WidgetUpdate::new();

    // Add whatever widget to the bar
    bar.push(...);
    ....

    bar.update_loop();

Implementations§

Source§

impl WidgetCollection

Source

pub fn new() -> WidgetCollection

Creates a new widget collection

Examples found in repository?
examples/sample-i3-bar/main.rs (line 5)
4fn main() {
5    let mut bar = WidgetCollection::new();
6
7    //Add realtime stock prices, for example: Microsoft, AMD and Facebook
8    let stock_client = StockClient::new("your-alphavantage-API-key");
9    bar.push(StockClient::create_widget(&stock_client, "MSFT"));
10    bar.push(StockClient::create_widget(&stock_client, "AMD"));
11    bar.push(StockClient::create_widget(&stock_client, "FB"));
12
13    //Realtime upload/download rate for a interface
14    bar.push(NetworkSpeedWidget::new("wlp58s0"));
15
16    //Display all the cpu usage for each core
17    for i in 0..4 {
18        bar.push(CpuWidget::new(i));
19    }
20
21    //Volume widget
22    bar.push(VolumeWidget::new("default", "Master", 0));
23
24    //Battery status
25    bar.push(BatteryWidget::new(0));
26
27    //Time
28    bar.push(DateTimeWidget::new());
29
30    // Then start updating the satus bar
31    bar.update_loop(I3Protocol::new(Header::new(1), std::io::stdout()));
32}
Source

pub fn push<W: Widget + 'static>(&mut self, widget: W) -> &mut Self

Push a new widget to the collection

Examples found in repository?
examples/sample-i3-bar/main.rs (line 9)
4fn main() {
5    let mut bar = WidgetCollection::new();
6
7    //Add realtime stock prices, for example: Microsoft, AMD and Facebook
8    let stock_client = StockClient::new("your-alphavantage-API-key");
9    bar.push(StockClient::create_widget(&stock_client, "MSFT"));
10    bar.push(StockClient::create_widget(&stock_client, "AMD"));
11    bar.push(StockClient::create_widget(&stock_client, "FB"));
12
13    //Realtime upload/download rate for a interface
14    bar.push(NetworkSpeedWidget::new("wlp58s0"));
15
16    //Display all the cpu usage for each core
17    for i in 0..4 {
18        bar.push(CpuWidget::new(i));
19    }
20
21    //Volume widget
22    bar.push(VolumeWidget::new("default", "Master", 0));
23
24    //Battery status
25    bar.push(BatteryWidget::new(0));
26
27    //Time
28    bar.push(DateTimeWidget::new());
29
30    // Then start updating the satus bar
31    bar.update_loop(I3Protocol::new(Header::new(1), std::io::stdout()));
32}
Source

pub fn update_loop<T: Write>(&mut self, proto_inst: I3Protocol<T>)

Start the main update loop and drawing the wigets on the i3bar

Examples found in repository?
examples/sample-i3-bar/main.rs (line 31)
4fn main() {
5    let mut bar = WidgetCollection::new();
6
7    //Add realtime stock prices, for example: Microsoft, AMD and Facebook
8    let stock_client = StockClient::new("your-alphavantage-API-key");
9    bar.push(StockClient::create_widget(&stock_client, "MSFT"));
10    bar.push(StockClient::create_widget(&stock_client, "AMD"));
11    bar.push(StockClient::create_widget(&stock_client, "FB"));
12
13    //Realtime upload/download rate for a interface
14    bar.push(NetworkSpeedWidget::new("wlp58s0"));
15
16    //Display all the cpu usage for each core
17    for i in 0..4 {
18        bar.push(CpuWidget::new(i));
19    }
20
21    //Volume widget
22    bar.push(VolumeWidget::new("default", "Master", 0));
23
24    //Battery status
25    bar.push(BatteryWidget::new(0));
26
27    //Time
28    bar.push(DateTimeWidget::new());
29
30    // Then start updating the satus bar
31    bar.update_loop(I3Protocol::new(Header::new(1), std::io::stdout()));
32}

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> 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<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, 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.