summaryrefslogtreecommitdiffstats
path: root/src/imgview.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/imgview.rs')
-rw-r--r--src/imgview.rs32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/imgview.rs b/src/imgview.rs
index c52abee..d84fc03 100644
--- a/src/imgview.rs
+++ b/src/imgview.rs
@@ -1,4 +1,5 @@
use crate::widget::{Widget, WidgetCore};
+use crate::coordinates::Coordinates;
use crate::fail::HResult;
use std::path::{Path, PathBuf};
@@ -18,7 +19,19 @@ pub struct ImgView {
impl ImgView {
pub fn new_from_file(core: WidgetCore, file: &Path) -> HResult<ImgView> {
- let (xsize, ysize) = core.coordinates.size_u();
+ let mut view = ImgView {
+ core: core,
+ buffer: vec![],
+ file: file.to_path_buf()
+ };
+
+ view.encode_file()?;
+ Ok(view)
+ }
+
+ pub fn encode_file(&mut self) -> HResult<()> {
+ let (xsize, ysize) = self.core.coordinates.size_u();
+ let file = &self.file;
let output = std::process::Command::new("preview-gen")
.arg(format!("{}", (xsize)))
@@ -35,11 +48,9 @@ impl ImgView {
.map(|l| l.to_string())
.collect();
- Ok(ImgView {
- core: core,
- buffer: output,
- file: file.to_path_buf()
- })
+ self.buffer = output;
+
+ Ok(())
}
pub fn set_image_data(&mut self, img_data: Vec<String>) {
@@ -61,6 +72,15 @@ impl Widget for ImgView {
Ok(&mut self.core)
}
+ fn set_coordinates(&mut self, coordinates: &Coordinates) -> HResult<()> {
+ if &self.core.coordinates == coordinates { return Ok(()) }
+
+ self.core.coordinates = coordinates.clone();
+ self.encode_file()?;
+
+ Ok(())
+ }
+
fn refresh(&mut self) -> HResult<()> {
Ok(())