143 | 143 |
|
144 | 144 |
impl Widget for Battery {
|
145 | 145 |
fn draw(&self, d: &Drawing, loc: Located) -> i32 {
|
146 | |
let amt = self.read_status().unwrap();
|
| 146 |
let amt = self.read_status();
|
147 | 147 |
let sz = d.size.ht - 8;
|
148 | 148 |
let x = loc.target_x(d, sz);
|
149 | |
if amt < 0.1 {
|
150 | |
d.ctx.set_source_rgb(1.0, 0.0, 0.0);
|
151 | |
} else if amt < 0.5 {
|
152 | |
d.ctx.set_source_rgb(1.0, 1.0, 0.0);
|
153 | |
} else {
|
154 | |
d.ctx.set_source_rgb(0.0, 1.0, 0.5);
|
| 149 |
match amt {
|
| 150 |
Ok(x) if x < 0.1 =>
|
| 151 |
d.ctx.set_source_rgb(1.0, 0.0, 0.0),
|
| 152 |
Ok(x) if x < 0.5 =>
|
| 153 |
d.ctx.set_source_rgb(1.0, 1.0, 0.0),
|
| 154 |
Ok(_) =>
|
| 155 |
d.ctx.set_source_rgb(0.0, 1.0, 0.5),
|
| 156 |
Err(_) =>
|
| 157 |
d.ctx.set_source_rgb(0.0, 0.0, 0.0),
|
155 | 158 |
}
|
156 | |
d.ctx.rectangle(x, 8.0, sz as f64 * amt, sz as f64 - 8.0);
|
| 159 |
|
| 160 |
d.ctx.rectangle(
|
| 161 |
x,
|
| 162 |
8.0,
|
| 163 |
sz as f64 * amt.unwrap_or(1.0),
|
| 164 |
sz as f64 - 8.0,
|
| 165 |
);
|
157 | 166 |
d.ctx.fill();
|
158 | 167 |
|
159 | 168 |
d.ctx.set_source_rgb(1.0, 1.0, 1.0);
|