gdritter repos knurling / 5a51fad
Get rid of last remaining uses of unwrap Getty Ritter 5 years ago
2 changed file(s) with 18 addition(s) and 9 deletion(s). Collapse all Expand all
150150 // set up our widgets
151151 let text = widgets::Text::new(left);
152152 let time = widgets::Time::new();
153 let bat = widgets::Battery::new().unwrap();
153 let bat = widgets::Battery::new()?;
154154
155155 // and create a 'config' which tells us which widgets to draw from
156156 // the left, and which from the right
143143
144144 impl Widget for Battery {
145145 fn draw(&self, d: &Drawing, loc: Located) -> i32 {
146 let amt = self.read_status().unwrap();
146 let amt = self.read_status();
147147 let sz = d.size.ht - 8;
148148 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),
155158 }
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 );
157166 d.ctx.fill();
158167
159168 d.ctx.set_source_rgb(1.0, 1.0, 1.0);