refactor: move parse field algorithm to a separate file

This commit is contained in:
doryan 2024-07-29 01:17:52 +04:00
parent 0d676820c6
commit 18e857b40c

View File

@ -1,5 +1,5 @@
use gtk4 as gtk;
use std::{str::FromStr, sync::Arc, time::Duration};
use std::{fmt::Debug, num::ParseFloatError, str::FromStr, sync::Arc, time::Duration};
use crate::{
event_handlers::button_event_handlers::BtnEventHandler,
@ -8,6 +8,7 @@ use crate::{
components::{info_bar::InfoBar, input::Input},
properties::*,
},
view_utils::signal_reduce_input_utils::{get_error_message, parse_fields},
};
use gtk::{
prelude::{BoxExt, GridExt, TextBufferExt, TextViewExt},
@ -66,39 +67,10 @@ pub fn signal_reducing_page(wrapper: &Box) {
let calculate_button = Button::builder().label("Расчитать").build();
let info_bar: Arc<InfoBar> = Arc::new(InfoBar::get_instance());
EventHandler::new(calculate_button.clone(), move |_| {
let mut values: [f64; 6] = [0f64; 6];
let values: Option<[f64; 6]> = parse_fields(all_inputs.clone());
for (i, input) in all_inputs.iter().enumerate() {
let input_text_buffer: TextBuffer = input.clone().get_input().buffer();
let try_extract_value = f64::from_str(
input_text_buffer
.text(
&input_text_buffer.start_iter(),
&input_text_buffer.end_iter(),
false,
)
.as_str()
.trim(),
);
if let Ok(value) = try_extract_value {
values[i] = value;
} else {
info_bar.set_text_label(Some("Вы ввели некорректное значение поля."));
info_bar.set_reveal_child(true);
let info_bar_reference = info_bar.clone();
gio::spawn_blocking(move || {
std::thread::sleep(Duration::from_secs(5));
info_bar_reference.set_reveal_child(false);
});
break;
}
}
println!("values: {:?}", values);
})
.on_click();