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
impl WidgetCollection
Sourcepub fn new() -> WidgetCollection
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}
Sourcepub fn push<W: Widget + 'static>(&mut self, widget: W) -> &mut Self
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}
Sourcepub fn update_loop<T: Write>(&mut self, proto_inst: I3Protocol<T>)
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§
impl Freeze for WidgetCollection
impl !RefUnwindSafe for WidgetCollection
impl !Send for WidgetCollection
impl !Sync for WidgetCollection
impl Unpin for WidgetCollection
impl !UnwindSafe for WidgetCollection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more