From c6763fca4b9ecc3d6dcf08795552175dbce9ef53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piyush=20=E0=A4=AE=E0=A4=BF=E0=A4=B6=E0=A5=8D=E0=A4=B0?= Date: Fri, 19 Aug 2022 12:23:20 +0530 Subject: [PATCH] * Option to enable and disable line spacing * Version upgrade --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/config.rs | 4 +++- src/config_window.rs | 37 ++++++++++++++++++++++++++++++++----- src/utils.rs | 12 +++++++++--- 5 files changed, 46 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 345fee6..6af08d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -905,7 +905,7 @@ dependencies = [ [[package]] name = "post_maker" -version = "0.6.0-alpha.1" +version = "0.6.0-alpha.2" dependencies = [ "bichannel", "clap", diff --git a/Cargo.toml b/Cargo.toml index 1daa1b0..c82ea2e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "post_maker" -version = "0.6.0-alpha.1" +version = "0.6.0-alpha.2" edition = "2021" description = "Post Maker helps you to make post for Instagram and other Social Media apps easily." authors = ["PiyushXCoder "] diff --git a/src/config.rs b/src/config.rs index ddaaa30..624cb65 100644 --- a/src/config.rs +++ b/src/config.rs @@ -133,6 +133,7 @@ pub(crate) struct ConfigFile { pub(crate) minimum_width_limit: f64, // for export of image pub(crate) maximum_width_limit: f64, // for export of image pub(crate) draw_box_around_quote: bool, + pub(crate) line_spacing: bool, pub(crate) image_format: ImageType, } @@ -156,10 +157,11 @@ impl Default for ConfigFile { tag_y_position_ratio: 0.5, tag2_position_ratio: 0.95, image_ratio: (4.0, 5.0), - color_layer: [20, 22, 25, 80], + color_layer: [20, 22, 25, 0], minimum_width_limit: 650.0, maximum_width_limit: 1080.0, draw_box_around_quote: true, + line_spacing: true, image_format: ImageType::Jpeg, } } diff --git a/src/config_window.rs b/src/config_window.rs index aec0dd6..3de713b 100644 --- a/src/config_window.rs +++ b/src/config_window.rs @@ -66,6 +66,7 @@ pub(crate) struct ConfigWindow { pub(crate) image_ratio_width: ValueInput, pub(crate) image_ratio_height: ValueInput, pub(crate) draw_box_around_quote: CheckButton, + pub(crate) line_spacing: CheckButton, pub(crate) minimum_width_limit: ValueInput, pub(crate) maximum_width_limit: ValueInput, /// RGB value of top translucent layer @@ -391,16 +392,18 @@ impl ConfigWindow { col.set_size(&image_ratio_grp, 30); // Draw box around Quote - let mut label = Frame::default().with_label("Draw Box:"); + let mut label = Frame::default().with_label("Quote Special:"); label.set_label_font(enums::Font::HelveticaBold); col.set_size(&label, 15); - let mut draw_box_around_quote_flex = Flex::default().row(); - draw_box_around_quote_flex.set_size(&Frame::default(), 20); + let mut quote_special_flex = Flex::default().row(); + quote_special_flex.set_size(&Frame::default(), 20); let mut draw_box_around_quote = CheckButton::default().with_label("Draw box around text"); draw_box_around_quote.set_value(true); - draw_box_around_quote_flex.end(); - col.set_size(&draw_box_around_quote_flex, 30); + let mut line_spacing = CheckButton::default().with_label("Line spacing in quotes"); + line_spacing.set_value(true); + quote_special_flex.end(); + col.set_size("e_special_flex, 30); let mut label = Frame::default().with_label("Image with limits:"); label.set_label_font(enums::Font::HelveticaBold); @@ -519,6 +522,7 @@ impl ConfigWindow { image_ratio_width, image_ratio_height, draw_box_around_quote, + line_spacing, minimum_width_limit, maximum_width_limit, translucent_layer_rgb, @@ -577,6 +581,7 @@ impl ConfigWindow { self.image_ratio_height.set_value(config.image_ratio.1); self.draw_box_around_quote .set_checked(config.draw_box_around_quote); + self.line_spacing.set_checked(config.line_spacing); self.minimum_width_limit .set_value(config.minimum_width_limit); self.maximum_width_limit @@ -628,6 +633,7 @@ impl ConfigWindow { let mut image_ratio_width = self.image_ratio_width.clone(); let mut image_ratio_height = self.image_ratio_height.clone(); let draw_box_around_quote = self.draw_box_around_quote.clone(); + let line_spacing = self.line_spacing.clone(); let mut minimum_width_limit = self.minimum_width_limit.clone(); let mut maximum_width_limit = self.maximum_width_limit.clone(); let mut layer_rgb = self.translucent_layer_rgb.clone(); @@ -675,6 +681,7 @@ impl ConfigWindow { image_ratio_width.set_value(conf.image_ratio.0); image_ratio_height.set_value(conf.image_ratio.1); draw_box_around_quote.set_checked(conf.draw_box_around_quote); + line_spacing.set_checked(conf.line_spacing); minimum_width_limit.set_value(conf.minimum_width_limit); maximum_width_limit.set_value(conf.maximum_width_limit); utils::set_color_btn_rgba(conf.color_layer, &mut layer_rgb); @@ -706,6 +713,7 @@ impl ConfigWindow { let mut image_ratio_width = self.image_ratio_width.clone(); let mut image_ratio_height = self.image_ratio_height.clone(); let draw_box_around_quote = self.draw_box_around_quote.clone(); + let line_spacing = self.line_spacing.clone(); let mut minimum_width_limit = self.minimum_width_limit.clone(); let mut maximum_width_limit = self.maximum_width_limit.clone(); let mut layer_rgb = self.translucent_layer_rgb.clone(); @@ -752,6 +760,7 @@ impl ConfigWindow { image_ratio_width.set_value(conf.image_ratio.0); image_ratio_height.set_value(conf.image_ratio.1); draw_box_around_quote.set_checked(conf.draw_box_around_quote); + line_spacing.set_checked(conf.line_spacing); minimum_width_limit.set_value(conf.minimum_width_limit); maximum_width_limit.set_value(conf.maximum_width_limit); utils::set_color_btn_rgba(conf.color_layer, &mut layer_rgb); @@ -780,6 +789,7 @@ impl ConfigWindow { let mut image_ratio_width = self.image_ratio_width.clone(); let mut image_ratio_height = self.image_ratio_height.clone(); let draw_box_around_quote = self.draw_box_around_quote.clone(); + let line_spacing = self.line_spacing.clone(); let mut minimum_width_limit = self.minimum_width_limit.clone(); let mut maximum_width_limit = self.maximum_width_limit.clone(); let mut layer_rgb = self.translucent_layer_rgb.clone(); @@ -816,6 +826,7 @@ impl ConfigWindow { image_ratio_width.set_value(conf.image_ratio.0); image_ratio_height.set_value(conf.image_ratio.1); draw_box_around_quote.set_checked(conf.draw_box_around_quote); + line_spacing.set_checked(conf.line_spacing); minimum_width_limit.set_value(conf.minimum_width_limit); maximum_width_limit.set_value(conf.maximum_width_limit); utils::set_color_btn_rgba(conf.color_layer, &mut layer_rgb); @@ -1130,6 +1141,7 @@ impl ConfigWindow { true }); + // Draw box around quote let browse = self.browse.clone(); let configs = Rc::clone(&self.configs); self.draw_box_around_quote.handle(move |f, _| { @@ -1142,6 +1154,19 @@ impl ConfigWindow { true }); + // line spacing + let browse = self.browse.clone(); + let configs = Rc::clone(&self.configs); + self.line_spacing.handle(move |f, _| { + if let Some(conf) = configs + .borrow_mut() + .get_mut(&browse.selected_text().unwrap()) + { + conf.line_spacing = f.value(); + } + true + }); + // Minimum Width Limit let browse = self.browse.clone(); let configs = Rc::clone(&self.configs); @@ -1260,6 +1285,7 @@ impl ConfigWindow { let mut image_ratio_width = self.image_ratio_width.clone(); let mut image_ratio_height = self.image_ratio_height.clone(); let draw_box_around_quote = self.draw_box_around_quote.clone(); + let line_spacing = self.line_spacing.clone(); let mut minimum_width_limit = self.minimum_width_limit.clone(); let mut maximum_width_limit = self.maximum_width_limit.clone(); let mut layer_rgb = self.translucent_layer_rgb.clone(); @@ -1289,6 +1315,7 @@ impl ConfigWindow { image_ratio_width.set_value(conf.image_ratio.0); image_ratio_height.set_value(conf.image_ratio.1); draw_box_around_quote.set_checked(conf.draw_box_around_quote); + line_spacing.set_checked(conf.line_spacing); minimum_width_limit.set_value(conf.minimum_width_limit); maximum_width_limit.set_value(conf.maximum_width_limit); utils::set_color_btn_rgba(conf.color_layer, &mut layer_rgb); diff --git a/src/utils.rs b/src/utils.rs index 26ac041..11d9cdf 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -666,6 +666,7 @@ pub(crate) fn draw_multiline_mid_string( let (mut box_width, mut box_height) = (0.0, 0.0); let (width, height): (f64, f64) = Coord::from(tmp.dimensions()).into(); + let has_line_spacing = rw_read!(globals::CONFIG).line_spacing; for (index, line) in text.lines().enumerate() { let (text_width, text_height) = measure_line(font, line, rusttype::Scale::uniform(size as f32)); @@ -673,11 +674,16 @@ pub(crate) fn draw_multiline_mid_string( if text_width > box_width { box_width = text_width; } - box_height += text_height * 1.15; + box_height += text_height + * if index == 0 || !has_line_spacing { + 1.0 + } else { + 1.12 + }; let (x, y) = ( (width - text_width) / 2.0, - (position * height) / original_height + index as f64 * (text_height * 1.15), + (position * height) / original_height + index as f64 * (text_height * 1.12), ); if !boxed || !rw_read!(globals::CONFIG).draw_box_around_quote { @@ -733,7 +739,7 @@ fn draw_box( let (width, height): (f64, f64) = Coord::from(tmp.dimensions()).into(); let (delta_x, delta_y) = (width / original_width, height / original_height); - let (x_gap, y_gap) = (8.0 * delta_x, 5.0 * delta_y); + let (x_gap, y_gap) = (30.0 * delta_x, 10.0 * delta_y); let (x, y) = ( ((width - box_width) / 2.0 - x_gap) as u32, ((position * height) / original_height - y_gap) as u32,