Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of a bar displaying the name of the image being displayed #3

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Added commit that showed the images width and height
  • Loading branch information
alexcreamer committed Jul 9, 2017
commit 3ccc3aa2486cd161e6bcefe313625579e80b6ff7
31 changes: 30 additions & 1 deletion src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,33 @@ impl ImageCache {
ui.needs_update();
});
}
}

pub fn get_image_dimensions<'a>(&'a self, path: String, size: usize) -> Option<(usize,usize)>{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing the image all over again just to get the dimensions is just broken.

let maxwidth = SIZES[size][0];
let maxheight = SIZES[size][1];

let decoded = match rawloader::decode(&path) {
Ok(img) => img.to_srgb(maxwidth, maxheight).unwrap(),
// If we couldn't load it as a raw try with the normal image loading
Err(_) => match image::open(&Path::new(&path)) {
Ok(img) => {
let rgb = img.to_rgb();
let width = rgb.width() as usize;
let height = rgb.height() as usize;
SRGBImage {
data: rgb.into_raw(),
width: width,
height: height,
}
}
Err(_) => {
println!("Don't know how to load \"{}\"", path);
return None
}
},
};
let imgwidth = decoded.width;
let imgheight = decoded.height;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't return the image dimensions, it will return the decoded dimensions that in the case of raws has been downsized.

return Some((imgwidth, imgheight));
}
}
35 changes: 26 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,32 @@ fn main() {

if let Some(ref f) = file {
let file_name = Path::new(f).file_name().unwrap();
widget::Text::new(file_name.to_str().unwrap())
.color( color::WHITE)
.font_size(18)
.padded_w_of(ids.footer, PAD)
.mid_top_with_margin_on(ids.footer, PAD)
.center_justify()
.line_spacing(10.0)
.set(ids.lefttext, ui);
}
let option_dimensions: Option<(usize, usize)> = icache.get_image_dimensions(
file.clone().unwrap(),
size);

if let Some(dimensions) = option_dimensions {
let width_usize = dimensions.0;
let height_usize = dimensions.1;


let width = &width_usize.to_string();
let height = &height_usize.to_string();
let output = format!(
"{} {}x{}", file_name.to_str().unwrap(),
width,
height);

widget::Text::new(&output)
.color( color::WHITE)
.font_size(18)
.padded_w_of(ids.footer, PAD)
.mid_top_with_margin_on(ids.footer, PAD)
.center_justify()
.line_spacing(10.0)
.set(ids.lefttext, ui);
}
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably excess white space.

for event in widget::FileNavigator::all(&directory)
.color(conrod::color::LIGHT_BLUE)
Expand Down