2024-03-17 20:34:12 +03:00
|
|
|
use gtk4 as gtk;
|
2024-07-29 00:17:52 +03:00
|
|
|
use std::{fmt::Debug, num::ParseFloatError, str::FromStr, sync::Arc, 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::*},
|
2024-07-27 21:20:21 +03:00
|
|
|
view::{
|
|
|
|
components::{info_bar::InfoBar, input::Input},
|
|
|
|
properties::*,
|
|
|
|
},
|
2024-07-29 00:17:52 +03:00
|
|
|
view_utils::signal_reduce_input_utils::{get_error_message, parse_fields},
|
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-27 21:20:21 +03:00
|
|
|
pub fn signal_reducing_page(wrapper: &Box) {
|
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
|
|
|
|
|
|
|
EventHandler::new(calculate_button.clone(), move |_| {
|
2024-07-29 00:17:52 +03:00
|
|
|
let values: Option<[f64; 6]> = parse_fields(all_inputs.clone());
|
2024-07-27 22:28:35 +03:00
|
|
|
|
2024-07-29 00:17:52 +03:00
|
|
|
println!("values: {:?}", 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
|
|
|
}
|