Minor codestyle fixes

pull/21/head
talha 7 years ago committed by Florian Dehau
parent 80f5f9f481
commit 3045ac4124

@ -175,31 +175,31 @@ fn draw(t: &mut Terminal<MouseBackend>, 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,
});
})

@ -153,21 +153,21 @@ pub fn split(area: &Rect, dir: &Direction, margin: u16, sizes: &[Size]) -> Vec<R
}
let mut constraints: Vec<Constraint> = 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<R
constraints.push((pair[0].x + pair[0].width) | EQ(REQUIRED) | pair[1].x);
}
for (i, size) in sizes.iter().enumerate() {
constraints.push(elements[i].y | EQ(REQUIRED) | dest_area.y as f64);
constraints.push(elements[i].height | EQ(REQUIRED) | dest_area.height as f64);
constraints.push(elements[i].y | EQ(REQUIRED) | f64::from(dest_area.y));
constraints.push(elements[i].height | EQ(REQUIRED) | f64::from(dest_area.height));
constraints.push(match *size {
Size::Fixed(v) => 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<R
constraints.push((pair[0].y + pair[0].height) | EQ(REQUIRED) | pair[1].y);
}
for (i, size) in sizes.iter().enumerate() {
constraints.push(elements[i].x | EQ(REQUIRED) | dest_area.x as f64);
constraints.push(elements[i].width | EQ(REQUIRED) | dest_area.width as f64);
constraints.push(elements[i].x | EQ(REQUIRED) | f64::from(dest_area.x));
constraints.push(elements[i].width | EQ(REQUIRED) | f64::from(dest_area.width));
constraints.push(match *size {
Size::Fixed(v) => 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),
});
}
}

@ -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::<Vec<(&str, u64)>>();
for j in (0..chart_area.height - 1).rev() {
for (i, d) in data.iter_mut().enumerate() {

@ -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(

@ -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;

@ -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,
}

@ -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::<Vec<u64>>();
for j in (0..spark_area.height).rev() {
for (i, d) in data.iter_mut().enumerate() {

Loading…
Cancel
Save