Skip to content

Commit

Permalink
move hex parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Jun 8, 2019
1 parent d0de5d8 commit 53d87af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 1 addition & 7 deletions editor/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,7 @@ pub fn rotating_color_total(idx: usize, total: usize) -> Color {
colorbrewer::get_color_ramp(colorbrewer::Palette::YlOrBr, total as u32)
.unwrap()
.into_iter()
.map(|raw| {
// Skip the leading '#'
let r = usize::from_str_radix(&raw[1..3], 16).unwrap();
let g = usize::from_str_radix(&raw[3..5], 16).unwrap();
let b = usize::from_str_radix(&raw[5..7], 16).unwrap();
Color::rgb(r, g, b)
})
.map(Color::from_hex)
.collect();

colors[idx % total]
Expand Down
8 changes: 8 additions & 0 deletions ezgui/src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,12 @@ impl Color {
}
panic!("Can't transform {} to a string", self);
}

pub fn from_hex(raw: &str) -> Color {
// Skip the leading '#'
let r = usize::from_str_radix(&raw[1..3], 16).unwrap();
let g = usize::from_str_radix(&raw[3..5], 16).unwrap();
let b = usize::from_str_radix(&raw[5..7], 16).unwrap();
Color::rgb(r, g, b)
}
}

0 comments on commit 53d87af

Please sign in to comment.