2024-07-19 22:16:11 +03:00
|
|
|
use glib::property::PropertyGet;
|
2024-03-17 20:34:12 +03:00
|
|
|
use gtk4 as gtk;
|
2024-07-19 22:16:11 +03:00
|
|
|
use gtk4::prelude::WidgetExt;
|
|
|
|
use std::{str::FromStr, time::Duration};
|
2024-03-17 20:34:12 +03:00
|
|
|
|
2024-04-14 19:13:15 +03:00
|
|
|
use crate::{
|
2024-07-19 22:16:11 +03:00
|
|
|
event_handlers::button_event_handlers::BtnEventHandler,
|
|
|
|
model::{builder_traits::Product, models::*},
|
|
|
|
view::{components::input::Input, properties::*},
|
2024-03-17 20:34:12 +03:00
|
|
|
};
|
2024-04-19 11:03:16 +03:00
|
|
|
use gtk::{
|
2024-07-19 22:16:11 +03:00
|
|
|
prelude::{BoxExt, GridExt, TextBufferExt, TextViewExt},
|
2024-04-19 11:03:16 +03:00
|
|
|
Align, WrapMode, *,
|
|
|
|
};
|
2024-03-17 20:34:12 +03:00
|
|
|
|
2024-07-19 22:16:11 +03:00
|
|
|
pub fn signal_reducing_page(wrapper: &Box, info_bar: Revealer) {
|
2024-04-14 19:13:15 +03:00
|
|
|
let (input_height, monospace, input_alignment, input_wrapping): (i32, bool, Align, WrapMode) =
|
|
|
|
(24, true, Align::Fill, WrapMode::Word);
|
2024-03-17 20:34:12 +03:00
|
|
|
|
2024-07-19 22:16:11 +03:00
|
|
|
let input_block: Grid = Grid::new();
|
|
|
|
|
|
|
|
input_block.set_column_homogeneous(true);
|
|
|
|
input_block.set_row_homogeneous(true);
|
|
|
|
|
2024-04-14 19:13:15 +03:00
|
|
|
let input_label_alignment = Alignment {
|
|
|
|
horizontal: Align::Start,
|
|
|
|
vertical: Align::Fill,
|
|
|
|
};
|
2024-03-17 20:34:12 +03:00
|
|
|
|
2024-07-19 22:16:11 +03:00
|
|
|
let input_labels: [&str; 6] = [
|
|
|
|
"l, м:",
|
|
|
|
"Rм, Ом:",
|
|
|
|
"Cм, пФ:",
|
|
|
|
"Vи, мВ",
|
|
|
|
"Rи, Ом:",
|
|
|
|
"f, мГц:",
|
2024-04-19 00:30:51 +03:00
|
|
|
];
|
|
|
|
|
2024-07-19 22:16:11 +03:00
|
|
|
let all_inputs: Vec<Input> = input_labels
|
|
|
|
.iter()
|
|
|
|
.map(move |label| {
|
|
|
|
Input::builder()
|
|
|
|
.set_label(label)
|
|
|
|
.set_margins(MarginData::EqualsMargin(5))
|
|
|
|
.set_align(input_label_alignment)
|
|
|
|
.build(monospace, input_wrapping, input_height)
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
let mut row_position = 0i32;
|
|
|
|
|
|
|
|
for (id, elem) in all_inputs.iter().enumerate() {
|
|
|
|
if id % 3 == 0 {
|
|
|
|
row_position += 1;
|
2024-04-19 11:03:16 +03:00
|
|
|
}
|
|
|
|
|
2024-07-19 22:16:11 +03:00
|
|
|
input_block.attach(
|
|
|
|
&elem.clone().get(),
|
|
|
|
(id as i32) - (3 * row_position),
|
|
|
|
row_position,
|
|
|
|
1,
|
|
|
|
1,
|
|
|
|
);
|
2024-04-19 11:03:16 +03:00
|
|
|
}
|
|
|
|
|
2024-07-19 22:16:11 +03:00
|
|
|
let calculate_button = Button::builder().label("Расчитать").build();
|
2024-04-18 11:23:13 +03:00
|
|
|
|
2024-07-19 22:16:11 +03:00
|
|
|
// TODO: Make asynchronious auto-hide info bar.
|
|
|
|
let test = info_bar.clone();
|
2024-04-19 11:03:16 +03:00
|
|
|
|
2024-07-19 22:16:11 +03:00
|
|
|
// let (tx, rx) = std::sync::mpsc::channel::<bool>();
|
2024-04-19 00:30:51 +03:00
|
|
|
|
2024-04-18 11:23:13 +03:00
|
|
|
EventHandler::new(calculate_button.clone(), move |_| {
|
2024-07-19 22:16:11 +03:00
|
|
|
let mut values: [f64; 6] = [0f64; 6];
|
|
|
|
|
|
|
|
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 {
|
|
|
|
test.set_reveal_child(true);
|
|
|
|
|
|
|
|
// TODO: Make asynchronious auto-hide info bar.
|
|
|
|
// let transmitter = tx.clone();
|
|
|
|
//
|
|
|
|
// gio::spawn_blocking(move || {
|
|
|
|
// std::thread::sleep(Duration::from_secs(5));
|
|
|
|
// transmitter.send(false).unwrap();
|
|
|
|
// });
|
|
|
|
//
|
|
|
|
// test.set_reveal_child(rx.recv().unwrap());
|
|
|
|
|
|
|
|
println!("Вы ввели некорректное значение поля.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
println!("{:?}", values);
|
2024-04-18 11:23:13 +03:00
|
|
|
})
|
|
|
|
.on_click();
|
|
|
|
|
2024-07-19 22:16:11 +03:00
|
|
|
wrapper.append(&input_block);
|
|
|
|
wrapper.append(&calculate_button);
|
2024-04-14 19:13:15 +03:00
|
|
|
}
|