fixed dimension issue and text not clearing issue
This commit is contained in:
parent
a5b4b84eec
commit
e2f92fbce8
|
|
@ -41,44 +41,38 @@ pub(crate) fn spawn_image_thread(
|
|||
let mut quote_position = main_win.quote_position.clone();
|
||||
let mut tag_position = main_win.tag_position.clone();
|
||||
let mut page = main_win.page.clone();
|
||||
let mut status = main_win.status.clone();
|
||||
|
||||
let mut _container: Option<ImageContainer> = None;
|
||||
std::thread::spawn(move || loop {
|
||||
if let Ok(val) = reciver.recv() {
|
||||
match val {
|
||||
DrawMessage::Open => load_image(
|
||||
&mut file_choice,
|
||||
&mut quote,
|
||||
&mut tag,
|
||||
&mut layer_red,
|
||||
&mut layer_green,
|
||||
&mut layer_blue,
|
||||
&mut layer_alpha,
|
||||
&mut quote_position,
|
||||
&mut tag_position,
|
||||
&mut page,
|
||||
&app_sender,
|
||||
&properties,
|
||||
&mut _container,
|
||||
),
|
||||
DrawMessage::Open => {
|
||||
status.set_label("Loading...");
|
||||
load_image(
|
||||
&mut file_choice,
|
||||
&mut quote,
|
||||
&mut tag,
|
||||
&mut layer_red,
|
||||
&mut layer_green,
|
||||
&mut layer_blue,
|
||||
&mut layer_alpha,
|
||||
&mut quote_position,
|
||||
&mut tag_position,
|
||||
&mut page,
|
||||
&app_sender,
|
||||
&properties,
|
||||
&mut _container,
|
||||
);
|
||||
status.set_label("");
|
||||
}
|
||||
DrawMessage::Recalc => {
|
||||
if let Some(cont) = &mut _container {
|
||||
cont.recalc();
|
||||
}
|
||||
}
|
||||
// DrawMessage::CropPos(x, y) => {
|
||||
// if let Some(cont) = &mut _container {
|
||||
// cont.apply_crop_pos(x, y);
|
||||
// }
|
||||
// }
|
||||
// DrawMessage::Crop => {
|
||||
// if let Some(cont) = &mut _container {
|
||||
// cont.apply_crop();
|
||||
// }
|
||||
// }
|
||||
DrawMessage::Flush => {
|
||||
flush_buffer(&app_sender, &mut _container);
|
||||
println!("recived");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -108,6 +102,9 @@ fn load_image(
|
|||
*container = Some(ImageContainer::new(&file, Arc::clone(properties)));
|
||||
|
||||
if let Some(cont) = container {
|
||||
quote.set_value("");
|
||||
tag.set_value("");
|
||||
|
||||
let file = Path::new(&file);
|
||||
let conf = file.with_extension("conf");
|
||||
|
||||
|
|
@ -144,8 +141,8 @@ fn load_image(
|
|||
|
||||
if use_defaults {
|
||||
let mut prop = properties.write().unwrap();
|
||||
quote.set_value("");
|
||||
tag.set_value("");
|
||||
prop.quote = "".to_owned();
|
||||
prop.tag = "".to_owned();
|
||||
|
||||
quote_position.set_range(0.0, prop.original_dimension.1 as f64);
|
||||
quote_position.set_value(prop.quote_position as f64);
|
||||
|
|
@ -162,6 +159,7 @@ fn load_image(
|
|||
cont.apply_crop();
|
||||
}
|
||||
|
||||
cont.apply_scale();
|
||||
let prop = properties.read().unwrap();
|
||||
let (width, height) = prop.dimension;
|
||||
page.col_flex.set_size(&page.image, height as i32);
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ fn main() {
|
|||
AppMessage::RedrawMainWindowImage(data) => {
|
||||
let mut buff = draw_buff.write().unwrap();
|
||||
*buff = data;
|
||||
println!("copy buff");
|
||||
main_window.win.redraw();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -280,7 +280,6 @@ impl MainWindow {
|
|||
}
|
||||
|
||||
fn draw(&mut self) {
|
||||
println!("in draw");
|
||||
let buff = Arc::clone(&self.draw_buff);
|
||||
let properties = Arc::clone(&self.properties);
|
||||
self.page.image.draw(move |f| {
|
||||
|
|
@ -299,6 +298,33 @@ impl MainWindow {
|
|||
}
|
||||
|
||||
fn events(&mut self) {
|
||||
let mut file_choice = self.file_choice.clone();
|
||||
let sender = self.sender.clone();
|
||||
self.next_btn.set_callback(move |_| {
|
||||
if file_choice.value() == file_choice.size() - 2 {
|
||||
file_choice.set_value(0);
|
||||
} else {
|
||||
file_choice.set_value(file_choice.value() + 1);
|
||||
}
|
||||
sender.send(DrawMessage::Open).unwrap();
|
||||
});
|
||||
|
||||
let mut file_choice = self.file_choice.clone();
|
||||
let sender = self.sender.clone();
|
||||
self.back_btn.set_callback(move |_| {
|
||||
if file_choice.value() == 0 {
|
||||
file_choice.set_value(file_choice.size() - 2);
|
||||
} else {
|
||||
file_choice.set_value(file_choice.value() - 1);
|
||||
}
|
||||
sender.send(DrawMessage::Open).unwrap();
|
||||
});
|
||||
|
||||
let sender = self.sender.clone();
|
||||
self.file_choice.set_callback(move |_| {
|
||||
sender.send(DrawMessage::Open).unwrap();
|
||||
});
|
||||
|
||||
let mut image = self.page.image.clone();
|
||||
let properties = Arc::clone(&self.properties);
|
||||
let sender = self.sender.clone();
|
||||
|
|
@ -394,79 +420,3 @@ impl MainWindow {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
// fn load_image(
|
||||
// file_choice: &mut menu::Choice,
|
||||
// quote: &mut MultilineInput,
|
||||
// tag: &mut Input,
|
||||
// layer_red: &mut Spinner,
|
||||
// layer_green: &mut Spinner,
|
||||
// layer_blue: &mut Spinner,
|
||||
// layer_alpha: &mut Spinner,
|
||||
// quote_position: &mut Spinner,
|
||||
// tag_position: &mut Spinner,
|
||||
// page: &mut Page,
|
||||
// properties: &Arc<RwLock<ImageProperties>>,
|
||||
// sender: &mpsc::Sender<DrawMessage>,
|
||||
// ) {
|
||||
// let file: String = match file_choice.choice() {
|
||||
// Some(val) => val,
|
||||
// None => return,
|
||||
// };
|
||||
|
||||
// sender.send(DrawMessage::Open(file.clone())).unwrap();
|
||||
|
||||
// let file = Path::new(&file);
|
||||
// let conf = file.with_extension("conf");
|
||||
|
||||
// let mut prop = properties.write().unwrap();
|
||||
// let mut use_defaults = true;
|
||||
// if conf.exists() {
|
||||
// let read = fs::read_to_string(&conf).unwrap();
|
||||
// if let Ok(saved_prop) = serde_json::from_str::<ImageProperties>(&read) {
|
||||
// layer_red.set_value(saved_prop.rgba[0] as f64);
|
||||
// layer_green.set_value(saved_prop.rgba[1] as f64);
|
||||
// layer_blue.set_value(saved_prop.rgba[2] as f64);
|
||||
// layer_alpha.set_value(saved_prop.rgba[3] as f64);
|
||||
// quote.set_value(&saved_prop.quote);
|
||||
// tag.set_value(&saved_prop.tag);
|
||||
// quote_position.set_range(0.0, prop.original_dimension.1 as f64);
|
||||
// quote_position.set_value(saved_prop.quote_position as f64);
|
||||
// tag_position.set_range(0.0, prop.original_dimension.1 as f64);
|
||||
// tag_position.set_value(saved_prop.tag_position as f64);
|
||||
|
||||
// if let Some((x, y)) = saved_prop.crop_position {
|
||||
// sender.send(DrawMessage::CropPos(x, y)).unwrap();
|
||||
// }
|
||||
|
||||
// prop.quote = saved_prop.quote;
|
||||
// prop.tag = saved_prop.tag;
|
||||
// prop.quote_position = saved_prop.quote_position;
|
||||
// prop.tag_position = saved_prop.quote_position;
|
||||
// prop.rgba = saved_prop.rgba;
|
||||
// use_defaults = false;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if use_defaults {
|
||||
// quote.set_value("");
|
||||
// tag.set_value("");
|
||||
|
||||
// quote_position.set_range(0.0, prop.original_dimension.1 as f64);
|
||||
// quote_position.set_value(prop.quote_position as f64);
|
||||
// tag_position.set_range(0.0, prop.original_dimension.1 as f64);
|
||||
// tag_position.set_value(prop.tag_position as f64);
|
||||
|
||||
// sender.send(DrawMessage::Crop).unwrap();
|
||||
|
||||
// prop.rgba = [
|
||||
// layer_red.value() as u8,
|
||||
// layer_green.value() as u8,
|
||||
// layer_blue.value() as u8,
|
||||
// layer_alpha.value() as u8,
|
||||
// ];
|
||||
// }
|
||||
// sender.send(DrawMessage::Recalc).unwrap();
|
||||
// println!("sent");
|
||||
// sender.send(DrawMessage::Flush).unwrap();
|
||||
// }
|
||||
|
|
|
|||
16
src/utils.rs
16
src/utils.rs
|
|
@ -16,12 +16,9 @@ impl ImageContainer {
|
|||
pub(crate) fn new(path: &str, properties: Arc<RwLock<ImageProperties>>) -> Self {
|
||||
let img = image::open(path).unwrap();
|
||||
let (width, height) = img.dimensions();
|
||||
let (s_width, s_height) = ((width * 500) / height, 500);
|
||||
let img = img.resize(s_width, s_height, image::imageops::FilterType::Triangle);
|
||||
|
||||
let mut prop = properties.write().unwrap();
|
||||
prop.path = path.to_owned();
|
||||
prop.dimension = (s_width, s_height);
|
||||
prop.original_dimension = (width, height);
|
||||
prop.quote_position = height / 2;
|
||||
prop.tag_position = (height * 2) / 3;
|
||||
|
|
@ -33,6 +30,19 @@ impl ImageContainer {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn apply_scale(&mut self) {
|
||||
let mut prop = self.properties.write().unwrap();
|
||||
let (width, height) = prop.dimension;
|
||||
let (s_width, s_height) = ((width * 500) / height, 500);
|
||||
self.image =
|
||||
self.image
|
||||
.resize_exact(s_width, s_height, image::imageops::FilterType::Nearest);
|
||||
|
||||
self.buffer = self.image.clone();
|
||||
|
||||
prop.dimension = (s_width, s_height);
|
||||
}
|
||||
|
||||
pub(crate) fn apply_crop(&mut self) {
|
||||
let mut prop = self.properties.write().unwrap();
|
||||
let (original_width, original_height) = prop.original_dimension;
|
||||
|
|
|
|||
Loading…
Reference in New Issue