dialogs positioning and minimum image size delete dialog
This commit is contained in:
parent
6f39a8209a
commit
627912f89e
|
|
@ -15,7 +15,7 @@
|
|||
//! load, save configuration and parse cli args
|
||||
use crate::{config_picker::ConfigPicker, globals, result_ext::ResultExt, utils::ImageType};
|
||||
use clap::{ArgEnum, Parser};
|
||||
use fltk::dialog;
|
||||
use crate::dialog;
|
||||
use fltk_theme::ThemeType;
|
||||
use lazy_static::lazy_static;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
|
|||
|
|
@ -15,12 +15,13 @@
|
|||
//! Window to edit configuration
|
||||
|
||||
use std::{cell::RefCell, collections::HashMap, rc::Rc};
|
||||
use crate::dialog;
|
||||
|
||||
use fltk::{
|
||||
app,
|
||||
browser::{Browser, BrowserType},
|
||||
button::{Button, RadioRoundButton},
|
||||
dialog::{self, FileDialogOptions, NativeFileChooser},
|
||||
dialog::{FileDialogOptions, NativeFileChooser},
|
||||
enums::{self, Align, Event, Font},
|
||||
frame::Frame,
|
||||
group::{Flex, Scroll},
|
||||
|
|
@ -683,7 +684,7 @@ impl ConfigWindow {
|
|||
let configs = Rc::clone(&self.configs);
|
||||
let selected_browse_line = Rc::clone(&self.selected_browse_line);
|
||||
self.del_config_btn.set_callback(move |_| {
|
||||
let ch = dialog::choice_default("Do you want to delete??", "Yes", "No", "");
|
||||
let ch = dialog::choice_default("Do you want to delete??", "Yes", "No");
|
||||
if ch == 1 {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
use fltk::dialog;
|
||||
use fltk::app::get_mouse;
|
||||
pub(crate) use dialog::color_chooser_with_default;
|
||||
pub(crate) use dialog::ColorMode;
|
||||
|
||||
pub(crate) fn input_default(txt: &str, deflt: &str) -> Option<String> {
|
||||
let (x,y) = get_mouse();
|
||||
dialog::input(x, y, txt, deflt)
|
||||
}
|
||||
|
||||
pub(crate) fn alert_default(txt: &str) {
|
||||
let (x,y) = get_mouse();
|
||||
dialog::alert(x, y, txt)
|
||||
}
|
||||
|
||||
pub(crate) fn message_default(txt: &str) {
|
||||
let (x,y) = get_mouse();
|
||||
dialog::message(x, y, txt)
|
||||
}
|
||||
|
||||
pub(crate) fn choice_default(txt: &str, b0: &str, b1: &str) -> i32 {
|
||||
let (x,y) = get_mouse();
|
||||
dialog::choice(x, y, txt, b0, b1, "")
|
||||
}
|
||||
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
//! Thread to manage drawing in background
|
||||
|
||||
use crate::globals;
|
||||
use crate::result_ext::ResultExt;
|
||||
use crate::utils::{ImageContainer, ImageProperties, ImageInfo};
|
||||
use crate::{
|
||||
|
|
@ -54,7 +55,9 @@ pub(crate) enum DrawMessage {
|
|||
/// Delete file
|
||||
Delete,
|
||||
/// Show details about images linke count of quotes
|
||||
ShowImagesDetails
|
||||
ShowImagesDetails,
|
||||
/// Check If image is proper
|
||||
CheckImage
|
||||
}
|
||||
|
||||
/// Spawn thread to manage all actions related to image, like: edit, save, delete
|
||||
|
|
@ -222,6 +225,15 @@ pub(crate) fn spawn_image_thread(
|
|||
DrawMessage::ShowImagesDetails => {
|
||||
show_images_details(Arc::clone(&images_list))
|
||||
}
|
||||
DrawMessage::CheckImage => {
|
||||
let (width, height) = properties.read().unwrap().original_dimension;
|
||||
if utils::is_too_small(width, height) {
|
||||
let a = globals::MAIN_SENDER.read().unwrap();
|
||||
if let Some(a) = &*a {
|
||||
a.send(crate::AppMessage::DeleteImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
17
src/main.rs
17
src/main.rs
|
|
@ -17,6 +17,7 @@
|
|||
extern crate log;
|
||||
extern crate simplelog;
|
||||
|
||||
mod dialog;
|
||||
mod about_window;
|
||||
mod config;
|
||||
mod config_picker;
|
||||
|
|
@ -30,7 +31,7 @@ mod result_ext;
|
|||
|
||||
use fltk::{
|
||||
app::{channel, App},
|
||||
dialog,
|
||||
// dialog,
|
||||
prelude::*,
|
||||
};
|
||||
use fltk_theme::WidgetTheme;
|
||||
|
|
@ -43,7 +44,10 @@ pub(crate) enum AppMessage {
|
|||
/// Copy recived image buffer from draw_thread to Buffer for fltk frame
|
||||
RedrawMainWindowImage(Option<Vec<u8>>),
|
||||
Message(String),
|
||||
Alert(String)
|
||||
Alert(String),
|
||||
|
||||
// Only for Main windows
|
||||
DeleteImage
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
@ -86,6 +90,15 @@ fn main() {
|
|||
AppMessage::Alert(msg) => {
|
||||
dialog::alert_default(&msg)
|
||||
}
|
||||
AppMessage::DeleteImage => {
|
||||
let ch = dialog::choice_default("Image is too small", "Delete", "Keep");
|
||||
if ch == 0 {
|
||||
main_window.sender.send(draw_thread::DrawMessage::Delete).unwrap();
|
||||
main_window.sender.send(draw_thread::DrawMessage::Open).unwrap();
|
||||
main_window.page.image.redraw();
|
||||
main_window.file_choice.redraw();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,9 +22,9 @@ use crate::utils::ImageInfo;
|
|||
use crate::utils::ImageType;
|
||||
use crate::utils::ImageProperties;
|
||||
use crate::{config_window::ConfigWindow, globals};
|
||||
use crate::dialog;
|
||||
use fltk::{
|
||||
button::Button,
|
||||
dialog,
|
||||
dialog::NativeFileChooser,
|
||||
draw as dr, enums,
|
||||
enums::Shortcut,
|
||||
|
|
@ -651,10 +651,11 @@ impl MainWindow {
|
|||
let mut file_choice = self.file_choice.clone();
|
||||
let sender = self.sender.clone();
|
||||
self.clone_btn.set_callback(move |_| {
|
||||
let ch = dialog::choice_default("Do you want to clone??", "Yes", "No", "");
|
||||
let ch = dialog::choice_default("Do you want to clone??", "Yes", "No");
|
||||
if ch == 0 {
|
||||
sender.send(DrawMessage::Clone).unwrap();
|
||||
sender.send(DrawMessage::Open).unwrap();
|
||||
sender.send(DrawMessage::CheckImage).unwrap();
|
||||
image.redraw();
|
||||
file_choice.redraw();
|
||||
}
|
||||
|
|
@ -665,10 +666,11 @@ impl MainWindow {
|
|||
let mut file_choice = self.file_choice.clone();
|
||||
let sender = self.sender.clone();
|
||||
self.delete_btn.set_callback(move |_| {
|
||||
let ch = dialog::choice_default("Do you want to delete??", "Yes", "No", "");
|
||||
let ch = dialog::choice_default("Do you want to delete??", "Yes", "No");
|
||||
if ch == 0 {
|
||||
sender.send(DrawMessage::Delete).unwrap();
|
||||
sender.send(DrawMessage::Open).unwrap();
|
||||
sender.send(DrawMessage::CheckImage).unwrap();
|
||||
image.redraw();
|
||||
file_choice.redraw();
|
||||
}
|
||||
|
|
@ -709,6 +711,7 @@ impl MainWindow {
|
|||
file_choice.set_value(file_choice.value() + 1);
|
||||
}
|
||||
sender.send(DrawMessage::Open).unwrap();
|
||||
sender.send(DrawMessage::CheckImage).unwrap();
|
||||
});
|
||||
|
||||
// Back Image Button
|
||||
|
|
@ -732,6 +735,7 @@ impl MainWindow {
|
|||
file_choice.set_value(file_choice.value() - 1);
|
||||
}
|
||||
sender.send(DrawMessage::Open).unwrap();
|
||||
sender.send(DrawMessage::CheckImage).unwrap();
|
||||
});
|
||||
|
||||
// File Choice
|
||||
|
|
@ -748,6 +752,7 @@ impl MainWindow {
|
|||
}
|
||||
}
|
||||
sender.send(DrawMessage::Open).unwrap();
|
||||
sender.send(DrawMessage::CheckImage).unwrap();
|
||||
});
|
||||
|
||||
// Quote Input
|
||||
|
|
@ -1054,4 +1059,5 @@ fn load_dir(
|
|||
file_choice.add_choice(&text[1..]);
|
||||
file_choice.set_value(0);
|
||||
sender.send(DrawMessage::Open).unwrap();
|
||||
sender.send(DrawMessage::CheckImage).unwrap();
|
||||
}
|
||||
|
|
|
|||
16
src/utils.rs
16
src/utils.rs
|
|
@ -118,12 +118,6 @@ impl ImageContainer {
|
|||
let img = load_image(&image_info);
|
||||
let (width, height): (f64, f64) = Coord::from(img.dimensions()).into();
|
||||
|
||||
let (crop_width, _) = croped_ratio(width, height);
|
||||
println!("{} {}", crop_width, globals::CONFIG.read().unwrap().minimum_width_limit);
|
||||
if crop_width < globals::CONFIG.read().unwrap().minimum_width_limit {
|
||||
show_alert("Image width is below limit");
|
||||
}
|
||||
|
||||
let config = globals::CONFIG.read().unwrap();
|
||||
let mut prop = properties.write().unwrap();
|
||||
prop.image_info = Some(image_info.to_owned());
|
||||
|
|
@ -696,6 +690,16 @@ pub(crate) fn set_color_btn_rgba(rgba: [u8; 4], btn: &mut Button) {
|
|||
btn.set_color(enums::Color::from_rgb(r, g, b));
|
||||
}
|
||||
|
||||
/// Check if image is too small
|
||||
pub(crate) fn is_too_small(width: f64, height: f64) -> bool {
|
||||
let (crop_width, _) = croped_ratio(width, height);
|
||||
if crop_width < globals::CONFIG.read().unwrap().minimum_width_limit {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// Get required size to crop image as per image ratio
|
||||
pub(crate) fn croped_ratio(width: f64, height: f64) -> (f64, f64) {
|
||||
if width > width_from_height(height) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue