diff --git a/examples/canvas.rs b/examples/canvas.rs index e1bade61..0dce5dd8 100644 --- a/examples/canvas.rs +++ b/examples/canvas.rs @@ -175,31 +175,31 @@ fn draw(t: &mut Terminal, app: &App) { .block(Block::default().borders(border::ALL).title("List")) .paint(|ctx| { ctx.draw(&Line { - x1: app.ball.left() as f64, - y1: app.ball.top() as f64, - x2: app.ball.right() as f64, - y2: app.ball.top() as f64, + x1: f64::from(app.ball.left()), + y1: f64::from(app.ball.top()), + x2: f64::from(app.ball.right()), + y2: f64::from(app.ball.top()), color: Color::Yellow, }); ctx.draw(&Line { - x1: app.ball.right() as f64, - y1: app.ball.top() as f64, - x2: app.ball.right() as f64, - y2: app.ball.bottom() as f64, + x1: f64::from(app.ball.right()), + y1: f64::from(app.ball.top()), + x2: f64::from(app.ball.right()), + y2: f64::from(app.ball.bottom()), color: Color::Yellow, }); ctx.draw(&Line { - x1: app.ball.right() as f64, - y1: app.ball.bottom() as f64, - x2: app.ball.left() as f64, - y2: app.ball.bottom() as f64, + x1: f64::from(app.ball.right()), + y1: f64::from(app.ball.bottom()), + x2: f64::from(app.ball.left()), + y2: f64::from(app.ball.bottom()), color: Color::Yellow, }); ctx.draw(&Line { - x1: app.ball.left() as f64, - y1: app.ball.bottom() as f64, - x2: app.ball.left() as f64, - y2: app.ball.top() as f64, + x1: f64::from(app.ball.left()), + y1: f64::from(app.ball.bottom()), + x2: f64::from(app.ball.left()), + y2: f64::from(app.ball.top()), color: Color::Yellow, }); }) diff --git a/src/layout.rs b/src/layout.rs index 5ef8b11e..d9ddb730 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -153,21 +153,21 @@ pub fn split(area: &Rect, dir: &Direction, margin: u16, sizes: &[Size]) -> Vec = Vec::with_capacity(elements.len() * 4 + sizes.len() * 6); for elt in &elements { - constraints.push(elt.left() | GE(REQUIRED) | dest_area.left() as f64); - constraints.push(elt.top() | GE(REQUIRED) | dest_area.top() as f64); - constraints.push(elt.right() | LE(REQUIRED) | dest_area.right() as f64); - constraints.push(elt.bottom() | LE(REQUIRED) | dest_area.bottom() as f64); + constraints.push(elt.left() | GE(REQUIRED) | f64::from(dest_area.left())); + constraints.push(elt.top() | GE(REQUIRED) | f64::from(dest_area.top())); + constraints.push(elt.right() | LE(REQUIRED) | f64::from(dest_area.right())); + constraints.push(elt.bottom() | LE(REQUIRED) | f64::from(dest_area.bottom())); } if let Some(first) = elements.first() { constraints.push(match *dir { - Direction::Horizontal => first.left() | EQ(REQUIRED) | dest_area.left() as f64, - Direction::Vertical => first.top() | EQ(REQUIRED) | dest_area.top() as f64, + Direction::Horizontal => first.left() | EQ(REQUIRED) | f64::from(dest_area.left()), + Direction::Vertical => first.top() | EQ(REQUIRED) | f64::from(dest_area.top()), }); } if let Some(last) = elements.last() { constraints.push(match *dir { - Direction::Horizontal => last.right() | EQ(REQUIRED) | dest_area.right() as f64, - Direction::Vertical => last.bottom() | EQ(REQUIRED) | dest_area.bottom() as f64, + Direction::Horizontal => last.right() | EQ(REQUIRED) | f64::from(dest_area.right()), + Direction::Vertical => last.bottom() | EQ(REQUIRED) | f64::from(dest_area.bottom()), }); } match *dir { @@ -176,15 +176,15 @@ pub fn split(area: &Rect, dir: &Direction, margin: u16, sizes: &[Size]) -> Vec elements[i].width | EQ(WEAK) | v as f64, + Size::Fixed(v) => elements[i].width | EQ(WEAK) | f64::from(v), Size::Percent(v) => { - elements[i].width | EQ(WEAK) | ((v * dest_area.width) as f64 / 100.0) + elements[i].width | EQ(WEAK) | (f64::from(v * dest_area.width) / 100.0) } - Size::Min(v) => elements[i].width | GE(WEAK) | v as f64, - Size::Max(v) => elements[i].width | LE(WEAK) | v as f64, + Size::Min(v) => elements[i].width | GE(WEAK) | f64::from(v), + Size::Max(v) => elements[i].width | LE(WEAK) | f64::from(v), }); } } @@ -193,15 +193,15 @@ pub fn split(area: &Rect, dir: &Direction, margin: u16, sizes: &[Size]) -> Vec elements[i].height | EQ(WEAK) | v as f64, + Size::Fixed(v) => elements[i].height | EQ(WEAK) | f64::from(v), Size::Percent(v) => { - elements[i].height | EQ(WEAK) | ((v * dest_area.height) as f64 / 100.0) + elements[i].height | EQ(WEAK) | (f64::from(v * dest_area.height) / 100.0) } - Size::Min(v) => elements[i].height | GE(WEAK) | v as f64, - Size::Max(v) => elements[i].height | LE(WEAK) | v as f64, + Size::Min(v) => elements[i].height | GE(WEAK) | f64::from(v), + Size::Max(v) => elements[i].height | LE(WEAK) | f64::from(v), }); } } diff --git a/src/widgets/barchart.rs b/src/widgets/barchart.rs index 0a7842ee..7b2f5fa6 100644 --- a/src/widgets/barchart.rs +++ b/src/widgets/barchart.rs @@ -133,7 +133,7 @@ impl<'a> Widget for BarChart<'a> { let mut data = self.data .iter() .take(max_index) - .map(|&(l, v)| (l, v * chart_area.height as u64 * 8 / max)) + .map(|&(l, v)| (l, v * u64::from(chart_area.height) * 8 / max)) .collect::>(); for j in (0..chart_area.height - 1).rev() { for (i, d) in data.iter_mut().enumerate() { diff --git a/src/widgets/canvas/mod.rs b/src/widgets/canvas/mod.rs index 073b5943..defc9acc 100644 --- a/src/widgets/canvas/mod.rs +++ b/src/widgets/canvas/mod.rs @@ -99,8 +99,8 @@ impl<'a> Context<'a> { !(x < left || x > right || y < bottom || y > top) }) { - let dy = ((top - y) * (self.height - 1) as f64 * 4.0 / (top - bottom)) as usize; - let dx = ((x - left) * (self.width - 1) as f64 * 2.0 / (right - left)) as usize; + let dy = ((top - y) * f64::from(self.height - 1) * 4.0 / (top - bottom)) as usize; + let dx = ((x - left) * f64::from(self.width - 1) * 2.0 / (right - left)) as usize; let index = dy / 4 * self.width as usize + dx / 2; self.grid.cells[index] |= DOTS[dy % 4][dx % 2]; self.grid.colors[index] = shape.color(); @@ -282,10 +282,10 @@ where l.y > self.y_bounds[1]) }) { - let dy = ((self.y_bounds[1] - label.y) * (canvas_area.height - 1) as f64 / + let dy = ((self.y_bounds[1] - label.y) * f64::from(canvas_area.height - 1) / (self.y_bounds[1] - self.y_bounds[0])) as u16; - let dx = ((label.x - self.x_bounds[0]) * (canvas_area.width - 1) as f64 / + let dx = ((label.x - self.x_bounds[0]) * f64::from(canvas_area.width - 1) / (self.x_bounds[1] - self.x_bounds[0])) as u16; buf.set_string( diff --git a/src/widgets/chart.rs b/src/widgets/chart.rs index b673ebfd..16c472c0 100644 --- a/src/widgets/chart.rs +++ b/src/widgets/chart.rs @@ -401,10 +401,10 @@ impl<'a> Widget for Chart<'a> { y > self.y_axis.bounds[1]) }) { - let dy = ((self.y_axis.bounds[1] - y) * (graph_area.height - 1) as f64 / + let dy = ((self.y_axis.bounds[1] - y) * f64::from(graph_area.height - 1) / (self.y_axis.bounds[1] - self.y_axis.bounds[0])) as u16; - let dx = ((x - self.x_axis.bounds[0]) * (graph_area.width - 1) as f64 / + let dx = ((x - self.x_axis.bounds[0]) * f64::from(graph_area.width - 1) / (self.x_axis.bounds[1] - self.x_axis.bounds[0])) as u16; diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs index 76734b2f..e95d948d 100644 --- a/src/widgets/mod.rs +++ b/src/widgets/mod.rs @@ -30,15 +30,15 @@ pub mod border { bitflags! { pub flags Flags: u32 { /// Show no border (default) - const NONE = 0b00000001, + const NONE = 0b0000_0001, /// Show the top border - const TOP = 0b00000010, + const TOP = 0b0000_0010, /// Show the right border - const RIGHT = 0b00000100, + const RIGHT = 0b0000_0100, /// Show the bottom border - const BOTTOM = 0b0001000, + const BOTTOM = 0b000_1000, /// Show the left border - const LEFT = 0b00010000, + const LEFT = 0b0001_0000, /// Show all borders const ALL = TOP.bits | RIGHT.bits | BOTTOM.bits | LEFT.bits, } diff --git a/src/widgets/sparkline.rs b/src/widgets/sparkline.rs index ec75a4fb..8f2d0d37 100644 --- a/src/widgets/sparkline.rs +++ b/src/widgets/sparkline.rs @@ -89,7 +89,7 @@ impl<'a> Widget for Sparkline<'a> { let mut data = self.data .iter() .take(max_index) - .map(|e| e * spark_area.height as u64 * 8 / max) + .map(|e| e * u64::from(spark_area.height) * 8 / max) .collect::>(); for j in (0..spark_area.height).rev() { for (i, d) in data.iter_mut().enumerate() {